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);