logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: db4d18f3362bd4a2e8e3600385947435843f60a7
parent: caa5d088a9540ac18e2ff36b55e5bc522d9dd8a4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 15 Mar 2019 18:12:59 +0100

WIP: Using g_object_new(WEBKIT_TYPE_WEB_VIEW, …) and webkit_settings_new_with_settings(…)

Diffstat:

Mbadwolf.c75++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 38 insertions(+), 37 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -298,6 +298,7 @@ struct Client * new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view) { struct Client *browser = g_malloc(sizeof(struct Client)); + if(target_url == NULL) target_url = "about:blank"; browser->window = window; browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); @@ -307,24 +308,41 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web browser->javascript = gtk_check_button_new(); browser->statusbar = gtk_label_new(NULL); - if(related_web_view == NULL) - { - WebKitWebContext *web_context = webkit_web_context_new_ephemeral(); - - webkit_web_context_set_process_model(web_context, - WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES); - - browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_context(web_context)); - - if(target_url == NULL) - { - target_url = "about:blank"; - } - } - else - { - browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_related_view(related_web_view)); - } + WebKitWebContext *web_context = webkit_web_context_new_ephemeral(); + webkit_web_context_set_process_model(web_context, + WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES); + + WebKitSettings *settings = + webkit_settings_new_with_settings("default-charset", + "utf-8", + "enable-caret-browsing", + TRUE, + "enable-developer-extras", + TRUE, + "enable-java", + FALSE, + "enable-javascript", + FALSE, + "enable-plugins", + FALSE, + "javascript-can-access-clipboard", + FALSE, + "javascript-can-open-windows-automatically", + FALSE, + "media-playback-requires-user-gesture", + TRUE, + "minimum-font-size", + 9, + NULL); + + browser->webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, + "web-context", + webkit_web_context_new_ephemeral(), + "related-view", + related_web_view, + "settings", + settings, + NULL)); gtk_widget_set_tooltip_text(browser->javascript, "Toggle javascript"); @@ -354,7 +372,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web gtk_widget_set_halign(browser->statusbar, GTK_ALIGN_START); gtk_label_set_single_line_mode(GTK_LABEL(browser->statusbar), TRUE); - if(target_url != NULL) gtk_entry_set_text(GTK_ENTRY(browser->location), target_url); + gtk_entry_set_text(GTK_ENTRY(browser->location), target_url); gtk_entry_set_has_frame(GTK_ENTRY(browser->location), FALSE); gtk_entry_set_input_purpose(GTK_ENTRY(browser->location), GTK_INPUT_PURPOSE_URL); @@ -393,24 +411,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web browser->search, "search-changed", G_CALLBACK(SearchEntryCb_search__changed), browser); g_signal_connect(browser->search, "stop-search", G_CALLBACK(SearchEntryCb_stop__search), browser); - WebKitSettings *settings = webkit_web_view_get_settings(browser->webView); - - webkit_settings_set_default_charset(settings, "utf-8"); - webkit_settings_set_enable_caret_browsing(settings, TRUE); - webkit_settings_set_enable_developer_extras(settings, TRUE); - webkit_settings_set_enable_java(settings, FALSE); /* dangerous */ - webkit_settings_set_enable_javascript(settings, FALSE); /* sane default 😏 */ - webkit_settings_set_enable_plugins(settings, FALSE); /* dangerous */ - webkit_settings_set_javascript_can_access_clipboard(settings, FALSE); /* dangerous */ - webkit_settings_set_javascript_can_open_windows_automatically(settings, FALSE); /* dangerous */ - webkit_settings_set_media_playback_requires_user_gesture( - settings, TRUE); /* typically breaks notification sounds */ - webkit_settings_set_minimum_font_size(settings, - 9); /* text needs to be readable; screw broken pages */ - - webkit_web_view_set_settings(browser->webView, settings); - - if(target_url != NULL) webkit_web_view_load_uri(browser->webView, target_url); + webkit_web_view_load_uri(browser->webView, target_url); return browser; }