logo

badwolf

Unnamed repository; edit this file 'description' to name the repository.
commit: 7a7bcba953565ba17dcfd99b95d4fe66447663d0
parent: c7bb0f29adbc6b45c1b9902d8f624ac0c0145d05
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 23 Jan 2019 10:35:31 +0100

badwolf.c: Add javascript toggle

Diffstat:

Mbadwolf.c35++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -10,7 +10,11 @@ struct Client { GtkWidget *main_window; GtkWidget *box; + + GtkWidget *toolbar; + GtkWidget *javascript; GtkWidget *location; + GtkWidget *statusbar; WebKitWebView *webView; }; @@ -115,6 +119,20 @@ static gboolean locationCb_activate(GtkEntry *location, gpointer user_data) return TRUE; } +static gboolean javascriptCb_toggled(GtkButton *javascript, gpointer user_data) +{ + struct Client *browser = (struct Client *)user_data; + + WebKitSettings *settings = webkit_web_view_get_settings(browser->webView); + + gboolean javascript_enabled = webkit_settings_get_enable_javascript(settings); + webkit_settings_set_enable_javascript(settings, !javascript_enabled); + + webkit_web_view_set_settings(browser->webView, settings); + + return TRUE; +} + int main(int argc, char *argv[]) { struct Client *browser = calloc(1, sizeof(struct Client)); @@ -126,12 +144,18 @@ int main(int argc, char *argv[]) browser->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + browser->toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); browser->location = gtk_entry_new(); + browser->javascript = gtk_check_button_new(); browser->statusbar = gtk_label_new(NULL); browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); gtk_container_add(GTK_CONTAINER(browser->main_window), browser->box); - gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->location), FALSE, FALSE, 0); + + gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->javascript), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->location), TRUE, TRUE, 0); + + gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->toolbar), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->webView), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->statusbar), FALSE, FALSE, 0); @@ -140,7 +164,11 @@ int main(int argc, char *argv[]) gtk_entry_set_text(GTK_ENTRY(browser->location), target_url); g_signal_connect(browser->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL); + g_signal_connect(browser->location, "activate", G_CALLBACK(locationCb_activate), browser); + + g_signal_connect(browser->javascript, "toggled", G_CALLBACK(javascriptCb_toggled), browser); + g_signal_connect(browser->webView, "close", G_CALLBACK(WebViewCb_close), browser->main_window); g_signal_connect(browser->webView, "web-process-terminated", @@ -159,9 +187,10 @@ int main(int argc, char *argv[]) WebKitSettings *settings = webkit_web_view_get_settings(browser->webView); - webkit_settings_set_javascript_can_access_clipboard(settings, FALSE); - webkit_settings_set_enable_developer_extras(settings, TRUE); webkit_settings_set_default_charset(settings, "utf-8"); + webkit_settings_set_enable_developer_extras(settings, TRUE); + webkit_settings_set_enable_javascript(settings, FALSE); /* sane default 😏 */ + webkit_settings_set_javascript_can_access_clipboard(settings, FALSE); /* dangerous */ webkit_web_view_set_settings(browser->webView, settings);