mirror of
https://invent.kde.org/network/falkon.git
synced 2024-09-22 02:02:10 +02:00
Rewrite JS and IMGs to use SiteSettingManager
- The set* functions needs a redesign - There is a chance that the database update will take longer than the time it takes to start reloading, need to stress test or redesign. - Might still need to look ar StatusBarIcons plugin for optimizations and potential changes - I am still unsure how to store data in the database, so far I use numbers which is good I believe since I want to have 3 states, (default, allow, deny) - Might need to add overloaded functions with bool arguments to make the rest of the code simpler. PS: I believe it is fine to have a bit more complicated logic in backend while the frontend will stay simple. Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
b10b310d11
commit
d0b9510b73
|
@ -46,8 +46,8 @@ SiteWebEngineSettings SiteSettingsManager::getWebEngineSettings(const QUrl& url)
|
||||||
SiteWebEngineSettings settings;
|
SiteWebEngineSettings settings;
|
||||||
|
|
||||||
QSqlQuery query(SqlDatabase::instance()->database());
|
QSqlQuery query(SqlDatabase::instance()->database());
|
||||||
query.prepare("SELECT allow_images, allow_javascript FROM history WHERE server=?");
|
query.prepare("SELECT allow_images, allow_javascript FROM site_settings WHERE server=?");
|
||||||
query.bindValue(0, url.host());
|
query.addBindValue(url.host());
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
if (query.next()) {
|
if (query.next()) {
|
||||||
|
@ -75,3 +75,35 @@ SiteWebEngineSettings SiteSettingsManager::getWebEngineSettings(const QUrl& url)
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SiteSettingsManager::setJavascript(const QUrl& url, int value)
|
||||||
|
{
|
||||||
|
auto job = new SqlQueryJob(QSL("UPDATE site_settings SET allow_javascript=? WHERE server=?"), this);
|
||||||
|
job->addBindValue(value);
|
||||||
|
job->addBindValue(url.host());
|
||||||
|
connect(job, &SqlQueryJob::finished, this, [=]() {
|
||||||
|
if (job->numRowsAffected() == 0) {
|
||||||
|
auto job = new SqlQueryJob(QSL("INSERT INTO site_settings (server, allow_javascript) VALUES (?,?)"), this);
|
||||||
|
job->addBindValue(url.host());
|
||||||
|
job->addBindValue(value);
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SiteSettingsManager::setImages(const QUrl& url, int value)
|
||||||
|
{
|
||||||
|
auto job = new SqlQueryJob(QSL("UPDATE site_settings SET allow_images=? WHERE server=?"), this);
|
||||||
|
job->addBindValue(value);
|
||||||
|
job->addBindValue(url.host());
|
||||||
|
connect(job, &SqlQueryJob::finished, this, [=]() {
|
||||||
|
if (job->numRowsAffected() == 0) {
|
||||||
|
auto job = new SqlQueryJob(QSL("INSERT INTO site_settings (server, allow_images) VALUES (?,?)"), this);
|
||||||
|
job->addBindValue(url.host());
|
||||||
|
job->addBindValue(value);
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ public:
|
||||||
*/
|
*/
|
||||||
SiteWebEngineSettings getWebEngineSettings(const QUrl &url);
|
SiteWebEngineSettings getWebEngineSettings(const QUrl &url);
|
||||||
|
|
||||||
|
void setJavascript(const QUrl &url, int value);
|
||||||
|
void setImages(const QUrl &url, int value);
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "delayedfilewatcher.h"
|
#include "delayedfilewatcher.h"
|
||||||
#include "searchenginesmanager.h"
|
#include "searchenginesmanager.h"
|
||||||
#include "html5permissions/html5permissionsmanager.h"
|
#include "html5permissions/html5permissionsmanager.h"
|
||||||
|
#include "sitesettingsmanager.h"
|
||||||
#include "javascript/externaljsobject.h"
|
#include "javascript/externaljsobject.h"
|
||||||
#include "tabwidget.h"
|
#include "tabwidget.h"
|
||||||
#include "networkmanager.h"
|
#include "networkmanager.h"
|
||||||
|
@ -451,8 +452,9 @@ bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::Navigatio
|
||||||
if (result) {
|
if (result) {
|
||||||
if (isMainFrame) {
|
if (isMainFrame) {
|
||||||
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");
|
||||||
const bool globalJsEnabled = mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled);
|
const SiteWebEngineSettings siteSettings = mApp->siteSettingsManager()->getWebEngineSettings(url);
|
||||||
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, isWeb ? globalJsEnabled : true);
|
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, isWeb ? siteSettings.allowJavaScript : true);
|
||||||
|
settings()->setAttribute(QWebEngineSettings::AutoLoadImages, isWeb ? siteSettings.allowImages : true);
|
||||||
}
|
}
|
||||||
Q_EMIT navigationRequestAccepted(url, type, isMainFrame);
|
Q_EMIT navigationRequestAccepted(url, type, isMainFrame);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "tabbedwebview.h"
|
#include "tabbedwebview.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
|
#include "sitesettingsmanager.h"
|
||||||
|
|
||||||
#include <QGraphicsColorizeEffect>
|
#include <QGraphicsColorizeEffect>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
@ -58,10 +59,10 @@ void SBI_ImagesIcon::showMenu(const QPoint &point)
|
||||||
menu.addAction(m_icon, tr("Current Page Settings"))->setFont(boldFont);
|
menu.addAction(m_icon, tr("Current Page Settings"))->setFont(boldFont);
|
||||||
|
|
||||||
if (testCurrentPageWebAttribute(QWebEngineSettings::AutoLoadImages)) {
|
if (testCurrentPageWebAttribute(QWebEngineSettings::AutoLoadImages)) {
|
||||||
menu.addAction(tr("Disable loading images (temporarily)"), this, &SBI_ImagesIcon::toggleLoadingImages);
|
menu.addAction(tr("Disable loading images"), this, &SBI_ImagesIcon::toggleLoadingImages);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
menu.addAction(tr("Enable loading images (temporarily)"), this, &SBI_ImagesIcon::toggleLoadingImages);
|
menu.addAction(tr("Enable loading images"), this, &SBI_ImagesIcon::toggleLoadingImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
@ -77,8 +78,13 @@ void SBI_ImagesIcon::showMenu(const QPoint &point)
|
||||||
|
|
||||||
void SBI_ImagesIcon::toggleLoadingImages()
|
void SBI_ImagesIcon::toggleLoadingImages()
|
||||||
{
|
{
|
||||||
|
WebPage *page = currentPage();
|
||||||
|
if (!page) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool current = testCurrentPageWebAttribute(QWebEngineSettings::AutoLoadImages);
|
bool current = testCurrentPageWebAttribute(QWebEngineSettings::AutoLoadImages);
|
||||||
setCurrentPageWebAttribute(QWebEngineSettings::AutoLoadImages, !current);
|
mApp->siteSettingsManager()->setImages(page->url(), (!current) ? 1 : -1);
|
||||||
|
|
||||||
// We should reload page on disabling images
|
// We should reload page on disabling images
|
||||||
if (current) {
|
if (current) {
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "tabbedwebview.h"
|
#include "tabbedwebview.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
#include "jsoptions.h"
|
#include "jsoptions.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "sitesettingsmanager.h"
|
||||||
|
|
||||||
#include <QGraphicsColorizeEffect>
|
#include <QGraphicsColorizeEffect>
|
||||||
#include <QWebEngineSettings>
|
#include <QWebEngineSettings>
|
||||||
|
@ -51,10 +53,10 @@ void SBI_JavaScriptIcon::showMenu(const QPoint &point)
|
||||||
menu.addAction(m_icon, tr("Current Page Settings"))->setFont(boldFont);
|
menu.addAction(m_icon, tr("Current Page Settings"))->setFont(boldFont);
|
||||||
|
|
||||||
if (testCurrentPageWebAttribute(QWebEngineSettings::JavascriptEnabled)) {
|
if (testCurrentPageWebAttribute(QWebEngineSettings::JavascriptEnabled)) {
|
||||||
menu.addAction(tr("Disable JavaScript (temporarily)"), this, &SBI_JavaScriptIcon::toggleJavaScript);
|
menu.addAction(tr("Disable JavaScript"), this, &SBI_JavaScriptIcon::toggleJavaScript);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
menu.addAction(tr("Enable JavaScript (temporarily)"), this, &SBI_JavaScriptIcon::toggleJavaScript);
|
menu.addAction(tr("Enable JavaScript"), this, &SBI_JavaScriptIcon::toggleJavaScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
// JavaScript needs to be always enabled for falkon: sites
|
// JavaScript needs to be always enabled for falkon: sites
|
||||||
|
@ -88,15 +90,10 @@ void SBI_JavaScriptIcon::toggleJavaScript()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool current = testCurrentPageWebAttribute(QWebEngineSettings::JavascriptEnabled);
|
bool current = testCurrentPageWebAttribute(QWebEngineSettings::JavascriptEnabled);
|
||||||
setCurrentPageWebAttribute(QWebEngineSettings::JavascriptEnabled, !current);
|
|
||||||
|
|
||||||
m_settings[page] = !current;
|
m_settings[page] = !current;
|
||||||
|
|
||||||
connect(page, &WebPage::navigationRequestAccepted, this, [=](const QUrl &, WebPage::NavigationType, bool isMainFrame) {
|
mApp->siteSettingsManager()->setJavascript(page->url(), m_settings[page] ? 1 : -1);
|
||||||
if (isMainFrame) {
|
|
||||||
page->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, m_settings[page]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_window->weView()->reload();
|
m_window->weView()->reload();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user