From 34e0c98cb7bd4b34b2a2e80ac3f9eff5144f9c73 Mon Sep 17 00:00:00 2001 From: Alexander Butenko Date: Sun, 30 Oct 2011 15:19:06 +0100 Subject: [PATCH] Use midori_web_settings_add_style for adblock CSS --- extensions/adblock.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/extensions/adblock.c b/extensions/adblock.c index 35f87821..803c197e 100644 --- a/extensions/adblock.c +++ b/extensions/adblock.c @@ -51,9 +51,12 @@ static guint debug; static gboolean adblock_parse_file (gchar* path); +static void +adblock_reload_rules (MidoriExtension* extension, + gboolean custom_only); + static gchar* -adblock_build_js (const gchar* style, - const gchar* private) +adblock_build_js (const gchar* private) { return g_strdup_printf ( "window.addEventListener ('DOMContentLoaded'," @@ -62,7 +65,7 @@ adblock_build_js (const gchar* style, " return;" " var URL = location.href;" " var sites = new Array(); %s;" - " var public = '%s';" + " var public = '';" " for (var i in sites) {" " if (URL.indexOf(i) != -1 && sites[i] ){" " public += ', .'+sites[i];" @@ -76,8 +79,7 @@ adblock_build_js (const gchar* style, " var head = document.getElementsByTagName('head')[0];" " if (head) head.appendChild(mystyle);" "}, true);", - private, - style); + private); } static GString* @@ -108,17 +110,24 @@ adblock_init_db () } static void -adblock_download_notify_status_cb (WebKitDownload* download, - GParamSpec* pspec, - gchar* path) +adblock_download_notify_status_cb (WebKitDownload* download, + GParamSpec* pspec, + MidoriExtension* extension) { + gchar* path; + if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_FINISHED) return; + path = g_filename_from_uri (webkit_download_get_destination_uri (download), NULL, NULL); adblock_parse_file (path); - katze_assign (blockscript, adblock_build_js (blockcss->str, blockcssprivate->str)); g_free (path); - /* g_object_unref (download); */ + + MidoriApp* app = midori_extension_get_app (extension); + MidoriWebSettings* settings = katze_object_get_object (app, "settings"); + midori_web_settings_add_style (settings, "adblock-blockcss", blockcss->str); + katze_assign (blockscript, adblock_build_js (blockcssprivate->str)); + g_object_unref (settings); } static gchar* @@ -186,17 +195,20 @@ adblock_reload_rules (MidoriExtension* extension, webkit_download_set_destination_uri (download, destination); g_free (destination); g_signal_connect (download, "notify::status", - G_CALLBACK (adblock_download_notify_status_cb), path); + G_CALLBACK (adblock_download_notify_status_cb), extension); webkit_download_start (download); } - else - g_free (path); + g_free (path); i++; } } g_strfreev (filters); - katze_assign (blockscript, adblock_build_js (blockcss->str, blockcssprivate->str)); + MidoriApp* app = midori_extension_get_app (extension); + MidoriWebSettings* settings = katze_object_get_object (app, "settings"); + katze_assign (blockscript, adblock_build_js (blockcssprivate->str)); + midori_web_settings_add_style (settings, "adblock-blockcss", blockcss->str); + g_object_unref (settings); } static void -- 2.39.5