/*
- Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
+ Copyright (C) 2009-2010 Christian Dywan <christian@twotoasts.de>
Copyright (C) 2009 Alexander Butenko <a.butenka@gmail.com>
This library is free software; you can redistribute it and/or
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);
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;
}
}
}
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;
}
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))
{
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
{
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);
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++;
}
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);
}
else
{
- /*g_debug ("patt: %s", patt); */
+ adblock_debug ("patt: %s%s", patt, "");
/* Pattern is a regexp chars */
g_hash_table_insert (tbl, opts, regex);
}
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);
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");