Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/networkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,29 @@
#include <QNetworkRequest>
#include <QList>
#include <QNetworkReply>
#include <QDesktopServices>
#include <QNetworkDiskCache>

#include "networkaccessmanager.h"

// public:
NetworkAccessManager::NetworkAccessManager(QObject *parent)
: QNetworkAccessManager(parent)
NetworkAccessManager::NetworkAccessManager(QObject *parent, bool diskCacheEnabled)
: QNetworkAccessManager(parent), m_networkDiskCache(0)
{
if (diskCacheEnabled) {
m_networkDiskCache = new QNetworkDiskCache();
m_networkDiskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
setCache(m_networkDiskCache);
}
connect(this, SIGNAL(finished(QNetworkReply*)), SLOT(handleFinished(QNetworkReply*)));
}

NetworkAccessManager::~NetworkAccessManager()
{
if (m_networkDiskCache)
delete m_networkDiskCache;
}

// protected:
QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData)
{
Expand Down
6 changes: 5 additions & 1 deletion src/networkaccessmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@

#include <QNetworkAccessManager>

class QNetworkDiskCache;

class NetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT
QNetworkDiskCache* m_networkDiskCache;
public:
NetworkAccessManager(QObject *parent = 0);
NetworkAccessManager(QObject *parent = 0, bool diskCacheEnabled = false);
virtual ~NetworkAccessManager();

protected:
QNetworkReply *createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0);
Expand Down
11 changes: 10 additions & 1 deletion src/phantom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Phantom::Phantom(QObject *parent)

bool autoLoadImages = true;
bool pluginsEnabled = false;
bool diskCacheEnabled = false;

// second argument: script name
QStringList args = QApplication::arguments();
Expand Down Expand Up @@ -98,6 +99,14 @@ Phantom::Phantom(QObject *parent)
pluginsEnabled = false;
continue;
}
if (arg == "--disk-cache=yes") {
diskCacheEnabled = true;
continue;
}
if (arg == "--disk-cache=no") {
diskCacheEnabled = false;
continue;
}
if (arg.startsWith("--proxy=")) {
m_proxyHost = arg.mid(8).trimmed();
if (m_proxyHost.lastIndexOf(':') > 0) {
Expand Down Expand Up @@ -139,7 +148,7 @@ Phantom::Phantom(QObject *parent)
}

// Provide WebPage with a non-standard Network Access Manager
m_netAccessMan = new NetworkAccessManager(this);
m_netAccessMan = new NetworkAccessManager(this, diskCacheEnabled);
m_page.setNetworkAccessManager(m_netAccessMan);

connect(m_page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), SLOT(inject()));
Expand Down
2 changes: 1 addition & 1 deletion src/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Options:
--proxy=address:port Set the network proxy.
--upload-file fileId=/file/path Upload a file by creating a '<input type="file" id="foo" />'
and calling phantom.setFormInputFile(document.getElementById('foo'), 'fileId').

--disk-cache=[yes|no] Enable disk cache (at desktop services cache storage location, default is 'no').