aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/browser.cpp29
-rw-r--r--src/webengine/webengineprofile.cpp176
-rw-r--r--src/webengine/webengineprofile.h2
-rw-r--r--src/webengine/webpage.cpp10
4 files changed, 127 insertions, 90 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 1d09951..d7834f4 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -110,30 +110,13 @@ std::shared_ptr<WebEngineProfile> Browser::profile(const QString storageName)
// profile with name storageName has not been loaded
Q_ASSERT(m_config);
- if(storageName.isEmpty()) {
- // construct off-the-record profile
- std::shared_ptr<WebEngineProfile> otr = std::make_shared<WebEngineProfile>(nullptr);
- otr->setRequestInterceptor(m_urlRequestInterceptor.get());
- connect(otr.get(), &WebEngineProfile::downloadRequested, m_downloadManager.get(), &DownloadsWidget::addDownload);
- m_profiles.insert("", otr);
-
- return otr;
- } else {
- // regular profile
- const QString &path = QString::fromStdString(m_config->value<std::string>("profile.path").value());
-
- // Build a profile list from the folders in the profile.path
- QDir profileDir(path);
-
- // set profile parents to nullptr, otherwise both Browser and std::shared_ptr try to free them
- std::shared_ptr<WebEngineProfile> profile = std::make_shared<WebEngineProfile>(storageName, profileDir.absoluteFilePath(storageName), nullptr);
- profile->setRequestInterceptor(m_urlRequestInterceptor.get());
- connect(profile.get(), &WebEngineProfile::downloadRequested, m_downloadManager.get(), &DownloadsWidget::addDownload);
- m_profiles.insert(storageName, profile);
-
- return profile;
- }
+ const QString &path = QString::fromStdString(m_config->value<std::string>("profile.path").value());
+ std::shared_ptr<WebEngineProfile> _profile = std::shared_ptr<WebEngineProfile>(createProfile(storageName, path, nullptr));
+ _profile->setRequestInterceptor(m_urlRequestInterceptor.get());
+ connect(_profile.get(), &WebEngineProfile::downloadRequested, m_downloadManager.get(), &DownloadsWidget::addDownload);
+ m_profiles.insert(storageName, _profile);
+ return _profile;
}
QStringList Browser::profiles() const
diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp
index 8bdf21c..2d98b3d 100644
--- a/src/webengine/webengineprofile.cpp
+++ b/src/webengine/webengineprofile.cpp
@@ -9,6 +9,7 @@
#include "webengineprofile.h"
#include <QSettings>
#include <QWebEngineSettings>
+#include <QFileInfo>
WebEngineProfile::WebEngineProfile(QObject *parent) :
QWebEngineProfile(parent)
@@ -33,73 +34,6 @@ WebEngineProfile::WebEngineProfile(const QString &name, const QString &path, QOb
setPersistentStoragePath(path + "/storage");
setCachePath(path + "/cache");
-
- // Read profile settings
- const QString profileIniPath = path + "/profile.ini";
- qDebug("Reading profile from [%s]", qUtf8Printable(profileIniPath));
- QSettings config(profileIniPath, QSettings::IniFormat);
-
- m_homepage = config.value("homepage", m_homepage).toUrl();
- m_newtab = config.value("newtab", m_newtab).toUrl();
-
- config.beginGroup("http");
- setHttpUserAgent(config.value("userAgent").toString());
- setHttpAcceptLanguage(config.value("accept-lang").toString());
- {
- QString cacheType = config.value("cacheType").toString();
- if(cacheType == "memory") {
- setHttpCacheType(MemoryHttpCache);
- } else if(cacheType == "disk") {
- setHttpCacheType(DiskHttpCache);
- } else if(cacheType == "disabled") {
- setHttpCacheType(NoCache);
- }
- }
- setHttpCacheMaximumSize(config.value("cacheSize").toInt());
- config.endGroup(); // http
-
- config.beginGroup("policy");
- {
- QString cookies = config.value("cookies").toString();
- if(cookies == "disabled") {
- setPersistentCookiesPolicy(NoPersistentCookies);
- } else if(cookies == "allow") {
- setPersistentCookiesPolicy(AllowPersistentCookies);
- } else if(cookies == "force") {
- setPersistentCookiesPolicy(ForcePersistentCookies);
- }
- }
- config.endGroup(); // policy
-
- config.beginGroup("attributes");
- settings()->setAttribute(QWebEngineSettings::AutoLoadImages, config.value("autoLoadImages", true).toBool());
- settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, config.value("javascriptEnabled", true).toBool());
- settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, config.value("javascriptCanOpenWindows", true).toBool());
- settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, config.value("javascriptCanAccessClipboard", false).toBool());
- settings()->setAttribute(QWebEngineSettings::LinksIncludedInFocusChain, config.value("linksIncludedInFocusChain", true).toBool());
- settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, config.value("localStorageEnabled", true).toBool());
- settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, config.value("localContentCanAccessRemoteUrls", false).toBool());
- settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, config.value("xssAuditingEnabled", false).toBool());
- settings()->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, config.value("spatialNavigationEnabled", false).toBool());
- settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, config.value("localContentCanAccessFileUrls", true).toBool());
- settings()->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, config.value("hyperlinkAuditingEnabled", false).toBool());
- settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, config.value("scrollAnimatorEnabled", false).toBool());
- settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, config.value("errorPageEnabled", true).toBool());
- settings()->setAttribute(QWebEngineSettings::PluginsEnabled, config.value("pluginsEnabled", false).toBool());
- settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, config.value("fullscreenSupportEnabled", false).toBool());
- settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, config.value("screenCaptureEnabled", false).toBool());
- settings()->setAttribute(QWebEngineSettings::WebGLEnabled, config.value("webglEnabled", true).toBool());
- settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, config.value("accelerated2dCanvasEnabled", true).toBool());
- settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, config.value("autoLoadIconsForPage", true).toBool());
- settings()->setAttribute(QWebEngineSettings::TouchIconsEnabled, config.value("touchIconsEnabled", false).toBool());
-#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
- settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, config.value("focusOnNavigationEnabled", true).toBool());
- settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, config.value("printElementBackgrounds", true).toBool());
- settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, config.value("allowRunningInsecureContent", false).toBool());
-#endif
- config.endGroup(); // attributes
-
-
}
WebEngineProfile::~WebEngineProfile()
@@ -203,3 +137,111 @@ void WebEngineProfile::saveProfile()
config.sync();
}
+
+WebEngineProfile *createProfile(const QString &name, const QString &path, QObject *parent)
+{
+ WebEngineProfile *profile;
+ if(name.isEmpty()) {
+ profile = new WebEngineProfile(parent);
+ } else {
+ profile = new WebEngineProfile(name, path, parent);
+ }
+
+ // Read profile settings
+ const QString profileIniPath = path + "/profile.ini";
+ if(QFileInfo::exists(profileIniPath)) {
+ qDebug("Reading profile from [%s]", qUtf8Printable(profileIniPath));
+ QSettings config(profileIniPath, QSettings::IniFormat);
+
+ profile->setHomepage(config.value("homepage", profile->homepage()).toUrl());
+ profile->setNewtab(config.value("newtab", profile->newtab()).toUrl());
+
+ config.beginGroup("http");
+ profile->setHttpUserAgent(config.value("userAgent").toString());
+ profile->setHttpAcceptLanguage(config.value("accept-lang").toString());
+ {
+ QString cacheType = config.value("cacheType").toString();
+ if(cacheType == "memory") {
+ profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
+ } else if(cacheType == "disk") {
+ profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
+ } else if(cacheType == "disabled") {
+ profile->setHttpCacheType(QWebEngineProfile::NoCache);
+ }
+ }
+ profile->setHttpCacheMaximumSize(config.value("cacheSize").toInt());
+ config.endGroup(); // http
+
+ config.beginGroup("policy");
+ {
+ QString cookies = config.value("cookies").toString();
+ if(cookies == "disabled") {
+ profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
+ } else if(cookies == "allow") {
+ profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
+ } else if(cookies == "force") {
+ profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
+ }
+ }
+ config.endGroup(); // policy
+
+ config.beginGroup("attributes");
+ QWebEngineSettings *s = profile->settings();
+ s->setAttribute(QWebEngineSettings::AutoLoadImages,
+ config.value("autoLoadImages", s->testAttribute(QWebEngineSettings::AutoLoadImages)).toBool());
+ s->setAttribute(QWebEngineSettings::JavascriptEnabled,
+ config.value("javascriptEnabled", s->testAttribute(QWebEngineSettings::JavascriptEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows,
+ config.value("javascriptCanOpenWindows", s->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows)).toBool());
+ s->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard,
+ config.value("javascriptCanAccessClipboard", s->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard)).toBool());
+ s->setAttribute(QWebEngineSettings::LinksIncludedInFocusChain,
+ config.value("linksIncludedInFocusChain", s->testAttribute(QWebEngineSettings::LinksIncludedInFocusChain)).toBool());
+ s->setAttribute(QWebEngineSettings::LocalStorageEnabled,
+ config.value("localStorageEnabled", s->testAttribute(QWebEngineSettings::LocalStorageEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls,
+ config.value("localContentCanAccessRemoteUrls", s->testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls)).toBool());
+ s->setAttribute(QWebEngineSettings::XSSAuditingEnabled,
+ config.value("xssAuditingEnabled", s->testAttribute(QWebEngineSettings::XSSAuditingEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::SpatialNavigationEnabled,
+ config.value("spatialNavigationEnabled", s->testAttribute(QWebEngineSettings::SpatialNavigationEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls,
+ config.value("localContentCanAccessFileUrls", s->testAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls)).toBool());
+ s->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled,
+ config.value("hyperlinkAuditingEnabled", s->testAttribute(QWebEngineSettings::HyperlinkAuditingEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled,
+ config.value("scrollAnimatorEnabled", s->testAttribute(QWebEngineSettings::ScrollAnimatorEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::ErrorPageEnabled,
+ config.value("errorPageEnabled", s->testAttribute(QWebEngineSettings::ErrorPageEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::PluginsEnabled,
+ config.value("pluginsEnabled", s->testAttribute(QWebEngineSettings::PluginsEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::FullScreenSupportEnabled,
+ config.value("fullscreenSupportEnabled", s->testAttribute(QWebEngineSettings::FullScreenSupportEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::ScreenCaptureEnabled,
+ config.value("screenCaptureEnabled", s->testAttribute(QWebEngineSettings::ScreenCaptureEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::WebGLEnabled,
+ config.value("webglEnabled", s->testAttribute(QWebEngineSettings::WebGLEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled,
+ config.value("accelerated2dCanvasEnabled", s->testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::AutoLoadIconsForPage,
+ config.value("autoLoadIconsForPage", s->testAttribute(QWebEngineSettings::AutoLoadIconsForPage)).toBool());
+ s->setAttribute(QWebEngineSettings::TouchIconsEnabled,
+ config.value("touchIconsEnabled", s->testAttribute(QWebEngineSettings::TouchIconsEnabled)).toBool());
+#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
+ s->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled,
+ config.value("focusOnNavigationEnabled", s->testAttribute(QWebEngineSettings::FocusOnNavigationEnabled)).toBool());
+ s->setAttribute(QWebEngineSettings::PrintElementBackgrounds,
+ config.value("printElementBackgrounds", s->testAttribute(QWebEngineSettings::PrintElementBackgrounds)).toBool());
+ s->setAttribute(QWebEngineSettings::AllowRunningInsecureContent,
+ config.value("allowRunningInsecureContent", s->testAttribute(QWebEngineSettings::AllowRunningInsecureContent)).toBool());
+#endif
+ config.endGroup(); // attributes
+ }
+#ifdef QT_DEBUG
+ else {
+ qDebug("No config for profile %s: %s", qUtf8Printable(name), qUtf8Printable(profileIniPath));
+ }
+#endif
+
+ return profile;
+}
diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h
index 54b2a56..63a97a4 100644
--- a/src/webengine/webengineprofile.h
+++ b/src/webengine/webengineprofile.h
@@ -41,4 +41,6 @@ private:
QUrl m_newtab = QUrl("about:blank");
};
+[[nodiscard]] WebEngineProfile *createProfile(const QString &name, const QString &path, QObject *parent);
+
#endif // WEBENGINEPROFILE_H
diff --git a/src/webengine/webpage.cpp b/src/webengine/webpage.cpp
index a39c942..96ae040 100644
--- a/src/webengine/webpage.cpp
+++ b/src/webengine/webpage.cpp
@@ -8,9 +8,19 @@
#include "webpage.h"
+#include <QWebEngineFullScreenRequest>
+
WebPage::WebPage(QWebEngineProfile *profile, QObject *parent) :
QWebEnginePage(profile, parent)
{
+ connect(this, &WebPage::fullScreenRequested, this, [](QWebEngineFullScreenRequest request) {
+ request.accept();
+ });
+#ifdef QT_DEBUG
+ connect(this, &WebPage::featurePermissionRequested, this, [](const QUrl &securityOrigin, QWebEnginePage::Feature feature) {
+ qDebug("Feature requested: %i", feature);
+ });
+#endif
}
bool WebPage::certificateError(const QWebEngineCertificateError &certificateError)