find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
Gui
+ WebEngineCore
WebEngineWidgets
Widgets
)
BrowserWindow();
private Q_SLOTS:
- // Define the private slots.
+ // The private slots.
void fileNew() const;
void settingsConfigure();
void updateSearchEngineLabel(const QString &searchEngineString) const;
void updateUserAgentLabel(const QString &userAgentName) const;
private:
- // Define the private variables.
+ // The private variables.
MainView *mainViewPointer;
QLabel *searchEngineLabelPointer;
QLabel *userAgentLabelPointer;
main.cpp
MainView.cpp
MouseEventFilter.cpp
+ UrlRequestInterceptor.cpp
)
# Add the Qt logging category. This will create the `debug.h` header file.
Qt5::Core
Qt5::Gui
Qt5::Widgets
+ Qt5::WebEngineCore
Qt5::WebEngineWidgets
KF5::Completion
KF5::ConfigWidgets
#include "MouseEventFilter.h"
#include "Settings.h"
#include "ui_MainView.h"
+#include "UrlRequestInterceptor.h"
#include "helpers/SearchEngineHelper.h"
#include "helpers/UserAgentHelper.h"
// Listen for hovered link URLs.
connect(webEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(pageLinkHovered(const QString)));
+ // Instantiate the URL request interceptor.
+ UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor();
+
+ // Set the URL request interceptor.
+ webEngineProfilePointer->setUrlRequestInterceptor(urlRequestInterceptorPointer);
+
+ // Reapply the domain settings when the host changes.
+ connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings()), this, SLOT(applyDomainSettingsWithoutReloading()));
+
// Disable the cache.
webEngineProfilePointer->setHttpCacheType(QWebEngineProfile::NoCache);
// This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument.
void MainView::applyDomainSettingsAndReload() const
{
- // Apply the domain setings. `true` reloads the website.
+ // Apply the domain settings. `true` reloads the website.
applyDomainSettings(true);
}
+// This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument.
+void MainView::applyDomainSettingsWithoutReloading() const
+{
+ // Apply the domain settings `false` does not reload the website.
+ applyDomainSettings(false);
+}
+
void MainView::applyDomainSettings(bool reloadWebsite) const
{
// Set the JavaScript status.
explicit MainView(QWidget *parent);
signals:
- // Define the signals.
+ // The signals.
void linkHovered(const QString &linkUrl) const;
public Q_SLOTS:
- // Define the public slots.
+ // The public slots.
void applyApplicationSettings() const;
void applyDomainSettingsAndReload() const;
+ void applyDomainSettingsWithoutReloading() const;
private Q_SLOTS:
- // Define the private slots.
+ // The private slots.
void goHome() const;
void loadUrlFromTextBox(QString urlFromUser) const;
void pageLinkHovered(const QString &linkUrl) const;
void updateInterface() const;
private:
- // Define the private variables.
+ // The private variables.
QPushButton *backButtonPointer;
QPushButton *forwardButtonPointer;
QPushButton *javaScriptButtonPointer;
QWebEngineSettings *webEngineSettingsPointer;
QWebEngineView *webEngineViewPointer;
- // Define the private functions.
+ // The private functions.
void applyDomainSettings(bool reloadWebsite) const;
};
#endif
MouseEventFilter(QWebEngineView *webEngineView);
protected:
+ // The protected functions.
bool eventFilter(QObject *objectPointer, QEvent *eventPointer) override;
private:
- // Define the private variables.
+ // The private variables.
QWebEngineView *webEngineViewPointer;
};
#endif
--- /dev/null
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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 resource type.
+ switch (urlRequestInfo.resourceType())
+ {
+ case QWebEngineUrlRequestInfo::ResourceTypePing:
+ // Block HTTP ping requests.
+ urlRequestInfo.block(true);
+ break;
+
+ default:
+ // Do nothing.
+ break;
+ }
+
+ // Get the hosts.
+ QString requestingHost = urlRequestInfo.firstPartyUrl().host();
+ QString requestedHost = urlRequestInfo.requestUrl().host();
+
+ // Reapply the domain settings if the host is changing.
+ if (requestingHost != requestedHost)
+ {
+ emit applyDomainSettings();
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef URLREQUESTINTERCEPTOR_H
+#define URLREQUESTINTERCEPTOR_H
+
+// Qt framework headers.
+#include <QtWebEngineCore>
+
+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;
+};
+#endif