talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit ae80c5e67ba82395c2c9db2ce6f451e2dbe9a2c8
parent db8edf89d8b6dd9f8f407336fc75764da1d670a7
Author: Jonathan Boeing <jonathan@claws-mail.org>
Date:   Sun,  9 Oct 2022 21:51:44 -0700

fix bug 4630, 'Fancy loads remote images when remote content is disabled'

Upstream changes broke the 'empty network proxy' method of blocking
remote content, so replace it with a WebKit extension that handles the
send-request signal.

Diffstat:
Msrc/plugins/fancy/Makefile.am | 10+++++++++-
Msrc/plugins/fancy/fancy_viewer.c | 16+++++++++-------
Msrc/plugins/fancy/fancy_viewer.h | 1-
Asrc/plugins/fancy/fancy_web_extension.c | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 130 insertions(+), 9 deletions(-)

diff --git a/src/plugins/fancy/Makefile.am b/src/plugins/fancy/Makefile.am @@ -12,9 +12,11 @@ IFLAGS = \ -I$(top_srcdir)/src/gtk plugindir = $(pkglibdir)/plugins +webextensiondir = $(pkglibdir)/plugins/web_extensions if BUILD_FANCY_PLUGIN plugin_LTLIBRARIES = fancy.la +webextension_LTLIBRARIES = libfancywebextension.la endif fancy_la_LDFLAGS = \ @@ -36,7 +38,8 @@ fancy_la_CPPFLAGS = \ $(ENCHANT_CFLAGS) \ $(WEBKIT_CFLAGS) \ $(LIBSOUP_GNOME_CFLAGS) \ - $(CURL_CFLAGS) + $(CURL_CFLAGS) \ + -DFANCY_WEB_EXTENSIONS_DIR=\""$(pkglibdir)/plugins/web_extensions"\" fancy_la_SOURCES = \ fancy_prefs.c \ @@ -44,4 +47,9 @@ fancy_la_SOURCES = \ fancy_viewer.c \ fancy_viewer.h +libfancywebextension_la_SOURCES = fancy_web_extension.c +libfancywebextension_la_CFLAGS = $(WEBKIT_CFLAGS) +libfancywebextension_la_LIBADD = $(WEBKIT_LIBS) +libfancywebextension_la_LDFLAGS = -module -avoid-version -no-undefined + .PHONY: test diff --git a/src/plugins/fancy/fancy_viewer.c b/src/plugins/fancy/fancy_viewer.c @@ -111,10 +111,12 @@ static void fancy_apply_prefs(FancyViewer *viewer) } webkit_web_view_set_settings(viewer->view, viewer->settings); webkit_web_context_set_cache_model(webkit_web_context_get_default(), WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER); - if (viewer->override_prefs_remote_content) - webkit_web_context_set_network_proxy_settings(webkit_web_context_get_default(), WEBKIT_NETWORK_PROXY_MODE_DEFAULT, NULL); - else - webkit_web_context_set_network_proxy_settings(webkit_web_context_get_default(), WEBKIT_NETWORK_PROXY_MODE_CUSTOM, viewer->no_remote_content_proxy_settings); + webkit_web_view_send_message_to_page(viewer->view, + webkit_user_message_new("LoadRemoteContent", + g_variant_new_boolean(viewer->override_prefs_remote_content)), + NULL, + NULL, + NULL); if (viewer->override_stylesheet) { /* copied from vimb */ @@ -1122,9 +1124,6 @@ static MimeViewer *fancy_viewer_create(void) } */ viewer->settings = webkit_settings_new(); - // Proxy "" makes libsoup backend think that there is no way - // to connect, which is ideal. - viewer->no_remote_content_proxy_settings = webkit_network_proxy_settings_new("", NULL); g_object_set(viewer->settings, "user-agent", "Fancy Viewer", NULL); viewer->scrollwin = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(viewer->scrollwin), @@ -1268,6 +1267,9 @@ gint plugin_init(gchar **error) } g_free(directory); + webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), + FANCY_WEB_EXTENSIONS_DIR); + fancy_prefs_init(); mimeview_register_viewer_factory(&fancy_viewer_factory); diff --git a/src/plugins/fancy/fancy_viewer.h b/src/plugins/fancy/fancy_viewer.h @@ -93,7 +93,6 @@ struct _FancyViewer GtkWidget *progress; WebKitSettings *settings; - WebKitNetworkProxySettings *no_remote_content_proxy_settings; gboolean printing; gboolean override_prefs_images; gboolean override_prefs_remote_content; diff --git a/src/plugins/fancy/fancy_web_extension.c b/src/plugins/fancy/fancy_web_extension.c @@ -0,0 +1,112 @@ +/* + * Claws Mail -- a GTK based, lightweight, and fast e-mail client + * Copyright (C) 2022 the Claws Mail team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define G_LOG_DOMAIN "Fancy-Web-Ext" + +#include <glib-object.h> +#include <webkit2/webkit-web-extension.h> + +static gboolean load_remote_content = FALSE; + +static gboolean web_page_send_request_cb(WebKitWebPage *web_page, + WebKitURIRequest *request, + WebKitURIResponse *redirected_response, + gpointer user_data) +{ + gboolean is_remote = TRUE; + gboolean should_block; + const char *request_uri = webkit_uri_request_get_uri(request); + const char *scheme = g_uri_peek_scheme(request_uri); + + if (scheme == NULL) + return TRUE; + + if (strcmp(scheme, "cid") == 0 || + strcmp(scheme, "file") == 0 || + strcmp(scheme, "about") == 0) + is_remote = FALSE; + + if (is_remote) + should_block = !load_remote_content; + else + should_block = FALSE; + + g_debug("Filter page: %s request: %s => %s uri %s", + webkit_web_page_get_uri(web_page), + request_uri, + is_remote ? "remote" : "local", + should_block ? "blocked" : "allowed"); + + return should_block; +} + +static gboolean web_page_user_message_received_cb(WebKitWebPage *page, + WebKitUserMessage *message, + gpointer user_data) +{ + const char *name = webkit_user_message_get_name(message); + + g_debug("WebPage user message received callback - %s", name); + + if (g_strcmp0(name, "LoadRemoteContent") == 0) { + GVariant *parameters; + + parameters = webkit_user_message_get_parameters(message); + if (!parameters) + return FALSE; + + load_remote_content = g_variant_get_boolean(parameters); + + g_debug("LoadRemoteContent param - %d", load_remote_content); + + return TRUE; + } + + return FALSE; +} + +static void web_page_created_cb(WebKitWebExtension *extension, + WebKitWebPage *web_page, + gpointer user_data) +{ + g_debug("Page %ld created for %s", + webkit_web_page_get_id(web_page), + webkit_web_page_get_uri(web_page)); + + g_signal_connect_object(web_page, + "send-request", + G_CALLBACK(web_page_send_request_cb), + NULL, + 0); + + g_signal_connect_object(web_page, + "user-message-received", + G_CALLBACK(web_page_user_message_received_cb), + NULL, + 0); +} + +G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension) +{ + g_debug("Initializing Fancy web process extension"); + + g_signal_connect(extension, + "page-created", + G_CALLBACK(web_page_created_cb), + NULL); +}