Refactor adblock_reload_rules to handle filters versus only custom
This commit is contained in:
parent
b0de3f35df
commit
cf9dec176c
1 changed files with 43 additions and 40 deletions
|
@ -96,23 +96,27 @@ adblock_download_notify_status_cb (WebKitDownload* download,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
adblock_reload_rules (MidoriExtension* extension)
|
adblock_reload_rules (MidoriExtension* extension,
|
||||||
|
gboolean custom_only)
|
||||||
{
|
{
|
||||||
gchar** filters;
|
|
||||||
gchar* folder;
|
|
||||||
guint i = 0;
|
|
||||||
filters = midori_extension_get_string_list (extension, "filters", NULL);
|
|
||||||
gchar* custom_list;
|
gchar* custom_list;
|
||||||
|
gchar* folder;
|
||||||
if (!filters)
|
gchar** filters;
|
||||||
return;
|
guint i = 0;
|
||||||
|
|
||||||
folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
|
|
||||||
"adblock", NULL);
|
|
||||||
katze_mkdir_with_parents (folder, 0700);
|
|
||||||
|
|
||||||
adblock_init_db ();
|
adblock_init_db ();
|
||||||
|
|
||||||
|
custom_list = g_build_filename (midori_extension_get_config_dir (extension),
|
||||||
|
CUSTOM_LIST_NAME, NULL);
|
||||||
|
adblock_parse_file (custom_list);
|
||||||
|
g_free (custom_list);
|
||||||
|
|
||||||
|
filters = midori_extension_get_string_list (extension, "filters", NULL);
|
||||||
|
if (!custom_only && filters && *filters)
|
||||||
|
{
|
||||||
|
folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
|
||||||
|
"adblock", NULL);
|
||||||
|
katze_mkdir_with_parents (folder, 0700);
|
||||||
while (filters[i++] != NULL)
|
while (filters[i++] != NULL)
|
||||||
{
|
{
|
||||||
gchar* filename = g_compute_checksum_for_string (G_CHECKSUM_MD5,
|
gchar* filename = g_compute_checksum_for_string (G_CHECKSUM_MD5,
|
||||||
|
@ -123,6 +127,7 @@ adblock_reload_rules (MidoriExtension* extension)
|
||||||
WebKitNetworkRequest* request;
|
WebKitNetworkRequest* request;
|
||||||
WebKitDownload* download;
|
WebKitDownload* download;
|
||||||
gchar* destination = g_filename_to_uri (path, NULL, NULL);
|
gchar* destination = g_filename_to_uri (path, NULL, NULL);
|
||||||
|
|
||||||
request = webkit_network_request_new (filters[i -1]);
|
request = webkit_network_request_new (filters[i -1]);
|
||||||
download = webkit_download_new (request);
|
download = webkit_download_new (request);
|
||||||
g_object_unref (request);
|
g_object_unref (request);
|
||||||
|
@ -136,14 +141,12 @@ adblock_reload_rules (MidoriExtension* extension)
|
||||||
g_free (path);
|
g_free (path);
|
||||||
g_free (filename);
|
g_free (filename);
|
||||||
}
|
}
|
||||||
custom_list = g_build_filename (midori_extension_get_config_dir (extension),
|
|
||||||
CUSTOM_LIST_NAME, NULL);
|
|
||||||
adblock_parse_file (custom_list);
|
|
||||||
g_free (custom_list);
|
|
||||||
katze_assign (blockscript, adblock_build_js (blockcss, blockcssprivate));
|
|
||||||
g_strfreev (filters);
|
|
||||||
g_free (folder);
|
g_free (folder);
|
||||||
}
|
}
|
||||||
|
g_strfreev (filters);
|
||||||
|
|
||||||
|
katze_assign (blockscript, adblock_build_js (blockcss, blockcssprivate));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
adblock_browser_populate_tool_menu_cb (MidoriBrowser* browser,
|
adblock_browser_populate_tool_menu_cb (MidoriBrowser* browser,
|
||||||
|
@ -254,7 +257,7 @@ adblock_preferences_model_row_changed_cb (GtkTreeModel* model,
|
||||||
midori_extension_set_string_list (extension, "filters", filters, i);
|
midori_extension_set_string_list (extension, "filters", filters, i);
|
||||||
g_free (filters);
|
g_free (filters);
|
||||||
if (need_reload)
|
if (need_reload)
|
||||||
adblock_reload_rules (extension);
|
adblock_reload_rules (extension, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -730,7 +733,7 @@ adblock_custom_block_image_cb (GtkWidget* widget,
|
||||||
g_fprintf (list, "%s\n", uri);
|
g_fprintf (list, "%s\n", uri);
|
||||||
g_fprintf (list, "%s##img[src*=\"%s\"]\n", s_req_domain->host, s_uri->path);
|
g_fprintf (list, "%s##img[src*=\"%s\"]\n", s_req_domain->host, s_uri->path);
|
||||||
fclose (list);
|
fclose (list);
|
||||||
adblock_reload_rules (extension);
|
adblock_reload_rules (extension, TRUE);
|
||||||
|
|
||||||
soup_uri_free (s_req_domain);
|
soup_uri_free (s_req_domain);
|
||||||
soup_uri_free (s_uri);
|
soup_uri_free (s_uri);
|
||||||
|
@ -1159,7 +1162,7 @@ adblock_activate_cb (MidoriExtension* extension,
|
||||||
G_CALLBACK (adblock_session_request_queued_cb), NULL);
|
G_CALLBACK (adblock_session_request_queued_cb), NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
adblock_reload_rules (extension);
|
adblock_reload_rules (extension, FALSE);
|
||||||
|
|
||||||
browsers = katze_object_get_object (app, "browsers");
|
browsers = katze_object_get_object (app, "browsers");
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
Loading…
Reference in a new issue