aboutsummaryrefslogtreecommitdiff
path: root/src/webengine
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-04-16 17:07:36 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-04-16 17:07:36 +0200
commitd796821f8304306dbe088701724243b39e8eb358 (patch)
tree836c85aa421db5c495e2b36f6a02cea924b6d919 /src/webengine
parentBranch of Qt5.11 features (diff)
downloadsmolbote-d796821f8304306dbe088701724243b39e8eb358.tar.xz
Multiple subwindows interface
Subwindows are similar to tab groups. - Rewrote Browser and MainWindow, so they should be somewhat cleaner now - Moved AboutDialog to lib/about What's broken: - loading bar - search box - address bar bookmark suggestions - plugins
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/urlinterceptor.h2
-rw-r--r--src/webengine/webengineprofile.cpp214
-rw-r--r--src/webengine/webengineprofile.h39
-rw-r--r--src/webengine/webprofile.cpp216
-rw-r--r--src/webengine/webprofile.h53
-rw-r--r--src/webengine/webview.cpp47
-rw-r--r--src/webengine/webview.h13
-rw-r--r--src/webengine/widgets/pagetoolsmenu.cpp2
8 files changed, 302 insertions, 284 deletions
diff --git a/src/webengine/urlinterceptor.h b/src/webengine/urlinterceptor.h
index af15f99..951eb52 100644
--- a/src/webengine/urlinterceptor.h
+++ b/src/webengine/urlinterceptor.h
@@ -9,8 +9,8 @@
#ifndef URLREQUESTINTERCEPTOR_H
#define URLREQUESTINTERCEPTOR_H
-#include <QWebEngineUrlRequestInterceptor>
#include <QMutex>
+#include <QWebEngineUrlRequestInterceptor>
class UrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
{
diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp
index 55af9f2..e69de29 100644
--- a/src/webengine/webengineprofile.cpp
+++ b/src/webengine/webengineprofile.cpp
@@ -1,214 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "webengineprofile.h"
-#include <QFileInfo>
-#include <QSettings>
-#include <QWebEngineCookieStore>
-#include <QWebEngineSettings>
-
-WebEngineProfile::WebEngineProfile(QObject *parent)
- : QWebEngineProfile(parent)
-{
- m_name = tr("Off-the-record");
-
-#ifdef QT_DEBUG
- qDebug("Creating off-the-record profile");
-#endif
-
- // Off-the-record profiles have no persistent path
-}
-
-WebEngineProfile::WebEngineProfile(const QString &name, QObject *parent)
- : QWebEngineProfile(name, parent)
-{
- m_name = name;
-
-#ifdef QT_DEBUG
- qDebug("Creating profile %s", qUtf8Printable(m_name));
-#endif
-}
-
-WebEngineProfile::~WebEngineProfile() = default;
-
-QString WebEngineProfile::name() const
-{
- return m_name;
-}
-
-QUrl WebEngineProfile::homepage() const
-{
- return m_homepage;
-}
-
-QUrl WebEngineProfile::newtab() const
-{
- return m_newtab;
-}
-
-void WebEngineProfile::loadProfile(QHash<QString, QString> conf, const QString &path)
-{
- m_configPath = path;
-
-#ifdef QT_DEBUG
- qDebug("Reading config for profile '%s': %s", qUtf8Printable(m_name), qUtf8Printable(m_configPath));
-#endif
- QSettings config(m_configPath, QSettings::IniFormat);
-
- m_homepage = config.value("homepage", conf["profile.homepage"]).toUrl();
- m_newtab = config.value("newtab", conf["profile.newtab"]).toUrl();
-
- config.beginGroup("http");
- setHttpUserAgent(config.value("userAgent", httpUserAgent()).toString());
- setHttpAcceptLanguage(config.value("accept-lang", httpAcceptLanguage()).toString());
- {
- QString cacheType = config.value("cacheType").toString();
- if(cacheType == "memory") {
- setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
- } else if(cacheType == "disk") {
- setHttpCacheType(QWebEngineProfile::DiskHttpCache);
- } else if(cacheType == "disabled") {
- setHttpCacheType(QWebEngineProfile::NoCache);
- }
- }
- setHttpCacheMaximumSize(config.value("cacheSize", httpCacheMaximumSize()).toInt());
- config.endGroup(); // http
-
- config.beginGroup("policy");
- {
- QString cookies = config.value("cookies").toString();
- if(cookies == "disabled") {
- setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
- } else if(cookies == "allow") {
- setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
- } else if(cookies == "force") {
- setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
- }
- }
- config.endGroup(); // policy
-
- config.beginGroup("attributes");
- QWebEngineSettings *s = 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());
- 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());
- config.endGroup(); // attributes
-}
-
-void WebEngineProfile::saveProfile(const QString &path)
-{
- QSettings config(persistentStoragePath() + "/profile.ini", QSettings::IniFormat);
-
- config.setValue("homepage", homepage().toString());
- config.setValue("newtab", newtab().toString());
-
- config.beginGroup("http");
- config.setValue("userAgent", httpUserAgent());
- config.setValue("accept-lang", httpAcceptLanguage());
- switch(httpCacheType()) {
- case MemoryHttpCache:
- config.setValue("cacheType", "memory");
- break;
- case DiskHttpCache:
- config.setValue("cacheType", "disk");
- break;
- case NoCache:
- config.setValue("cacheType", "disabled");
- break;
- }
- config.setValue("cacheSize", httpCacheMaximumSize());
- config.endGroup(); // http
-
- config.beginGroup("policy");
- switch(persistentCookiesPolicy()) {
- case NoPersistentCookies:
- config.setValue("cookies", "disabled");
- break;
- case AllowPersistentCookies:
- config.setValue("cookies", "allow");
- break;
- case ForcePersistentCookies:
- config.setValue("cookies", "force");
- break;
- }
- config.endGroup(); // policy
-
- QWebEngineSettings *s = settings();
- config.beginGroup("attributes");
- config.setValue("autoLoadImages", s->testAttribute(QWebEngineSettings::AutoLoadImages));
- config.setValue("javascriptEnabled", s->testAttribute(QWebEngineSettings::JavascriptEnabled));
- config.setValue("javascriptCanOpenWindows", s->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows));
- config.setValue("javascriptCanAccessClipboard", s->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard));
- config.setValue("linksIncludedInFocusChain", s->testAttribute(QWebEngineSettings::LinksIncludedInFocusChain));
- config.setValue("localStorageEnabled", s->testAttribute(QWebEngineSettings::LocalStorageEnabled));
- config.setValue("localContentCanAccessRemoteUrls", s->testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls));
- config.setValue("xssAuditingEnabled", s->testAttribute(QWebEngineSettings::XSSAuditingEnabled));
- config.setValue("spatialNavigationEnabled", s->testAttribute(QWebEngineSettings::SpatialNavigationEnabled));
- config.setValue("localContentCanAccessFileUrls", s->testAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls));
- config.setValue("hyperlinkAuditingEnabled", s->testAttribute(QWebEngineSettings::HyperlinkAuditingEnabled));
- config.setValue("scrollAnimatorEnabled", s->testAttribute(QWebEngineSettings::ScrollAnimatorEnabled));
- config.setValue("errorPageEnabled", s->testAttribute(QWebEngineSettings::ErrorPageEnabled));
- config.setValue("pluginsEnabled", s->testAttribute(QWebEngineSettings::PluginsEnabled));
- config.setValue("fullscreenSupportEnabled", s->testAttribute(QWebEngineSettings::FullScreenSupportEnabled));
- config.setValue("screenCaptureEnabled", s->testAttribute(QWebEngineSettings::ScreenCaptureEnabled));
- config.setValue("webglEnabled", s->testAttribute(QWebEngineSettings::WebGLEnabled));
- config.setValue("accelerated2dCanvasEnabled", s->testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled));
- config.setValue("autoLoadIconsForPage", s->testAttribute(QWebEngineSettings::AutoLoadIconsForPage));
- config.setValue("touchIconsEnabled", s->testAttribute(QWebEngineSettings::TouchIconsEnabled));
-#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
- config.setValue("focusOnNavigationEnabled", s->testAttribute(QWebEngineSettings::FocusOnNavigationEnabled));
- config.setValue("printElementBackgrounds", s->testAttribute(QWebEngineSettings::PrintElementBackgrounds));
- config.setValue("allowRunningInsecureContent", s->testAttribute(QWebEngineSettings::AllowRunningInsecureContent));
-#endif
- config.endGroup(); // attributes
-
- config.sync();
-}
diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h
index a38c977..e69de29 100644
--- a/src/webengine/webengineprofile.h
+++ b/src/webengine/webengineprofile.h
@@ -1,39 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#ifndef SMOLBOTE_WEBENGINEPROFILE_H
-#define SMOLBOTE_WEBENGINEPROFILE_H
-
-#include <QUrl>
-#include <QWebEngineProfile>
-
-class WebEngineProfile : public QWebEngineProfile
-{
- Q_OBJECT
-public:
- explicit WebEngineProfile(QObject *parent = nullptr);
- explicit WebEngineProfile(const QString &name, QObject *parent = nullptr);
-
- ~WebEngineProfile() override;
-
- QString name() const;
- QUrl homepage() const;
- QUrl newtab() const;
-
-public slots:
- void loadProfile(QHash<QString, QString> conf, const QString &path);
- void saveProfile(const QString &path = QString());
-
-private:
- QString m_configPath;
- QString m_name;
- QUrl m_homepage = QUrl("about:blank");
- QUrl m_newtab = QUrl("about:blank");
-};
-
-#endif // SMOLBOTE_WEBENGINEPROFILE_H
diff --git a/src/webengine/webprofile.cpp b/src/webengine/webprofile.cpp
new file mode 100644
index 0000000..24b23a0
--- /dev/null
+++ b/src/webengine/webprofile.cpp
@@ -0,0 +1,216 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "webprofile.h"
+#include <QFileInfo>
+#include <QSettings>
+#include <QWebEngineCookieStore>
+#include <QWebEngineSettings>
+
+WebProfile *WebProfile::profile = nullptr;
+
+WebProfile::WebProfile(QObject *parent)
+ : QWebEngineProfile(parent)
+{
+ m_name = tr("Off-the-record");
+
+#ifdef QT_DEBUG
+ qDebug("Creating off-the-record profile");
+#endif
+
+ // Off-the-record profiles have no persistent path
+}
+
+WebProfile::WebProfile(const QString &name, QObject *parent)
+ : QWebEngineProfile(name, parent)
+{
+ m_name = name;
+
+#ifdef QT_DEBUG
+ qDebug("Creating profile %s", qUtf8Printable(m_name));
+#endif
+}
+
+WebProfile::~WebProfile() = default;
+
+QString WebProfile::name() const
+{
+ return m_name;
+}
+
+QUrl WebProfile::homepage() const
+{
+ return m_homepage;
+}
+
+QUrl WebProfile::newtab() const
+{
+ return m_newtab;
+}
+
+void WebProfile::loadProfile(QHash<QString, QString> conf, const QString &path)
+{
+ m_configPath = path;
+
+#ifdef QT_DEBUG
+ qDebug("Reading config for profile '%s': %s", qUtf8Printable(m_name), qUtf8Printable(m_configPath));
+#endif
+ QSettings config(m_configPath, QSettings::IniFormat);
+
+ m_homepage = config.value("homepage", conf["profile.homepage"]).toUrl();
+ m_newtab = config.value("newtab", conf["profile.newtab"]).toUrl();
+
+ config.beginGroup("http");
+ setHttpUserAgent(config.value("userAgent", httpUserAgent()).toString());
+ setHttpAcceptLanguage(config.value("accept-lang", httpAcceptLanguage()).toString());
+ {
+ QString cacheType = config.value("cacheType").toString();
+ if(cacheType == "memory") {
+ setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
+ } else if(cacheType == "disk") {
+ setHttpCacheType(QWebEngineProfile::DiskHttpCache);
+ } else if(cacheType == "disabled") {
+ setHttpCacheType(QWebEngineProfile::NoCache);
+ }
+ }
+ setHttpCacheMaximumSize(config.value("cacheSize", httpCacheMaximumSize()).toInt());
+ config.endGroup(); // http
+
+ config.beginGroup("policy");
+ {
+ QString cookies = config.value("cookies").toString();
+ if(cookies == "disabled") {
+ setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
+ } else if(cookies == "allow") {
+ setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
+ } else if(cookies == "force") {
+ setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
+ }
+ }
+ config.endGroup(); // policy
+
+ config.beginGroup("attributes");
+ QWebEngineSettings *s = 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());
+ 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());
+ config.endGroup(); // attributes
+}
+
+void WebProfile::saveProfile(const QString &path)
+{
+ QSettings config(persistentStoragePath() + "/profile.ini", QSettings::IniFormat);
+
+ config.setValue("homepage", homepage().toString());
+ config.setValue("newtab", newtab().toString());
+
+ config.beginGroup("http");
+ config.setValue("userAgent", httpUserAgent());
+ config.setValue("accept-lang", httpAcceptLanguage());
+ switch(httpCacheType()) {
+ case MemoryHttpCache:
+ config.setValue("cacheType", "memory");
+ break;
+ case DiskHttpCache:
+ config.setValue("cacheType", "disk");
+ break;
+ case NoCache:
+ config.setValue("cacheType", "disabled");
+ break;
+ }
+ config.setValue("cacheSize", httpCacheMaximumSize());
+ config.endGroup(); // http
+
+ config.beginGroup("policy");
+ switch(persistentCookiesPolicy()) {
+ case NoPersistentCookies:
+ config.setValue("cookies", "disabled");
+ break;
+ case AllowPersistentCookies:
+ config.setValue("cookies", "allow");
+ break;
+ case ForcePersistentCookies:
+ config.setValue("cookies", "force");
+ break;
+ }
+ config.endGroup(); // policy
+
+ QWebEngineSettings *s = settings();
+ config.beginGroup("attributes");
+ config.setValue("autoLoadImages", s->testAttribute(QWebEngineSettings::AutoLoadImages));
+ config.setValue("javascriptEnabled", s->testAttribute(QWebEngineSettings::JavascriptEnabled));
+ config.setValue("javascriptCanOpenWindows", s->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows));
+ config.setValue("javascriptCanAccessClipboard", s->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard));
+ config.setValue("linksIncludedInFocusChain", s->testAttribute(QWebEngineSettings::LinksIncludedInFocusChain));
+ config.setValue("localStorageEnabled", s->testAttribute(QWebEngineSettings::LocalStorageEnabled));
+ config.setValue("localContentCanAccessRemoteUrls", s->testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls));
+ config.setValue("xssAuditingEnabled", s->testAttribute(QWebEngineSettings::XSSAuditingEnabled));
+ config.setValue("spatialNavigationEnabled", s->testAttribute(QWebEngineSettings::SpatialNavigationEnabled));
+ config.setValue("localContentCanAccessFileUrls", s->testAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls));
+ config.setValue("hyperlinkAuditingEnabled", s->testAttribute(QWebEngineSettings::HyperlinkAuditingEnabled));
+ config.setValue("scrollAnimatorEnabled", s->testAttribute(QWebEngineSettings::ScrollAnimatorEnabled));
+ config.setValue("errorPageEnabled", s->testAttribute(QWebEngineSettings::ErrorPageEnabled));
+ config.setValue("pluginsEnabled", s->testAttribute(QWebEngineSettings::PluginsEnabled));
+ config.setValue("fullscreenSupportEnabled", s->testAttribute(QWebEngineSettings::FullScreenSupportEnabled));
+ config.setValue("screenCaptureEnabled", s->testAttribute(QWebEngineSettings::ScreenCaptureEnabled));
+ config.setValue("webglEnabled", s->testAttribute(QWebEngineSettings::WebGLEnabled));
+ config.setValue("accelerated2dCanvasEnabled", s->testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled));
+ config.setValue("autoLoadIconsForPage", s->testAttribute(QWebEngineSettings::AutoLoadIconsForPage));
+ config.setValue("touchIconsEnabled", s->testAttribute(QWebEngineSettings::TouchIconsEnabled));
+#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
+ config.setValue("focusOnNavigationEnabled", s->testAttribute(QWebEngineSettings::FocusOnNavigationEnabled));
+ config.setValue("printElementBackgrounds", s->testAttribute(QWebEngineSettings::PrintElementBackgrounds));
+ config.setValue("allowRunningInsecureContent", s->testAttribute(QWebEngineSettings::AllowRunningInsecureContent));
+#endif
+ config.endGroup(); // attributes
+
+ config.sync();
+}
diff --git a/src/webengine/webprofile.h b/src/webengine/webprofile.h
new file mode 100644
index 0000000..41d1aec
--- /dev/null
+++ b/src/webengine/webprofile.h
@@ -0,0 +1,53 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_WEBENGINEPROFILE_H
+#define SMOLBOTE_WEBENGINEPROFILE_H
+
+#include <QHash>
+#include <QUrl>
+#include <QWebEngineProfile>
+
+class WebProfile : public QWebEngineProfile
+{
+ Q_OBJECT
+public:
+ explicit WebProfile(QObject *parent = nullptr);
+ explicit WebProfile(const QString &name, QObject *parent = nullptr);
+
+ ~WebProfile() override;
+
+ static void setDefaultProfile(WebProfile *profile)
+ {
+ Q_CHECK_PTR(profile);
+ WebProfile::profile = profile;
+ }
+ static WebProfile *defaultProfile()
+ {
+ Q_CHECK_PTR(WebProfile::profile);
+ return WebProfile::profile;
+ }
+
+ QString name() const;
+ QUrl homepage() const;
+ QUrl newtab() const;
+
+public slots:
+ void loadProfile(QHash<QString, QString> conf, const QString &path);
+ void saveProfile(const QString &path = QString());
+
+private:
+ static WebProfile *profile;
+
+ QString m_configPath;
+ QString m_name;
+ QUrl m_homepage = QUrl("about:blank");
+ QUrl m_newtab = QUrl("about:blank");
+};
+
+#endif // SMOLBOTE_WEBENGINEPROFILE_H
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index 7734aa0..d145d2b 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -7,19 +7,23 @@
*/
#include "webview.h"
-#include "mainwindow/mainwindow.h"
-#include "mainwindow/widgets/tabbar.h"
+#include "webpage.h"
+#include "webprofile.h"
#include "widgets/pagemenu.h"
#include "widgets/pagetoolsmenu.h"
#include <QDialog>
#include <QStatusBar>
#include <QVBoxLayout>
+#include "mainwindow/window.h"
-WebView::WebView(MainWindow *parentMainWindow, QWidget *parent)
+WebView::WebView(WebProfile *profile, QWidget *parent)
: QWebEngineView(parent)
{
- Q_CHECK_PTR(parentMainWindow);
- m_parent = parentMainWindow;
+ Q_CHECK_PTR(profile);
+ m_profile = profile;
+ setPage(new WebPage(profile, this));
+
+ m_parentWindow = qobject_cast<Window *>(parent);
// load status and progress
connect(this, &QWebEngineView::loadStarted, this, [this]() {
@@ -72,26 +76,32 @@ int WebView::loadProgress() const
WebView *WebView::createWindow(QWebEnginePage::WebWindowType type)
{
- WebView *view = new WebView(m_parent);
+ if(m_parentWindow == nullptr) {
+ qDebug("parent window not found!");
+ return nullptr;
+ }
+
+ // parent Window has been found
+ WebView *view = new WebView(m_profile, m_parentWindow);
switch(type) {
case QWebEnginePage::WebBrowserWindow:
// a complete web browser window
- m_parent->newWindow()->tabBar->addTab(view);
+ m_parentWindow->addTab(view);
break;
case QWebEnginePage::WebBrowserTab:
// a web browser tab
- m_parent->tabBar->setCurrentIndex(m_parent->tabBar->addTab(view));
+ m_parentWindow->swapToTab(m_parentWindow->addTab(view));
break;
case QWebEnginePage::WebDialog:
// a window without decorations
- m_parent->newWindow()->tabBar->addTab(view);
+ m_parentWindow->addTab(view);
break;
case QWebEnginePage::WebBrowserBackgroundTab:
// a web browser tab, but don't swap to it
- m_parent->tabBar->addTab(view);
+ m_parentWindow->addTab(view);
break;
}
@@ -100,26 +110,17 @@ WebView *WebView::createWindow(QWebEnginePage::WebWindowType type)
void WebView::handleLinkHovered(const QString &url)
{
- if(isVisible()) {
- m_parent->statusBar()->showMessage(url, 3000);
- }
+ // TODO: tooltip
+ qDebug("%s", qUtf8Printable(url));
}
void WebView::triggerViewAction(WebView::ViewAction action)
{
switch(action) {
+ case GoHome:
+ load(m_profile->homepage());
case BookmarkPage:
emit newBookmark(this->title(), this->url());
break;
}
}
-
-WebView *createWebView(const QUrl &url, WebEngineProfile *profile, MainWindow *parent)
-{
- auto *view = new WebView(parent);
- auto *page = new WebPage(profile);
- view->setPage(page);
- page->load(url);
-
- return view;
-}
diff --git a/src/webengine/webview.h b/src/webengine/webview.h
index 233565e..a27a61f 100644
--- a/src/webengine/webview.h
+++ b/src/webengine/webview.h
@@ -13,17 +13,18 @@
#include <QWebEngineView>
class QMenu;
-class MainWindow;
-class WebEngineProfile;
+class WebProfile;
+class Window;
class WebView : public QWebEngineView
{
Q_OBJECT
public:
enum ViewAction {
+ GoHome,
BookmarkPage
};
- explicit WebView(MainWindow *parentMainWindow, QWidget *parent = nullptr);
+ explicit WebView(WebProfile *profile = nullptr, QWidget *parent = nullptr);
~WebView() override;
QMenu *pageMenu();
@@ -53,7 +54,9 @@ private slots:
void handleLinkHovered(const QString &url);
private:
- MainWindow *m_parent = nullptr;
+ Window *m_parentWindow = nullptr;
+ WebProfile *m_profile = nullptr;
+
QMenu *m_pageMenu = nullptr;
QMenu *m_toolsMenu = nullptr;
@@ -61,6 +64,4 @@ private:
int m_loadProgress;
};
-WebView *createWebView(const QUrl &url, WebEngineProfile *profile, MainWindow *parent);
-
#endif // SMOLBOTE_WEBVIEW_H
diff --git a/src/webengine/widgets/pagetoolsmenu.cpp b/src/webengine/widgets/pagetoolsmenu.cpp
index 381c6f4..2a227ea 100644
--- a/src/webengine/widgets/pagetoolsmenu.cpp
+++ b/src/webengine/widgets/pagetoolsmenu.cpp
@@ -52,7 +52,7 @@ QDialog *PageToolsMenu::createDevToolsDialog(QWebEnginePage *page)
auto *devPage = new QWebEnginePage(view);
view->setPage(devPage);
-// page->setDevToolsPage(devPage);
+ // page->setDevToolsPage(devPage);
auto *l = new QVBoxLayout(popup);
l->setContentsMargins(0, 0, 0, 0);