diff --git a/webview/platform/linux/webview_linux_interface.xml b/webview/platform/linux/webview_linux_interface.xml index d689126..fd907e8 100644 --- a/webview/platform/linux/webview_linux_interface.xml +++ b/webview/platform/linux/webview_linux_interface.xml @@ -30,6 +30,7 @@ + diff --git a/webview/platform/linux/webview_linux_webkitgtk.cpp b/webview/platform/linux/webview_linux_webkitgtk.cpp index cb744ea..ec6ef3d 100644 --- a/webview/platform/linux/webview_linux_webkitgtk.cpp +++ b/webview/platform/linux/webview_linux_webkitgtk.cpp @@ -211,11 +211,13 @@ bool Instance::create(Config config) { const ::base::has_weak_ptr guard; std::optional success; + const auto debug = _debug; const auto r = config.opaqueBg.red(); const auto g = config.opaqueBg.green(); const auto b = config.opaqueBg.blue(); const auto a = config.opaqueBg.alpha(); - _helper.call_create(_debug, r, g, b, a, crl::guard(&guard, [&]( + const auto path = config.userDataPath; + _helper.call_create(debug, r, g, b, a, path, crl::guard(&guard, [&]( GObject::Object source_object, Gio::AsyncResult res) { success = _helper.call_create_finish(res, nullptr); @@ -263,7 +265,28 @@ bool Instance::create(Config config) { } else { gtk_widget_show_all(_window); } - _webview = webkit_web_view_new(); + + const auto base = config.userDataPath; + const auto baseCache = base + "/cache"; + const auto baseData = base + "/data"; + + if (webkit_network_session_new) { + _webview = GTK_WIDGET(g_object_new( + WEBKIT_TYPE_WEB_VIEW, + "network-session", + webkit_network_session_new(baseData.c_str(), baseCache.c_str()))); + } else { + WebKitWebsiteDataManager *data = webkit_website_data_manager_new( + "base-cache-directory", baseCache.c_str(), + "base-data-directory", baseData.c_str(), + nullptr); + WebKitWebContext *context = webkit_web_context_new_with_website_data_manager(data); + g_object_unref(data); + + _webview = webkit_web_view_new_with_context(context); + g_object_unref(context); + } + WebKitUserContentManager *manager = webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(_webview)); g_signal_connect_swapped( @@ -1054,8 +1077,13 @@ void Instance::registerHelperMethodHandlers() { int r, int g, int b, - int a) { - if (create({ .opaqueBg = QColor(r, g, b, a), .debug = debug })) { + int a, + const std::string &path) { + if (create({ + .opaqueBg = QColor(r, g, b, a), + .userDataPath = path, + .debug = debug, + })) { _helper.complete_create(invocation); } else { invocation.return_gerror(MethodError()); diff --git a/webview/platform/linux/webview_linux_webkitgtk_library.cpp b/webview/platform/linux/webview_linux_webkitgtk_library.cpp index 4feb976..c60d89d 100644 --- a/webview/platform/linux/webview_linux_webkitgtk_library.cpp +++ b/webview/platform/linux/webview_linux_webkitgtk_library.cpp @@ -44,7 +44,6 @@ ResolveResult Resolve(bool wayland) { && (wayland || LOAD_LIBRARY_SYMBOL(lib, gdk_x11_surface_get_xid) || LOAD_LIBRARY_SYMBOL(lib, gdk_x11_window_get_xid)) - && LOAD_LIBRARY_SYMBOL(lib, webkit_web_view_new) && LOAD_LIBRARY_SYMBOL(lib, webkit_web_view_get_type) && LOAD_LIBRARY_SYMBOL(lib, webkit_web_view_get_user_content_manager) && LOAD_LIBRARY_SYMBOL(lib, webkit_user_content_manager_register_script_message_handler) @@ -72,6 +71,19 @@ ResolveResult Resolve(bool wayland) { LOAD_LIBRARY_SYMBOL(lib, gtk_widget_show_all); LOAD_LIBRARY_SYMBOL(lib, gtk_widget_get_screen); LOAD_LIBRARY_SYMBOL(lib, webkit_javascript_result_get_js_value); + { + const auto available1 = LOAD_LIBRARY_SYMBOL(lib, webkit_web_view_new_with_context) + && LOAD_LIBRARY_SYMBOL(lib, webkit_website_data_manager_new) + && LOAD_LIBRARY_SYMBOL(lib, webkit_web_context_new_with_website_data_manager); + + const auto available2 = LOAD_LIBRARY_SYMBOL(lib, webkit_web_view_get_type) + && LOAD_LIBRARY_SYMBOL(lib, webkit_network_session_new); + if (!available1 && !available2) { + return ResolveResult::NoLibrary; + } + } + LOAD_LIBRARY_SYMBOL(lib, webkit_website_data_manager_new); + LOAD_LIBRARY_SYMBOL(lib, webkit_web_context_new_with_website_data_manager); { const auto available1 = LOAD_LIBRARY_SYMBOL(lib, jsc_value_to_string); diff --git a/webview/platform/linux/webview_linux_webkitgtk_library.h b/webview/platform/linux/webview_linux_webkitgtk_library.h index 2b2d3c8..2f65ea2 100644 --- a/webview/platform/linux/webview_linux_webkitgtk_library.h +++ b/webview/platform/linux/webview_linux_webkitgtk_library.h @@ -63,6 +63,9 @@ typedef struct _WebKitUserScript WebKitUserScript; typedef struct _WebKitWebView WebKitWebView; typedef struct _WebKitSettings WebKitSettings; typedef struct _WebKitScriptDialog WebKitScriptDialog; +typedef struct _WebKitWebsiteDataManager WebKitWebsiteDataManager; +typedef struct _WebKitWebContext WebKitWebContext; +typedef struct _WebKitNetworkSession WebKitNetworkSession; typedef enum { GTK_WINDOW_TOPLEVEL, @@ -197,7 +200,8 @@ inline void (*webkit_script_dialog_prompt_set_text)( WebKitScriptDialog *dialog, const gchar *text); -inline GtkWidget *(*webkit_web_view_new)(void); +inline GtkWidget *(*webkit_web_view_new)(); +inline GtkWidget *(*webkit_web_view_new_with_context)(WebKitWebContext *context); inline GType (*webkit_web_view_get_type)(void); inline WebKitUserContentManager *(*webkit_web_view_get_user_content_manager)( WebKitWebView *web_view); @@ -244,6 +248,14 @@ inline void (*webkit_web_view_run_javascript)( inline void (*webkit_web_view_set_background_color)( WebKitWebView *web_view, const GdkRGBA *rgba); +inline WebKitWebsiteDataManager *(*webkit_website_data_manager_new)( + const gchar *first_option_name, + ...); +inline WebKitWebContext *(*webkit_web_context_new_with_website_data_manager)( + WebKitWebsiteDataManager* manager); +inline WebKitNetworkSession *(*webkit_network_session_new)( + const char* data_directory, + const char* cache_directory); enum class ResolveResult { Success,