From 06e3978774328adac273f50491dcd6d629054f7a Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 30 Jul 2024 19:51:18 -0700 Subject: [PATCH] Apply domain settings even when the main URL is explicitly allowed by the filter lists. https://redmine.stoutner.com/issues/1218 --- doc/index.docbook | 3 +- src/helpers/UserAgentHelper.cpp | 2 +- src/interceptors/UrlRequestInterceptor.cpp | 44 +++++++++++----------- src/widgets/CMakeLists.txt | 1 + src/widgets/PrivacyWebEnginePage.cpp | 25 ++++++++++++ src/widgets/PrivacyWebEnginePage.h | 37 ++++++++++++++++++ src/widgets/PrivacyWebEngineView.cpp | 9 +++-- 7 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 src/widgets/PrivacyWebEnginePage.cpp create mode 100644 src/widgets/PrivacyWebEnginePage.h diff --git a/doc/index.docbook b/doc/index.docbook index 600dd3c..54b204d 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1795,7 +1795,8 @@ - 0.6 - 15 July 2024 + <ulink url="https://www.stoutner.com/privacy-browser-pc-0-6/">0.6</ulink> - + <ulink url="https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=commitdiff;h=dd08da27e3e1cae734790cae8e3b8626fdf40c4b;ds=sidebyside">15 July 2024</ulink> Add filter lists. diff --git a/src/helpers/UserAgentHelper.cpp b/src/helpers/UserAgentHelper.cpp index 1e49813..4bd1432 100644 --- a/src/helpers/UserAgentHelper.cpp +++ b/src/helpers/UserAgentHelper.cpp @@ -39,7 +39,7 @@ const QString UserAgentHelper::SAFARI_MACOS_DATABASE = QLatin1String("Safari mac // Define the public user agent constants. const QString UserAgentHelper::PRIVACY_BROWSER_USER_AGENT = QLatin1String("PrivacyBrowser/1.0"); const QString UserAgentHelper::FIREFOX_LINUX_USER_AGENT = QLatin1String("Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0"); -const QString UserAgentHelper::CHROMIUM_LINUX_USER_AGENT = QLatin1String("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"); +const QString UserAgentHelper::CHROMIUM_LINUX_USER_AGENT = QLatin1String("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"); const QString UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0"); const QString UserAgentHelper::CHROME_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"); const QString UserAgentHelper::EDGE_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0"); diff --git a/src/interceptors/UrlRequestInterceptor.cpp b/src/interceptors/UrlRequestInterceptor.cpp index 940848f..0a8c04f 100644 --- a/src/interceptors/UrlRequestInterceptor.cpp +++ b/src/interceptors/UrlRequestInterceptor.cpp @@ -78,35 +78,35 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlReques break; } } + } - // Handle the request according to the navigation type. - switch (urlRequestInfo.navigationType()) + // Handle the request according to the navigation type. + switch (urlRequestInfo.navigationType()) + { + case QWebEngineUrlRequestInfo::NavigationTypeLink: + case QWebEngineUrlRequestInfo::NavigationTypeTyped: + case QWebEngineUrlRequestInfo::NavigationTypeBackForward: + // case QWebEngineUrlRequestInfo::NavigationTypeReload: This can be uncommented once https://redmine.stoutner.com/issues/821 has been fixed. + case QWebEngineUrlRequestInfo::NavigationTypeRedirect: { - case QWebEngineUrlRequestInfo::NavigationTypeLink: - case QWebEngineUrlRequestInfo::NavigationTypeTyped: - case QWebEngineUrlRequestInfo::NavigationTypeBackForward: - // case QWebEngineUrlRequestInfo::NavigationTypeReload: This can be uncommented once https://redmine.stoutner.com/issues/821 has been fixed. - case QWebEngineUrlRequestInfo::NavigationTypeRedirect: + // Only check the hosts if the main URL is changing. + if (urlRequestInfo.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) { - // Only check the hosts if the main URL is changing. - if (urlRequestInfo.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) - { - // Get the hosts. - QString requestingHost = urlRequestInfo.initiator().host(); - QString requestedHost = urlRequestInfo.requestUrl().host(); - - // Reapply the domain settings if the host is changing. - if (requestingHost != requestedHost) - emit applyDomainSettings(requestedHost); - } + // Get the hosts. + QString requestingHost = urlRequestInfo.initiator().host(); + QString requestedHost = urlRequestInfo.requestUrl().host(); - break; + // Reapply the domain settings if the host is changing. + if (requestingHost != requestedHost) + emit applyDomainSettings(requestedHost); } - default: - // Do nothing. - break; + break; } + + default: + // Do nothing. + break; } // Send the request struct to the privacy WebEngine view. diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 9fe904f..9eaebbb 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -20,6 +20,7 @@ target_sources(privacybrowser PRIVATE DevToolsWebEngineView.cpp DraggableTreeView.cpp + PrivacyWebEnginePage.cpp PrivacyWebEngineView.cpp TabWidget.cpp UrlLineEdit.cpp diff --git a/src/widgets/PrivacyWebEnginePage.cpp b/src/widgets/PrivacyWebEnginePage.cpp new file mode 100644 index 0000000..b2fec02 --- /dev/null +++ b/src/widgets/PrivacyWebEnginePage.cpp @@ -0,0 +1,25 @@ +/* + * Copyright 2024 Soren Stoutner . + * + * This file is part of Privacy Browser PC . + * + * Privacy Browser PC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Browser PC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Browser PC. If not, see . + */ + +// Application headers. +#include "PrivacyWebEnginePage.h" + +// Construct the class. +PrivacyWebEnginePage::PrivacyWebEnginePage(QWebEngineProfile *webEngineProfilePointer, QObject *parentObjectPointer) : QWebEnginePage(webEngineProfilePointer, parentObjectPointer) {} + diff --git a/src/widgets/PrivacyWebEnginePage.h b/src/widgets/PrivacyWebEnginePage.h new file mode 100644 index 0000000..9880b0b --- /dev/null +++ b/src/widgets/PrivacyWebEnginePage.h @@ -0,0 +1,37 @@ +/* + * Copyright 2024 Soren Stoutner . + * + * This file is part of Privacy Browser PC . + * + * Privacy Browser PC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Browser PC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Browser PC. If not, see . + */ + +#ifndef PRIVACY_WEBENGINE_PAGE_H +#define PRIVACY_WEBENGINE_PAGE_H + +// Qt toolkit headers. +#include + +class PrivacyWebEnginePage : public QWebEnginePage +{ + // Include the Q_OBJECT macro. + Q_OBJECT + +public: + // The default constructor. + explicit PrivacyWebEnginePage(QWebEngineProfile *webEngineProfilePointer, QObject *parentObjectPointer = nullptr); + +//protected: +}; +#endif diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index 71f10a3..6314f2b 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -19,6 +19,7 @@ // Application headers. #include "PrivacyWebEngineView.h" +#include "PrivacyWebEnginePage.h" #include "Settings.h" #include "ui_HttpAuthenticationDialog.h" #include "databases/CookiesDatabase.h" @@ -39,13 +40,13 @@ PrivacyWebEngineView::PrivacyWebEngineView(QWidget *parentWidgetPointer) : QWebE webEngineProfilePointer = new QWebEngineProfile(QLatin1String("")); // Create a WebEngine page. - QWebEnginePage *webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer); + PrivacyWebEnginePage *privacyWebEnginePagePointer = new PrivacyWebEnginePage(webEngineProfilePointer); // Set the WebEngine page. - setPage(webEnginePagePointer); + setPage(privacyWebEnginePagePointer); // Get handles for the various aspects of the WebEngine. - webEngineSettingsPointer = webEnginePagePointer->settings(); + webEngineSettingsPointer = privacyWebEnginePagePointer->settings(); // Instantiate the URL request interceptor. UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor(this); @@ -60,7 +61,7 @@ PrivacyWebEngineView::PrivacyWebEngineView(QWidget *parentWidgetPointer) : QWebE connect(urlRequestInterceptorPointer, SIGNAL(requestProcessed(RequestStruct*)), this, SLOT(storeRequest(RequestStruct*))); // Handle HTTP authentication requests. - connect(webEnginePagePointer, SIGNAL(authenticationRequired(const QUrl&, QAuthenticator*)), this, SLOT(handleAuthenticationRequest(const QUrl&, QAuthenticator*))); + connect(privacyWebEnginePagePointer, SIGNAL(authenticationRequired(const QUrl&, QAuthenticator*)), this, SLOT(handleAuthenticationRequest(const QUrl&, QAuthenticator*))); } void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const -- 2.45.2