1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Clean and set default attributes for falkon pages

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2022-09-15 12:27:21 +02:00
parent 59e0517683
commit 25261d5402
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
3 changed files with 17 additions and 80 deletions

View File

@ -119,42 +119,7 @@ void SiteSettingsManager::saveSettings()
settings.endGroup(); settings.endGroup();
} }
SiteWebEngineSettings SiteSettingsManager::getWebEngineSettings(const QUrl& url) QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttributes(const QUrl& url)
{
SiteWebEngineSettings settings;
QSqlQuery query(SqlDatabase::instance()->database());
query.prepare(QSL("SELECT allow_images, allow_javascript FROM site_settings WHERE server=?"));
query.addBindValue(url.host());
query.exec();
if (query.next()) {
int allow_images = query.value(QSL("allow_images")).toInt();
int allow_javascript = query.value(QSL("allow_javascript")).toInt();
if (allow_images == 0) {
settings.allowImages = mApp->webSettings()->testAttribute(QWebEngineSettings::AutoLoadImages);
}
else {
settings.allowImages = (allow_images == 1);
}
if (allow_javascript == 0) {
settings.allowJavaScript = mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled);
}
else {
settings.allowJavaScript = (allow_javascript == 1);
}
}
else {
settings.allowImages = mApp->webSettings()->testAttribute(QWebEngineSettings::AutoLoadImages);
settings.allowJavaScript = mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled);
}
return settings;
}
QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttributes2(const QUrl& url)
{ {
QHash<QWebEngineSettings::WebAttribute, bool> attributes; QHash<QWebEngineSettings::WebAttribute, bool> attributes;
@ -183,34 +148,6 @@ QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttribu
return attributes; return attributes;
} }
QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttributes(const QUrl& url)
{
QHash<QWebEngineSettings::WebAttribute, bool> attributes;
QSqlQuery query(SqlDatabase::instance()->database());
query.prepare(QSL("SELECT allow_images, allow_javascript FROM site_settings WHERE server=?"));
query.addBindValue(url.host());
query.exec();
if (query.next()) {
auto permToBool = [&attributes](Permission perm, QWebEngineSettings::WebAttribute attribute) {
if (perm == Allow) {
attributes[attribute] = true;
}
else if (perm == Deny) {
attributes[attribute] = false;
}
};
for (int i = 0; i < query.record().count(); ++i) {
SiteSettingsManager::PageOptions option = static_cast<SiteSettingsManager::PageOptions>(i);
permToBool(intToPermission(query.value(i).toInt()), optionToAttribute(option));
}
}
return attributes;
}
void SiteSettingsManager::setJavascript(const QUrl& url, const int value) void SiteSettingsManager::setJavascript(const QUrl& url, const int value)
{ {
setOption(poJavascriptEnabled, url, value); setOption(poJavascriptEnabled, url, value);

View File

@ -93,15 +93,6 @@ public:
void loadSettings(); void loadSettings();
void saveSettings(); void saveSettings();
/**
* @brief Get settings which should be applied to webpage before loading.
* Since this is using blocking database querry group all settings
* in one SQL call for faster laoding.
* @param url Address for which to fetch the settings
*/
SiteWebEngineSettings getWebEngineSettings(const QUrl &url);
QHash<QWebEngineSettings::WebAttribute, bool> getWebAttributes2(const QUrl &url);
QHash<QWebEngineSettings::WebAttribute, bool> getWebAttributes(const QUrl &url); QHash<QWebEngineSettings::WebAttribute, bool> getWebAttributes(const QUrl &url);
void setJavascript(const QUrl &url, const int value); void setJavascript(const QUrl &url, const int value);

View File

@ -454,7 +454,7 @@ bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::Navigatio
const bool isWeb = url.scheme() == QL1S("http") || url.scheme() == QL1S("https") || url.scheme() == QL1S("file"); const bool isWeb = url.scheme() == QL1S("http") || url.scheme() == QL1S("https") || url.scheme() == QL1S("file");
if (isWeb) { if (isWeb) {
auto webAttributes = mApp->siteSettingsManager()->getWebAttributes2(url); auto webAttributes = mApp->siteSettingsManager()->getWebAttributes(url);
if (!webAttributes.empty()) { if (!webAttributes.empty()) {
QHash<QWebEngineSettings::WebAttribute, bool>::iterator it; QHash<QWebEngineSettings::WebAttribute, bool>::iterator it;
for (it = webAttributes.begin(); it != webAttributes.end(); ++it) { for (it = webAttributes.begin(); it != webAttributes.end(); ++it) {
@ -462,12 +462,21 @@ bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::Navigatio
} }
} }
} }
else {
settings()->setAttribute(QWebEngineSettings::AutoLoadImages, true);
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
// const SiteWebEngineSettings siteSettings = mApp->siteSettingsManager()->getWebEngineSettings(url); settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
// settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, isWeb ? siteSettings.allowJavaScript : true); settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, true);
// settings()->setAttribute(QWebEngineSettings::AutoLoadImages, isWeb ? siteSettings.allowImages : true); settings()->setAttribute(QWebEngineSettings::JavascriptCanPaste, false);
settings()->setAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript, false);
settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, mApp->webSettings()->testAttribute(QWebEngineSettings::ScrollAnimatorEnabled));
settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, mApp->webSettings()->testAttribute(QWebEngineSettings::FullScreenSupportEnabled));
settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, false);
settings()->setAttribute(QWebEngineSettings::AllowGeolocationOnInsecureOrigins, false);
settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, mApp->webSettings()->testAttribute(QWebEngineSettings::PlaybackRequiresUserGesture));
settings()->setAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly, false);
}
} }
Q_EMIT navigationRequestAccepted(url, type, isMainFrame); Q_EMIT navigationRequestAccepted(url, type, isMainFrame);
} }