From: Soren Stoutner Date: Wed, 30 Mar 2022 21:33:29 +0000 (-0700) Subject: Fix the application of Domain Settings when navigating history. https://redmine.stout... X-Git-Tag: v0.1~45 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=commitdiff_plain;h=bbc06827f4301381ee3882000abbba147607aa35 Fix the application of Domain Settings when navigating history. https://redmine.stoutner.com/issues/826 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55b3e3f..709b74c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,6 @@ add_executable(privacy-browser resources.qrc) target_sources(privacy-browser PRIVATE main.cpp MouseEventFilter.cpp - UrlRequestInterceptor.cpp ) # Add the Qt logging category. This will create the `debug.h` header file. @@ -64,6 +63,7 @@ target_link_libraries(privacy-browser # Add the subdirectories. add_subdirectory(dialogs) add_subdirectory(helpers) +add_subdirectory(interceptors) add_subdirectory(ui.rc) add_subdirectory(views) add_subdirectory(windows) diff --git a/src/UrlRequestInterceptor.cpp b/src/UrlRequestInterceptor.cpp deleted file mode 100644 index 10f9862..0000000 --- a/src/UrlRequestInterceptor.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright © 2022 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 "UrlRequestInterceptor.h" - -// The default constructor. -UrlRequestInterceptor::UrlRequestInterceptor(QObject *parentObjectPointer) : QWebEngineUrlRequestInterceptor(parentObjectPointer) {} - -void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo) -{ - // Handle the request according to the navigation type. - switch (urlRequestInfo.navigationType()) - { - case QWebEngineUrlRequestInfo::NavigationTypeLink: - case QWebEngineUrlRequestInfo::NavigationTypeTyped: - { - // 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); - } - } - - break; - } - - default: - // Do nothing. - break; - } - - // Handle the request according to the resource type. - switch (urlRequestInfo.resourceType()) - { - // A naughty HTTP ping request. - case QWebEngineUrlRequestInfo::ResourceTypePing: - { - // Block HTTP ping requests. - urlRequestInfo.block(true); - - break; - } - - default: - { - // Do nothing. - break; - } - } -} diff --git a/src/UrlRequestInterceptor.h b/src/UrlRequestInterceptor.h deleted file mode 100644 index 721d523..0000000 --- a/src/UrlRequestInterceptor.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2022 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 URLREQUESTINTERCEPTOR_H -#define URLREQUESTINTERCEPTOR_H - -// Qt framework headers. -#include - -class UrlRequestInterceptor : public QWebEngineUrlRequestInterceptor -{ - // Include the Q_OBJECT macro. - Q_OBJECT - -public: - // The default constructor. - UrlRequestInterceptor(QObject *parentObjectPointer = 0); - - // The public functions. - void interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo) override; - -signals: - // The signals. - void applyDomainSettings(const QString hostname) const; -}; -#endif diff --git a/src/interceptors/CMakeLists.txt b/src/interceptors/CMakeLists.txt new file mode 100644 index 0000000..6e92b32 --- /dev/null +++ b/src/interceptors/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright © 2022 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 . + + +# List the sources to include in the executable. +target_sources(privacy-browser PRIVATE + UrlRequestInterceptor.cpp +) diff --git a/src/interceptors/UrlRequestInterceptor.cpp b/src/interceptors/UrlRequestInterceptor.cpp new file mode 100644 index 0000000..2b9bd05 --- /dev/null +++ b/src/interceptors/UrlRequestInterceptor.cpp @@ -0,0 +1,76 @@ +/* + * Copyright © 2022 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 "UrlRequestInterceptor.h" + +// The default constructor. +UrlRequestInterceptor::UrlRequestInterceptor(QObject *parentObjectPointer) : QWebEngineUrlRequestInterceptor(parentObjectPointer) {} + +void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo) +{ + // Handle the request according to the navigation type. + switch (urlRequestInfo.navigationType()) + { + case QWebEngineUrlRequestInfo::NavigationTypeLink: + case QWebEngineUrlRequestInfo::NavigationTypeTyped: + case QWebEngineUrlRequestInfo::NavigationTypeBackForward: + case QWebEngineUrlRequestInfo::NavigationTypeRedirect: + { + // 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); + } + } + + break; + } + + default: + // Do nothing. + break; + } + + // Handle the request according to the resource type. + switch (urlRequestInfo.resourceType()) + { + // A naughty HTTP ping request. + case QWebEngineUrlRequestInfo::ResourceTypePing: + { + // Block HTTP ping requests. + urlRequestInfo.block(true); + + break; + } + + default: + { + // Do nothing. + break; + } + } +} diff --git a/src/interceptors/UrlRequestInterceptor.h b/src/interceptors/UrlRequestInterceptor.h new file mode 100644 index 0000000..721d523 --- /dev/null +++ b/src/interceptors/UrlRequestInterceptor.h @@ -0,0 +1,42 @@ +/* + * Copyright © 2022 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 URLREQUESTINTERCEPTOR_H +#define URLREQUESTINTERCEPTOR_H + +// Qt framework headers. +#include + +class UrlRequestInterceptor : public QWebEngineUrlRequestInterceptor +{ + // Include the Q_OBJECT macro. + Q_OBJECT + +public: + // The default constructor. + UrlRequestInterceptor(QObject *parentObjectPointer = 0); + + // The public functions. + void interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo) override; + +signals: + // The signals. + void applyDomainSettings(const QString hostname) const; +}; +#endif diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 90539a3..d190dbe 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -22,10 +22,10 @@ #include "MouseEventFilter.h" #include "Settings.h" #include "ui_BrowserView.h" -#include "UrlRequestInterceptor.h" #include "helpers/DomainsDatabaseHelper.h" #include "helpers/SearchEngineHelper.h" #include "helpers/UserAgentHelper.h" +#include "interceptors/UrlRequestInterceptor.h" #include "windows/BrowserWindow.h" // Qt framework headers. @@ -162,7 +162,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabaseHelper::USER_AGENT).value().toString())); - // Check if a custom zoom factor is set. This can be removed once has been resolved. + // Check if a custom zoom factor is set. if (domainRecord.field(DomainsDatabaseHelper::ZOOM_FACTOR).value().toInt()) { // Store the current zoom factor. @@ -174,7 +174,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload currentZoomFactor = Settings::zoomFactor(); } - // Set the zoom factor. + // Set the zoom factor. The use of `currentZoomFactor` can be removed once has been resolved. webEngineViewPointer->setZoomFactor(currentZoomFactor); // Apply the domain settings palette to the URL line edit. @@ -188,11 +188,11 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent())); - // Store the current zoom factor. + // Store the current zoom factor. This can be removed once has been resolved. currentZoomFactor = Settings::zoomFactor(); // Set the zoom factor. - webEngineViewPointer->setZoomFactor(currentZoomFactor); + webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); // Apply the no domain settings palette to the URL line edit. emit updateDomainSettingsIndicator(false); @@ -237,8 +237,12 @@ void BrowserView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const webEngineViewPointer->reload(); } -void BrowserView::applyOnTheFlyZoomFactor(const double &zoomFactor) const +// This can be const once has been resolved. +void BrowserView::applyOnTheFlyZoomFactor(const double &zoomFactor) { + // Update the current zoom factor. This can be removed once has been resolved. + currentZoomFactor = zoomFactor; + // Set the zoom factor. webEngineViewPointer->setZoomFactor(zoomFactor); } diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index 12f0274..6088a63 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -39,7 +39,7 @@ public: explicit BrowserView(QWidget *parent); // The public functions. - void applyOnTheFlyZoomFactor(const double &zoomFactor) const; + void applyOnTheFlyZoomFactor(const double &zoomFactor); void loadInitialWebsite(); signals: diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index e2dd301..2d64794 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -511,7 +511,7 @@ void BrowserWindow::updateOnTheFlyUserAgent(const QString &userAgent) const void BrowserWindow::updateOnTheFlyZoomFactor(const double &zoomFactor) { // Set the current zoom factor. - currentZoomFactor = Settings::zoomFactor(); + currentZoomFactor = zoomFactor; // Update the zoom factor action text, formatting the double with 2 decimal places. zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());