From 5e7964460e8f5cec2a2b823d9814e491e36b6979 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 3 Jul 2020 06:34:05 +0200 Subject: badwolf.1: Fix syntax issues This seems to fix some issues with how GNU groff renders it. --- badwolf.1 | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index d25674b..a9c2ce1 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -2,7 +2,7 @@ ./" Copyright © 2019-2020 Badwolf Authors ./" SPDX-License-Identifier: BSD-3-Clause .Dd 2019-10-31 -.Dt badwolf 1 +.Dt BADWOLF 1 .Sh NAME .Nm badwolf .Nd minimalist and privacy-oriented WebkitGTK browser @@ -20,8 +20,9 @@ will probably get added at a later release. .Sh KEYBINDINGS The following section lists the keybinding by their action, each item is described by the widget the focus is on or .Aq any -if it works for the whole window, followed by the keybind it grabs. A is short for Alt, C is short for Control, S is short for Shift. -.Bl -width Ds -tag +if it works for the whole window, followed by the keybind it grabs. +A is short for Alt, C is short for Control, S is short for Shift. +.Bl -tag -width Ds .It webview C-Scroll Zooms the webpage in/out. .It webview C-0 @@ -51,11 +52,12 @@ Go to the previous/next tab .It any F1 Shows the about dialog .It any Alt-n -Where n is any numeric-row key. Go to the n-th tab, 0 goes to the last one. +Where n is any numeric-row key. +Go to the n-th tab, 0 goes to the last one. .El .Ss DEFAULT ONES Here is a incomplete list of the default Webkit/GTK keybindings: -.Bl -width Ds -tag +.Bl -tag -width Ds .It any C-PageUp / C-PageDown Go to the previous/next tab .It search C-g / C-S-g @@ -64,11 +66,13 @@ When the search box is focused it goes to the Next/Previous search term. Cancels current search .El .Sh ENVIRONMENT -.Bl -width Ds -tag +.Bl -tag -width Ds .It Ev BADWOLF_L10N -A colon-separated list in the form lang_COUNTRY where lang is in ISO-639 and COUNTRY in ISO-3166. For example +A colon-separated list in the form lang_COUNTRY where lang is in ISO-639 and COUNTRY in ISO-3166. +For example .Ic BADWOLF_L10N="en_GB:fr_FR:de_DE" . -When this variable isn't set, spelling isn't activated. A more generic variable name is also intended to be used in the future. +When this variable isn't set, spelling isn't activated. +A more generic variable name is also intended to be used in the future. .El .Sh FILES .Bl -tag -width Ds -compact @@ -79,13 +83,14 @@ 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 -compact +.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. See +CSS files (respectively system and user-level) for styling badwolf interface. +See .Lk https://developer.gnome.org/gtk3/stable/chap-css-properties.html for the properties being available. .Pp @@ -95,6 +100,8 @@ environment variable on launching .Nm and going to the CSS tab. .El +.Sh AUTHORS +.An Haelwenn (lanodan) Monnier Aq Mt contact+badwolf@hacktivis.me .Sh BUGS You can submit contributions or tickets to .Lk https://gitlab.com/lanodan/badwolf @@ -102,5 +109,3 @@ or .Mt contact+badwolf@hacktivis.me , with .Xr git-send-email 1 for patches. -.Sh AUTHORS -.An Haelwenn (lanodan) Monnier Aq Mt contact+badwolf@hacktivis.me -- cgit v1.3.1-23-gd82d From 2ccd806e3927e440773e64cb7eb47b9607c648c9 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 3 Jul 2020 06:43:07 +0200 Subject: badwolf.1: Use full modifier names instead of A/C/S --- badwolf.1 | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index a9c2ce1..d1bda3e 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -21,21 +21,20 @@ will probably get added at a later release. The following section lists the keybinding by their action, each item is described by the widget the focus is on or .Aq any if it works for the whole window, followed by the keybind it grabs. -A is short for Alt, C is short for Control, S is short for Shift. .Bl -tag -width Ds -.It webview C-Scroll +.It webview Ctrl-Scroll Zooms the webpage in/out. -.It webview C-0 +.It webview Ctrl-0 Resets webpage zoom to 100%. -.It any C-t +.It any Ctrl-t Creates a new tab (in a new session, similar as pressing the button) -.It browser C-F4, browser A-d +.It browser Ctrl-F4, browser Alt-d Closes the current tab -.It browser C-f +.It browser Ctrl-f Focuses on the search entry -.It browser C-l +.It browser Ctrl-l Focuses on the location(URL) entry -.It browser C-S-r / C-r, browser F5 +.It browser Ctrl-Shift-r / Ctrl-r, browser F5 Reloads the content in the current tab (with/without clearing cache) .It browser Escape Stops loading the content in the current tab @@ -43,11 +42,11 @@ Stops loading the content in the current tab Toggles caret browsing. .It browser F12 Opens the web inspector. -.It browser C-[ / C-] +.It browser Ctrl-[ / Ctrl-] Go back/forward in current tab’s history -.It browser C-p +.It browser Ctrl-p Print the current page. (spawns a dialog) -.It any A-Left / A-Right +.It any Alt-Left / Alt-Right Go to the previous/next tab .It any F1 Shows the about dialog @@ -58,9 +57,9 @@ Go to the n-th tab, 0 goes to the last one. .Ss DEFAULT ONES Here is a incomplete list of the default Webkit/GTK keybindings: .Bl -tag -width Ds -.It any C-PageUp / C-PageDown +.It any Ctrl-PageUp / Ctrl-PageDown Go to the previous/next tab -.It search C-g / C-S-g +.It search Ctrl-g / Ctrl-Shift-g When the search box is focused it goes to the Next/Previous search term. .It search Escape Cancels current search -- cgit v1.3.1-23-gd82d From abb47b4c0faf2eadcdce62c285fea8af7edd8894 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 2 Nov 2019 22:01:00 +0100 Subject: Add completion --- Makefile | 4 ++-- badwolf.1 | 2 ++ badwolf.c | 4 ++++ bookmarks.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ bookmarks.h | 3 +++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 bookmarks.c create mode 100644 bookmarks.h (limited to 'badwolf.1') diff --git a/Makefile b/Makefile index a136a28..8ba3003 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ INKSCAPE ?= inkscape ICON_SIZES = icons/hicolor/24x24/apps/badwolf.png icons/hicolor/32x32/apps/badwolf.png icons/hicolor/48x48/apps/badwolf.png icons/hicolor/64x64/apps/badwolf.png icons/hicolor/128x128/apps/badwolf.png icons/hicolor/256x256/apps/badwolf.png DEPS = gtk+-3.0 webkit2gtk-4.0 libsoup-2.4 -SRCS = uri.c uri_test.c keybindings.c downloads.c badwolf.c -OBJS = uri.o keybindings.o downloads.o badwolf.o +SRCS = bookmarks.c uri.c uri_test.c keybindings.c downloads.c badwolf.c +OBJS = bookmarks.o uri.o keybindings.o downloads.o badwolf.o OBJS_test = uri_test.o EXE = badwolf EXE_test = uri_test diff --git a/badwolf.1 b/badwolf.1 index d1bda3e..96a20d3 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -75,6 +75,8 @@ 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_DATA_HOME:-$HOME/.local/share}/badwolf/URLs.txt +File containing a URL on each line. [UNSTABLE] .It Pa ${XDG_DATA_HOME:-$HOME/.local/share}/badwolf/webkit-web-extensions/ Directory containing the .Lk https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebExtension.html WebKitWebExtensions diff --git a/badwolf.c b/badwolf.c index d0b337a..bf4916b 100644 --- a/badwolf.c +++ b/badwolf.c @@ -6,6 +6,7 @@ #include "config.h" #include "downloads.h" +#include "bookmarks.h" #include "keybindings.h" #include "uri.h" @@ -738,6 +739,7 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b gtk_entry_set_text(GTK_ENTRY(browser->location), target_url); gtk_entry_set_input_purpose(GTK_ENTRY(browser->location), GTK_INPUT_PURPOSE_URL); + gtk_entry_set_completion(GTK_ENTRY(browser->location), location_completion); gtk_entry_set_placeholder_text(GTK_ENTRY(browser->search), _("search in current page")); @@ -930,6 +932,8 @@ main(int argc, char *argv[]) g_build_filename(g_get_user_data_dir(), "badwolf", "webkit-web-extension", NULL); fprintf(stderr, _("webkit-web-extension directory set to: %s\n"), web_extensions_directory); + location_completion_init(); + 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); diff --git a/bookmarks.c b/bookmarks.c new file mode 100644 index 0000000..f43ed46 --- /dev/null +++ b/bookmarks.c @@ -0,0 +1,45 @@ +#include "badwolf.h" +#include "bookmarks.h" + +#include +#include /* g_fprintf() */ + +void +location_completion_init() +{ + GtkTreeIter iter; + GtkListStore *list_store; + GIOChannel *file_channel; + GError *file_err = NULL; + gchar *file_line; + + location_completion = gtk_entry_completion_new(); + + list_store = gtk_list_store_new(1, G_TYPE_STRING); + + gchar *filename = g_build_filename(g_get_user_data_dir(), "badwolf", "URLs.txt", NULL); + g_fprintf(stderr, "URL Completion: loading at %s\n", filename); + file_channel = g_io_channel_new_file(filename, "r", &file_err); + + if(file_channel != NULL) + { + while(G_IO_STATUS_NORMAL == + g_io_channel_read_line(file_channel, &file_line, NULL, NULL, &file_err)) + { + gtk_list_store_append(list_store, &iter); + gtk_list_store_set(list_store, &iter, 0, g_strchomp(file_line), -1); + } + g_free(file_line); + g_io_channel_unref(file_channel); + //g_io_channel_shutdown(file_channel, FALSE, &file_err); + g_fprintf(stderr, "URL Completion: Done.\n"); + } + else + g_fprintf(stderr, "URL Completion: Failed to load file.\n"); + + gtk_list_store_append(list_store, &iter); + gtk_list_store_set(list_store, &iter, 0, homepage, -1); + + gtk_entry_completion_set_model(location_completion, GTK_TREE_MODEL(list_store)); + gtk_entry_completion_set_text_column(location_completion, 0); +} diff --git a/bookmarks.h b/bookmarks.h new file mode 100644 index 0000000..2e44eb3 --- /dev/null +++ b/bookmarks.h @@ -0,0 +1,3 @@ +#include +GtkEntryCompletion *location_completion; +void location_completion_init(); -- cgit v1.3.1-23-gd82d From a7ba36264f3a62013d393075bd992ac252d3e51a Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 3 Nov 2019 21:34:46 +0100 Subject: Add support for XBEL Bookmarks --- KnowledgeBase.md | 17 ++++++++++ Makefile | 2 +- README.md | 1 + badwolf.1 | 10 ++++-- badwolf.c | 1 + bookmarks.c | 99 ++++++++++++++++++++++++++++++++++++++++---------------- 6 files changed, 100 insertions(+), 30 deletions(-) (limited to 'badwolf.1') diff --git a/KnowledgeBase.md b/KnowledgeBase.md index f5f9f9a..af59415 100644 --- a/KnowledgeBase.md +++ b/KnowledgeBase.md @@ -2,3 +2,20 @@ - WebKit2 Extensions Tutorial: https://blogs.igalia.com/carlosgc/2013/09/10/webkit2gtk-web-process-extensions/ - https://trac.torproject.org/projects/tor/wiki/doc/ImportantGoogleChromeBugs / https://trac.torproject.org/projects/tor/ticket/1925 - https://webkit.org/blog/3476/content-blockers-first-look/ + +# Bookmark formats +The different plain-text formats used by web browsers found in the wild, done +in Augmented Backus–Naur Form (ABNF). + +url = *CHAR +title = *CHAR + +## uzbl +bookmark = URL TAB title [TAB tags] +tags = *(*CHAR SP) + +Documenter comment: How does it manages when the separator (TAB here) is +present in the title? + +## qutebrowser +bookmark = URL SP title diff --git a/Makefile b/Makefile index 8ba3003..8ba9b7e 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ INKSCAPE ?= inkscape # for i in 24 32 48 64 128 256; do echo icons/hicolor/${i}x${i}/apps/badwolf.png; done | tr '\n' ' ' ICON_SIZES = icons/hicolor/24x24/apps/badwolf.png icons/hicolor/32x32/apps/badwolf.png icons/hicolor/48x48/apps/badwolf.png icons/hicolor/64x64/apps/badwolf.png icons/hicolor/128x128/apps/badwolf.png icons/hicolor/256x256/apps/badwolf.png -DEPS = gtk+-3.0 webkit2gtk-4.0 libsoup-2.4 +DEPS = gtk+-3.0 webkit2gtk-4.0 libsoup-2.4 libxml-2.0 SRCS = bookmarks.c uri.c uri_test.c keybindings.c downloads.c badwolf.c OBJS = bookmarks.o uri.o keybindings.o downloads.o badwolf.o OBJS_test = uri_test.o diff --git a/README.md b/README.md index 6804aea..b83d134 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Dependencies are: - C11 Compiler (such as clang or gcc) - [WebKitGTK](https://webkitgtk.org/), only the latest stable is supported +- [libxml-2.0](http://www.xmlsoft.org/), no known version limitation - POSIX make with extension for shell in variables (works with GNU, {Net,Free,Open}BSD) - A pkg-config implementation (pkgconf is recommended) - (optionnal) gettext implementation (such as GNU Gettext) diff --git a/badwolf.1 b/badwolf.1 index 96a20d3..6bbe2b2 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -75,8 +75,14 @@ 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_DATA_HOME:-$HOME/.local/share}/badwolf/URLs.txt -File containing a URL on each line. [UNSTABLE] +.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 , +.Xr konqueror 1 , +.Xr kbookmarkeditor 1 . Doing a symbolic link from their path works fine. +.Pp +For more information about this format see: +.Lk http://pyxml.sourceforge.net/topics/xbel/ .It Pa ${XDG_DATA_HOME:-$HOME/.local/share}/badwolf/webkit-web-extensions/ Directory containing the .Lk https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebExtension.html WebKitWebExtensions diff --git a/badwolf.c b/badwolf.c index bf4916b..f284378 100644 --- a/badwolf.c +++ b/badwolf.c @@ -7,6 +7,7 @@ #include "config.h" #include "downloads.h" #include "bookmarks.h" +#include "config.h" #include "keybindings.h" #include "uri.h" diff --git a/bookmarks.c b/bookmarks.c index f43ed46..23cb558 100644 --- a/bookmarks.c +++ b/bookmarks.c @@ -1,45 +1,90 @@ -#include "badwolf.h" #include "bookmarks.h" -#include +#include "badwolf.h" + #include /* g_fprintf() */ +#include +#include void -location_completion_init() +location_completion_setup(GtkListStore *list_store) { - GtkTreeIter iter; - GtkListStore *list_store; - GIOChannel *file_channel; - GError *file_err = NULL; - gchar *file_line; + gtk_entry_completion_set_model(location_completion, GTK_TREE_MODEL(list_store)); + gtk_entry_completion_set_text_column(location_completion, 0); +} - location_completion = gtk_entry_completion_new(); +void +location_completion_cleanup(xmlXPathObjectPtr xpathObj, xmlXPathContextPtr xpathCtx, xmlDocPtr doc) +{ + if(xpathObj != NULL) xmlXPathFreeObject(xpathObj); + if(xpathCtx != NULL) xmlXPathFreeContext(xpathCtx); + if(doc != NULL) xmlFreeDoc(doc); +} - list_store = gtk_list_store_new(1, G_TYPE_STRING); +GtkTreeIter +load_xpath_results(GtkListStore *list_store, xmlNodeSetPtr nodes) +{ + GtkTreeIter iter; + int size; - gchar *filename = g_build_filename(g_get_user_data_dir(), "badwolf", "URLs.txt", NULL); - g_fprintf(stderr, "URL Completion: loading at %s\n", filename); - file_channel = g_io_channel_new_file(filename, "r", &file_err); + size = (nodes) ? nodes->nodeNr : 0; - if(file_channel != NULL) - { - while(G_IO_STATUS_NORMAL == - g_io_channel_read_line(file_channel, &file_line, NULL, NULL, &file_err)) + g_fprintf(stderr, "Bookmarks: Found %d bookmarks.\n", size); + for(int i = 0; i < size; i++) + if(nodes->nodeTab[i]) { gtk_list_store_append(list_store, &iter); - gtk_list_store_set(list_store, &iter, 0, g_strchomp(file_line), -1); + gtk_list_store_set( + list_store, &iter, 0, (char *)xmlXPathCastNodeToString(nodes->nodeTab[i]), -1); } - g_free(file_line); - g_io_channel_unref(file_channel); - //g_io_channel_shutdown(file_channel, FALSE, &file_err); - g_fprintf(stderr, "URL Completion: Done.\n"); - } - else - g_fprintf(stderr, "URL Completion: Failed to load file.\n"); + return iter; +} + +void +location_completion_init() +{ + const xmlChar *xpathExpr = "//bookmark/@href"; + char *filename = g_build_filename(g_get_user_data_dir(), "badwolf", "bookmarks.xbel", NULL); + xmlDocPtr doc = NULL; + xmlXPathContextPtr xpathCtx = NULL; + xmlXPathObjectPtr xpathObj = NULL; + GtkTreeIter iter; + GtkListStore *list_store = gtk_list_store_new(1, G_TYPE_STRING); + + location_completion = gtk_entry_completion_new(); gtk_list_store_append(list_store, &iter); gtk_list_store_set(list_store, &iter, 0, homepage, -1); - gtk_entry_completion_set_model(location_completion, GTK_TREE_MODEL(list_store)); - gtk_entry_completion_set_text_column(location_completion, 0); + g_fprintf(stderr, "Bookmarks: loading at %s\n", filename); + doc = xmlParseFile(filename); + if(doc == NULL) + { + g_fprintf(stderr, "Bookmarks: unable to parse file \"%s\"\n", filename); + location_completion_cleanup(xpathObj, xpathCtx, doc); + return; + } + + xpathCtx = xmlXPathNewContext(doc); + if(xpathCtx == NULL) + { + g_fprintf(stderr, "Bookmarks: unable to create new XPath context\n"); + location_completion_cleanup(xpathObj, xpathCtx, doc); + return; + } + + xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx); + if(xpathObj == NULL) + { + g_fprintf(stderr, "Bookmarks: unable to evaluate xpath expression \"%s\"\n", xpathExpr); + location_completion_cleanup(xpathObj, xpathCtx, doc); + return; + } + + iter = load_xpath_results(list_store, xpathObj->nodesetval); + + location_completion_cleanup(xpathObj, xpathCtx, doc); + location_completion_setup(list_store); + + g_fprintf(stderr, "Bookmarks: Done.\n"); } -- cgit v1.3.1-23-gd82d From 2938c5cf138bef4f65644d9213233fa0e5a5ee6f Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 11 Oct 2020 20:50:39 +0200 Subject: bookmarks: Add support for XInclude --- badwolf.1 | 2 +- bookmarks.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index 6bbe2b2..ca02f83 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -79,7 +79,7 @@ A more generic variable name is also intended to be used in the future. XBEL (XML Bookmark Exchange Language) file, known to be currently supported by: .Xr elinks 1 , .Xr konqueror 1 , -.Xr kbookmarkeditor 1 . Doing a symbolic link from their path works fine. +.Xr kbookmarkeditor 1 . Doing a symbolic link from their path works fine but you might also want to use XInclude to merge multiple XBEL files. .Pp For more information about this format see: .Lk http://pyxml.sourceforge.net/topics/xbel/ diff --git a/bookmarks.c b/bookmarks.c index c6e2ece..6d35216 100644 --- a/bookmarks.c +++ b/bookmarks.c @@ -92,6 +92,8 @@ bookmarks_completion_init() return NULL; } + xmlXIncludeProcess(doc); + xpathCtx = xmlXPathNewContext(doc); if(xpathCtx == NULL) { -- cgit v1.3.1-23-gd82d From 38cbe249da856189a8463d3d49a96dbaf0df72db Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 22 Oct 2020 20:02:08 +0200 Subject: badwolf.1: Update description to include "web browser" As suggested by msiism on IRC --- badwolf.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index ca02f83..68a39ed 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -5,7 +5,7 @@ .Dt BADWOLF 1 .Sh NAME .Nm badwolf -.Nd minimalist and privacy-oriented WebkitGTK browser +.Nd minimalist and privacy-oriented web browser based on WebKitGTK .Sh SYNOPSIS .Nm .Op Ar webkit/gtk options -- 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.1') 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 From 0521e91dbc6cf31ac7d2961ab87ff4c1787184fa Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 9 Apr 2021 07:11:30 +0200 Subject: badwolf.1: Add "Targeting Domains with Content Blockers" --- badwolf.1 | 3 +++ 1 file changed, 3 insertions(+) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index ae2dfa1..52638f0 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -78,7 +78,10 @@ A more generic variable name is also intended to be used in the future. .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: +.Bl -compact .Lk https://webkit.org/blog/3476/content-blockers-first-look/ +.Lk https://webkit.org/blog/4062/targeting-domains-with-content-blockers/ +.El .Pp For a converter using AblockPlus-style filters, try: .Lk https://gitlab.com/eyeo/adblockplus/abp2blocklist -- cgit v1.3.1-23-gd82d From 972a5337be4b687388dd12a72343f0593d39a2ce Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 9 Apr 2021 07:13:02 +0200 Subject: badwolf.1: Add "Creating a Content Blocker" --- badwolf.1 | 1 + 1 file changed, 1 insertion(+) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index 52638f0..502d07e 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -81,6 +81,7 @@ For some introductory information about the format see: .Bl -compact .Lk https://webkit.org/blog/3476/content-blockers-first-look/ .Lk https://webkit.org/blog/4062/targeting-domains-with-content-blockers/ +.Lk https://developer.apple.com/documentation/safariservices/creating_a_content_blocker .El .Pp For a converter using AblockPlus-style filters, try: -- cgit v1.3.1-23-gd82d From edbbb27736db50534c9f0e029bc04f3f462596d3 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 9 Apr 2021 08:47:01 +0200 Subject: Move filter directory information to manpage --- badwolf.1 | 2 ++ badwolf.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index 502d07e..111c0cc 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -89,6 +89,8 @@ For a converter using AblockPlus-style filters, try: .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_CACHE_HOME:-$HOME/.cache}/badwolf/filters +This is where the compiled filters are stored, the file(s) in it are automatically generated and so shouldn't be edited. .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 , diff --git a/badwolf.c b/badwolf.c index bf5d183..84f4104 100644 --- a/badwolf.c +++ b/badwolf.c @@ -1060,7 +1060,6 @@ main(int argc, char *argv[]) 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, -- cgit v1.3.1-23-gd82d