Permalink
Browse files

Using SoupSession for intercepting working SoupMessages

  • Loading branch information...
1 parent a73f50e commit 8016a974d3769656deab96518aaa45b936bac615 @potyl committed May 16, 2011
Showing with 29 additions and 16 deletions.
  1. +29 −16 download-cb.c
View
@@ -4,7 +4,10 @@
static void
-tracker_start_cb (WebKitWebView *web_view, WebKitWebFrame *web_frame, WebKitWebResource *web_resource, WebKitNetworkRequest *request, WebKitNetworkResponse *response, gpointer user_data);
+request_started_cb (SoupSession *session, SoupMessage *message, SoupSocket *socket, gpointer data);
+
+static void
+request_finished_cb (SoupMessage *message, gpointer data);
static void
tracker_end_cb (SoupMessage *message, gpointer data);
@@ -14,20 +17,27 @@ load_status_cb (GObject* object, GParamSpec* pspec, gpointer data);
static void
-tracker_start_cb (WebKitWebView *web_view, WebKitWebFrame *web_frame, WebKitWebResource *web_resource, WebKitNetworkRequest *request, WebKitNetworkResponse *response, gpointer user_data) {
- SoupMessage *message;
- const char *uri;
-
- uri = webkit_network_request_get_uri(request);
- if (strcmp(uri, "about:blank") == 0) {return;}
-
- message = webkit_network_request_get_message(request);
- if (message == NULL) {
- printf("Can't get message for %s\n", uri);
- return;
- }
- printf("Start download of %s\n", uri);
- g_signal_connect(message, "finished", G_CALLBACK(tracker_end_cb), request);
+request_started_cb (SoupSession *session, SoupMessage *message, SoupSocket *socket, gpointer data) {
+ SoupURI *uri;
+ char *uri_string;
+
+ uri = soup_message_get_uri(message);
+ uri_string = soup_uri_to_string(uri, FALSE);
+ printf("Start download of %s\n", uri_string);
+ g_free(uri_string);
+ g_signal_connect(message, "finished", G_CALLBACK(request_finished_cb), NULL);
+}
+
+
+static void
+request_finished_cb (SoupMessage *message, gpointer data) {
+ SoupURI *uri;
+ char *uri_string;
+
+ uri = soup_message_get_uri(message);
+ uri_string = soup_uri_to_string(uri, FALSE);
+ printf("Finished download of %s\n", uri_string);
+ g_free(uri_string);
}
@@ -61,6 +71,7 @@ main (int argc, char* argv[]) {
const char *uri;
WebKitWebView* web_view;
GMainLoop* loop;
+ SoupSession *session;
gtk_init(&argc, &argv);
@@ -74,10 +85,12 @@ main (int argc, char* argv[]) {
loop = g_main_loop_new(NULL, TRUE);
+ session = webkit_get_default_session();
+ g_signal_connect(session, "request-started", G_CALLBACK(request_started_cb), NULL);
+
web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
g_object_ref_sink(G_OBJECT(web_view));
- g_signal_connect(web_view, "resource-request-starting", G_CALLBACK(tracker_start_cb), NULL);
g_signal_connect(web_view, "notify::load-status", G_CALLBACK(load_status_cb), loop);
webkit_web_view_load_uri(web_view, uri);

0 comments on commit 8016a97

Please sign in to comment.