]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/views/BrowserView.cpp
Initial Cookies implementation using a QVBoxLayout.
[PrivacyBrowserPC.git] / src / views / BrowserView.cpp
index 873b9476da8bd0cce0bd441e742e0f79d7febb05..07ce5f5d897039339513fa075e6ed401d3d67906 100644 (file)
@@ -30,7 +30,6 @@
 
 // Qt framework headers.
 #include <QAction>
-#include <QWebEngineProfile>
 
 // Initialize the public static variables.
 QString BrowserView::webEngineDefaultUserAgent = QStringLiteral("");
@@ -50,7 +49,7 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     webEngineProfilePointer = new QWebEngineProfile(QStringLiteral(""));
 
     // Create a WebEngine page.
-    QWebEnginePage *webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer);
+    webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer);
 
     // Set the WebEngine page.
     webEngineViewPointer->setPage(webEnginePagePointer);
@@ -58,6 +57,10 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     // Get handles for the aspects of the WebEngine.
     webEngineHistoryPointer = webEnginePagePointer->history();
     webEngineSettingsPointer = webEngineViewPointer->settings();
+    webEngineCookieStorePointer = webEngineProfilePointer->cookieStore();
+
+    // Store a copy of each cookie when it is added.
+    connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), this, SLOT(cookieAdded(QNetworkCookie)));
 
     // Store a copy of the WebEngine default user agent.
     webEngineDefaultUserAgent = webEngineProfilePointer->httpUserAgent();
@@ -111,6 +114,12 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     webEngineViewPointer->setFocus();
 }
 
+BrowserView::~BrowserView()
+{
+    // Delay the deletion of the WebEngine page to prevent the following error:  `Release of profile requested but WebEnginePage still not deleted. Expect troubles !`
+    webEnginePagePointer->deleteLater();
+}
+
 void BrowserView::applyApplicationSettings()
 {
     // Set the search engine URL.
@@ -302,6 +311,18 @@ void BrowserView::back() const
     webEngineViewPointer->back();
 }
 
+void BrowserView::cookieAdded(const QNetworkCookie &cookie) const
+{
+    // Add the cookie to the cookie list.
+    emit addCookie(cookie);
+}
+
+void BrowserView::deleteAllCookies() const
+{
+    // Delete all the cookies.
+    webEngineCookieStorePointer->deleteAllCookies();
+}
+
 void BrowserView::forward() const
 {
     // Go forward.