]> spindle.queued.net Git - midori/commitdiff
Handle https:// URIs in Adblock properly
authorChristian Dywan <christian@twotoasts.de>
Mon, 5 Apr 2010 21:20:45 +0000 (23:20 +0200)
committerChristian Dywan <christian@twotoasts.de>
Tue, 6 Apr 2010 00:41:29 +0000 (02:41 +0200)
We mark URIs as 'disabled' by replacing the : with a -. This
fails if there is an https:// URI and we want to restore it.

For clarity, the macros ADBLOCK_FILTER_SET and
ADBLOCK_FILTER_IS_SET are introduced to handle the details.

extensions/adblock.c

index 6112a946041ca381526f4f4fa4a9dc045b60b0a9..0ec1c22b80e3980b9c8cf4d0865d36c2148764f7 100644 (file)
 #define ADBLOCK_FILTER_VALID(__filter) \
     (__filter && (g_str_has_prefix (__filter, "http") \
                || g_str_has_prefix (__filter, "file")))
+#define ADBLOCK_FILTER_SET(__filter,__active) \
+    filter[4] = __active ? (__filter[5] == ':' ? 's' : ':') : '-'
+#define ADBLOCK_FILTER_IS_SET(__filter) \
+    filter[4] != '-'
 
 static GHashTable* pattern;
 static GHashTable* keys;
@@ -192,7 +196,7 @@ adblock_preferences_render_tick_cb (GtkTreeViewColumn* column,
 
     g_object_set (renderer,
         "activatable", ADBLOCK_FILTER_VALID (filter),
-        "active", ADBLOCK_FILTER_VALID (filter) && filter[4] != '-',
+        "active", ADBLOCK_FILTER_VALID (filter) && ADBLOCK_FILTER_IS_SET (filter),
         NULL);
 
     g_free (filter);
@@ -225,7 +229,7 @@ adblock_preferences_renderer_toggle_toggled_cb (GtkCellRendererToggle* renderer,
 
         if (ADBLOCK_FILTER_VALID (filter))
         {
-            filter[4] = ':';
+            ADBLOCK_FILTER_SET (filter, TRUE);
             if (gtk_cell_renderer_toggle_get_active (renderer))
             {
                 if (!strncmp (filter, "http", 4))
@@ -234,7 +238,7 @@ adblock_preferences_renderer_toggle_toggled_cb (GtkCellRendererToggle* renderer,
                     g_unlink (filename);
                     g_free (filename);
                 }
-                filter[4] = '-';
+                ADBLOCK_FILTER_SET (filter, FALSE);
             }
 
             gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, filter, -1);
@@ -256,7 +260,7 @@ adblock_preferences_render_text_cb (GtkTreeViewColumn* column,
     gtk_tree_model_get (model, iter, 0, &filter, -1);
 
     if (ADBLOCK_FILTER_VALID (filter))
-        filter[4] = ':';
+        ADBLOCK_FILTER_SET (filter, TRUE);
 
     g_object_set (renderer,
         "text", filter,