Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Fixes --local-storage-path and localStoragePath config option
Browse files Browse the repository at this point in the history
Issue: #11596
  • Loading branch information
allbin-tomas authored and ariya committed Jul 21, 2015
1 parent e4c0d9f commit 5c66f38
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
40 changes: 37 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ static const struct QCommandLineConfigEntry flags[] = {
{ QCommandLine::Option, '\0', "disk-cache", "Enables disk cache: 'true' or 'false' (default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ignore-ssl-errors", "Ignores SSL errors (expired/self-signed certificate errors): 'true' or 'false' (default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "load-images", "Loads all inlined images: 'true' (default) or 'false'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-storage-path", "Specifies the location for offline local storage", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-storage-quota", "Sets the maximum size of the offline local storage (in KB)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-url-access", "Allows use of 'file:///' URLs: 'true' (default) or 'false'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-storage-path", "Specifies the location for local storage", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-storage-quota", "Sets the maximum size of the local storage (in KB)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "offline-storage-path", "Specifies the location for offline storage", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "offline-storage-quota", "Sets the maximum size of the offline storage (in KB)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-to-remote-url-access", "Allows local content to access remote URL: 'true' or 'false' (default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "max-disk-cache-size", "Limits the size of the disk cache (in KB)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "output-encoding", "Sets the encoding for the terminal output, default is 'utf8'", QCommandLine::Optional },
Expand Down Expand Up @@ -223,6 +225,28 @@ void Config::setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota)
m_offlineStorageDefaultQuota = offlineStorageDefaultQuota * 1024;
}


QString Config::localStoragePath() const
{
return m_localStoragePath;
}

void Config::setLocalStoragePath(const QString &value)
{
QDir dir(value);
m_localStoragePath = dir.absolutePath();
}

int Config::localStorageDefaultQuota() const
{
return m_localStorageDefaultQuota;
}

void Config::setLocalStorageDefaultQuota(int localStorageDefaultQuota)
{
m_localStorageDefaultQuota = localStorageDefaultQuota * 1024;
}

bool Config::diskCacheEnabled() const
{
return m_diskCacheEnabled;
Expand Down Expand Up @@ -546,6 +570,8 @@ void Config::resetToDefaults()
m_cookiesFile = QString();
m_offlineStoragePath = QString();
m_offlineStorageDefaultQuota = -1;
m_localStoragePath = QString();
m_localStorageDefaultQuota = -1;
m_diskCacheEnabled = false;
m_maxDiskCacheSize = -1;
m_ignoreSslErrors = false;
Expand Down Expand Up @@ -698,10 +724,18 @@ void Config::handleOption(const QString& option, const QVariant& value)
}

if (option == "local-storage-path") {
setOfflineStoragePath(value.toString());
setLocalStoragePath(value.toString());
}

if (option == "local-storage-quota") {
setLocalStorageDefaultQuota(value.toInt());
}

if (option == "offline-storage-path") {
setOfflineStoragePath(value.toString());
}

if (option == "offline-storage-quota") {
setOfflineStorageDefaultQuota(value.toInt());
}

Expand Down
10 changes: 10 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Config: public QObject
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(QString localStoragePath READ localStoragePath WRITE setLocalStoragePath)
Q_PROPERTY(int localStorageDefaultQuota READ localStorageDefaultQuota WRITE setLocalStorageDefaultQuota)
Q_PROPERTY(int offlineStorageDefaultQuota READ offlineStorageDefaultQuota WRITE setOfflineStorageDefaultQuota)
Q_PROPERTY(bool printDebugMessages READ printDebugMessages WRITE setPrintDebugMessages)
Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows)
Expand Down Expand Up @@ -90,6 +92,12 @@ class Config: public QObject
int offlineStorageDefaultQuota() const;
void setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota);

QString localStoragePath() const;
void setLocalStoragePath(const QString &value);

int localStorageDefaultQuota() const;
void setLocalStorageDefaultQuota(int localStorageDefaultQuota);

bool diskCacheEnabled() const;
void setDiskCacheEnabled(const bool value);

Expand Down Expand Up @@ -214,6 +222,8 @@ public slots:
QString m_cookiesFile;
QString m_offlineStoragePath;
int m_offlineStorageDefaultQuota;
QString m_localStoragePath;
int m_localStorageDefaultQuota;
bool m_diskCacheEnabled;
int m_maxDiskCacheSize;
bool m_ignoreSslErrors;
Expand Down
7 changes: 6 additions & 1 deletion src/webpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,12 @@ WebPage::WebPage(QObject* parent, const QUrl& baseUrl)
m_customWebPage->settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, true);

m_customWebPage->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
m_customWebPage->settings()->setLocalStoragePath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));

if (phantomCfg->localStoragePath().isEmpty()) {
m_customWebPage->settings()->setLocalStoragePath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
} else {
m_customWebPage->settings()->setLocalStoragePath(phantomCfg->localStoragePath());
}

// Custom network access manager to allow traffic monitoring.
m_networkAccessManager = new NetworkAccessManager(this, phantomCfg);
Expand Down

0 comments on commit 5c66f38

Please sign in to comment.