From bbad4d86a80dedb7f71790105959b7e9f53fcfad Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Fri, 9 Sep 2022 09:45:59 +0200 Subject: [PATCH] Start working on QWESettings Attributes Signed-off-by: Juraj Oravec --- src/lib/other/sitesettingsmanager.cpp | 47 +++++++++++++++++++++++++++ src/lib/other/sitesettingsmanager.h | 21 ++++++++++-- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/lib/other/sitesettingsmanager.cpp b/src/lib/other/sitesettingsmanager.cpp index e1eae164d..e25f0e585 100644 --- a/src/lib/other/sitesettingsmanager.cpp +++ b/src/lib/other/sitesettingsmanager.cpp @@ -111,6 +111,53 @@ SiteWebEngineSettings SiteSettingsManager::getWebEngineSettings(const QUrl& url) return settings; } +QHash SiteSettingsManager::getWebAttributes(const QUrl& url) +{ + QHash attribute; + + QSqlQuery query(SqlDatabase::instance()->database()); + query.prepare(QSL("SELECT allow_images, allow_javascript FROM site_settings WHERE server=?")); + query.addBindValue(url.host()); + query.exec(); + + // Fill the default values + // Might not be required + // TODO I hope the defaults are set with default webengine profile settings, needs testing + attribute[QWebEngineSettings::AutoLoadImages] = getDefaultPermission(poAllowImages) == Allow; + attribute[QWebEngineSettings::JavascriptEnabled] = getDefaultPermission(poAllowJavascript) == Allow; + + if (query.next()) { + Permission perm; + + auto paerToBool = [&perm, &attribute]() { + if (perm == Allow) { + attribute[QWebEngineSettings::AutoLoadImages] = true; + } + else if (perm == Deny) { + attribute[QWebEngineSettings::AutoLoadImages] = false; + } + }; + + perm = intToPermission(query.value(QSL("allow_images")).toInt()); + if (perm == Allow) { + attribute[QWebEngineSettings::AutoLoadImages] = true; + } + else if (perm == Deny) { + attribute[QWebEngineSettings::AutoLoadImages] = false; + } + + perm = intToPermission(query.value(QSL("allow_javascript")).toInt()); + if (perm == Allow) { + attribute[QWebEngineSettings::JavascriptEnabled] = true; + } + else if (perm == Deny) { + attribute[QWebEngineSettings::JavascriptEnabled] = false; + } + } + + return attribute; +} + void SiteSettingsManager::setJavascript(const QUrl& url, const int value) { setOption(poAllowJavascript, url, value); diff --git a/src/lib/other/sitesettingsmanager.h b/src/lib/other/sitesettingsmanager.h index ae5da762d..9f0bfff07 100644 --- a/src/lib/other/sitesettingsmanager.h +++ b/src/lib/other/sitesettingsmanager.h @@ -46,8 +46,23 @@ public: Q_ENUM(Permission); enum PageOptions { - poAllowJavascript, poAllowImages, + + /* Javascript stuff */ + poAllowJavascript, + poJavascriptCanOpenWindows, + poJavascriptCanAccessClipboard, + poJavascriptCanPaste, + poAllowWindowActivationFromJavaScript, + + poLocalStorageEnabled, + poScrollAnimatorEnabled, + poFullScreenSupportEnabled, + poAllowRunningInsecureContent, + poAllowGeolocationOnInsecureOrigins, + poPlaybackRequiresUserGesture, + poWebRTCPublicInterfacesOnly, + poAllowCookies, poZoomLevel, poAllowNotifications, @@ -66,7 +81,7 @@ public: Permission AllowJavascript; Permission AllowImages; Permission AllowCookies; - Permission ZoomLevel; + int ZoomLevel; Permission AllowNotifications; Permission AllowGeolocation; Permission AllowMediaAudioCapture; @@ -92,6 +107,8 @@ public: */ SiteWebEngineSettings getWebEngineSettings(const QUrl &url); + QHash getWebAttributes(const QUrl &url); + void setJavascript(const QUrl &url, const int value); void setImages(const QUrl &url, const int value);