[epiphany] web-extension: Remove EphyURITester based ad blocker
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] web-extension: Remove EphyURITester based ad blocker
- Date: Mon, 5 Aug 2019 23:59:22 +0000 (UTC)
commit 83ff5bff56b0de72f46447653ad79451c53d85fa
Author: Adrian Perez de Castro <aperez igalia com>
Date: Thu Dec 13 13:32:30 2018 +0200
web-extension: Remove EphyURITester based ad blocker
This will not be needed anymore when using WebKitUserContentFilter.
embed/ephy-embed-shell.c | 3 +-
embed/web-process-extension/ephy-uri-tester.c | 843 ---------------------
embed/web-process-extension/ephy-uri-tester.h | 38 -
.../ephy-web-process-extension-main.c | 4 +-
.../ephy-web-process-extension.c | 114 +--
.../ephy-web-process-extension.h | 1 -
embed/web-process-extension/meson.build | 1 -
7 files changed, 8 insertions(+), 996 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 6c990f3e8..01344a737 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -954,11 +954,10 @@ initialize_web_process_extensions (WebKitWebContext *web_context,
private_profile = priv->mode == EPHY_EMBED_SHELL_MODE_PRIVATE || priv->mode ==
EPHY_EMBED_SHELL_MODE_INCOGNITO || priv->mode == EPHY_EMBED_SHELL_MODE_AUTOMATION;
browser_mode = priv->mode == EPHY_EMBED_SHELL_MODE_BROWSER;
- user_data = g_variant_new ("(smsmssbb)",
+ user_data = g_variant_new ("(smsmsbb)",
priv->guid,
address,
ephy_profile_dir_is_default () ? NULL : ephy_profile_dir (),
- ephy_filters_manager_get_adblock_filters_dir (priv->filters_manager),
private_profile,
browser_mode);
webkit_web_context_set_web_extensions_initialization_user_data (web_context, g_steal_pointer (&user_data));
diff --git a/embed/web-process-extension/ephy-web-process-extension-main.c
b/embed/web-process-extension/ephy-web-process-extension-main.c
index bfdf4bbf8..f235dd2dc 100644
--- a/embed/web-process-extension/ephy-web-process-extension-main.c
+++ b/embed/web-process-extension/ephy-web-process-extension-main.c
@@ -37,12 +37,11 @@ webkit_web_extension_initialize_with_user_data (WebKitWebExtension *webkit_exten
const char *guid;
const char *server_address;
const char *profile_dir;
- const char *adblock_data_dir;
gboolean private_profile;
gboolean browser_mode;
g_autoptr (GError) error = NULL;
- g_variant_get (user_data, "(&sm&sm&s&sbb)", &guid, &server_address, &profile_dir, &adblock_data_dir,
&private_profile, &browser_mode);
+ g_variant_get (user_data, "(&sm&sm&sbb)", &guid, &server_address, &profile_dir, &private_profile,
&browser_mode);
if (!server_address) {
g_warning ("UI process did not start D-Bus server, giving up.");
@@ -60,7 +59,6 @@ webkit_web_extension_initialize_with_user_data (WebKitWebExtension *webkit_exten
webkit_extension,
guid,
server_address,
- adblock_data_dir,
private_profile,
browser_mode);
}
diff --git a/embed/web-process-extension/ephy-web-process-extension.c
b/embed/web-process-extension/ephy-web-process-extension.c
index d44ba89da..46c5e1c28 100644
--- a/embed/web-process-extension/ephy-web-process-extension.c
+++ b/embed/web-process-extension/ephy-web-process-extension.c
@@ -29,7 +29,6 @@
#include "ephy-prefs.h"
#include "ephy-settings.h"
#include "ephy-uri-helpers.h"
-#include "ephy-uri-tester.h"
#include "ephy-web-overview-model.h"
#include <gio/gio.h>
@@ -53,7 +52,6 @@ struct _EphyWebProcessExtension {
EphyWebOverviewModel *overview_model;
EphyPermissionsManager *permissions_manager;
- EphyUriTester *uri_tester;
WebKitScriptWorld *script_world;
@@ -102,116 +100,20 @@ static const char introspection_xml[] =
G_DEFINE_TYPE (EphyWebProcessExtension, ephy_web_process_extension, G_TYPE_OBJECT)
-static void
-log_to_js_console (EphyWebProcessExtension *extension,
- WebKitWebPage *page,
- const char *str,
- ...)
-{
- g_autoptr (JSCContext) js_context = NULL;
- g_autoptr (JSCValue) js_console = NULL;
- g_autoptr (JSCValue) js_result = NULL;
- g_autofree char *expanded_str = NULL;
- WebKitFrame *frame;
- va_list args;
- int ret;
-
- va_start (args, str);
- ret = g_vasprintf (&expanded_str, str, args);
- g_assert (ret > 0);
- va_end (args);
-
- frame = webkit_web_page_get_main_frame (page);
- js_context = webkit_frame_get_js_context_for_script_world (frame, extension->script_world);
- js_console = jsc_context_get_value (js_context, "console");
- js_result = jsc_value_object_invoke_method (js_console,
- "log",
- G_TYPE_STRING, expanded_str,
- G_TYPE_NONE);
-}
-
-static gboolean
-should_use_adblocker (const char *request_uri,
- const char *page_uri,
- const char *redirected_request_uri,
- EphyWebProcessExtension *extension)
-{
- g_autofree gchar *origin = ephy_uri_to_security_origin (page_uri);
- EphyPermission permission = EPHY_PERMISSION_UNDECIDED;
-
- /* Check page setting first in case it overwrites global setting */
- if (origin) {
- permission = ephy_permissions_manager_get_permission (extension->permissions_manager,
- EPHY_PERMISSION_TYPE_SHOW_ADS,
- origin);
- if (permission == EPHY_PERMISSION_PERMIT)
- return FALSE;
- }
-
- if (permission == EPHY_PERMISSION_UNDECIDED && !g_settings_get_boolean
(EPHY_SETTINGS_WEB_PROCESS_EXTENSION_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK))
- return FALSE;
-
- /* Always load the main resource... */
- if (g_strcmp0 (request_uri, page_uri) == 0)
- return FALSE;
-
- /* ...even during a redirect, when page_uri is stale. */
- if (g_strcmp0 (page_uri, redirected_request_uri) == 0)
- return FALSE;
-
- /* Always load data requests, as uri_tester won't do any good here. */
- if (g_str_has_prefix (request_uri, SOUP_URI_SCHEME_DATA))
- return FALSE;
-
- /* Always load about pages */
- if (g_str_has_prefix (request_uri, "about") ||
- g_str_has_prefix (request_uri, "ephy-about"))
- return FALSE;
-
- /* Always load resources */
- if (g_str_has_prefix (request_uri, "resource://") ||
- g_str_has_prefix (request_uri, "ephy-resource://"))
- return FALSE;
-
- /* Always load local files */
- if (g_str_has_prefix (request_uri, "file://"))
- return FALSE;
-
- return TRUE;
-}
-
static gboolean
web_page_send_request (WebKitWebPage *web_page,
WebKitURIRequest *request,
WebKitURIResponse *redirected_response,
EphyWebProcessExtension *extension)
{
- const char *request_uri;
- const char *redirected_response_uri;
- const char *page_uri;
- g_autofree char *modified_uri = NULL;
-
- request_uri = webkit_uri_request_get_uri (request);
- page_uri = webkit_web_page_get_uri (web_page);
- redirected_response_uri = redirected_response ? webkit_uri_response_get_uri (redirected_response) : NULL;
-
- if (g_settings_get_boolean (EPHY_SETTINGS_WEB_PROCESS_EXTENSION_WEB, EPHY_PREFS_WEB_DO_NOT_TRACK))
- modified_uri = ephy_remove_tracking_from_uri (request_uri);
-
- if (should_use_adblocker (request_uri, page_uri, redirected_response_uri, extension)) {
- gboolean result;
-
- ephy_uri_tester_load (extension->uri_tester);
- result = ephy_uri_tester_is_uri_allowed (extension->uri_tester,
- modified_uri ? modified_uri : request_uri,
- page_uri);
- if (!result) {
- LOG ("Adblocker refused to load %s", request_uri);
- log_to_js_console (extension, web_page, _("Epiphany adblocker refused to load %s"), request_uri);
- return TRUE;
+ if (g_settings_get_boolean (EPHY_SETTINGS_WEB_PROCESS_EXTENSION_WEB, EPHY_PREFS_WEB_DO_NOT_TRACK)) {
+ const char *request_uri = webkit_uri_request_get_uri (request);
+ g_autofree char *modified_uri = ephy_remove_tracking_from_uri (request_uri);
+ if (modified_uri && g_strcmp0 (request_uri, modified_uri) != 0) {
+ LOG ("Rewrote %s to %s", request_uri, modified_uri);
+ webkit_uri_request_set_uri (request, modified_uri);
}
}
-
return FALSE;
}
@@ -580,7 +482,6 @@ ephy_web_process_extension_dispose (GObject *object)
{
EphyWebProcessExtension *extension = EPHY_WEB_PROCESS_EXTENSION (object);
- g_clear_object (&extension->uri_tester);
g_clear_object (&extension->overview_model);
g_clear_object (&extension->permissions_manager);
@@ -849,7 +750,6 @@ ephy_web_process_extension_initialize (EphyWebProcessExtension *extension,
WebKitWebExtension *wk_extension,
const char *guid,
const char *server_address,
- const char *adblock_data_dir,
gboolean is_private_profile,
gboolean is_browser_mode)
{
@@ -889,8 +789,6 @@ ephy_web_process_extension_initialize (EphyWebProcessExtension *extension,
(GAsyncReadyCallback)dbus_connection_created_cb,
extension);
- extension->uri_tester = ephy_uri_tester_new (adblock_data_dir);
-
extension->frames_map = g_hash_table_new_full (g_direct_hash, g_direct_equal,
NULL, NULL);
}
diff --git a/embed/web-process-extension/ephy-web-process-extension.h
b/embed/web-process-extension/ephy-web-process-extension.h
index 9463a96f0..7fc9fa9da 100644
--- a/embed/web-process-extension/ephy-web-process-extension.h
+++ b/embed/web-process-extension/ephy-web-process-extension.h
@@ -34,7 +34,6 @@ void ephy_web_process_extension_initialize (EphyWebProcessEx
WebKitWebExtension *wk_extension,
const char *guid,
const char *server_address,
- const char *adblock_data_dir,
gboolean is_private_profile,
gboolean is_browser_mode);
diff --git a/embed/web-process-extension/meson.build b/embed/web-process-extension/meson.build
index d4ee37319..398aa5ad1 100644
--- a/embed/web-process-extension/meson.build
+++ b/embed/web-process-extension/meson.build
@@ -6,7 +6,6 @@ resources = gnome.compile_resources('epiphany-web-process-extension-resources',
)
web_process_extension_sources = [
- 'ephy-uri-tester.c',
'ephy-web-process-extension.c',
'ephy-web-process-extension-main.c',
'ephy-web-overview-model.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]