[epiphany] Add adblock GSetting, use it



commit a5121fa4a435b4cee404ed8280b14debc174996e
Author: Xan Lopez <xan igalia com>
Date:   Mon Oct 1 20:48:59 2012 +0200

    Add adblock GSetting, use it
    
    org.gnome.epiphany.web.enable-adblock, controls whether adblock is
    enabled (globally).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681657

 data/org.gnome.epiphany.gschema.xml |    5 +++++
 embed/ephy-embed.c                  |   34 +++++++++++++++++++++++++++++++++-
 lib/ephy-prefs.h                    |    1 +
 3 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index 7437c85..f97681e 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -189,6 +189,11 @@
 			<summary>Do Not Track</summary>
 			<description>Whether to tell websites that we do not wish to be tracked. Please note that web pages are not forced to follow this setting.</description>
 		</key>
+		<key type="b" name="enable-adblock">
+			<default>false</default>
+			<summary>Enable Adblock</summary>
+			<description>Whether to block the embedded advertisements that web pages might want to show.</description>
+		</key>
 	</schema>
 	<schema path="/org/gnome/epiphany/state/" id="org.gnome.Epiphany.state">
 		<key type="s" name="open-dir">
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index cd11748..c6c7579 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -96,6 +96,8 @@ struct _EphyEmbedPrivate
 
   gulong status_handler_id;
   gulong progress_update_handler_id;
+
+  gulong adblock_handler_id;
 };
 
 enum
@@ -408,6 +410,11 @@ ephy_embed_dispose (GObject *object)
     priv->fullscreen_message_id = 0;
   }
 
+  if (priv->adblock_handler_id) {
+    g_signal_handler_disconnect (priv->web_view, priv->adblock_handler_id);
+    priv->adblock_handler_id = 0;
+  }
+
   G_OBJECT_CLASS (ephy_embed_parent_class)->dispose (object);
 }
 
@@ -824,6 +831,26 @@ progress_update (EphyWebView *view, GParamSpec *pspec, EphyEmbed *embed)
                                  (loading || progress == 1.0) ? progress : 0.0);
 }
 
+#ifndef HAVE_WEBKIT2
+static void
+setup_adblock (GSettings *settings,
+               char *key,
+               EphyEmbed *embed)
+{
+  EphyEmbedPrivate *priv = embed->priv;
+  EphyWebView *web_view = ephy_embed_get_web_view (embed);
+
+  if (g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK) &&
+      priv->adblock_handler_id == 0) {
+    priv->adblock_handler_id = g_signal_connect (web_view, "resource_request_starting",
+                                                 G_CALLBACK (resource_request_starting_cb), embed);
+  } else if (priv->adblock_handler_id) {
+    g_signal_handler_disconnect (web_view, priv->adblock_handler_id);
+    priv->adblock_handler_id = 0;
+  }
+}
+#endif
+
 static void
 ephy_embed_constructed (GObject *object)
 {
@@ -919,11 +946,16 @@ ephy_embed_constructed (GObject *object)
 #else
   g_object_connect (web_view,
                     "signal::notify::load-status", G_CALLBACK (load_status_changed_cb), embed,
-                    "signal::resource-request-starting", G_CALLBACK (resource_request_starting_cb), embed,
                     "signal::download-requested", G_CALLBACK (download_requested_cb), embed,
                     "signal::entering-fullscreen", G_CALLBACK (entering_fullscreen_cb), embed,
                     "signal::leaving-fullscreen", G_CALLBACK (leaving_fullscreen_cb), embed,
                     NULL);
+
+  g_signal_connect (EPHY_SETTINGS_WEB,
+                    "changed::" EPHY_PREFS_WEB_ENABLE_ADBLOCK,
+                    G_CALLBACK (setup_adblock), embed);
+
+  setup_adblock (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK, embed);
 #endif
 
   priv->status_handler_id = g_signal_connect (web_view, "notify::status-message",
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index a5b182d..ccc7238 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -108,6 +108,7 @@ typedef enum
 #define EPHY_PREFS_WEB_IMAGE_ANIMATION_MODE  "image-animation-mode"
 #define EPHY_PREFS_WEB_DEFAULT_ENCODING      "default-encoding"
 #define EPHY_PREFS_WEB_DO_NOT_TRACK          "do-not-track"
+#define EPHY_PREFS_WEB_ENABLE_ADBLOCK        "enable-adblock"
 
 #define EPHY_PREFS_SCHEMA                         "org.gnome.Epiphany"
 #define EPHY_PREFS_USER_AGENT                     "user-agent"



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