Skip to content

Commit

Permalink
Implement distinct storages on Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Apr 25, 2024
1 parent 81f15a7 commit 9f9bcaa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions webview/platform/linux/webview_linux_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<arg type='i' name='g' direction='in'/>
<arg type='i' name='b' direction='in'/>
<arg type='i' name='a' direction='in'/>
<arg type='s' name='path' direction='in'/>
</method>
<method name='Reload'/>
<method name='Resolve'>
Expand Down
36 changes: 32 additions & 4 deletions webview/platform/linux/webview_linux_webkitgtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,13 @@ bool Instance::create(Config config) {

const ::base::has_weak_ptr guard;
std::optional<bool> 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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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());
Expand Down
14 changes: 13 additions & 1 deletion webview/platform/linux/webview_linux_webkitgtk_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 13 additions & 1 deletion webview/platform/linux/webview_linux_webkitgtk_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9f9bcaa

Please sign in to comment.