summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2019-11-06 18:52:08 +0100
committerJan-Michael Brummer <jan.brummer@tabos.org>2019-11-12 19:45:04 +0100
commit7362c2abc20004ff58b88dab7b6d9bd3a971d909 (patch)
tree652525d3f71111e63708aa1689901c9cca03da2c
parentc9955c4ebc845efbff3dd57747c001ac752ba185 (diff)
downloadepiphany-7362c2abc20004ff58b88dab7b6d9bd3a971d909.tar.gz
Use an own user content manager for each webview
-rw-r--r--embed/ephy-embed-prefs.c49
-rw-r--r--embed/ephy-embed-prefs.h11
-rw-r--r--embed/ephy-embed-shell.c227
-rw-r--r--embed/ephy-embed-shell.h7
-rw-r--r--embed/ephy-filters-manager.c42
-rw-r--r--embed/ephy-filters-manager.h5
-rw-r--r--embed/ephy-web-view.c42
7 files changed, 246 insertions, 137 deletions
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c
index bb75271bf..a7bf7b80d 100644
--- a/embed/ephy-embed-prefs.c
+++ b/embed/ephy-embed-prefs.c
@@ -42,6 +42,23 @@ typedef struct {
/* FIXME: Refactor this code to remove the need of those globals */
static WebKitSettings *webkit_settings = NULL;
static GFileMonitor *user_style_sheet_monitor = NULL;
+static WebKitUserStyleSheet *style_sheet = NULL;
+static GList *ucm_list = NULL;
+
+static void
+update_user_style_on_all_ucm (void)
+{
+ GList *list = NULL;
+
+ for (list = ucm_list; list != NULL; list = list->next) {
+ WebKitUserContentManager *ucm = list->data;
+
+ if (style_sheet)
+ webkit_user_content_manager_add_style_sheet (ucm, style_sheet);
+ else
+ webkit_user_content_manager_remove_all_style_sheets (ucm);
+ }
+}
static void
user_style_sheet_output_stream_splice_cb (GOutputStream *output_stream,
@@ -52,14 +69,13 @@ user_style_sheet_output_stream_splice_cb (GOutputStream *output_stream,
bytes = g_output_stream_splice_finish (output_stream, result, NULL);
if (bytes > 0) {
- WebKitUserStyleSheet *style_sheet;
+ g_clear_pointer (&style_sheet, webkit_user_style_sheet_unref);
style_sheet = webkit_user_style_sheet_new (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output_stream)),
WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER,
NULL, NULL);
- webkit_user_content_manager_add_style_sheet (WEBKIT_USER_CONTENT_MANAGER (ephy_embed_shell_get_user_content_manager (ephy_embed_shell_get_default ())),
- style_sheet);
- webkit_user_style_sheet_unref (style_sheet);
+
+ update_user_style_on_all_ucm ();
}
}
@@ -95,8 +111,6 @@ user_style_sheet_file_changed (GFileMonitor *monitor,
gpointer user_data)
{
if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) {
- webkit_user_content_manager_remove_all_style_sheets (WEBKIT_USER_CONTENT_MANAGER (ephy_embed_shell_get_user_content_manager (ephy_embed_shell_get_default ())));
-
g_file_read_async (file, G_PRIORITY_DEFAULT, NULL,
(GAsyncReadyCallback)user_style_sheet_read_cb, NULL);
}
@@ -113,7 +127,9 @@ webkit_pref_callback_user_stylesheet (GSettings *settings,
if (!value) {
g_clear_object (&user_style_sheet_monitor);
- webkit_user_content_manager_remove_all_style_sheets (WEBKIT_USER_CONTENT_MANAGER (ephy_embed_shell_get_user_content_manager (ephy_embed_shell_get_default ())));
+ g_clear_pointer (&style_sheet, webkit_user_style_sheet_unref);
+
+ update_user_style_on_all_ucm ();
} else {
GFile *file;
GError *error = NULL;
@@ -551,3 +567,22 @@ ephy_embed_prefs_get_settings (void)
return g_once (&once_init, ephy_embed_prefs_init, NULL);
}
+
+void
+ephy_embed_prefs_apply_user_style (WebKitUserContentManager *ucm)
+{
+ if (style_sheet)
+ webkit_user_content_manager_add_style_sheet (ucm, style_sheet);
+}
+
+void
+ephy_embed_prefs_register_ucm (WebKitUserContentManager *ucm)
+{
+ ucm_list = g_list_append (ucm_list, ucm);
+}
+
+void
+ephy_embed_prefs_unregister_ucm (WebKitUserContentManager *ucm)
+{
+ ucm_list = g_list_remove (ucm_list, ucm);
+}
diff --git a/embed/ephy-embed-prefs.h b/embed/ephy-embed-prefs.h
index 6fc94b70a..50f063aad 100644
--- a/embed/ephy-embed-prefs.h
+++ b/embed/ephy-embed-prefs.h
@@ -30,8 +30,13 @@
G_BEGIN_DECLS
-WebKitSettings *ephy_embed_prefs_get_settings (void);
-void ephy_embed_prefs_set_cookie_accept_policy (WebKitCookieManager *cookie_manager,
- const char *settings_policy);
+WebKitSettings *ephy_embed_prefs_get_settings (void);
+void ephy_embed_prefs_set_cookie_accept_policy (WebKitCookieManager *cookie_manager,
+ const char *settings_policy);
+void ephy_embed_prefs_apply_user_style (WebKitUserContentManager *ucm);
+
+void ephy_embed_prefs_register_ucm (WebKitUserContentManager *ucm);
+void ephy_embed_prefs_unregister_ucm (WebKitUserContentManager *ucm);
+
G_END_DECLS
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 2aab3cc45..12ce9c2a5 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -60,7 +60,6 @@ typedef struct {
GtkPageSetup *page_setup;
GtkPrintSettings *print_settings;
EphyEmbedShellMode mode;
- WebKitUserContentManager *user_content;
EphyDownloadsManager *downloads_manager;
EphyPermissionsManager *permissions_manager;
EphyPasswordManager *password_manager;
@@ -208,7 +207,6 @@ ephy_embed_shell_dispose (GObject *object)
g_clear_object (&priv->global_gsb_service);
g_clear_object (&priv->about_handler);
g_clear_object (&priv->source_handler);
- g_clear_object (&priv->user_content);
g_clear_object (&priv->downloads_manager);
g_clear_object (&priv->password_manager);
g_clear_object (&priv->permissions_manager);
@@ -1150,70 +1148,6 @@ ephy_embed_shell_startup (GApplication *application)
ephy_embed_shell_setup_web_process_extensions_server (shell);
- /* User content manager */
- if (priv->mode != EPHY_EMBED_SHELL_MODE_TEST)
- priv->user_content = webkit_user_content_manager_new ();
-
- webkit_user_content_manager_register_script_message_handler_in_world (priv->user_content,
- "overview",
- priv->guid);
- g_signal_connect_object (priv->user_content, "script-message-received::overview",
- G_CALLBACK (web_process_extension_overview_message_received_cb),
- shell, 0);
-
- webkit_user_content_manager_register_script_message_handler (priv->user_content,
- "tlsErrorPage");
- g_signal_connect_object (priv->user_content, "script-message-received::tlsErrorPage",
- G_CALLBACK (web_process_extension_tls_error_page_message_received_cb),
- shell, 0);
-
- webkit_user_content_manager_register_script_message_handler (priv->user_content,
- "unsafeBrowsingErrorPage");
- g_signal_connect_object (priv->user_content, "script-message-received::unsafeBrowsingErrorPage",
- G_CALLBACK (web_process_extension_unsafe_browsing_error_page_message_received_cb),
- shell, 0);
-
- webkit_user_content_manager_register_script_message_handler_in_world (priv->user_content,
- "passwordFormFocused",
- priv->guid);
- g_signal_connect_object (priv->user_content, "script-message-received::passwordFormFocused",
- G_CALLBACK (web_process_extension_password_form_focused_message_received_cb),
- shell, 0);
-
- webkit_user_content_manager_register_script_message_handler (priv->user_content,
- "aboutApps");
- g_signal_connect_object (priv->user_content, "script-message-received::aboutApps",
- G_CALLBACK (web_process_extension_about_apps_message_received_cb),
- shell, 0);
-
- webkit_user_content_manager_register_script_message_handler_in_world (priv->user_content,
- "passwordManagerQuery",
- priv->guid);
- g_signal_connect_object (priv->user_content, "script-message-received::passwordManagerQuery",
- G_CALLBACK (web_process_extension_password_manager_query_received_cb),
- shell, 0);
-
- webkit_user_content_manager_register_script_message_handler_in_world (priv->user_content,
- "passwordManagerQueryUsernames",
- priv->guid);
- g_signal_connect_object (priv->user_content, "script-message-received::passwordManagerQueryUsernames",
- G_CALLBACK (web_process_extension_password_manager_query_usernames_received_cb),
- shell, 0);
-
- webkit_user_content_manager_register_script_message_handler_in_world (priv->user_content,
- "passwordManagerSave",
- priv->guid);
- g_signal_connect_object (priv->user_content, "script-message-received::passwordManagerSave",
- G_CALLBACK (web_process_extension_password_manager_save_received_cb),
- shell, 0);
-
- webkit_user_content_manager_register_script_message_handler_in_world (priv->user_content,
- "passwordManagerRequestSave",
- priv->guid);
- g_signal_connect_object (priv->user_content, "script-message-received::passwordManagerRequestSave",
- G_CALLBACK (web_process_extension_password_manager_request_save_received_cb),
- shell, 0);
-
webkit_web_context_set_process_model (priv->web_context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
webkit_web_context_set_sandbox_enabled (priv->web_context, TRUE);
@@ -1290,19 +1224,6 @@ ephy_embed_shell_startup (GApplication *application)
priv->filters_manager = ephy_filters_manager_new (NULL);
- g_signal_connect_object (priv->filters_manager, "filters-disabled",
- G_CALLBACK (webkit_user_content_manager_remove_all_filters),
- priv->user_content,
- G_CONNECT_SWAPPED);
- g_signal_connect_object (priv->filters_manager, "filter-ready",
- G_CALLBACK (webkit_user_content_manager_add_filter),
- priv->user_content,
- G_CONNECT_SWAPPED);
- g_signal_connect_object (priv->filters_manager, "filter-removed",
- G_CALLBACK (webkit_user_content_manager_remove_filter_by_id),
- priv->user_content,
- G_CONNECT_SWAPPED);
-
g_signal_connect_object (priv->web_context, "download-started",
G_CALLBACK (download_started_cb), shell, 0);
@@ -1320,29 +1241,6 @@ ephy_embed_shell_shutdown (GApplication *application)
if (priv->dbus_server)
g_dbus_server_stop (priv->dbus_server);
- webkit_user_content_manager_unregister_script_message_handler_in_world (priv->user_content,
- "overview",
- priv->guid);
- webkit_user_content_manager_unregister_script_message_handler (priv->user_content,
- "tlsErrorPage");
- webkit_user_content_manager_unregister_script_message_handler (priv->user_content,
- "unsafeBrowsingErrorPage");
- webkit_user_content_manager_unregister_script_message_handler_in_world (priv->user_content,
- "passwordManagerRequestSave",
- priv->guid);
- webkit_user_content_manager_unregister_script_message_handler_in_world (priv->user_content,
- "passwordFormFocused",
- priv->guid);
- webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "aboutApps");
- webkit_user_content_manager_unregister_script_message_handler_in_world (priv->user_content,
- "passwordManagerQuery",
- priv->guid);
- webkit_user_content_manager_unregister_script_message_handler_in_world (priv->user_content,
- "passwordManagerSave",
- priv->guid);
- webkit_user_content_manager_unregister_script_message_handler_in_world (priv->user_content,
- "passwordManagerQueryUsernames",
- priv->guid);
g_object_unref (ephy_embed_prefs_get_settings ());
ephy_embed_utils_shutdown ();
@@ -1401,7 +1299,6 @@ ephy_embed_shell_constructed (GObject *object)
if (mode == EPHY_EMBED_SHELL_MODE_TEST ||
mode == EPHY_EMBED_SHELL_MODE_SEARCH_PROVIDER) {
ephy_embed_shell_create_web_context (shell);
- priv->user_content = webkit_user_content_manager_new ();
}
}
@@ -1700,14 +1597,6 @@ ephy_embed_shell_get_filters_manager (EphyEmbedShell *shell)
return priv->filters_manager;
}
-WebKitUserContentManager *
-ephy_embed_shell_get_user_content_manager (EphyEmbedShell *shell)
-{
- EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
-
- return priv->user_content;
-}
-
const char *
ephy_embed_shell_get_guid (EphyEmbedShell *shell)
{
@@ -1759,3 +1648,119 @@ ephy_embed_shell_get_password_manager (EphyEmbedShell *shell)
return priv->password_manager;
}
+
+void
+ephy_embed_shell_register_ucm_handler (EphyEmbedShell *shell,
+ WebKitUserContentManager *ucm)
+{
+ EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
+
+ /* User content manager */
+ webkit_user_content_manager_register_script_message_handler_in_world (ucm,
+ "overview",
+ priv->guid);
+ g_signal_connect_object (ucm, "script-message-received::overview",
+ G_CALLBACK (web_process_extension_overview_message_received_cb),
+ shell, 0);
+
+ webkit_user_content_manager_register_script_message_handler (ucm,
+ "tlsErrorPage");
+ g_signal_connect_object (ucm, "script-message-received::tlsErrorPage",
+ G_CALLBACK (web_process_extension_tls_error_page_message_received_cb),
+ shell, 0);
+
+ webkit_user_content_manager_register_script_message_handler (ucm,
+ "unsafeBrowsingErrorPage");
+ g_signal_connect_object (ucm, "script-message-received::unsafeBrowsingErrorPage",
+ G_CALLBACK (web_process_extension_unsafe_browsing_error_page_message_received_cb),
+ shell, 0);
+
+ webkit_user_content_manager_register_script_message_handler_in_world (ucm,
+ "passwordFormFocused",
+ priv->guid);
+ g_signal_connect_object (ucm, "script-message-received::passwordFormFocused",
+ G_CALLBACK (web_process_extension_password_form_focused_message_received_cb),
+ shell, 0);
+
+ webkit_user_content_manager_register_script_message_handler (ucm,
+ "aboutApps");
+ g_signal_connect_object (ucm, "script-message-received::aboutApps",
+ G_CALLBACK (web_process_extension_about_apps_message_received_cb),
+ shell, 0);
+
+ webkit_user_content_manager_register_script_message_handler_in_world (ucm,
+ "passwordManagerQuery",
+ priv->guid);
+ g_signal_connect_object (ucm, "script-message-received::passwordManagerQuery",
+ G_CALLBACK (web_process_extension_password_manager_query_received_cb),
+ shell, 0);
+
+ webkit_user_content_manager_register_script_message_handler_in_world (ucm,
+ "passwordManagerQueryUsernames",
+ priv->guid);
+ g_signal_connect_object (ucm, "script-message-received::passwordManagerQueryUsernames",
+ G_CALLBACK (web_process_extension_password_manager_query_usernames_received_cb),
+ shell, 0);
+
+ webkit_user_content_manager_register_script_message_handler_in_world (ucm,
+ "passwordManagerSave",
+ priv->guid);
+ g_signal_connect_object (ucm, "script-message-received::passwordManagerSave",
+ G_CALLBACK (web_process_extension_password_manager_save_received_cb),
+ shell, 0);
+
+ webkit_user_content_manager_register_script_message_handler_in_world (ucm,
+ "passwordManagerRequestSave",
+ priv->guid);
+ g_signal_connect_object (ucm, "script-message-received::passwordManagerRequestSave",
+ G_CALLBACK (web_process_extension_password_manager_request_save_received_cb),
+ shell, 0);
+
+ /* Filter Manager */
+ g_signal_connect_object (priv->filters_manager, "filters-disabled",
+ G_CALLBACK (webkit_user_content_manager_remove_all_filters),
+ ucm,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (priv->filters_manager, "filter-ready",
+ G_CALLBACK (webkit_user_content_manager_add_filter),
+ ucm,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (priv->filters_manager, "filter-removed",
+ G_CALLBACK (webkit_user_content_manager_remove_filter_by_id),
+ ucm,
+ G_CONNECT_SWAPPED);
+
+ /* User Scripts */
+ ephy_embed_prefs_apply_user_style (ucm);
+}
+
+void
+ephy_embed_shell_unregister_ucm_handler (EphyEmbedShell *shell,
+ WebKitUserContentManager *ucm)
+{
+ EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
+
+ webkit_user_content_manager_unregister_script_message_handler_in_world (ucm,
+ "overview",
+ priv->guid);
+ webkit_user_content_manager_unregister_script_message_handler (ucm,
+ "tlsErrorPage");
+ webkit_user_content_manager_unregister_script_message_handler (ucm,
+ "unsafeBrowsingErrorPage");
+ webkit_user_content_manager_unregister_script_message_handler_in_world (ucm,
+ "passwordManagerRequestSave",
+ priv->guid);
+ webkit_user_content_manager_unregister_script_message_handler_in_world (ucm,
+ "passwordFormFocused",
+ priv->guid);
+ webkit_user_content_manager_unregister_script_message_handler (ucm, "aboutApps");
+ webkit_user_content_manager_unregister_script_message_handler_in_world (ucm,
+ "passwordManagerQuery",
+ priv->guid);
+ webkit_user_content_manager_unregister_script_message_handler_in_world (ucm,
+ "passwordManagerSave",
+ priv->guid);
+ webkit_user_content_manager_unregister_script_message_handler_in_world (ucm,
+ "passwordManagerQueryUsernames",
+ priv->guid);
+}
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index 6abfddbc0..d4ec41f26 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -81,10 +81,15 @@ void ephy_embed_shell_set_thumbnail_path (EphyEmbedShell
void ephy_embed_shell_schedule_thumbnail_update (EphyEmbedShell *shell,
EphyHistoryURL *url);
EphyFiltersManager *ephy_embed_shell_get_filters_manager (EphyEmbedShell *shell);
-WebKitUserContentManager *ephy_embed_shell_get_user_content_manager (EphyEmbedShell *shell);
EphyDownloadsManager *ephy_embed_shell_get_downloads_manager (EphyEmbedShell *shell);
EphyPermissionsManager *ephy_embed_shell_get_permissions_manager (EphyEmbedShell *shell);
EphySearchEngineManager *ephy_embed_shell_get_search_engine_manager (EphyEmbedShell *shell);
EphyPasswordManager *ephy_embed_shell_get_password_manager (EphyEmbedShell *shell);
+void ephy_embed_shell_register_ucm_handler (EphyEmbedShell *shell,
+ WebKitUserContentManager *ucm);
+void ephy_embed_shell_unregister_ucm_handler (EphyEmbedShell *shell,
+ WebKitUserContentManager *ucm);
+
+
G_END_DECLS
diff --git a/embed/ephy-filters-manager.c b/embed/ephy-filters-manager.c
index f9c5b4f6e..198fd7207 100644
--- a/embed/ephy-filters-manager.c
+++ b/embed/ephy-filters-manager.c
@@ -44,6 +44,7 @@ struct _EphyFiltersManager {
gint64 update_time;
guint update_timeout_id;
GCancellable *cancellable;
+ WebKitUserContentFilter *wk_filter;
WebKitUserContentFilterStore *store;
};
@@ -471,7 +472,6 @@ filter_saved_cb (WebKitUserContentFilterStore *store,
FilterInfo *self)
{
g_autoptr (GError) error = NULL;
- g_autoptr (WebKitUserContentFilter) wk_filter = NULL;
if (!self->manager)
return;
@@ -481,12 +481,13 @@ filter_saved_cb (WebKitUserContentFilterStore *store,
g_assert (self);
g_assert (self->manager->store == store);
- wk_filter = webkit_user_content_filter_store_save_finish (self->manager->store,
- result,
- &error);
- if (wk_filter) {
+ g_clear_object (&self->manager->wk_filter);
+ self->manager->wk_filter = webkit_user_content_filter_store_save_finish (self->manager->store,
+ result,
+ &error);
+ if (self->manager->wk_filter) {
LOG ("Filter %s compiled successfully.", filter_info_get_identifier (self));
- filter_info_setup_enable_compiled_filter (self, wk_filter);
+ filter_info_setup_enable_compiled_filter (self, self->manager->wk_filter);
filter_info_save_sidecar (self,
self->manager->cancellable,
(GAsyncReadyCallback)sidecar_saved_cb,
@@ -623,7 +624,6 @@ filter_load_cb (WebKitUserContentFilterStore *store,
FilterInfo *self)
{
g_autoptr (GError) error = NULL;
- g_autoptr (WebKitUserContentFilter) wk_filter = NULL;
g_autoptr (GFile) source_file = NULL;
g_autoptr (GFile) json_file = NULL;
g_autofree char *json_file_uri = NULL;
@@ -637,14 +637,15 @@ filter_load_cb (WebKitUserContentFilterStore *store,
g_assert (self);
g_assert (store == self->manager->store);
- wk_filter = webkit_user_content_filter_store_load_finish (self->manager->store,
- result,
- &error);
- self->found = (wk_filter != NULL);
+ g_clear_object (&self->manager->wk_filter);
+ self->manager->wk_filter = webkit_user_content_filter_store_load_finish (self->manager->store,
+ result,
+ &error);
+ self->found = (self->manager->wk_filter != NULL);
- if (wk_filter) {
+ if (self->manager->wk_filter) {
LOG ("Found compiled filter %s.", filter_info_get_identifier (self));
- filter_info_setup_enable_compiled_filter (self, wk_filter);
+ filter_info_setup_enable_compiled_filter (self, self->manager->wk_filter);
LOG ("Update %sneeded for filter %s (last %" PRIu64 "s ago, interval %us)",
filter_info_needs_updating_from_source (self) ? "" : "not ",
filter_info_get_identifier (self),
@@ -916,6 +917,7 @@ ephy_filters_manager_dispose (GObject *object)
g_cancellable_cancel (manager->cancellable);
g_clear_object (&manager->cancellable);
}
+ g_clear_object (&manager->wk_filter);
g_clear_object (&manager->store);
G_OBJECT_CLASS (ephy_filters_manager_parent_class)->dispose (object);
@@ -1093,3 +1095,17 @@ ephy_filters_manager_get_is_initialized (EphyFiltersManager *manager)
g_return_val_if_fail (EPHY_IS_FILTERS_MANAGER (manager), FALSE);
return manager->is_initialized;
}
+
+void
+ephy_filters_manager_set_ucm_forbids_ads (EphyFiltersManager *manager,
+ WebKitUserContentManager *ucm,
+ gboolean forbids_ads)
+{
+ if (!manager->wk_filter)
+ return;
+
+ if (forbids_ads)
+ webkit_user_content_manager_add_filter (ucm, manager->wk_filter);
+ else
+ webkit_user_content_manager_remove_filter (ucm, manager->wk_filter);
+}
diff --git a/embed/ephy-filters-manager.h b/embed/ephy-filters-manager.h
index a6dc4c8d0..a69d84ea2 100644
--- a/embed/ephy-filters-manager.h
+++ b/embed/ephy-filters-manager.h
@@ -21,6 +21,7 @@
#pragma once
#include <glib-object.h>
+#include <webkit2/webkit2.h>
G_BEGIN_DECLS
@@ -31,5 +32,9 @@ G_DECLARE_FINAL_TYPE (EphyFiltersManager, ephy_filters_manager, EPHY, FILTERS_MA
EphyFiltersManager *ephy_filters_manager_new (const char *adblock_filters_dir);
const char *ephy_filters_manager_get_adblock_filters_dir (EphyFiltersManager *manager);
gboolean ephy_filters_manager_get_is_initialized (EphyFiltersManager *manager);
+void ephy_filters_manager_set_ucm_forbids_ads (EphyFiltersManager *manager,
+ WebKitUserContentManager *ucm,
+ gboolean forbids_ads);
+
G_END_DECLS
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 8b563b8ad..de394f104 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -34,6 +34,7 @@
#include "ephy-file-chooser.h"
#include "ephy-file-helpers.h"
#include "ephy-file-monitor.h"
+#include "ephy-filters-manager.h"
#include "ephy-gsb-utils.h"
#include "ephy-history-service.h"
#include "ephy-lib-type-builtins.h"
@@ -925,6 +926,10 @@ static void
ephy_web_view_dispose (GObject *object)
{
EphyWebView *view = EPHY_WEB_VIEW (object);
+ WebKitUserContentManager *ucm = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (view));
+
+ ephy_embed_prefs_unregister_ucm (ucm);
+ ephy_embed_shell_unregister_ucm_handler (ephy_embed_shell_get_default (), ucm);
if (view->web_process_extension) {
g_object_remove_weak_pointer (G_OBJECT (view->web_process_extension), (gpointer *)&view->web_process_extension);
@@ -1928,6 +1933,30 @@ update_security_status_for_committed_load (EphyWebView *view,
}
static void
+update_ucm_ads_state (WebKitWebView *web_view,
+ const char *uri)
+{
+ WebKitUserContentManager *ucm = webkit_web_view_get_user_content_manager (web_view);
+ EphyPermission permission = EPHY_PERMISSION_UNDECIDED;
+ gboolean enable = FALSE;
+ g_autofree gchar *origin = NULL;
+ EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+
+ origin = ephy_uri_to_security_origin (uri);
+
+ /* Check page setting first in case it overwrites global setting */
+ if (origin)
+ permission = ephy_permissions_manager_get_permission (ephy_embed_shell_get_permissions_manager (shell),
+ EPHY_PERMISSION_TYPE_SHOW_ADS,
+ origin);
+ enable = permission == EPHY_PERMISSION_DENY;
+ if (permission == EPHY_PERMISSION_UNDECIDED && g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK))
+ enable = TRUE;
+
+ ephy_filters_manager_set_ucm_forbids_ads (ephy_embed_shell_get_filters_manager (shell), ucm, enable);
+}
+
+static void
load_changed_cb (WebKitWebView *web_view,
WebKitLoadEvent load_event,
gpointer user_data)
@@ -1979,6 +2008,7 @@ load_changed_cb (WebKitWebView *web_view,
uri = webkit_web_view_get_uri (web_view);
ephy_web_view_set_committed_location (view, uri);
update_security_status_for_committed_load (view, uri);
+ update_ucm_ads_state (web_view, uri);
/* History. */
if (ephy_embed_utils_is_no_show_address (uri))
@@ -3045,10 +3075,14 @@ GtkWidget *
ephy_web_view_new (void)
{
EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+ WebKitUserContentManager *ucm = webkit_user_content_manager_new ();
+
+ ephy_embed_shell_register_ucm_handler (shell, ucm);
+ ephy_embed_prefs_register_ucm (ucm);
return g_object_new (EPHY_TYPE_WEB_VIEW,
"web-context", ephy_embed_shell_get_web_context (shell),
- "user-content-manager", ephy_embed_shell_get_user_content_manager (shell),
+ "user-content-manager", ucm,
"settings", ephy_embed_prefs_get_settings (),
"is-controlled-by-automation", ephy_embed_shell_get_mode (shell) == EPHY_EMBED_SHELL_MODE_AUTOMATION,
NULL);
@@ -3058,10 +3092,14 @@ GtkWidget *
ephy_web_view_new_with_related_view (WebKitWebView *related_view)
{
EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+ WebKitUserContentManager *ucm = webkit_user_content_manager_new ();
+
+ ephy_embed_shell_register_ucm_handler (shell, ucm);
+ ephy_embed_prefs_register_ucm (ucm);
return g_object_new (EPHY_TYPE_WEB_VIEW,
"related-view", related_view,
- "user-content-manager", ephy_embed_shell_get_user_content_manager (shell),
+ "user-content-manager", ucm,
"settings", ephy_embed_prefs_get_settings (),
NULL);
}