From bbc06827f4301381ee3882000abbba147607aa35 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 30 Mar 2022 14:33:29 -0700 Subject: [PATCH] Fix the application of Domain Settings when navigating history. https://redmine.stoutner.com/issues/826 --- src/CMakeLists.txt | 2 +- src/interceptors/CMakeLists.txt | 22 +++++++++++++++++++ .../UrlRequestInterceptor.cpp | 2 ++ .../UrlRequestInterceptor.h | 0 src/views/BrowserView.cpp | 16 +++++++++----- src/views/BrowserView.h | 2 +- src/windows/BrowserWindow.cpp | 2 +- 7 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 src/interceptors/CMakeLists.txt rename src/{ => interceptors}/UrlRequestInterceptor.cpp (95%) rename src/{ => interceptors}/UrlRequestInterceptor.h (100%) 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/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/UrlRequestInterceptor.cpp b/src/interceptors/UrlRequestInterceptor.cpp similarity index 95% rename from src/UrlRequestInterceptor.cpp rename to src/interceptors/UrlRequestInterceptor.cpp index 10f9862..2b9bd05 100644 --- a/src/UrlRequestInterceptor.cpp +++ b/src/interceptors/UrlRequestInterceptor.cpp @@ -30,6 +30,8 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlReques { 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) diff --git a/src/UrlRequestInterceptor.h b/src/interceptors/UrlRequestInterceptor.h similarity index 100% rename from src/UrlRequestInterceptor.h rename to src/interceptors/UrlRequestInterceptor.h 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()); -- 2.45.2