2 * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers.
21 #include "PrivacyWebEngineView.h"
22 #include "databases/CookiesDatabase.h"
23 #include "windows/BrowserWindow.h"
25 // Construct the class.
26 PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr) {}
28 void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const
30 //qDebug() << "Add cookie: " << cookie.toRawForm();
32 // Add the new cookie to the list.
33 cookieListPointer->push_front(cookie);
35 // Update the cookie if it is durable and has new data.
36 if (CookiesDatabase::isUpdate(cookie))
37 CookiesDatabase::updateCookie(cookie);
39 // Update the cookies action.
40 emit updateCookiesAction(cookieListPointer->size());
43 QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType webWindowType) {
44 // Get a handle for the browser window.
45 BrowserWindow *browserWindowPointer = qobject_cast<BrowserWindow*>(window());
47 // Create the requsted window type.
48 switch (webWindowType) {
49 case QWebEnginePage::WebBrowserTab: {
50 // Create the new tab and return the privacy WebEngine view pointer. `true` removes the focus from the blank URL line edit.
51 // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu.
52 return browserWindowPointer->tabWidgetPointer->addTab(true);
55 case QWebEnginePage::WebBrowserWindow: {
56 // Create a new browser window.
57 BrowserWindow *newBrowserWindowPointer = new BrowserWindow();
59 // Show the new browser window.
60 newBrowserWindowPointer->show();
62 // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu.
63 return newBrowserWindowPointer->tabWidgetPointer->loadBlankInitialWebsite();
67 // Return an null pointer for opening a background tab and opening a web dialog.
73 void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const
75 //qDebug() << "Remove cookie: " << cookie.toRawForm();
77 // Remove the cookie from the list.
78 cookieListPointer->remove(cookie);
80 // Update the cookies action.
81 emit updateCookiesAction(cookieListPointer->size());