]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/views/BrowserView.cpp
Change the cookie implementation to a QTreeView.
[PrivacyBrowserPC.git] / src / views / BrowserView.cpp
index 07ce5f5d897039339513fa075e6ed401d3d67906..82e7e3ee0d0614d4e32e78e8984a2d6da3a8f59c 100644 (file)
@@ -59,8 +59,9 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     webEngineSettingsPointer = webEngineViewPointer->settings();
     webEngineCookieStorePointer = webEngineProfilePointer->cookieStore();
 
-    // Store a copy of each cookie when it is added.
+    // Process cookie changes.
     connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), this, SLOT(cookieAdded(QNetworkCookie)));
+    connect(webEngineCookieStorePointer, SIGNAL(cookieRemoved(QNetworkCookie)), this, SLOT(cookieRemoved(QNetworkCookie)));
 
     // Store a copy of the WebEngine default user agent.
     webEngineDefaultUserAgent = webEngineProfilePointer->httpUserAgent();
@@ -120,6 +121,27 @@ BrowserView::~BrowserView()
     webEnginePagePointer->deleteLater();
 }
 
+// The cookie is copied instead of referenced so that changes made to the cookie do not create a race condition with the display of the cookie in the dialog.
+void BrowserView::addCookieToStore(QNetworkCookie cookie) const
+{
+    // Create a url.
+    QUrl url;
+
+    // Check to see if the domain does not start with a `.` because Qt makes this harder than it should be.  <https://doc.qt.io/qt-5/qwebenginecookiestore.html#setCookie>
+    if (!cookie.domain().startsWith(QStringLiteral(".")))
+    {
+        // Populate the URL.
+        url.setHost(cookie.domain());
+        url.setScheme(QStringLiteral("https"));
+
+        // Clear the domain from the cookie.
+        cookie.setDomain(QStringLiteral(""));
+    }
+
+    // Add the cookie to the store.
+    webEngineCookieStorePointer->setCookie(cookie, url);
+}
+
 void BrowserView::applyApplicationSettings()
 {
     // Set the search engine URL.
@@ -317,12 +339,24 @@ void BrowserView::cookieAdded(const QNetworkCookie &cookie) const
     emit addCookie(cookie);
 }
 
+void BrowserView::cookieRemoved(const QNetworkCookie &cookie) const
+{
+    // Remove the cookie from the cookie list.
+    emit removeCookie(cookie);
+}
+
 void BrowserView::deleteAllCookies() const
 {
     // Delete all the cookies.
     webEngineCookieStorePointer->deleteAllCookies();
 }
 
+void BrowserView::deleteCookieFromStore(const QNetworkCookie &cookie) const
+{
+    // Delete the cookie.
+    webEngineCookieStorePointer->deleteCookie(cookie);
+}
+
 void BrowserView::forward() const
 {
     // Go forward.