]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/views/BrowserView.cpp
Add a WebEngine Default user agent.
[PrivacyBrowserPC.git] / src / views / BrowserView.cpp
index 933a300816208a1ad3528b29fb429f8cab742564..2e29ea0caf9fd515690e9205f498cdd621659c20 100644 (file)
@@ -32,6 +32,9 @@
 #include <QAction>
 #include <QWebEngineProfile>
 
+// 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)));
 
@@ -75,9 +88,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);
 
@@ -209,7 +219,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
         webEngineViewPointer->setZoomFactor(currentZoomFactor);
 
         // Apply the domain settings palette to the URL line edit.
-        emit updateDomainSettingsIndicator(true);
+        emit updateDomainSettingsIndicator(true, domainRecord.field(DomainsDatabaseHelper::DOMAIN_NAME).value().toString());
     }
     else  // The hostname does not have domain settings.
     {
@@ -229,7 +239,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
         webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 
         // Apply the no domain settings palette to the URL line edit.
-        emit updateDomainSettingsIndicator(false);
+        emit updateDomainSettingsIndicator(false, QStringLiteral(""));
     }
 
     // Emit the update actions signals.
@@ -405,7 +415,7 @@ void BrowserView::toggleLocalStorage() const
 void BrowserView::updateUrl(const QUrl &url) const
 {
     // Update the URL line edit.
-    emit updateUrlLineEdit(url.toString());
+    emit updateUrlLineEdit(url);
 
     // Update the status of the forward and back buttons.
     emit updateBackAction(webEngineHistoryPointer->canGoBack());