From cb232d9e919d67c71a96d7ab1fc85cf5aa968b81 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 16 Jun 2020 01:45:13 +0200 Subject: Add webcontext hex id to tab label --- badwolf.h | 1 + 1 file changed, 1 insertion(+) (limited to 'badwolf.h') diff --git a/badwolf.h b/badwolf.h index 7911c33..99d7b78 100644 --- a/badwolf.h +++ b/badwolf.h @@ -26,6 +26,7 @@ struct Client GtkWidget *auto_load_images; GtkWidget *location; + int context_id; WebKitWebView *webView; struct Window *window; -- cgit v1.3.1-23-gd82d From 31e176f6f7c2ac8cf7d1c147a2f20c4e74b21932 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 16 Jun 2020 06:21:16 +0200 Subject: fix context_id incrementation --- badwolf.c | 23 ++++++++++++++--------- badwolf.h | 2 +- po/messages.pot | 50 +++++++++++++++++++++++++------------------------- 3 files changed, 40 insertions(+), 35 deletions(-) (limited to 'badwolf.h') diff --git a/badwolf.c b/badwolf.c index b0e2beb..a8b8802 100644 --- a/badwolf.c +++ b/badwolf.c @@ -293,10 +293,15 @@ WebViewCb_create(WebKitWebView *related_web_view, gpointer user_data) { (void)navigation_action; - struct Window *window = (struct Window *)user_data; - struct Client *browser = new_browser(window, NULL, related_web_view); + struct Client *old_browser = (struct Client *)user_data; + struct Client *browser = NULL; + + // shouldn't be needed but better be safe + old_browser->webView = related_web_view; + + browser = new_browser(old_browser->window, NULL, old_browser); - if(badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser) < 0) + if(badwolf_new_tab(GTK_NOTEBOOK(old_browser->window->notebook), browser) < 0) return NULL; else return browser->webView; @@ -590,16 +595,16 @@ widgetCb_drop_button3_event(GtkWidget *widget, GdkEvent *event, gpointer user_da } struct Client * -new_browser(struct Window *window, const gchar *target_url, WebKitWebView *related_web_view) +new_browser(struct Window *window, const gchar *target_url, struct Client *old_browser) { struct Client *browser = malloc(sizeof(struct Client)); - target_url = badwolf_ensure_uri_scheme(target_url, (related_web_view == NULL)); + target_url = badwolf_ensure_uri_scheme(target_url, (old_browser == NULL)); char *badwolf_l10n = NULL; if(browser == NULL) return NULL; browser->window = window; - browser->context_id = context_id_counter++; + browser->context_id = old_browser == NULL ? context_id_counter++ : old_browser->context_id; browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_name(browser->box, "browser__box"); @@ -670,7 +675,7 @@ new_browser(struct Window *window, const gchar *target_url, WebKitWebView *relat "web-context", web_context, "related-view", - related_web_view, + old_browser == NULL ? NULL : old_browser->webView, "settings", settings, NULL)); @@ -799,7 +804,7 @@ new_browser(struct Window *window, const gchar *target_url, WebKitWebView *relat "notify::estimated-load-progress", G_CALLBACK(WebViewCb_notify__estimated_load_progress), browser); - g_signal_connect(browser->webView, "create", G_CALLBACK(WebViewCb_create), window); + g_signal_connect(browser->webView, "create", G_CALLBACK(WebViewCb_create), browser); g_signal_connect(browser->webView, "close", G_CALLBACK(WebViewCb_close), browser); g_signal_connect( browser->webView, "key-press-event", G_CALLBACK(WebViewCb_key_press_event), browser); @@ -830,7 +835,7 @@ new_browser(struct Window *window, const gchar *target_url, WebKitWebView *relat /* signals for box container */ g_signal_connect(browser->box, "key-press-event", G_CALLBACK(boxCb_key_press_event), browser); - if(related_web_view == NULL) webkit_web_view_load_uri(browser->webView, target_url); + if(old_browser == NULL) webkit_web_view_load_uri(browser->webView, target_url); return browser; } diff --git a/badwolf.h b/badwolf.h index 99d7b78..530f9c8 100644 --- a/badwolf.h +++ b/badwolf.h @@ -38,7 +38,7 @@ struct Client GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser); void webView_tab_label_change(struct Client *browser, const gchar *title); struct Client * -new_browser(struct Window *window, const gchar *target_url, WebKitWebView *related_web_view); +new_browser(struct Window *window, const gchar *target_url, struct Client *old_browser); int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser); gint badwolf_get_tab_position(GtkContainer *notebook, GtkWidget *child); #endif /* BADWOLF_H_INCLUDED */ diff --git a/po/messages.pot b/po/messages.pot index c150e4e..e669e74 100644 --- a/po/messages.pot +++ b/po/messages.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: Badwolf 1.0.0+g4b85e08.context-id\n" +"Project-Id-Version: Badwolf 1.0.0+g5c8cf6d.develop\n" "Report-Msgid-Bugs-To: contact+badwolf-msgid@hacktivis.me\n" -"POT-Creation-Date: 2020-06-16 01:41+0200\n" +"POT-Creation-Date: 2020-06-16 06:32+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -41,16 +41,16 @@ msgstr "" msgid "Badwolf Downloads" msgstr "" -#: badwolf.c:920 +#: badwolf.c:925 #, c-format msgid "Buildtime WebKit version: %d.%d.%d\n" msgstr "" -#: badwolf.c:412 +#: badwolf.c:417 msgid "Continue" msgstr "" -#: badwolf.c:362 +#: badwolf.c:367 msgid "" "Couldn't verify the TLS certificate to ensure a better security of the " "connection. You might want to verify your machine and network.\n" @@ -65,31 +65,31 @@ msgstr "" msgid "Download starting…" msgstr "" -#: badwolf.c:385 +#: badwolf.c:390 msgid "Error: Some unknown error occurred validating the certificate.\n" msgstr "" -#: badwolf.c:366 +#: badwolf.c:371 msgid "Error: The X509 Certificate Authority is unknown.\n" msgstr "" -#: badwolf.c:379 +#: badwolf.c:384 msgid "Error: The certificate has been revoked.\n" msgstr "" -#: badwolf.c:376 +#: badwolf.c:381 msgid "Error: The certificate has expired. Check your system's clock.\n" msgstr "" -#: badwolf.c:382 +#: badwolf.c:387 msgid "Error: The certificate is considered to be insecure.\n" msgstr "" -#: badwolf.c:373 +#: badwolf.c:378 msgid "Error: The certificate isn't valid yet. Check your system's clock.\n" msgstr "" -#: badwolf.c:369 +#: badwolf.c:374 msgid "Error: The given identity doesn't match the expected one.\n" msgstr "" @@ -100,11 +100,11 @@ msgid "" "Runtime WebKit version: %d.%d.%d" msgstr "" -#: badwolf.c:849 +#: badwolf.c:854 msgid "New tab" msgstr "" -#: badwolf.c:969 +#: badwolf.c:974 msgid "Open new tab" msgstr "" @@ -112,30 +112,30 @@ msgstr "" msgid "Out of Memory" msgstr "" -#: badwolf.c:918 +#: badwolf.c:923 #, c-format msgid "Running Badwolf version: %s\n" msgstr "" -#: badwolf.c:925 +#: badwolf.c:930 #, c-format msgid "Runtime WebKit version: %d.%d.%d\n" msgstr "" -#: badwolf.c:409 +#: badwolf.c:414 #, c-format msgid "TLS Error for %s." msgstr "" -#: badwolf.c:412 +#: badwolf.c:417 msgid "Temporarily Add Exception" msgstr "" -#: badwolf.c:620 +#: badwolf.c:625 msgid "Toggle javascript" msgstr "" -#: badwolf.c:625 +#: badwolf.c:630 msgid "Toggle loading images automatically" msgstr "" @@ -143,15 +143,15 @@ msgstr "" msgid "Unknown Crash" msgstr "" -#: badwolf.c:623 +#: badwolf.c:628 msgid "_IMG" msgstr "" -#: badwolf.c:618 +#: badwolf.c:623 msgid "_JS" msgstr "" -#: badwolf.c:738 +#: badwolf.c:743 msgid "search in current page" msgstr "" @@ -167,12 +167,12 @@ msgstr "" msgid "the web process terminated for an unknown reason.\n" msgstr "" -#: badwolf.c:932 +#: badwolf.c:937 #, c-format msgid "webkit-web-extension directory set to: %s\n" msgstr "" #. TRANSLATOR Ignore this entry. Done for forcing Unicode in xgettext. -#: badwolf.c:1003 +#: badwolf.c:1008 msgid "ø" msgstr "" -- cgit v1.3.1-23-gd82d From eaf289e8ebb017f7de4081a1564737da044dd341 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 4 Jul 2020 07:15:29 +0200 Subject: Switch automatically to a tab when user-requested This changes behavior but doesn't breaks meaning nor documentation and significantly improves usability. So meant to be applied directly into 1.0.x release branch. Closes: https://gitlab.com/lanodan/badWolf/-/issues/8 --- badwolf.c | 18 ++++++++++++------ badwolf.h | 2 +- keybindings.c | 6 ++++-- po/messages.pot | 18 +++++++++--------- 4 files changed, 26 insertions(+), 18 deletions(-) (limited to 'badwolf.h') diff --git a/badwolf.c b/badwolf.c index 6bb0470..d3dcde9 100644 --- a/badwolf.c +++ b/badwolf.c @@ -300,7 +300,7 @@ WebViewCb_create(WebKitWebView *related_web_view, browser = new_browser(old_browser->window, NULL, old_browser); - if(badwolf_new_tab(GTK_NOTEBOOK(old_browser->window->notebook), browser) < 0) + if(badwolf_new_tab(GTK_NOTEBOOK(old_browser->window->notebook), browser, FALSE) < 0) return NULL; else return browser->webView; @@ -839,7 +839,8 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b return browser; } -/* badwolf_new_tab: Inserts struct Client *browser in GtkNotebook *notebook +/* badwolf_new_tab: Inserts struct Client *browser in GtkNotebook *notebook + * and optionally switches selected tab to it. * * returns: * 0 : Ran successfully @@ -847,7 +848,7 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b * -2 : browser is NULL */ int -badwolf_new_tab(GtkNotebook *notebook, struct Client *browser) +badwolf_new_tab(GtkNotebook *notebook, struct Client *browser, bool auto_switch) { gint current_page = gtk_notebook_get_current_page(notebook); gchar *title = _("New tab"); @@ -864,6 +865,11 @@ badwolf_new_tab(GtkNotebook *notebook, struct Client *browser) gtk_widget_queue_draw(GTK_WIDGET(notebook)); + if(auto_switch) + { + gtk_notebook_set_current_page(notebook, gtk_notebook_page_num(notebook, browser->box)); + } + return 0; } @@ -874,7 +880,7 @@ new_tabCb_clicked(GtkButton *new_tab, gpointer user_data) struct Window *window = (struct Window *)user_data; struct Client *browser = new_browser(window, NULL, NULL); - badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser); + badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser, TRUE); } static void @@ -982,10 +988,10 @@ main(int argc, char *argv[]) gtk_widget_show_all(window->main_window); if(argc == 1) - badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, NULL, NULL)); + badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, NULL, NULL), FALSE); else for(int i = 1; i < argc; ++i) - badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, argv[i], NULL)); + badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, argv[i], NULL), FALSE); gtk_notebook_set_current_page(GTK_NOTEBOOK(window->notebook), 1); diff --git a/badwolf.h b/badwolf.h index 530f9c8..a375be6 100644 --- a/badwolf.h +++ b/badwolf.h @@ -39,6 +39,6 @@ GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser); void webView_tab_label_change(struct Client *browser, const gchar *title); struct Client * new_browser(struct Window *window, const gchar *target_url, struct Client *old_browser); -int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser); +int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser, bool auto_switch); gint badwolf_get_tab_position(GtkContainer *notebook, GtkWidget *child); #endif /* BADWOLF_H_INCLUDED */ diff --git a/keybindings.c b/keybindings.c index 75860ed..95e3fd5 100644 --- a/keybindings.c +++ b/keybindings.c @@ -14,7 +14,7 @@ about_dialogCb_activate_link(GtkAboutDialog *about_dialog, gchar *uri, gpointer (void)about_dialog; struct Window *window = (struct Window *)user_data; - badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, uri, NULL)); + badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, uri, NULL), FALSE); gtk_widget_destroy(GTK_WIDGET(about_dialog)); @@ -112,7 +112,9 @@ commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client * { case GDK_KEY_Page_Down: gtk_notebook_next_page(notebook); return TRUE; case GDK_KEY_Page_Up: gtk_notebook_prev_page(notebook); return TRUE; - case GDK_KEY_t: badwolf_new_tab(notebook, new_browser(window, NULL, NULL)); return TRUE; + case GDK_KEY_t: + badwolf_new_tab(notebook, new_browser(window, NULL, NULL), TRUE); + return TRUE; } } } diff --git a/po/messages.pot b/po/messages.pot index b2ca404..fd9ca35 100644 --- a/po/messages.pot +++ b/po/messages.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: Badwolf 1.0.0+g498bce5.develop\n" +"Project-Id-Version: Badwolf 1.0.0+ge94212d.develop\n" "Report-Msgid-Bugs-To: contact+badwolf-msgid@hacktivis.me\n" -"POT-Creation-Date: 2020-07-04 06:53+0200\n" +"POT-Creation-Date: 2020-07-04 07:13+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -41,7 +41,7 @@ msgstr "" msgid "Badwolf Downloads" msgstr "" -#: badwolf.c:913 +#: badwolf.c:919 #, c-format msgid "Buildtime WebKit version: %d.%d.%d\n" msgstr "" @@ -100,11 +100,11 @@ msgid "" "Runtime WebKit version: %d.%d.%d" msgstr "" -#: badwolf.c:853 +#: badwolf.c:854 msgid "New tab" msgstr "" -#: badwolf.c:962 +#: badwolf.c:968 msgid "Open new tab" msgstr "" @@ -112,12 +112,12 @@ msgstr "" msgid "Out of Memory" msgstr "" -#: badwolf.c:911 +#: badwolf.c:917 #, c-format msgid "Running Badwolf version: %s\n" msgstr "" -#: badwolf.c:918 +#: badwolf.c:924 #, c-format msgid "Runtime WebKit version: %d.%d.%d\n" msgstr "" @@ -167,12 +167,12 @@ msgstr "" msgid "the web process terminated for an unknown reason.\n" msgstr "" -#: badwolf.c:925 +#: badwolf.c:931 #, c-format msgid "webkit-web-extension directory set to: %s\n" msgstr "" #. TRANSLATOR Ignore this entry. Done for forcing Unicode in xgettext. -#: badwolf.c:996 +#: badwolf.c:1002 msgid "ø" msgstr "" -- cgit v1.3.1-23-gd82d From c2b4c8fb07b50c064d8ffe5ce02e84e21b6cffaa Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 26 Oct 2020 07:28:06 +0100 Subject: Use [A..Z] instead of [0..F] for representing the context_id --- badwolf.c | 29 ++++++++++++++++++++++++++--- badwolf.h | 2 +- interface.txt | 2 +- 3 files changed, 28 insertions(+), 5 deletions(-) (limited to 'badwolf.h') diff --git a/badwolf.c b/badwolf.c index 665f144..0d391e1 100644 --- a/badwolf.c +++ b/badwolf.c @@ -21,7 +21,7 @@ const gchar *homepage = "https://hacktivis.me/projects/badwolf"; const gchar *version = VERSION; static gchar *web_extensions_directory; -static int context_id_counter = 0; +static uint64_t context_id_counter = 0; GtkTreeModel *bookmarks_completion_model; static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); @@ -130,13 +130,36 @@ WebViewCb_notify__uri(WebKitWebView *webView, GParamSpec *pspec, gpointer user_d return TRUE; } +static char * +fmt_context_id(uint64_t num, char *out) +{ + const char alpha_digits[27] = {" ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + char buf[66] = {'\0'}; + int i, len = 0; + + // Get 0 = 'A' instead of 0 = '' and 1 = 'A' + num++; + + buf[len++] = ' '; + buf[len++] = ':'; + do + { + buf[len++] = alpha_digits[num % 26]; + } while(num /= 26); + + for(i = 0; len > 0; i++) + out[i] = buf[--len]; + + return out; +} + GtkWidget * badwolf_new_tab_box(const gchar *title, struct Client *browser) { (void)browser; - char context_id_str[7]; + char context_id_str[7] = ""; - snprintf(context_id_str, 7, "%4X: ", browser->context_id); + fmt_context_id(browser->context_id, context_id_str); GtkWidget *tab_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_set_name(tab_box, "browser__tabbox"); diff --git a/badwolf.h b/badwolf.h index a375be6..8a4edec 100644 --- a/badwolf.h +++ b/badwolf.h @@ -26,7 +26,7 @@ struct Client GtkWidget *auto_load_images; GtkWidget *location; - int context_id; + uint64_t context_id; WebKitWebView *webView; struct Window *window; diff --git a/interface.txt b/interface.txt index f23a149..42f7f5c 100644 --- a/interface.txt +++ b/interface.txt @@ -3,7 +3,7 @@ - Each tab contains a Browser View or the Downloads View ## Tab Labels -- An hexadecimal number identifying the webkit process context +- An A-Z represented number identifying the webkit process context - An icon to indicate if a media is playing - The title of the web view - A close button -- cgit v1.3.1-23-gd82d From af32582914ca06ff422ea4f7bad0f593447fd8da Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 28 Oct 2020 06:48:50 +0100 Subject: badwolf.h: Have uint64_t defined, explain context_id decision --- badwolf.h | 1 + decisions.md | 3 +++ 2 files changed, 4 insertions(+) (limited to 'badwolf.h') diff --git a/badwolf.h b/badwolf.h index 8a4edec..fc3328f 100644 --- a/badwolf.h +++ b/badwolf.h @@ -3,6 +3,7 @@ #include #include +#include /* uint64_t */ extern const gchar *homepage; extern const gchar *version; diff --git a/decisions.md b/decisions.md index 7d0712e..7e254ad 100644 --- a/decisions.md +++ b/decisions.md @@ -5,6 +5,9 @@ Bascially, the idea is to have a file in your projects repo, where you record the decisions you make over the course of the project's lifetime. Rewriting history will not be done but Post-Scriptum notices will. +## 2020-10-22 : Mark the context_id as A-Z instead of Hex +The way I did it at first was to use the hexadecimal representation, but as it starts from 0 there could be confusions with a shortcut hint for alt-n, there could still be confusion with some kind of tab numbering but with a bit of usage it's hopefully going to be obvious. + ## 2020-07-04 : Automatically switch to a user-created tab / Breaking the UI I got pointed out that when creating a new tab the user has to needlessly switch to it while it could be done when they request it. I also decided to still release it in a point release, so without bump of Major because while it does changes the behavior it doesn't break the associated meaning, while this would be a breaking change for an API I could take it as a minor adjustment in a user-interface. -- cgit v1.3.1-23-gd82d From 13b89829812598a1d2612d8304491afbcf01cf55 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 1 Nov 2020 23:56:49 +0100 Subject: Makefile: Fix PIE/PIC flags --- Makefile | 2 +- badwolf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'badwolf.h') diff --git a/Makefile b/Makefile index 7b24b4d..a7409ab 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ DATADIR ?= $(PREFIX)/share/badwolf APPSDIR ?= $(PREFIX)/share/applications CC ?= cc -CFLAGS ?= -g -O2 -fPIC -fPIE -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wconversion -Wsign-conversion -O2 -Werror=implicit-function-declaration -Werror=implicit-int -Werror=vla +CFLAGS ?= -g -O2 -pie -fPIE -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wconversion -Wsign-conversion -O2 -Werror=implicit-function-declaration -Werror=implicit-int -Werror=vla DBG ?= PKGCONFIG ?= pkg-config MSGFMT ?= msgfmt diff --git a/badwolf.h b/badwolf.h index fc3328f..e5b33f0 100644 --- a/badwolf.h +++ b/badwolf.h @@ -2,8 +2,8 @@ #define BADWOLF_H_INCLUDED #include -#include #include /* uint64_t */ +#include extern const gchar *homepage; extern const gchar *version; -- cgit v1.3.1-23-gd82d From 5547d3a708e75a62553b19c81e1afc66ef668a5c Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 15 Mar 2019 10:26:31 +0100 Subject: Handle WebKit content-filter --- badwolf.1 | 19 +++++++++---- badwolf.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- badwolf.h | 2 ++ po/messages.pot | 87 +++++++++++++++++++++++++++++++++++++-------------------- 4 files changed, 156 insertions(+), 39 deletions(-) (limited to 'badwolf.h') diff --git a/badwolf.1 b/badwolf.1 index 68a39ed..ae2dfa1 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -1,6 +1,6 @@ -./" BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser -./" Copyright © 2019-2020 Badwolf Authors -./" SPDX-License-Identifier: BSD-3-Clause +.\" BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser +.\" Copyright © 2019-2021 Badwolf Authors +.\" SPDX-License-Identifier: BSD-3-Clause .Dd 2019-10-31 .Dt BADWOLF 1 .Sh NAME @@ -75,6 +75,16 @@ A more generic variable name is also intended to be used in the future. .El .Sh FILES .Bl -tag -width Ds -compact +.It Pa ${XDG_CONFIG_HOME:-$HOME/.config}/badwolf/content-filters.json +WebKit-specific content-filter file, this allows to block unwanted content (ads, nagware, ...). +For some introductory information about the format see: +.Lk https://webkit.org/blog/3476/content-blockers-first-look/ +.Pp +For a converter using AblockPlus-style filters, try: +.Lk https://gitlab.com/eyeo/adblockplus/abp2blocklist +.Pp +For a ready-to-use file (that you should update periodically), try: +.Lk https://easylist-downloads.adblockplus.org/easylist_min_content_blocker.json .It Pa ${XDG_DATA_HOME:-$HOME/.local/share}/badwolf/bookmarks.xbel XBEL (XML Bookmark Exchange Language) file, known to be currently supported by: .Xr elinks 1 , @@ -90,10 +100,7 @@ to be loaded into .Nm . Note: They aren't the JavaScript-based Web-Extensions supported by Firefox or Chrome, but native code in shared objects using the WebKitGTK API. .Pp Examples of useful extensions may be found at: -.Bl -item -compact .Lk https://hacktivis.me/git/badwolf-extensions -.Lk https://github.com/jun7/wyebadblock -.El .It Pa ${DATADIR:-/usr/local/share}/badwolf/interface.css .It Pa ${XDG_DATA_HOME:-$HOME/.local/share}/badwolf/interface.css CSS files (respectively system and user-level) for styling badwolf interface. diff --git a/badwolf.c b/badwolf.c index 23c444c..ec2a691 100644 --- a/badwolf.c +++ b/badwolf.c @@ -70,6 +70,7 @@ static void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data); static void closeCb_clicked(GtkButton *close, gpointer user_data); static void notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data); +void content_managerCb_ready(GObject *store, GAsyncResult *result, gpointer user_data); static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data) @@ -710,6 +711,8 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b old_browser == NULL ? NULL : old_browser->webView, "settings", settings, + "user-content-manager", + window->content_manager, NULL)); gtk_widget_set_name(GTK_WIDGET(browser->webView), "browser__webView"); if(old_browser == NULL) @@ -950,10 +953,73 @@ notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gtk_window_set_title(GTK_WINDOW(window->main_window), gtk_widget_get_tooltip_text(label)); } +void +content_managerCb_ready(GObject *store, GAsyncResult *result, gpointer user_data) +{ + struct Window *window = (struct Window *)user_data; + GError *err = NULL; + + WebKitUserContentFilter *filter = + webkit_user_content_filter_store_load_finish(window->content_store, result, &err); + + if(filter == NULL) + { + if(err == NULL) + { + fprintf(stderr, _("badwolf: failed to load content-filter, err: [%d] %s\n"), -1, "unknown"); + } + else + { + fprintf(stderr, + _("badwolf: failed to load content-filter, err: [%d] %s\n"), + err->code, + err->message); + } + } + else + { + fprintf(stderr, _("badwolf: content-filter loaded, adding to content-manager…\n")); + webkit_user_content_manager_add_filter(window->content_manager, filter); + } +} + +static void +storeCb_finish(WebKitUserContentFilterStore *store, GAsyncResult *result, gpointer user_data) +{ + struct Window *window = (struct Window *)user_data; + GError *err = NULL; + + WebKitUserContentFilter *filter = + webkit_user_content_filter_store_save_finish(window->content_store, result, &err); + + if(filter == NULL) + { + if(err == NULL) + { + fprintf(stderr, + _("badwolf: failed to compile content-filters.json, err: [%d] %s\n"), + -1, + "unknown"); + } + else + { + fprintf(stderr, + _("badwolf: failed to compile content-filters.json, err: [%d] %s\n"), + err->code, + err->message); + } + } + else + { + webkit_user_content_filter_store_load( + window->content_store, "a", NULL, content_managerCb_ready, window); + } +} + int main(int argc, char *argv[]) { - struct Window *window = &(struct Window){NULL, NULL, NULL, NULL}; + struct Window *window = &(struct Window){NULL, NULL, NULL, NULL, NULL, NULL}; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, DATADIR "/locale"); bind_textdomain_codeset(PACKAGE, "UTF-8"); @@ -983,7 +1049,24 @@ main(int argc, char *argv[]) window->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); window->notebook = gtk_notebook_new(); window->new_tab = gtk_button_new_from_icon_name("tab-new-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); - window->downloads_tab = badwolf_downloads_tab_new(); + window->downloads_tab = badwolf_downloads_tab_new(); + window->content_manager = webkit_user_content_manager_new(); + + gchar *contentFilterPath = + g_build_filename(g_get_user_config_dir(), g_get_prgname(), "content-filters.json", NULL); + GFile *contentFilterFile = g_file_new_for_path(contentFilterPath); + fprintf(stderr, _("content-filters file set to: %s\n"), contentFilterPath); + + gchar *filtersPath = g_build_filename(g_get_user_cache_dir(), g_get_prgname(), "filters", NULL); + fprintf(stderr, _("content-filters directory set to: %s\n"), filtersPath); + window->content_store = webkit_user_content_filter_store_new(filtersPath); + + webkit_user_content_filter_store_save_from_file(window->content_store, + "a", + contentFilterFile, + NULL, + (GAsyncReadyCallback)storeCb_finish, + window); gtk_window_set_default_size( GTK_WINDOW(window->main_window), BADWOLF_DEFAULT_WIDTH, BADWOLF_DEFAULT_HEIGHT); diff --git a/badwolf.h b/badwolf.h index e5b33f0..7919be8 100644 --- a/badwolf.h +++ b/badwolf.h @@ -14,6 +14,8 @@ struct Window GtkWidget *notebook; GtkWidget *new_tab; GtkWidget *downloads_tab; + WebKitUserContentManager *content_manager; + WebKitUserContentFilterStore *content_store; }; struct Client diff --git a/po/messages.pot b/po/messages.pot index c5a821c..093ddf2 100644 --- a/po/messages.pot +++ b/po/messages.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: Badwolf 1.0.3+g1b10b339.develop\n" +"Project-Id-Version: Badwolf 1.0.3+gdf1e25f.content-blockers\n" "Report-Msgid-Bugs-To: contact+badwolf-msgid@hacktivis.me\n" -"POT-Creation-Date: 2021-03-30 14:25+0200\n" +"POT-Creation-Date: 2021-04-09 06:17+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -74,23 +74,23 @@ msgstr "" msgid "Bookmarks: unable to parse file \"%s\"\n" msgstr "" -#: badwolf.c:954 +#: badwolf.c:1030 #, c-format msgid "Buildtime WebKit version: %d.%d.%d\n" msgstr "" -#: badwolf.c:439 +#: badwolf.c:440 msgid "Continue" msgstr "" -#: badwolf.c:389 +#: badwolf.c:390 msgid "" "Couldn't verify the TLS certificate to ensure a better security of the " "connection. You might want to verify your machine and network.\n" "\n" msgstr "" -#: badwolf.c:99 +#: badwolf.c:100 msgid "Crashed" msgstr "" @@ -98,31 +98,31 @@ msgstr "" msgid "Download starting…" msgstr "" -#: badwolf.c:412 +#: badwolf.c:413 msgid "Error: Some unknown error occurred validating the certificate.\n" msgstr "" -#: badwolf.c:393 +#: badwolf.c:394 msgid "Error: The X509 Certificate Authority is unknown.\n" msgstr "" -#: badwolf.c:406 +#: badwolf.c:407 msgid "Error: The certificate has been revoked.\n" msgstr "" -#: badwolf.c:403 +#: badwolf.c:404 msgid "Error: The certificate has expired. Check your system's clock.\n" msgstr "" -#: badwolf.c:409 +#: badwolf.c:410 msgid "Error: The certificate is considered to be insecure.\n" msgstr "" -#: badwolf.c:400 +#: badwolf.c:401 msgid "Error: The certificate isn't valid yet. Check your system's clock.\n" msgstr "" -#: badwolf.c:396 +#: badwolf.c:397 msgid "Error: The given identity doesn't match the expected one.\n" msgstr "" @@ -133,79 +133,104 @@ msgid "" "Runtime WebKit version: %d.%d.%d" msgstr "" -#: badwolf.c:889 +#: badwolf.c:904 msgid "New tab" msgstr "" -#: badwolf.c:1006 +#: badwolf.c:1099 msgid "Open new tab" msgstr "" -#: badwolf.c:103 +#: badwolf.c:104 msgid "Out of Memory" msgstr "" -#: badwolf.c:952 +#: badwolf.c:1028 #, c-format msgid "Running Badwolf version: %s\n" msgstr "" -#: badwolf.c:959 +#: badwolf.c:1035 #, c-format msgid "Runtime WebKit version: %d.%d.%d\n" msgstr "" -#: badwolf.c:436 +#: badwolf.c:437 #, c-format msgid "TLS Error for %s." msgstr "" -#: badwolf.c:439 +#: badwolf.c:440 msgid "Temporarily Add Exception" msgstr "" -#: badwolf.c:647 +#: badwolf.c:650 msgid "Toggle javascript" msgstr "" -#: badwolf.c:652 +#: badwolf.c:655 msgid "Toggle loading images automatically" msgstr "" -#: badwolf.c:107 +#: badwolf.c:108 msgid "Unknown Crash" msgstr "" -#: badwolf.c:650 +#: badwolf.c:653 msgid "_IMG" msgstr "" -#: badwolf.c:645 +#: badwolf.c:648 msgid "_JS" msgstr "" -#: badwolf.c:777 +#: badwolf.c:981 +#, c-format +msgid "badwolf: content-filter loaded, adding to content-manager…\n" +msgstr "" + +#: badwolf.c:999 badwolf.c:1004 +#, c-format +msgid "badwolf: failed to compile content-filters.json, err: [%d] %s\n" +msgstr "" + +#: badwolf.c:969 badwolf.c:974 +#, c-format +msgid "badwolf: failed to load content-filter, err: [%d] %s\n" +msgstr "" + +#: badwolf.c:1059 +#, c-format +msgid "content-filters directory set to: %s\n" +msgstr "" + +#: badwolf.c:1056 +#, c-format +msgid "content-filters file set to: %s\n" +msgstr "" + +#: badwolf.c:792 msgid "search in current page" msgstr "" -#: badwolf.c:98 +#: badwolf.c:99 msgid "the web process crashed.\n" msgstr "" -#: badwolf.c:102 +#: badwolf.c:103 msgid "the web process exceeded the memory limit.\n" msgstr "" -#: badwolf.c:106 +#: badwolf.c:107 msgid "the web process terminated for an unknown reason.\n" msgstr "" -#: badwolf.c:966 +#: badwolf.c:1042 #, c-format msgid "webkit-web-extension directory set to: %s\n" msgstr "" #. TRANSLATOR Ignore this entry. Done for forcing Unicode in xgettext. -#: badwolf.c:1042 +#: badwolf.c:1135 msgid "ø" msgstr "" -- cgit v1.3.1-23-gd82d