[epiphany] uri-tester: Use GFile intead of WebKitDownload to retrieve the filters
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] uri-tester: Use GFile intead of WebKitDownload to retrieve the filters
- Date: Wed, 6 Mar 2013 11:47:14 +0000 (UTC)
commit 1000c061d19a4d25cd9891655356ab17b80c0ed2
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Tue Mar 5 11:35:39 2013 +0100
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
embed/uri-tester.c | 62 +++++++++++++++++++++++++++------------------------
1 files changed, 33 insertions(+), 29 deletions(-)
---
diff --git a/embed/uri-tester.c b/embed/uri-tester.c
index e719902..5426315 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]