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 qDebug().noquote().nospace() << "Web window type: " << webWindowType;
46 // Get a handle for the browser window.
47 BrowserWindow *browserWindowPointer = qobject_cast<BrowserWindow*>(window());
49 // Create the requsted window type.
50 switch (webWindowType) {
51 case QWebEnginePage::WebBrowserTab: {
52 // Create the new tab and return the privacy WebEngine view pointer. `true` removes the focus from the blank URL line edit.
53 // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu.
54 return browserWindowPointer->tabWidgetPointer->addTab(true);
58 // Return an null pointer.
64 void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const
66 //qDebug() << "Remove cookie: " << cookie.toRawForm();
68 // Remove the cookie from the list.
69 cookieListPointer->remove(cookie);
71 // Update the cookies action.
72 emit updateCookiesAction(cookieListPointer->size());