[Xfce4-commits] <midori:master> Refactor JS code generation for adblock

Christian Dywan noreply at xfce.org
Tue Jan 10 02:14:02 CET 2012


Updating branch refs/heads/master
         to 835f808115ef961e4008e7f9e6a8f31e540b7f6c (commit)
       from 729e960cd602bd0b37f233ed853ad23996dfcd66 (commit)

commit 835f808115ef961e4008e7f9e6a8f31e540b7f6c
Author: Alexander Butenko <a.butenka at gmail.com>
Date:   Sat Jan 7 20:28:42 2012 -0400

    Refactor JS code generation for adblock

 extensions/adblock.c |   49 +++++++++++++++++--------------------------------
 1 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index 3f0c29b..ed788e8 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -1,6 +1,6 @@
 /*
- Copyright (C) 2009-2010 Christian Dywan <christian at twotoasts.de>
- Copyright (C) 2009 Alexander Butenko <a.butenka at gmail.com>
+ Copyright (C) 2009-2012 Christian Dywan <christian at twotoasts.de>
+ Copyright (C) 2009-2012 Alexander Butenko <a.butenka at gmail.com>
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
@@ -9,7 +9,6 @@
 
  See the file COPYING for the full license text.
 */
-
 #include <midori/midori.h>
 #include <glib/gstdio.h>
 
@@ -55,13 +54,18 @@ adblock_reload_rules (MidoriExtension* extension,
 static gchar*
 adblock_build_js (const gchar* uri)
 {
-    const gchar* domain;
-    const gchar* block;
+    gchar* domain;
+    const gchar* style;
     GString* subdomain;
     GString* code;
     int cnt = 0, blockscnt = 0;
     gchar** subdomains;
-    SoupURI* suri;
+
+    domain = midori_uri_parse_hostname (uri, NULL);
+    subdomains = g_strsplit (domain, ".", -1);
+    g_free (domain);
+    if (!subdomains)
+        return NULL;
 
     code = g_string_new (
         "window.addEventListener ('DOMContentLoaded',"
@@ -70,32 +74,17 @@ adblock_build_js (const gchar* uri)
         "       return;"
         "   public = '");
 
-    suri = soup_uri_new (uri);
-    if (!suri)
-        return NULL;
-
-    domain = soup_uri_get_host (suri);
-    subdomains = g_strsplit (domain, ".", -1);
-    if (!subdomains)
-    {
-        soup_uri_free (suri);
-        g_string_free (code, TRUE);
-        return NULL;
-    }
-
-    while (subdomains[cnt] != NULL)
-        cnt++;
-    cnt--;
-
+    cnt = g_strv_length (subdomains) - 1;
     subdomain = g_string_new (subdomains [cnt]);
     g_string_prepend_c (subdomain, '.');
     cnt--;
-    while  (cnt >= 0)
+    while (cnt >= 0)
     {
         g_string_prepend (subdomain, subdomains[cnt]);
-        if ((block = g_hash_table_lookup (blockcssprivate, subdomain->str)))
+        /* g_debug ("processing %s", subdomain->str); */
+        if ((style = g_hash_table_lookup (blockcssprivate, subdomain->str)))
         {
-            g_string_append (code, block);
+            g_string_append (code, style);
             g_string_append_c (code, ',');
             blockscnt++;
         }
@@ -104,13 +93,9 @@ adblock_build_js (const gchar* uri)
     }
     g_string_free (subdomain, TRUE);
     g_strfreev (subdomains);
-    soup_uri_free (suri);
 
     if (blockscnt == 0)
-    {
-        g_string_free (code, TRUE);
-        return NULL;
-    }
+        return g_string_free (code, TRUE);
 
     g_string_append (code,
         "   zz-non-existent {display: none !important}';"
@@ -1562,7 +1547,7 @@ extension_init (void)
     MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION,
         "name", _("Advertisement blocker"),
         "description", _("Block advertisements according to a filter list"),
-        "version", "0.5" MIDORI_VERSION_SUFFIX,
+        "version", "0.6" MIDORI_VERSION_SUFFIX,
         "authors", "Christian Dywan <christian at twotoasts.de>",
         NULL);
     midori_extension_install_string_list (extension, "filters", NULL, G_MAXSIZE);


More information about the Xfce4-commits mailing list