diff --git a/src/lib/other/sitesettingsmanager.cpp b/src/lib/other/sitesettingsmanager.cpp index 14267d8b2..8943ae88d 100644 --- a/src/lib/other/sitesettingsmanager.cpp +++ b/src/lib/other/sitesettingsmanager.cpp @@ -26,6 +26,32 @@ SiteSettingsManager::SiteSettingsManager ( QObject* parent ) : QObject(parent) { loadSettings(); + + supportedAttribute.append(QWebEngineSettings::AutoLoadImages); + supportedAttribute.append(QWebEngineSettings::JavascriptEnabled); +// supportedAttribute.append(QWebEngineSettings::JavascriptCanOpenWindows); +// supportedAttribute.append(QWebEngineSettings::JavascriptCanAccessClipboard); +// supportedAttribute.append(QWebEngineSettings::JavascriptCanPaste); +// supportedAttribute.append(QWebEngineSettings::AllowWindowActivationFromJavaScript); +// supportedAttribute.append(QWebEngineSettings::LocalStorageEnabled); +// supportedAttribute.append(QWebEngineSettings::ScrollAnimatorEnabled); +// supportedAttribute.append(QWebEngineSettings::FullScreenSupportEnabled); +// supportedAttribute.append(QWebEngineSettings::AllowRunningInsecureContent); +// supportedAttribute.append(QWebEngineSettings::AllowGeolocationOnInsecureOrigins); +// supportedAttribute.append(QWebEngineSettings::PlaybackRequiresUserGesture); +// supportedAttribute.append(QWebEngineSettings::WebRTCPublicInterfacesOnly); + + + attributesSql = QSL("SELECT "); + + for (int i = 0; i < supportedAttribute.size(); ++i) { + if (i > 0) { + attributesSql.append(QSL(", ")); + } + attributesSql.append(webAttributeToSqlColumn(supportedAttribute[i])); + } + + attributesSql.append(QSL(" FROM site_settings WHERE server=?")); } SiteSettingsManager::~SiteSettingsManager() noexcept @@ -128,6 +154,32 @@ SiteWebEngineSettings SiteSettingsManager::getWebEngineSettings(const QUrl& url) return settings; } +QHash SiteSettingsManager::getWebAttributes2(const QUrl& url) +{ + QHash attributes; + + QSqlQuery query(SqlDatabase::instance()->database()); + query.prepare(attributesSql); + query.addBindValue(url.host()); + query.exec(); + + if (query.next()) { + for (int i = 0; i < query.record().count(); ++i) { + Permission perm = intToPermission(query.value(i).toInt()); + QWebEngineSettings::WebAttribute attribute = supportedAttribute[i]; + + if (perm == Allow) { + attributes[attribute] = true; + } + else if (perm == Deny) { + attributes[attribute] = false; + } + } + } + + return attributes; +} + QHash SiteSettingsManager::getWebAttributes(const QUrl& url) { QHash attributes; @@ -494,3 +546,43 @@ QWebEngineSettings::WebAttribute SiteSettingsManager::optionToAttribute(const Si return QWebEngineSettings::JavascriptEnabled; } } + +QString SiteSettingsManager::webAttributeToSqlColumn(const QWebEngineSettings::WebAttribute& attribute) +{ + switch (attribute) { + case QWebEngineSettings::AutoLoadImages: + return QSL("allow_images"); +// return QSL("wa_autoload_images"); + + case QWebEngineSettings::JavascriptEnabled: + return QSL("allow_javascript"); +// return QSL("wa_js_enabled"); + case QWebEngineSettings::JavascriptCanOpenWindows: + return QSL("wa_js_open_windows"); + case QWebEngineSettings::JavascriptCanAccessClipboard: + return QSL("wa_js_access_clipboard"); + case QWebEngineSettings::JavascriptCanPaste: + return QSL("wa_js_can_paste"); + case QWebEngineSettings::AllowWindowActivationFromJavaScript: + return QSL("wa_js_window_activation"); + + case QWebEngineSettings::LocalStorageEnabled: + return QSL("wa_local_storage"); + case QWebEngineSettings::ScrollAnimatorEnabled: + return QSL("wa_acroll_animator"); + case QWebEngineSettings::FullScreenSupportEnabled: + return QSL("wa_fullscreen_support"); + case QWebEngineSettings::AllowRunningInsecureContent: + return QSL("wa_run_insecure_content"); + case QWebEngineSettings::AllowGeolocationOnInsecureOrigins: + return QSL("wa_insecure_geolocation"); + case QWebEngineSettings::PlaybackRequiresUserGesture: + return QSL("wa_playback_needs_gesture"); + case QWebEngineSettings::WebRTCPublicInterfacesOnly: + return QSL("wa_webrtc_public_interface_only"); + + default: + qWarning() << "Unknown attribute: " << attribute; + return QSL("wa_js_enabled"); + } +} diff --git a/src/lib/other/sitesettingsmanager.h b/src/lib/other/sitesettingsmanager.h index 7a61679ad..0434ce040 100644 --- a/src/lib/other/sitesettingsmanager.h +++ b/src/lib/other/sitesettingsmanager.h @@ -101,6 +101,7 @@ public: */ SiteWebEngineSettings getWebEngineSettings(const QUrl &url); + QHash getWebAttributes2(const QUrl &url); QHash getWebAttributes(const QUrl &url); void setJavascript(const QUrl &url, const int value); @@ -126,6 +127,7 @@ public: QString getPermissionName(const Permission permission); private: + QString webAttributeToSqlColumn(const QWebEngineSettings::WebAttribute &attribute); QString optionToSqlColumn(const PageOptions &option); PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature) const; Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const; @@ -133,6 +135,8 @@ private: QWebEngineSettings::WebAttribute optionToAttribute(const PageOptions &option) const; QMap m_defaults; + QList supportedAttribute; + QString attributesSql; }; diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index e49887300..84b8c9145 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -452,9 +452,22 @@ bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::Navigatio if (result) { if (isMainFrame) { const bool isWeb = url.scheme() == QL1S("http") || url.scheme() == QL1S("https") || url.scheme() == QL1S("file"); - const SiteWebEngineSettings siteSettings = mApp->siteSettingsManager()->getWebEngineSettings(url); - settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, isWeb ? siteSettings.allowJavaScript : true); - settings()->setAttribute(QWebEngineSettings::AutoLoadImages, isWeb ? siteSettings.allowImages : true); + + if (isWeb) { + auto webAttributes = mApp->siteSettingsManager()->getWebAttributes2(url); + if (!webAttributes.empty()) { + QHash::iterator it; + for (it = webAttributes.begin(); it != webAttributes.end(); ++it) { + settings()->setAttribute(it.key(), it.value()); + } + } + } + + + +// const SiteWebEngineSettings siteSettings = mApp->siteSettingsManager()->getWebEngineSettings(url); +// settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, isWeb ? siteSettings.allowJavaScript : true); +// settings()->setAttribute(QWebEngineSettings::AutoLoadImages, isWeb ? siteSettings.allowImages : true); } Q_EMIT navigationRequestAccepted(url, type, isMainFrame); }