KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wxgtk/webview.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <kiplatform/webview.h>
21
22#include <wx/webview.h>
23#include <wx/log.h>
24#include <wx/ffile.h>
25#include <wx/filename.h>
26
27#include <nlohmann/json.hpp>
28
29#include <dlfcn.h>
30
31namespace KIPLATFORM::WEBVIEW
32{
33
34// Opaque types
35typedef struct _WebKitWebView WebKitWebView;
36typedef struct _WebKitWebContext WebKitWebContext;
37typedef struct _WebKitWebsiteDataManager WebKitWebsiteDataManager;
38
39// Constants
43
44// Function pointers
45typedef WebKitWebContext* (*webkit_web_view_get_context_t)(WebKitWebView*);
46typedef WebKitWebsiteDataManager* (*webkit_web_context_get_website_data_manager_t)(WebKitWebContext*);
48
49bool SaveCookies( wxWebView* aWebView, const wxString& aTargetFile )
50{
51 // Not implemented for GTK due to ABI issues with libsoup2/3
52 return false;
53}
54
55bool LoadCookies( wxWebView* aWebView, const wxString& aSourceFile )
56{
57 // Not implemented for GTK due to ABI issues with libsoup2/3
58 return false;
59}
60
61bool DeleteCookies( wxWebView* aWebView )
62{
63 if( !aWebView )
64 return false;
65
66 void* nativeBackend = aWebView->GetNativeBackend();
67
68 if( !nativeBackend )
69 return false;
70
71 // Load symbols
72 auto get_context = (webkit_web_view_get_context_t) dlsym(RTLD_DEFAULT, "webkit_web_view_get_context");
73 auto get_data_manager = (webkit_web_context_get_website_data_manager_t) dlsym(RTLD_DEFAULT, "webkit_web_context_get_website_data_manager");
74 auto clear_data = (webkit_website_data_manager_clear_t) dlsym(RTLD_DEFAULT, "webkit_website_data_manager_clear");
75
76 if( !get_context || !get_data_manager || !clear_data )
77 {
78 wxLogDebug("Failed to load WebKit symbols");
79 return false;
80 }
81
82 WebKitWebView* webView = (WebKitWebView*) nativeBackend;
83 WebKitWebContext* context = get_context(webView);
84 if( !context ) return false;
85
86 WebKitWebsiteDataManager* dataManager = get_data_manager(context);
87 if( !dataManager ) return false;
88
89 clear_data(dataManager, WEBKIT_WEBSITE_DATA_COOKIES, 0, nullptr, nullptr, nullptr);
90
91 return true;
92}
93
94} // namespace KIPLATFORM::WEBVIEW
95
void(* webkit_website_data_manager_clear_t)(WebKitWebsiteDataManager *, WebKitWebsiteDataTypes, int64_t, void *, void *, void *)
struct _WebKitWebView WebKitWebView
struct _WebKitWebsiteDataManager WebKitWebsiteDataManager
struct _WebKitWebContext WebKitWebContext
bool SaveCookies(wxWebView *aWebView, const wxString &aTargetFile)
Save cookies from the given WebView to the specified file.
bool LoadCookies(wxWebView *aWebView, const wxString &aSourceFile)
Load cookies from the specified file into the given WebView.
WebKitWebContext *(* webkit_web_view_get_context_t)(WebKitWebView *)
bool DeleteCookies(wxWebView *aWebView)
Delete all cookies from the given WebView.
WebKitWebsiteDataManager *(* webkit_web_context_get_website_data_manager_t)(WebKitWebContext *)