2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2022 the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #define G_LOG_DOMAIN "Fancy-Web-Ext"
21 #include <glib-object.h>
22 #include <webkit2/webkit-web-extension.h>
24 static gboolean load_remote_content
= FALSE
;
26 static gboolean
web_page_send_request_cb(WebKitWebPage
*web_page
,
27 WebKitURIRequest
*request
,
28 WebKitURIResponse
*redirected_response
,
31 gboolean is_remote
= TRUE
;
32 gboolean should_block
;
33 const char *request_uri
= webkit_uri_request_get_uri(request
);
34 #if GLIB_CHECK_VERSION(2,66,0)
35 const char *scheme
= g_uri_peek_scheme(request_uri
);
37 gchar
*scheme
= g_uri_parse_scheme(request_uri
);
41 #if GLIB_CHECK_VERSION(2,66,0)
42 if (strcmp(scheme
, "cid") == 0 ||
43 strcmp(scheme
, "file") == 0 ||
44 strcmp(scheme
, "about") == 0)
47 if (g_ascii_strcasecmp(scheme
, "cid") == 0 ||
48 g_ascii_strcasecmp(scheme
, "file") == 0 ||
49 g_ascii_strcasecmp(scheme
, "about") == 0)
54 should_block
= !load_remote_content
;
58 g_debug("Filter page: %s request: %s => %s uri %s",
59 webkit_web_page_get_uri(web_page
),
61 is_remote
? "remote" : "local",
62 should_block
? "blocked" : "allowed");
67 static gboolean
web_page_user_message_received_cb(WebKitWebPage
*page
,
68 WebKitUserMessage
*message
,
71 const char *name
= webkit_user_message_get_name(message
);
73 g_debug("WebPage user message received callback - %s", name
);
75 if (g_strcmp0(name
, "LoadRemoteContent") == 0) {
78 parameters
= webkit_user_message_get_parameters(message
);
82 load_remote_content
= g_variant_get_boolean(parameters
);
84 g_debug("LoadRemoteContent param - %d", load_remote_content
);
92 static void web_page_created_cb(WebKitWebExtension
*extension
,
93 WebKitWebPage
*web_page
,
96 g_debug("Page %ld created for %s",
97 webkit_web_page_get_id(web_page
),
98 webkit_web_page_get_uri(web_page
));
100 g_signal_connect_object(web_page
,
102 G_CALLBACK(web_page_send_request_cb
),
106 g_signal_connect_object(web_page
,
107 "user-message-received",
108 G_CALLBACK(web_page_user_message_received_cb
),
113 G_MODULE_EXPORT
void webkit_web_extension_initialize(WebKitWebExtension
*extension
)
115 if (!g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN
, FALSE
))
116 g_warning("could not set G_MESSAGES_DEBUG\n");
118 g_debug("Initializing Fancy web process extension");
120 g_signal_connect(extension
,
122 G_CALLBACK(web_page_created_cb
),