sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 04d84ca53de522b1da559dd297904ccb571a7db1
parent 794081bc5f215455a8b99d0f9d0c045db14989bd
Author: Nick White <hg@njw.me.uk>
Date:   Wed, 28 Sep 2011 14:26:21 +0100

Add surf downloading patch
Diffstat:
Msurf.suckless.org/failing_sites.md | 2+-
Asurf.suckless.org/patches/download.md | 19+++++++++++++++++++
Asurf.suckless.org/patches/surf-0.4.1-download.diff | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 130 insertions(+), 1 deletion(-)

diff --git a/surf.suckless.org/failing_sites.md b/surf.suckless.org/failing_sites.md @@ -4,4 +4,4 @@ Rapidshare ========== Downloads from Rapidshare and similar javascript-heavy download sites don't tend to work. Building downloads into surf directly rather than calling an -external tool should fix this. +external tool fixes this - see the [downloading](patches/downloading) patch. diff --git a/surf.suckless.org/patches/download.md b/surf.suckless.org/patches/download.md @@ -0,0 +1,19 @@ +Built in Downloading +==================== + +Description +----------- + +Builds in download support, rather than invoking an external tool such as +wget. This ensures that complicated javascript using download sites such +as rapidshare and sendspace work correctly. + +Download +-------- + +* [surf-0.4.1-download.diff](surf-0.4.1-download.diff) (3.4k) (20110928) + +Author +------ + +* Nick White <[http://njw.me.uk](http://njw.me.uk)> diff --git a/surf.suckless.org/patches/surf-0.4.1-download.diff b/surf.suckless.org/patches/surf-0.4.1-download.diff @@ -0,0 +1,110 @@ +diff -r 71388899ac09 config.def.h +--- a/config.def.h Tue Jun 08 09:06:10 2010 +0200 ++++ b/config.def.h Wed Sep 28 14:15:32 2011 +0100 +@@ -5,6 +5,7 @@ + static char *stylefile = ".surf/style.css"; + static char *scriptfile = ".surf/script.js"; + static char *cookiefile = ".surf/cookies.txt"; ++static char *downdir = "/tmp"; + static time_t sessiontime = 3600; + #define NOBACKGROUND 0 + +diff -r 71388899ac09 surf.c +--- a/surf.c Tue Jun 08 09:06:10 2010 +0200 ++++ b/surf.c Wed Sep 28 14:15:32 2011 +0100 +@@ -74,7 +74,9 @@ + static void destroyclient(Client *c); + static void destroywin(GtkWidget* w, Client *c); + static void die(char *str); ++static void download(WebKitDownload *o, GParamSpec *pspec, Client *c); + static void drawindicator(Client *c); ++static void evalscript(Client *c, char *script); + static gboolean exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c); + static void find(Client *c, const Arg *arg); + static const char *getatom(Client *c, int a); +@@ -239,6 +241,21 @@ + } + + void ++download(WebKitDownload *o, GParamSpec *pspec, Client *c) { ++ WebKitDownloadStatus status; ++ char script[2048]; ++ ++ status = webkit_download_get_status(o); ++ if(status == WEBKIT_DOWNLOAD_STATUS_STARTED || status == WEBKIT_DOWNLOAD_STATUS_CREATED) { ++ snprintf(script, 2048, "u(%d, %d, %d)", ++ (gint)webkit_download_get_current_size(o), ++ (gint)webkit_download_get_total_size(o), ++ (gint)(webkit_download_get_progress(o) * 100)); ++ evalscript(c, script); ++ } ++} ++ ++void + drawindicator(Client *c) { + gint width; + const char *uri; +@@ -261,6 +278,17 @@ + g_object_unref(gc); + } + ++void ++evalscript(Client *c, char *script) { ++ JSValueRef exception = NULL; ++ WebKitWebFrame *frame = webkit_web_view_get_main_frame(c->view); ++ JSContextRef js = webkit_web_frame_get_global_context(frame); ++ JSStringRef jsscript = JSStringCreateWithUTF8CString(script); ++ ++ JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js), NULL, 0, &exception) ++; ++} ++ + gboolean + exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c) { + drawindicator(c); +@@ -328,12 +356,40 @@ + + gboolean + initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) { +- Arg arg; ++ gchar *uri, *path; ++ const gchar *filename; ++ Client *n; ++ char html[1024]; + +- updatewinid(c); +- arg = (Arg)DOWNLOAD((char *)webkit_download_get_uri(o)); +- spawn(c, &arg); +- return FALSE; ++ n = newclient(); ++ filename = webkit_download_get_suggested_filename(o); ++ ++ path = g_build_filename(downdir, filename, NULL); ++ uri = g_filename_to_uri(path, NULL, NULL); ++ webkit_download_set_destination_uri(o, uri); ++ g_free(path); ++ g_free(uri); ++ ++ snprintf(html, 1024, ++ "<html><head><script>" \ ++ "function u(c, t, p) {" \ ++ " document.getElementById('c').innerHTML = c;" \ ++ " document.getElementById('t').innerHTML = t;" \ ++ " document.getElementById('p').innerHTML = p;}" \ ++ "</script></head><body><p>Downloading %s</p>" \ ++ "<p><span id='c'>0</span> / <span id='t'>0</span> " \ ++ "(<span id='p'>0</span>%%)</p></body></html>", ++ filename); ++ webkit_web_view_load_string(n->view, html, NULL, NULL, NULL); ++ ++ g_signal_connect(o, "notify::progress", G_CALLBACK(download), n); ++ g_signal_connect(o, "notify::status", G_CALLBACK(download), n); ++ webkit_download_start(o); ++ n->title = g_strdup_printf("Downloading %s", filename); ++ n->progress = 0; ++ update(n); ++ ++ return TRUE; + } + + gboolean