#if WEBKIT_CHECK_VERSION (1, 1, 14)
-static GHashTable* pattern = NULL;
+static GHashTable* pattern;
static gchar* blockcss = "";
-static GHashTable*
+static void
adblock_parse_file (gchar* path);
static gchar *
GParamSpec* pspec,
gchar* path)
{
- pattern = adblock_parse_file (path);
+ if (!g_file_test (path, G_FILE_TEST_EXISTS))
+ return;
+ adblock_parse_file (path);
g_free (path);
/* g_object_unref (download); */
}
if (!filters)
return;
- pattern = NULL;
+ pattern = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)g_regex_unref);
blockcss = "";
while (filters[i++] != NULL)
}
else
{
- pattern = adblock_parse_file (path);
+ adblock_parse_file (path);
g_free (path);
}
g_free (filename);
if (blockcss && *blockcss)
g_signal_connect (web_view, "window-object-cleared",
G_CALLBACK (adblock_window_object_cleared_cb), 0);
- if (pattern)
- g_signal_connect (web_view, "resource-request-starting",
- G_CALLBACK (adblock_resource_request_starting_cb), view);
+ g_signal_connect (web_view, "resource-request-starting",
+ G_CALLBACK (adblock_resource_request_starting_cb), view);
}
static void
MidoriBrowser* browser,
MidoriExtension* extension)
{
- if (pattern)
- {
- midori_browser_foreach (browser,
- (GtkCallback)adblock_add_tab_foreach_cb, browser);
- g_signal_connect (browser, "add-tab", G_CALLBACK (adblock_add_tab_cb), 0);
- }
+ midori_browser_foreach (browser,
+ (GtkCallback)adblock_add_tab_foreach_cb, browser);
+ g_signal_connect (browser, "add-tab", G_CALLBACK (adblock_add_tab_cb), 0);
g_signal_connect (browser, "populate-tool-menu",
G_CALLBACK (adblock_browser_populate_tool_menu_cb), extension);
g_signal_connect (extension, "deactivate",
return adblock_fixup_regexp (line);
}
-static GHashTable*
+static void
adblock_parse_file (gchar* path)
{
FILE* file;
if ((file = g_fopen (path, "r")))
{
- GHashTable* patt = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)g_regex_unref);
-
- gboolean have_pattern = FALSE;
gchar line[500];
GRegex* regex;
g_free (parsed);
}
else
- {
- have_pattern = TRUE;
- g_hash_table_insert (patt, parsed, regex);
- }
+ g_hash_table_insert (pattern, parsed, regex);
}
fclose (file);
-
- if (have_pattern)
- return patt;
}
- return NULL;
}
static void
midori_browser_foreach (browser, (GtkCallback)adblock_deactivate_tabs, browser);
blockcss = "";
- if (pattern)
- g_hash_table_destroy (pattern);
+ g_hash_table_destroy (pattern);
}
static void
"http://ads.bla.blub/*\n"
"http://ads.blub.boing/*",
-1, NULL);
- pattern = adblock_parse_file (filename);
+ adblock_parse_file (filename);
g_assert (g_hash_table_find (pattern, (GHRFunc) adblock_is_matched,
"http://ads.foo.bar/teddy"));
gdouble elapsed = 0.0;
gchar* str;
int i;
- pattern = adblock_parse_file (filename);
+ adblock_parse_file (filename);
for (i = 0; i < 6; i++)
{
str = urls[i];