fix(browser): always use off-the-record profile

This commit is contained in:
Oleg Shparber 2020-05-20 01:03:20 -04:00
parent 794e2373b7
commit 384d94ac66
4 changed files with 19 additions and 10 deletions

View File

@ -40,11 +40,17 @@ constexpr char HighlightOnNavigateCssUrl[] = "qrc:///browser/assets/css/highligh
using namespace Zeal; using namespace Zeal;
using namespace Zeal::Browser; using namespace Zeal::Browser;
QWebEngineProfile *Settings::m_webProfile = nullptr;
Settings::Settings(Core::Settings *appSettings, QObject *parent) Settings::Settings(Core::Settings *appSettings, QObject *parent)
: QObject(parent) : QObject(parent)
, m_appSettings(appSettings) , m_appSettings(appSettings)
, m_webProfile(QWebEngineProfile::defaultProfile())
{ {
Q_ASSERT(!m_webProfile);
// Create a new off-the-record profile.
m_webProfile = new QWebEngineProfile(this);
// Setup URL interceptor. // Setup URL interceptor.
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
m_webProfile->setUrlRequestInterceptor(new UrlRequestInterceptor(this)); m_webProfile->setUrlRequestInterceptor(new UrlRequestInterceptor(this));
@ -52,9 +58,6 @@ Settings::Settings(Core::Settings *appSettings, QObject *parent)
m_webProfile->setRequestInterceptor(new UrlRequestInterceptor(this)); m_webProfile->setRequestInterceptor(new UrlRequestInterceptor(this));
#endif #endif
// Disable on-disk cache.
m_webProfile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
// Listen to settings changes. // Listen to settings changes.
connect(m_appSettings, &Core::Settings::updated, this, &Settings::applySettings); connect(m_appSettings, &Core::Settings::updated, this, &Settings::applySettings);
applySettings(); applySettings();
@ -82,6 +85,12 @@ void Settings::applySettings()
} }
} }
QWebEngineProfile *Settings::defaultProfile()
{
Q_ASSERT(m_webProfile);
return m_webProfile;
}
void Settings::setCustomStyleSheet(const QString &name, const QString &cssUrl) void Settings::setCustomStyleSheet(const QString &name, const QString &cssUrl)
{ {
QString cssInjectCode = QLatin1String("(function() {" QString cssInjectCode = QLatin1String("(function() {"

View File

@ -42,6 +42,8 @@ class Settings final : public QObject
public: public:
explicit Settings(Core::Settings *appSettings, QObject *parent = nullptr); explicit Settings(Core::Settings *appSettings, QObject *parent = nullptr);
static QWebEngineProfile *defaultProfile();
private slots: private slots:
void applySettings(); void applySettings();
@ -49,7 +51,7 @@ private:
void setCustomStyleSheet(const QString &name, const QString &cssUrl); void setCustomStyleSheet(const QString &name, const QString &cssUrl);
Core::Settings *m_appSettings = nullptr; Core::Settings *m_appSettings = nullptr;
QWebEngineProfile *m_webProfile = nullptr; static QWebEngineProfile *m_webProfile;
}; };
} // namespace Browser } // namespace Browser

View File

@ -23,6 +23,8 @@
#include "webpage.h" #include "webpage.h"
#include "settings.h"
#include <core/application.h> #include <core/application.h>
#include <core/networkaccessmanager.h> #include <core/networkaccessmanager.h>
#include <core/settings.h> #include <core/settings.h>
@ -36,7 +38,7 @@
using namespace Zeal::Browser; using namespace Zeal::Browser;
WebPage::WebPage(QObject *parent) WebPage::WebPage(QObject *parent)
: QWebEnginePage(parent) : QWebEnginePage(Settings::defaultProfile(), parent)
{ {
} }

View File

@ -52,10 +52,6 @@ Settings::Settings(QObject *parent)
{ {
qRegisterMetaTypeStreamOperators<ExternalLinkPolicy>("ExternalLinkPolicy"); qRegisterMetaTypeStreamOperators<ExternalLinkPolicy>("ExternalLinkPolicy");
// Enable local storage due to https://github.com/zealdocs/zeal/issues/872.
QWebEngineSettings *webSettings = QWebEngineSettings::globalSettings();
webSettings->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
load(); load();
} }