diff options
author | Marco Peereboom <marco@conformal.com> | 2010-12-22 23:18:16 +0000 |
---|---|---|
committer | Marco Peereboom <marco@conformal.com> | 2010-12-22 23:18:16 +0000 |
commit | 1ff47ed57671c94e1d94c1440690f844e872bb5c (patch) | |
tree | f3123a35b2e08bdf07c0b250e34d7c9e2945b957 /xxxterm.c | |
parent | feae18c5d974a00d4c5c42570365937a808b2856 (diff) | |
download | xombrero-1ff47ed57671c94e1d94c1440690f844e872bb5c.tar.gz |
Add runtime javascript toggle for current domain in tab
Diffstat (limited to 'xxxterm.c')
-rw-r--r-- | xxxterm.c | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/xxxterm.c b/xxxterm.c index cae7077..f231712 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -681,9 +681,9 @@ wl_find_uri(gchar *s, struct domain_list *wl) if (strlen(s) < 2) return (NULL); - for (i = 0; i < strlen(s); i++) + for (i = 0; i < strlen(s) + 1 /* yes er need this */; i++) /* chop string at first slash */ - if (s[i] == '/') { + if (s[i] == '/' || s[i] == '\0') { s[i] = '\0'; return (wl_find(s, wl)); } @@ -932,6 +932,54 @@ quit(struct tab *t, struct karg *args) } int +toggle_js(struct tab *t, struct karg *args) +{ + int es, i; + WebKitWebFrame *frame; + gchar *s; + struct domain *d; + + g_object_get((GObject *)t->settings, + "enable-scripts", &es, (char *)NULL); + es = !es; + g_object_set((GObject *)t->settings, + "enable-scripts", es, (char *)NULL); + webkit_web_view_set_settings(t->wv, t->settings); + + frame = webkit_web_view_get_main_frame(t->wv); + s = (gchar *)webkit_web_frame_get_uri(frame); + + /* this code is shared with wl_find_uri, refactor */ + if (s == NULL) + return (NULL); + + if (!strncmp(s, "http://", strlen("http://"))) + s = &s[strlen("http://")]; + else if (!strncmp(s, "https://", strlen("https://"))) + s = &s[strlen("https://")]; + + if (strlen(s) < 2) + return (NULL); + + for (i = 0; i < strlen(s) + 1; i++) + /* chop string at first slash */ + if (s[i] == '/' || s[i] == '\0') { + s[i] = '\0'; + if (es) + wl_add(s, &js_wl); + else { + d = wl_find(s, &js_wl); + if (d) + RB_REMOVE(domain_list, &js_wl, d); + } + webkit_web_view_reload(t->wv); + return (0); + } + + return (0); +} + +int focus(struct tab *t, struct karg *args) { if (t == NULL || args == NULL) @@ -1837,6 +1885,7 @@ struct key { { GDK_SHIFT_MASK, 0, GDK_question, command, {.i = '?'} }, { GDK_SHIFT_MASK, 0, GDK_colon, command, {.i = ':'} }, { GDK_CONTROL_MASK, 0, GDK_q, quit, {0} }, + { GDK_CONTROL_MASK, 0, GDK_j, toggle_js, {0} }, /* search */ { 0, 0, GDK_n, search, {.i = XT_SEARCH_NEXT} }, @@ -2245,7 +2294,6 @@ notify_load_status_cb(WebKitWebView* wview, GParamSpec* pspec, struct tab *t) gtk_widget_set_sensitive(GTK_WIDGET(t->stop), TRUE); t->focus_wv = 1; - /* check if js white listing is enabled */ if (enable_js_whitelist) { frame = webkit_web_view_get_main_frame(wview); |