X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fviews%2FBrowserView.cpp;h=873b9476da8bd0cce0bd441e742e0f79d7febb05;hp=edcd26c0f42276cd77ceb88efc1b65adcdc131b4;hb=34816101e23ae2b489d64d540534125cf2c2e925;hpb=cca335d6b9751fbf0e87daa5f122a1b8770488c8 diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index edcd26c..873b947 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -19,9 +19,9 @@ // Application headers. #include "BrowserView.h" -#include "MouseEventFilter.h" #include "Settings.h" #include "ui_BrowserView.h" +#include "filters/MouseEventFilter.h" #include "helpers/DomainsDatabaseHelper.h" #include "helpers/SearchEngineHelper.h" #include "helpers/UserAgentHelper.h" @@ -32,6 +32,9 @@ #include #include +// Initialize the public static variables. +QString BrowserView::webEngineDefaultUserAgent = QStringLiteral(""); + BrowserView::BrowserView(QWidget *parent) : QWidget(parent) { // Instantiate the browser view UI. @@ -43,12 +46,22 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) // Get handles for the views. webEngineViewPointer = browserViewUi.webEngineView; + // Create an off-the-record profile (the default when no profile name is specified). + webEngineProfilePointer = new QWebEngineProfile(QStringLiteral("")); + + // Create a WebEngine page. + QWebEnginePage *webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer); + + // Set the WebEngine page. + webEngineViewPointer->setPage(webEnginePagePointer); + // Get handles for the aspects of the WebEngine. - QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page(); webEngineHistoryPointer = webEnginePagePointer->history(); - webEngineProfilePointer = webEnginePagePointer->profile(); webEngineSettingsPointer = webEngineViewPointer->settings(); + // Store a copy of the WebEngine default user agent. + webEngineDefaultUserAgent = webEngineProfilePointer->httpUserAgent(); + // Update the URL line edit when the URL changes. connect(webEngineViewPointer, SIGNAL(urlChanged(const QUrl)), this, SLOT(updateUrl(const QUrl))); @@ -58,11 +71,15 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) connect(webEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(loadFinished())); // Instantiate the mouse event filter pointer. - MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer); + MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(); // Install the mouse event filter. qApp->installEventFilter(mouseEventFilterPointer); + // Process mouse forward and back commands. + connect(mouseEventFilterPointer, SIGNAL(mouseBack()), this, SLOT(mouseBack())); + connect(mouseEventFilterPointer, SIGNAL(mouseForward()), this, SLOT(mouseForward())); + // Listen for hovered link URLs. connect(webEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(pageLinkHovered(const QString))); @@ -75,9 +92,6 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) // Reapply the domain settings when the host changes. connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings(QString)), this, SLOT(applyDomainSettingsWithoutReloading(QString))); - // Disable the cache. - webEngineProfilePointer->setHttpCacheType(QWebEngineProfile::NoCache); - // Don't allow JavaScript to open windows. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false); @@ -366,6 +380,32 @@ void BrowserView::loadUrlFromLineEdit(QString url) const } } +void BrowserView::mouseBack() const +{ + // Go back if possible. + if (webEngineHistoryPointer->canGoBack()) + { + // Clear the URL line edit focus. + emit clearUrlLineEditFocus(); + + // Go back. + webEngineViewPointer->back(); + } +} + +void BrowserView::mouseForward() const +{ + // Go forward if possible. + if (webEngineHistoryPointer->canGoForward()) + { + // Clear the URL line edit focus. + emit clearUrlLineEditFocus(); + + // Go forward. + webEngineViewPointer->forward(); + } +} + void BrowserView::pageLinkHovered(const QString &linkUrl) const { // Emit a signal so that the browser window can update the status bar.