[Xfce4-commits] <midori:master> Handle abp: and abp:// links

Christian Dywan noreply at xfce.org
Thu Jun 28 00:00:01 CEST 2012


Updating branch refs/heads/master
         to b18667220c8cf6c80d0866328d2e73fec6edb3b6 (commit)
       from 2cec07a6ea9d1d7d0da4ed4c45d0a3dbcda677a4 (commit)

commit b18667220c8cf6c80d0866328d2e73fec6edb3b6
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed Jun 27 23:58:07 2012 +0200

    Handle abp: and abp:// links
    
    Fixed: https://bugs.launchpad.net/midori/+bug/942978

 extensions/adblock.c |   46 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index e9cb482..852a4b1 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -571,6 +571,7 @@ adblock_get_preferences_dialog (MidoriExtension* extension)
     vbox = gtk_vbox_new (FALSE, 4);
     gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 4);
     button = gtk_button_new_from_stock (GTK_STOCK_ADD);
+    g_object_set_data (G_OBJECT (dialog), "entry", entry);
     g_object_set_data (G_OBJECT (button), "entry", entry);
     g_signal_connect (button, "clicked",
         G_CALLBACK (adblock_preferences_add_clicked_cb), liststore);
@@ -619,8 +620,9 @@ adblock_get_preferences_dialog (MidoriExtension* extension)
     return dialog;
 }
 
-static void
-adblock_open_preferences_cb (MidoriExtension* extension)
+static GtkWidget*
+adblock_show_preferences_dialog (MidoriExtension* extension,
+                                 const gchar*     uri)
 {
     static GtkWidget* dialog = NULL;
 
@@ -633,6 +635,19 @@ adblock_open_preferences_cb (MidoriExtension* extension)
     }
     else
         gtk_window_present (GTK_WINDOW (dialog));
+
+    if (uri != NULL)
+    {
+        GtkWidget* entry = g_object_get_data (G_OBJECT (dialog), "entry");
+        gtk_entry_set_text (GTK_ENTRY (entry), uri);
+    }
+    return dialog;
+}
+
+static void
+adblock_open_preferences_cb (MidoriExtension* extension)
+{
+    adblock_show_preferences_dialog (extension, NULL);
 }
 
 static inline gint
@@ -791,8 +806,29 @@ adblock_navigation_policy_decision_requested_cb (WebKitWebView*             web_
                                                  WebKitNetworkRequest*      request,
                                                  WebKitWebNavigationAction* action,
                                                  WebKitWebPolicyDecision*   decision,
-                                                 MidoriView*                view)
+                                                 MidoriExtension*           extension)
 {
+    const gchar* uri = webkit_network_request_get_uri (request);
+    if (g_str_has_prefix (uri, "abp:"))
+    {
+        gchar** parts;
+        gchar* filter;
+        if (g_str_has_prefix (uri, "abp:subscribe?location="))
+            uri = &uri[23];
+        else if (g_str_has_prefix (uri, "abp://subscribe?location="))
+            uri = &uri[25];
+        else
+            return FALSE;
+
+        parts = g_strsplit (uri, "&", 2);
+        filter = soup_uri_decode (parts[0]);
+        webkit_web_policy_decision_ignore (decision);
+        adblock_show_preferences_dialog (extension, filter);
+        g_free (filter);
+        g_strfreev (parts);
+        return TRUE;
+    }
+
     if (web_frame == webkit_web_view_get_main_frame (web_view))
     {
         const gchar* req_uri = webkit_network_request_get_uri (request);
@@ -1019,7 +1055,7 @@ adblock_add_tab_cb (MidoriBrowser*   browser,
     g_signal_connect_after (web_view, "populate-popup",
         G_CALLBACK (adblock_populate_popup_cb), extension);
     g_signal_connect (web_view, "navigation-policy-decision-requested",
-        G_CALLBACK (adblock_navigation_policy_decision_requested_cb), view);
+        G_CALLBACK (adblock_navigation_policy_decision_requested_cb), extension);
     g_signal_connect (web_view, "resource-request-starting",
         G_CALLBACK (adblock_resource_request_starting_cb), view);
     g_signal_connect (web_view, "load-finished",
@@ -1510,7 +1546,7 @@ adblock_deactivate_tabs (MidoriView*      view,
     g_signal_handlers_disconnect_by_func (
        web_view, adblock_load_finished_cb, view);
     g_signal_handlers_disconnect_by_func (
-       web_view, adblock_navigation_policy_decision_requested_cb, view);
+       web_view, adblock_navigation_policy_decision_requested_cb, extension);
 }
 
 static void


More information about the Xfce4-commits mailing list