From 63a5eeb0f0b18e5fa3cd0c260e47b7fe7491bfeb Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 8 Apr 2010 21:39:05 +0200 Subject: [PATCH] Output adblock debug if variable MIDORI_ADBLOCK set If Midori is compiled with full debug mode, and the environment variable MIDORI_ADBLOCK is set, Adblock will output a lot of debugging information. This spares testers from editing code. grep is recommended. --- extensions/adblock.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/extensions/adblock.c b/extensions/adblock.c index 0ec1c22b..2b142c7f 100644 --- a/extensions/adblock.c +++ b/extensions/adblock.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2009 Christian Dywan + Copyright (C) 2009-2010 Christian Dywan Copyright (C) 2009 Alexander Butenko This library is free software; you can redistribute it and/or @@ -32,12 +32,19 @@ filter[4] = __active ? (__filter[5] == ':' ? 's' : ':') : '-' #define ADBLOCK_FILTER_IS_SET(__filter) \ filter[4] != '-' +#ifdef G_ENABLE_DEBUG + #define adblock_debug(dmsg, darg1, darg2) \ + do { if (debug) g_debug (dmsg, darg1, darg2); } while (0) +#else + #define adblock_debug(dmsg, darg1, darg2) /* nothing */ +#endif static GHashTable* pattern; static GHashTable* keys; static gchar* blockcss = NULL; static gchar* blockcssprivate = NULL; static gchar* blockscript = NULL; +static gboolean debug; static gboolean adblock_parse_file (gchar* path); @@ -613,7 +620,7 @@ adblock_is_matched_by_pattern (const gchar* req_uri, return FALSE; else { - /* g_debug("blocked by pattern regexp=%s -- %s", g_regex_get_pattern (regex), req_uri); */ + adblock_debug ("blocked by pattern regexp=%s -- %s", g_regex_get_pattern (regex), req_uri); return TRUE; } } @@ -650,7 +657,7 @@ adblock_is_matched_by_key (const gchar* opts, } else { - /* g_debug("blocked by key sig=%s regexp=%s -- %s", sig, g_regex_get_pattern (regex), req_uri); */ + adblock_debug ("blocked by regexp=%s -- %s", g_regex_get_pattern (regex), uri); g_list_free (regex_bl); return TRUE; } @@ -756,7 +763,10 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view, if (!page_uri || !strcmp (page_uri, "about:blank")) page_uri = req_uri; - /* g_test_timer_start (); */ + #ifdef G_ENABLE_DEBUG + if (debug) + g_test_timer_start (); + #endif /* TODO: opts should be defined */ if (adblock_is_matched (NULL, req_uri, page_uri)) { @@ -765,7 +775,7 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view, webkit_network_request_set_uri (request, "about:blank"); g_object_set_data (G_OBJECT (web_view), "blocked-uris", blocked_uris); } - /* g_debug ("%f", g_test_timer_elapsed ()); */ + adblock_debug ("match: %f%s", g_test_timer_elapsed (), "seconds"); } #else @@ -911,13 +921,16 @@ adblock_load_finished_cb (WebKitWebView *web_view, { JSContextRef js_context = webkit_web_frame_get_global_context (web_frame); GList* uris = g_object_get_data (G_OBJECT (web_view), "blocked-uris"); + gchar* script; + GList* li; + if (g_list_nth_data (uris, 0) == NULL) return; - gchar* script = adblock_prepare_urihider_js (uris); + script = adblock_prepare_urihider_js (uris); webkit_web_view_execute_script (web_view, script); sokoke_js_script_eval (js_context, script, NULL); - GList* li = NULL; + li = NULL; for (li = uris; li != NULL; li = g_list_next (li)) uris = g_list_remove (uris, li->data); g_free (script); @@ -1086,7 +1099,7 @@ adblock_compile_regexp (GHashTable* tbl, if (!g_regex_match_simple ("[\\*]", sig, G_REGEX_UNGREEDY, G_REGEX_MATCH_NOTEMPTY) && !g_hash_table_lookup (keystbl, sig)) { - /* g_debug ("sig: %s %s", sig, patt); */ + adblock_debug ("sig: %s %s", sig, patt); g_hash_table_insert (keystbl, sig, regex); signature_count++; } @@ -1095,7 +1108,7 @@ adblock_compile_regexp (GHashTable* tbl, if (g_regex_match_simple ("^\\*", sig, G_REGEX_UNGREEDY, G_REGEX_MATCH_NOTEMPTY) && !g_hash_table_lookup (tbl, opts)) { - /* g_debug ("patt2: %s %s", sig, patt); */ + adblock_debug ("patt2: %s %s", sig, patt); g_hash_table_insert (tbl, opts, regex); } g_free (sig); @@ -1106,7 +1119,7 @@ adblock_compile_regexp (GHashTable* tbl, } else { - /*g_debug ("patt: %s", patt); */ + adblock_debug ("patt: %s%s", patt, ""); /* Pattern is a regexp chars */ g_hash_table_insert (tbl, opts, regex); } @@ -1143,7 +1156,7 @@ adblock_add_url_pattern (gchar* format, fixed_patt = adblock_fixup_regexp (patt); format_patt = g_strdup_printf (format, fixed_patt); - /* g_debug ("got: %s opts %s", format_patt, opts); */ + adblock_debug ("got: %s opts %s", format_patt, opts); adblock_compile_regexp (pattern, keys, format_patt, opts); g_strfreev (data); @@ -1346,6 +1359,8 @@ adblock_activate_cb (MidoriExtension* extension, G_CALLBACK (adblock_session_request_queued_cb), NULL); #endif + debug = g_getenv ("MIDORI_ADBLOCK") != NULL; + adblock_reload_rules (extension, FALSE); browsers = katze_object_get_object (app, "browsers"); -- 2.39.5