[epiphany] Only download adblock filters if adblocker is actually enabled



commit b360172a7d53bc54607c766918f508dc12ad698d
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Jan 22 22:23:42 2017 -0600

    Only download adblock filters if adblocker is actually enabled
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776286

 embed/ephy-embed-shell.c              |   19 +++++++++++++++++--
 embed/web-extension/ephy-uri-tester.c |   28 ++++++++++++++++++++++++----
 2 files changed, 41 insertions(+), 6 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 794e3d3..b3c7d29 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -862,6 +862,11 @@ ephy_embed_shell_update_adblock_filter_files (EphyEmbedShell *shell)
   char **filters;
   GList *files = NULL;
 
+  if (!g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK)) {
+    ephy_embed_shell_remove_old_adblock_filters (shell, files);
+    return;
+  }
+
   filters = g_settings_get_strv (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ADBLOCK_FILTERS);
   for (guint i = 0; filters[i]; i++) {
     GFile *filter_file;
@@ -887,6 +892,14 @@ ephy_uri_tester_adblock_filters_changed_cb (GSettings      *settings,
 }
 
 static void
+ephy_uri_tester_enable_adblock_changed_cb (GSettings      *settings,
+                                           char           *key,
+                                           EphyEmbedShell *shell)
+{
+  ephy_embed_shell_update_adblock_filter_files (shell);
+}
+
+static void
 ephy_embed_shell_update_uri_tester (EphyEmbedShell *shell)
 {
   EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
@@ -1109,9 +1122,11 @@ ephy_embed_shell_startup (GApplication *application)
 
   G_APPLICATION_CLASS (ephy_embed_shell_parent_class)->startup (application);
 
-  /* Note: it's up here because we must connect *before* reading the setting. */
-  g_signal_connect (EPHY_SETTINGS_WEB, "changed::adblock-filters",
+  /* Note: up here because we must connect *before* reading the settings. */
+  g_signal_connect (EPHY_SETTINGS_WEB, "changed::" EPHY_PREFS_WEB_ADBLOCK_FILTERS,
                     G_CALLBACK (ephy_uri_tester_adblock_filters_changed_cb), shell);
+  g_signal_connect (EPHY_SETTINGS_WEB, "changed::" EPHY_PREFS_WEB_ENABLE_ADBLOCK,
+                    G_CALLBACK (ephy_uri_tester_enable_adblock_changed_cb), shell);
 
   ephy_embed_shell_update_uri_tester (shell);
 
diff --git a/embed/web-extension/ephy-uri-tester.c b/embed/web-extension/ephy-uri-tester.c
index fa82efe..4e46eb0 100644
--- a/embed/web-extension/ephy-uri-tester.c
+++ b/embed/web-extension/ephy-uri-tester.c
@@ -864,9 +864,7 @@ ephy_uri_tester_new (const char *adblock_data_dir)
 }
 
 static void
-ephy_uri_tester_adblock_filters_changed_cb (GSettings     *settings,
-                                            char          *key,
-                                            EphyUriTester *tester)
+ephy_uri_tester_reload_adblock_filters (EphyUriTester *tester)
 {
   g_hash_table_remove_all (tester->pattern);
   g_hash_table_remove_all (tester->keys);
@@ -882,6 +880,22 @@ ephy_uri_tester_adblock_filters_changed_cb (GSettings     *settings,
   ephy_uri_tester_load (tester);
 }
 
+static void
+ephy_uri_tester_adblock_filters_changed_cb (GSettings     *settings,
+                                            char          *key,
+                                            EphyUriTester *tester)
+{
+  ephy_uri_tester_reload_adblock_filters (tester);
+}
+
+static void
+ephy_uri_tester_enable_adblock_changed_cb (GSettings     *settings,
+                                           char          *key,
+                                           EphyUriTester *tester)
+{
+  ephy_uri_tester_reload_adblock_filters (tester);
+}
+
 void
 ephy_uri_tester_load (EphyUriTester *tester)
 {
@@ -890,6 +904,9 @@ ephy_uri_tester_load (EphyUriTester *tester)
 
   g_return_if_fail (EPHY_IS_URI_TESTER (tester));
 
+  if (!g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK))
+    tester->adblock_loaded = TRUE;
+
   if (tester->adblock_loaded
 #ifdef HAVE_LIBHTTPSEVERYWHERE
       && tester->https_everywhere_loaded
@@ -898,13 +915,16 @@ ephy_uri_tester_load (EphyUriTester *tester)
     return;
 
   g_signal_handlers_disconnect_by_func (EPHY_SETTINGS_WEB, ephy_uri_tester_adblock_filters_changed_cb, 
tester);
+  g_signal_handlers_disconnect_by_func (EPHY_SETTINGS_WEB, ephy_uri_tester_enable_adblock_changed_cb, 
tester);
 
   task = g_task_new (tester, NULL, NULL, NULL);
   g_task_run_in_thread_sync (task, (GTaskThreadFunc)ephy_uri_tester_load_sync);
   g_object_unref (task);
 
-  g_signal_connect (EPHY_SETTINGS_WEB, "changed::adblock-filters",
+  g_signal_connect (EPHY_SETTINGS_WEB, "changed::" EPHY_PREFS_WEB_ADBLOCK_FILTERS,
                     G_CALLBACK (ephy_uri_tester_adblock_filters_changed_cb), tester);
+  g_signal_connect (EPHY_SETTINGS_WEB, "changed::" EPHY_PREFS_WEB_ENABLE_ADBLOCK,
+                    G_CALLBACK (ephy_uri_tester_enable_adblock_changed_cb), tester);
   /* GSettings never emits the changed signal until after we read the setting
    * the first time after connecting the handler... work around this.*/
   trash = g_settings_get_strv (EPHY_SETTINGS_WEB, "adblock-filters");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]