aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2013-03-05 18:35:39 +0800
committerCarlos Garcia Campos <carlosgc@gnome.org>2013-03-06 19:46:58 +0800
commit1000c061d19a4d25cd9891655356ab17b80c0ed2 (patch)
treedec70901a7f8999f683bd975e6542112c426e5cd /embed
parentfe0eceee0f75e3f2189e27e0222a2c8119ed9d1d (diff)
downloadgsoc2013-epiphany-1000c061d19a4d25cd9891655356ab17b80c0ed2.tar
gsoc2013-epiphany-1000c061d19a4d25cd9891655356ab17b80c0ed2.tar.gz
gsoc2013-epiphany-1000c061d19a4d25cd9891655356ab17b80c0ed2.tar.bz2
gsoc2013-epiphany-1000c061d19a4d25cd9891655356ab17b80c0ed2.tar.lz
gsoc2013-epiphany-1000c061d19a4d25cd9891655356ab17b80c0ed2.tar.xz
gsoc2013-epiphany-1000c061d19a4d25cd9891655356ab17b80c0ed2.tar.zst
gsoc2013-epiphany-1000c061d19a4d25cd9891655356ab17b80c0ed2.zip
uri-tester: Use GFile intead of WebKitDownload to retrieve the filters
It removes the WebKit dependency from uri-tester that will allow us to use it also from a WebKit2 web extension. https://bugzilla.gnome.org/show_bug.cgi?id=695198
Diffstat (limited to 'embed')
-rw-r--r--embed/uri-tester.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/embed/uri-tester.c b/embed/uri-tester.c
index e71990252..542631591 100644
--- a/embed/uri-tester.c
+++ b/embed/uri-tester.c
@@ -31,9 +31,6 @@
#include <gio/gio.h>
#include <glib/gstdio.h>
#include <string.h>
-#ifndef HAVE_WEBKIT2
-#include <webkit/webkit.h>
-#endif
#define DEFAULT_FILTER_URL "http://adblockplus.mozdev.org/easylist/easylist.txt"
#define FILTERS_LIST_FILENAME "filters.list"
@@ -110,49 +107,56 @@ uri_tester_get_fileuri_for_url (const char *url)
return uri;
}
+typedef struct {
+ UriTester *tester;
+ char *dest_uri;
+} RetrieveFilterAsyncData;
+
static void
-uri_tester_download_notify_status_cb (WebKitDownload *download,
- GParamSpec *pspec,
- UriTester *tester)
+uri_tester_retrieve_filter_finished (GFile *src,
+ GAsyncResult *result,
+ RetrieveFilterAsyncData *data)
{
-#ifndef HAVE_WEBKIT2
- const char *dest = NULL;
-
- if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_FINISHED)
- return;
+ GError *error = NULL;
- LOG ("Download from %s to %s completed",
- webkit_download_get_uri (download),
- webkit_download_get_destination_uri (download));
+ if (!g_file_copy_finish (src, result, &error)) {
+ LOG ("Error retrieving filter: %s\n", error->message);
+ g_error_free (error);
+ } else
+ uri_tester_parse_file_at_uri (data->tester, data->dest_uri);
- /* Parse the file from disk. */
- dest = webkit_download_get_destination_uri (download);
- uri_tester_parse_file_at_uri (tester, dest);
-#endif
+ g_object_unref (data->tester);
+ g_free (data->dest_uri);
+ g_slice_free (RetrieveFilterAsyncData, data);
}
static void
uri_tester_retrieve_filter (UriTester *tester, const char *url, const char *fileuri)
{
-#ifndef HAVE_WEBKIT2
- WebKitNetworkRequest *request = NULL;
- WebKitDownload *download = NULL;
+ GFile *src;
+ GFile *dest;
+ RetrieveFilterAsyncData *data;
g_return_if_fail (IS_URI_TESTER (tester));
g_return_if_fail (url != NULL);
g_return_if_fail (fileuri != NULL);
- request = webkit_network_request_new (url);
- download = webkit_download_new (request);
- g_object_unref (request);
+ src = g_file_new_for_uri (url);
+ dest = g_file_new_for_uri (fileuri);
- webkit_download_set_destination_uri (download, fileuri);
+ data = g_slice_new (RetrieveFilterAsyncData);
+ data->tester = g_object_ref (tester);
+ data->dest_uri = g_file_get_uri (dest);
- g_signal_connect (download, "notify::status",
- G_CALLBACK (uri_tester_download_notify_status_cb), tester);
+ g_file_copy_async (src, dest,
+ G_FILE_COPY_NONE,
+ G_PRIORITY_DEFAULT,
+ NULL, NULL, NULL,
+ (GAsyncReadyCallback)uri_tester_retrieve_filter_finished,
+ data);
- webkit_download_start (download);
-#endif
+ g_object_unref (src);
+ g_object_unref (dest);
}
static gboolean