mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-22 21:53:03 +03:00
fix(browser): always use off-the-record profile
This commit is contained in:
parent
794e2373b7
commit
384d94ac66
@ -40,11 +40,17 @@ constexpr char HighlightOnNavigateCssUrl[] = "qrc:///browser/assets/css/highligh
|
||||
using namespace Zeal;
|
||||
using namespace Zeal::Browser;
|
||||
|
||||
QWebEngineProfile *Settings::m_webProfile = nullptr;
|
||||
|
||||
Settings::Settings(Core::Settings *appSettings, QObject *parent)
|
||||
: QObject(parent)
|
||||
, 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.
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
|
||||
m_webProfile->setUrlRequestInterceptor(new UrlRequestInterceptor(this));
|
||||
@ -52,9 +58,6 @@ Settings::Settings(Core::Settings *appSettings, QObject *parent)
|
||||
m_webProfile->setRequestInterceptor(new UrlRequestInterceptor(this));
|
||||
#endif
|
||||
|
||||
// Disable on-disk cache.
|
||||
m_webProfile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
|
||||
|
||||
// Listen to settings changes.
|
||||
connect(m_appSettings, &Core::Settings::updated, this, &Settings::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)
|
||||
{
|
||||
QString cssInjectCode = QLatin1String("(function() {"
|
||||
|
@ -42,6 +42,8 @@ class Settings final : public QObject
|
||||
public:
|
||||
explicit Settings(Core::Settings *appSettings, QObject *parent = nullptr);
|
||||
|
||||
static QWebEngineProfile *defaultProfile();
|
||||
|
||||
private slots:
|
||||
void applySettings();
|
||||
|
||||
@ -49,7 +51,7 @@ private:
|
||||
void setCustomStyleSheet(const QString &name, const QString &cssUrl);
|
||||
|
||||
Core::Settings *m_appSettings = nullptr;
|
||||
QWebEngineProfile *m_webProfile = nullptr;
|
||||
static QWebEngineProfile *m_webProfile;
|
||||
};
|
||||
|
||||
} // namespace Browser
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include "webpage.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include <core/application.h>
|
||||
#include <core/networkaccessmanager.h>
|
||||
#include <core/settings.h>
|
||||
@ -36,7 +38,7 @@
|
||||
using namespace Zeal::Browser;
|
||||
|
||||
WebPage::WebPage(QObject *parent)
|
||||
: QWebEnginePage(parent)
|
||||
: QWebEnginePage(Settings::defaultProfile(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -52,10 +52,6 @@ Settings::Settings(QObject *parent)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user