mirror of https://github.com/vitalif/phantomjs
Add --local-storage-quota and --local-storage-path options for issue 300.
Add sanity check for the configuration of --local-storage-quota and --local-storage-path. issue 300 - http://code.google.com/p/phantomjs/issues/detail?id=3001.6
parent
ca60a58596
commit
c85a26a229
|
@ -118,6 +118,14 @@ void Config::processArgs(const QStringList &args)
|
|||
setCookiesFile(arg.mid(15).trimmed());
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--local-storage-path=")) {
|
||||
setOfflineStoragePath(arg.mid(21).trimmed());
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--local-storage-quota=")) {
|
||||
setOfflineStorageDefaultQuota(arg.mid(arg.indexOf("=") + 1).trimmed().toInt());
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--output-encoding=")) {
|
||||
setOutputEncoding(arg.mid(18).trimmed());
|
||||
continue;
|
||||
|
@ -220,6 +228,27 @@ void Config::setCookiesFile(const QString &value)
|
|||
m_cookiesFile = value;
|
||||
}
|
||||
|
||||
QString Config::offlineStoragePath() const
|
||||
{
|
||||
return m_offlineStoragePath;
|
||||
}
|
||||
|
||||
void Config::setOfflineStoragePath(const QString &value)
|
||||
{
|
||||
QDir dir(value);
|
||||
m_offlineStoragePath = dir.absolutePath();
|
||||
}
|
||||
|
||||
int Config::offlineStorageDefaultQuota() const
|
||||
{
|
||||
return m_offlineStorageDefaultQuota;
|
||||
}
|
||||
|
||||
void Config::setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota)
|
||||
{
|
||||
m_offlineStorageDefaultQuota = offlineStorageDefaultQuota * 1024;
|
||||
}
|
||||
|
||||
bool Config::diskCacheEnabled() const
|
||||
{
|
||||
return m_diskCacheEnabled;
|
||||
|
@ -450,6 +479,8 @@ void Config::resetToDefaults()
|
|||
{
|
||||
m_autoLoadImages = true;
|
||||
m_cookiesFile = QString();
|
||||
m_offlineStoragePath = QString();
|
||||
m_offlineStorageDefaultQuota = -1;
|
||||
m_diskCacheEnabled = false;
|
||||
m_maxDiskCacheSize = -1;
|
||||
m_ignoreSslErrors = false;
|
||||
|
|
10
src/config.h
10
src/config.h
|
@ -49,6 +49,8 @@ class Config: QObject
|
|||
Q_PROPERTY(QString proxyAuth READ proxyAuth WRITE setProxyAuth)
|
||||
Q_PROPERTY(QString scriptEncoding READ scriptEncoding WRITE setScriptEncoding)
|
||||
Q_PROPERTY(bool webSecurityEnabled READ webSecurityEnabled WRITE setWebSecurityEnabled)
|
||||
Q_PROPERTY(QString offlineStoragePath READ offlineStoragePath WRITE setOfflineStoragePath)
|
||||
Q_PROPERTY(int offlineStorageDefaultQuota READ offlineStorageDefaultQuota WRITE setOfflineStorageDefaultQuota)
|
||||
|
||||
public:
|
||||
Config(QObject *parent = 0);
|
||||
|
@ -63,6 +65,12 @@ public:
|
|||
QString cookiesFile() const;
|
||||
void setCookiesFile(const QString &cookiesFile);
|
||||
|
||||
QString offlineStoragePath() const;
|
||||
void setOfflineStoragePath(const QString &value);
|
||||
|
||||
int offlineStorageDefaultQuota() const;
|
||||
void setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota);
|
||||
|
||||
bool diskCacheEnabled() const;
|
||||
void setDiskCacheEnabled(const bool value);
|
||||
|
||||
|
@ -132,6 +140,8 @@ private:
|
|||
|
||||
bool m_autoLoadImages;
|
||||
QString m_cookiesFile;
|
||||
QString m_offlineStoragePath;
|
||||
int m_offlineStorageDefaultQuota;
|
||||
bool m_diskCacheEnabled;
|
||||
int m_maxDiskCacheSize;
|
||||
bool m_ignoreSslErrors;
|
||||
|
|
|
@ -18,6 +18,8 @@ Options:
|
|||
--proxy-type=[http|socks5] Sets the proxy type, either "http" (default) or "socks5"
|
||||
--script-encoding Sets the encoding used for the starting script (default is 'utf8')
|
||||
--web-security=[yes|no] Enable web security (default is 'yes')
|
||||
--local-storage-path=/path/to/storage Sets the offline local storage location
|
||||
--local-storage-quota=size Sets the max size of the offline local storage (in KB)
|
||||
-v, --version Prints out PhantomJS version
|
||||
-h, --help Shows this message and quits
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
|
||||
#include "networkaccessmanager.h"
|
||||
#include "utils.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <gifwriter.h>
|
||||
|
||||
|
@ -136,7 +137,14 @@ WebPage::WebPage(QObject *parent, const Config *config, const QUrl &baseUrl)
|
|||
m_mainFrame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
|
||||
|
||||
m_webPage->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
|
||||
m_webPage->settings()->setOfflineStoragePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
||||
if (config->offlineStoragePath().isEmpty()) {
|
||||
m_webPage->settings()->setOfflineStoragePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
||||
} else {
|
||||
m_webPage->settings()->setOfflineStoragePath(config->offlineStoragePath());
|
||||
}
|
||||
if (config->offlineStorageDefaultQuota() > 0) {
|
||||
m_webPage->settings()->setOfflineStorageDefaultQuota(config->offlineStorageDefaultQuota());
|
||||
}
|
||||
|
||||
m_webPage->settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
|
||||
m_webPage->settings()->setOfflineWebApplicationCachePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
||||
|
@ -185,6 +193,16 @@ QString WebPage::libraryPath() const
|
|||
void WebPage::setLibraryPath(const QString &libraryPath)
|
||||
{
|
||||
m_libraryPath = libraryPath;
|
||||
}
|
||||
|
||||
QString WebPage::offlineStoragePath() const
|
||||
{
|
||||
return m_webPage->settings()->offlineStoragePath();
|
||||
}
|
||||
|
||||
int WebPage::offlineStorageQuota() const
|
||||
{
|
||||
return m_webPage->settings()->offlineStorageDefaultQuota();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -50,6 +50,8 @@ class WebPage: public REPLCompletable, public QWebFrame::PrintCallback
|
|||
Q_PROPERTY(QString content READ content WRITE setContent)
|
||||
Q_PROPERTY(QString plainText READ plainText)
|
||||
Q_PROPERTY(QString libraryPath READ libraryPath WRITE setLibraryPath)
|
||||
Q_PROPERTY(QString offlineStoragePath READ offlineStoragePath)
|
||||
Q_PROPERTY(int offlineStorageQuota READ offlineStorageQuota)
|
||||
Q_PROPERTY(QVariantMap viewportSize READ viewportSize WRITE setViewportSize)
|
||||
Q_PROPERTY(QVariantMap paperSize READ paperSize WRITE setPaperSize)
|
||||
Q_PROPERTY(QVariantMap clipRect READ clipRect WRITE setClipRect)
|
||||
|
@ -69,6 +71,10 @@ public:
|
|||
QString libraryPath() const;
|
||||
void setLibraryPath(const QString &dirPath);
|
||||
|
||||
QString offlineStoragePath() const;
|
||||
|
||||
int offlineStorageQuota() const;
|
||||
|
||||
void setViewportSize(const QVariantMap &size);
|
||||
QVariantMap viewportSize() const;
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@ describe("WebPage object", function() {
|
|||
expectHasPropertyString(page, 'plainText');
|
||||
|
||||
expectHasPropertyString(page, 'libraryPath');
|
||||
expectHasPropertyString(page, 'offlineStoragePath');
|
||||
expectHasProperty(page, 'offlineStorageQuota');
|
||||
|
||||
it("should have objectName as 'WebPage'", function() {
|
||||
expect(page.objectName).toEqual('WebPage');
|
||||
|
|
Loading…
Reference in New Issue