summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Rameau <quinq@fifth.space>2015-11-18 19:05:59 +0100
committerQuentin Rameau <quinq@fifth.space>2015-11-20 00:34:21 +0100
commit96188f83f0f77f93fc5f4590c1f1c8f13b78e599 (patch)
tree8fa9e5c4813637f5487decfa1f229bc4987c8787
parent26a2dbac6501d095937568cdb9f00083e0b02146 (diff)
downloadsurf-96188f83f0f77f93fc5f4590c1f1c8f13b78e599.tar.gz
surf-96188f83f0f77f93fc5f4590c1f1c8f13b78e599.tar.bz2
surf-96188f83f0f77f93fc5f4590c1f1c8f13b78e599.zip
Replace initdownload() and intercept global download requests.
Attach to download requests on WebKitContext, this way we can easily manage all types of downloads (coming from views or not).
-rw-r--r--surf.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/surf.c b/surf.c
index 2e8ca70..d893b27 100644
--- a/surf.c
+++ b/surf.c
@@ -141,7 +141,10 @@ static void setstyle(Client *c, const char *style);
static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri);
-static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
+static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
+ Client *c);
+static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
+static void download(Client *c, WebKitURIResponse *r);
static void inspector(Client *c, const Arg *arg);
static WebKitWebView *inspector_new(WebKitWebInspector *i, WebKitWebView *v,
@@ -698,15 +701,27 @@ handleplumb(Client *c, WebKitWebView *w, const gchar *uri)
spawn(c, &arg);
}
-gboolean
-initdownload(WebKitWebView *view, WebKitDownload *o, Client *c)
+void
+downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
{
- Arg arg;
+ g_signal_connect(G_OBJECT(d), "notify::response",
+ G_CALLBACK(responsereceived), c);
+}
- updatewinid(c);
- arg = (Arg)DOWNLOAD((char *)webkit_download_get_uri(o), geturi(c));
- spawn(c, &arg);
- return FALSE;
+void
+responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
+{
+ download(c, webkit_download_get_response(d));
+ webkit_download_cancel(d);
+}
+
+void
+download(Client *c, WebKitURIResponse *r)
+{
+ Arg a;
+
+ a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
+ spawn(c, &a);
}
void
@@ -962,6 +977,9 @@ newview(Client *c, WebKitWebView *rv)
webkit_web_context_get_cookie_manager(context),
cookiepolicy_get());
+ g_signal_connect(G_OBJECT(context), "download-started",
+ G_CALLBACK(downloadstarted), c);
+
v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
"settings", settings,
"user-content-manager", contentmanager,
@@ -996,9 +1014,6 @@ newview(Client *c, WebKitWebView *rv)
"notify::estimated-load-progress",
G_CALLBACK(progresschanged), c);
g_signal_connect(G_OBJECT(v),
- "download-requested",
- G_CALLBACK(initdownload), c);
- g_signal_connect(G_OBJECT(v),
"button-release-event",
G_CALLBACK(buttonrelease), c);
g_signal_connect(G_OBJECT(v),