]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/widgets/PrivacyWebEngineView.cpp
10bff6d14554f45a2d922d4a1ae831e935705637
[PrivacyBrowserPC.git] / src / widgets / PrivacyWebEngineView.cpp
1 /*
2  * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 // Application headers.
21 #include "PrivacyWebEngineView.h"
22 #include "databases/CookiesDatabase.h"
23 #include "windows/BrowserWindow.h"
24
25 // Construct the class.
26 PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr) {}
27
28 void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const
29 {
30     //qDebug() << "Add cookie:  " << cookie.toRawForm();
31
32     // Add the new cookie to the list.
33     cookieListPointer->push_front(cookie);
34
35     // Update the cookie if it is durable and has new data.
36     if (CookiesDatabase::isUpdate(cookie))
37         CookiesDatabase::updateCookie(cookie);
38
39     // Update the cookies action.
40     emit updateCookiesAction(cookieListPointer->size());
41 }
42
43 QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType webWindowType) {
44     qDebug().noquote().nospace() << "Web window type:  " << webWindowType;
45
46     // Get a handle for the browser window.
47     BrowserWindow *browserWindowPointer = qobject_cast<BrowserWindow*>(window());
48
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.  It will then be populated with the link from the context menu.
53             return browserWindowPointer->tabWidgetPointer->addTab();
54         }
55
56         default: {
57             // Return an null pointer.
58             return nullptr;
59         }
60     }
61 }
62
63 void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const
64 {
65     //qDebug() << "Remove cookie:  " << cookie.toRawForm();
66
67     // Remove the cookie from the list.
68     cookieListPointer->remove(cookie);
69
70     // Update the cookies action.
71     emit updateCookiesAction(cookieListPointer->size());
72 }