]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/widgets/PrivacyWebEngineView.cpp
Enable opening links in new windows.
[PrivacyBrowserPC.git] / src / widgets / PrivacyWebEngineView.cpp
index 28fb66da18f32d7b66420a3cf361b960b873f0d9..10a3a47fcf3f7124a194ce4c62f31b273c5eeaac 100644 (file)
@@ -20,6 +20,7 @@
 // Application headers.
 #include "PrivacyWebEngineView.h"
 #include "databases/CookiesDatabase.h"
+#include "windows/BrowserWindow.h"
 
 // Construct the class.
 PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr) {}
@@ -39,6 +40,36 @@ void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const
     emit updateCookiesAction(cookieListPointer->size());
 }
 
+QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType webWindowType) {
+    // Get a handle for the browser window.
+    BrowserWindow *browserWindowPointer = qobject_cast<BrowserWindow*>(window());
+
+    // Create the requsted window type.
+    switch (webWindowType) {
+        case QWebEnginePage::WebBrowserTab: {
+            // Create the new tab and return the privacy WebEngine view pointer.  `true` removes the focus from the blank URL line edit.
+            // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu.
+            return browserWindowPointer->tabWidgetPointer->addTab(true);
+        }
+
+        case QWebEnginePage::WebBrowserWindow: {
+            // Create a new browser window.
+            BrowserWindow *newBrowserWindowPointer = new BrowserWindow();
+
+            // Show the new browser window.
+            newBrowserWindowPointer->show();
+
+            // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu.
+            return newBrowserWindowPointer->tabWidgetPointer->loadBlankInitialWebsite();
+        }
+
+        default: {
+            // Return an null pointer for opening a background tab and opening a web dialog.
+            return nullptr;
+        }
+    }
+}
+
 void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const
 {
     //qDebug() << "Remove cookie:  " << cookie.toRawForm();