From c08a584333eeec67115bf945073214c10a53e4cd Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 22 May 2015 21:46:55 +0200 Subject: [PATCH] Set correct paths for cache and persistent data Also disable persistent data storage when in private mode --- src/lib/app/mainapplication.cpp | 33 ++++++++++++----------------- src/lib/app/mainapplication.h | 5 +---- src/lib/other/clearprivatedata.cpp | 3 +-- src/lib/preferences/preferences.cpp | 6 +++--- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index db7d83662..10691e465 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2015 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,7 +49,6 @@ #include "html5permissions/html5permissionsmanager.h" #include -#include #include #include #include @@ -61,7 +60,7 @@ #include #include #include - +#include #include #if defined(Q_OS_WIN) && !defined(Q_OS_OS2) @@ -80,7 +79,6 @@ MainApplication::MainApplication(int &argc, char** argv) , m_autoFill(0) , m_cookieJar(0) , m_plugins(0) - , m_networkCache(0) , m_browsingLibrary(0) , m_rssManager(0) , m_networkManager(0) @@ -507,21 +505,6 @@ PluginProxy* MainApplication::plugins() return m_plugins; } -QNetworkDiskCache* MainApplication::networkCache() -{ - if (!m_networkCache) { - Settings settings; - const QString defaultBasePath = QString("%1/networkcache/").arg(DataPaths::currentProfilePath()); - const QString basePath = settings.value("Web-Browser-Settings/CachePath", defaultBasePath).toString(); - const QString cachePath = QString("%1/QtWebEngine/").arg(basePath); - - m_networkCache = new QNetworkDiskCache(this); - m_networkCache->setCacheDirectory(cachePath); - } - - return m_networkCache; -} - BrowsingLibrary* MainApplication::browsingLibrary() { if (!m_browsingLibrary) { @@ -893,11 +876,23 @@ void MainApplication::loadSettings() webSettings->setFontSize(QWebEngineSettings::MinimumLogicalFontSize, settings.value("MinimumLogicalFontSize", 5).toInt()); settings.endGroup(); + QWebEngineProfile* profile = QWebEngineProfile::defaultProfile(); + profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); + profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies); + profile->setPersistentStoragePath(DataPaths::currentProfilePath()); + + const QString defaultBasePath = QSL("%1/networkcache/").arg(DataPaths::currentProfilePath()); + const QString basePath = settings.value("Web-Browser-Settings/CachePath", defaultBasePath).toString(); + const QString cachePath = QString("%1/QtWebEngine/").arg(basePath); + profile->setCachePath(cachePath); + if (isPrivate()) { webSettings->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); #if QTWEBENGINE_DISABLED webSettings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); #endif + profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache); + profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); history()->setSaving(false); } diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index 9ace42b86..ba3fb11bb 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2015 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,7 +27,6 @@ #include "qzcommon.h" class QMenu; -class QNetworkDiskCache; class QNetworkAccessManager; class History; @@ -88,7 +87,6 @@ public: AutoFill* autoFill(); CookieJar* cookieJar(); PluginProxy* plugins(); - QNetworkDiskCache* networkCache(); BrowsingLibrary* browsingLibrary(); RSSManager* rssManager(); @@ -153,7 +151,6 @@ private: AutoFill* m_autoFill; CookieJar* m_cookieJar; PluginProxy* m_plugins; - QNetworkDiskCache* m_networkCache; BrowsingLibrary* m_browsingLibrary; RSSManager* m_rssManager; diff --git a/src/lib/other/clearprivatedata.cpp b/src/lib/other/clearprivatedata.cpp index 48efe60ca..086a46c61 100644 --- a/src/lib/other/clearprivatedata.cpp +++ b/src/lib/other/clearprivatedata.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2015 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -82,7 +82,6 @@ void ClearPrivateData::clearWebDatabases() void ClearPrivateData::clearCache() { - mApp->networkCache()->clear(); #if QTWEBENGINE_DISABLED QWebEngineSettings::globalSettings()->clearMemoryCaches(); #endif diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index b87805811..4224fc2bb 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2015 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include static QString createLanguageItem(const QString &lang) @@ -306,7 +306,7 @@ Preferences::Preferences(BrowserWindow* window, QWidget* parent) ui->allowCache->setChecked(settings.value("AllowLocalCache", true).toBool()); ui->cacheMB->setValue(settings.value("LocalCacheSize", 50).toInt()); ui->MBlabel->setText(settings.value("LocalCacheSize", 50).toString() + " MB"); - ui->cachePath->setText(settings.value("CachePath", mApp->networkCache()->cacheDirectory()).toString()); + ui->cachePath->setText(settings.value("CachePath", QWebEngineProfile::defaultProfile()->cachePath()).toString()); connect(ui->allowCache, SIGNAL(clicked(bool)), this, SLOT(allowCacheChanged(bool))); connect(ui->cacheMB, SIGNAL(valueChanged(int)), this, SLOT(cacheValueChanged(int))); connect(ui->changeCachePath, SIGNAL(clicked()), this, SLOT(changeCachePathClicked()));