logo

badwolf

minimalist and privacy-oriented web browser based on WebKitGTK git clone https://hacktivis.me/git/badwolf.git
commit: 47be92a843fe469256ec136dd13f5b2ee69c7d27
parent 3ba43be13812acf9b8d12186d74468cd0e295b79
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 11 May 2019 08:16:38 +0200

ensure_uri_scheme: Don’t try to resolve as a file on opening a related view

Diffstat:

Mbadwolf.c21++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -37,7 +37,7 @@ struct Client GtkWidget *search; }; -gchar *ensure_uri_scheme(gchar *text); +gchar *ensure_uri_scheme(gchar *text, gbool try_file); static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); static gboolean commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser); @@ -83,15 +83,15 @@ notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gint get_tab_position(GtkContainer *notebook, GtkWidget *child); gchar * -ensure_uri_scheme(gchar *text) +ensure_uri_scheme(gchar *text, gbool try_file) { if(text == NULL) return "about:blank"; char *scheme = g_uri_parse_scheme(text); - if(scheme != NULL) - return text; - else + if(scheme != NULL) return text; + + if(try_file) { gchar *f; char *path; @@ -101,12 +101,11 @@ ensure_uri_scheme(gchar *text) { f = g_strdup_printf("file://%s", path); free(path); + return f; } - else - f = g_strdup_printf("http://%s", text); - - return f; } + + return g_strdup_printf("http://%s", text); } static void @@ -457,7 +456,7 @@ locationCb_activate(GtkEntry *location, gpointer user_data) char *target_url; struct Client *browser = (struct Client *)user_data; - target_url = ensure_uri_scheme((char *)gtk_entry_get_text(location)); + target_url = ensure_uri_scheme((char *)gtk_entry_get_text(location), FALSE); if(target_url != NULL) webkit_web_view_load_uri(browser->webView, target_url); @@ -531,7 +530,7 @@ struct Client * new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view) { struct Client *browser = g_malloc(sizeof(struct Client)); - target_url = ensure_uri_scheme(target_url); + target_url = ensure_uri_scheme(target_url, (related_web_view != NULL)); browser->window = window; browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);