Use midori_web_settings_add_style for adblock CSS

This commit is contained in:
Alexander Butenko 2011-10-30 15:19:06 +01:00 committed by Christian Dywan
parent e4601778c2
commit 34e0c98cb7

View file

@ -51,9 +51,12 @@ static guint debug;
static gboolean static gboolean
adblock_parse_file (gchar* path); adblock_parse_file (gchar* path);
static void
adblock_reload_rules (MidoriExtension* extension,
gboolean custom_only);
static gchar* static gchar*
adblock_build_js (const gchar* style, adblock_build_js (const gchar* private)
const gchar* private)
{ {
return g_strdup_printf ( return g_strdup_printf (
"window.addEventListener ('DOMContentLoaded'," "window.addEventListener ('DOMContentLoaded',"
@ -62,7 +65,7 @@ adblock_build_js (const gchar* style,
" return;" " return;"
" var URL = location.href;" " var URL = location.href;"
" var sites = new Array(); %s;" " var sites = new Array(); %s;"
" var public = '%s';" " var public = '';"
" for (var i in sites) {" " for (var i in sites) {"
" if (URL.indexOf(i) != -1 && sites[i] ){" " if (URL.indexOf(i) != -1 && sites[i] ){"
" public += ', .'+sites[i];" " public += ', .'+sites[i];"
@ -76,8 +79,7 @@ adblock_build_js (const gchar* style,
" var head = document.getElementsByTagName('head')[0];" " var head = document.getElementsByTagName('head')[0];"
" if (head) head.appendChild(mystyle);" " if (head) head.appendChild(mystyle);"
"}, true);", "}, true);",
private, private);
style);
} }
static GString* static GString*
@ -110,15 +112,22 @@ adblock_init_db ()
static void static void
adblock_download_notify_status_cb (WebKitDownload* download, adblock_download_notify_status_cb (WebKitDownload* download,
GParamSpec* pspec, GParamSpec* pspec,
gchar* path) MidoriExtension* extension)
{ {
gchar* path;
if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_FINISHED) if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_FINISHED)
return; return;
path = g_filename_from_uri (webkit_download_get_destination_uri (download), NULL, NULL);
adblock_parse_file (path); adblock_parse_file (path);
katze_assign (blockscript, adblock_build_js (blockcss->str, blockcssprivate->str));
g_free (path); 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* static gchar*
@ -186,17 +195,20 @@ adblock_reload_rules (MidoriExtension* extension,
webkit_download_set_destination_uri (download, destination); webkit_download_set_destination_uri (download, destination);
g_free (destination); g_free (destination);
g_signal_connect (download, "notify::status", 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); webkit_download_start (download);
} }
else
g_free (path); g_free (path);
i++; i++;
} }
} }
g_strfreev (filters); 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 static void