Downloading via an external tool poses a problem: You have to pass the
current "web context" from the browser to your tool. This context
comprises cookies, the referrer, the user agent and information about
HTTP basic auth. With some effort, you can pass most of this to your
tool -- except for HTTP basic auth.
tl;dr: Downloading via wget is pretty complicated.
With this commit, WebKit handles the downloads. What's missing, are some
GUI elements to monitor and cancel downloads.
- An input box to change the current URL
- Global content zoom
- Pluggability into suckless' tabbed
- An input box to change the current URL
- Global content zoom
- Pluggability into suckless' tabbed
- - Downloading files using wget
- vi-like scrolling (modified by CTRL)
- Searching the current page for a word
- Adblock
- vi-like scrolling (modified by CTRL)
- Searching the current page for a word
- Adblock
+ - Monitoring and canceling downloads
- Keyword based searching (opening "wi foo" will search wikipedia)
- Keyword based searching (opening "wi foo" will search wikipedia)
gpointer data);
static void changed_title(GObject *, GParamSpec *, gpointer);
static void changed_uri(GObject *, GParamSpec *, gpointer);
gpointer data);
static void changed_title(GObject *, GParamSpec *, gpointer);
static void changed_uri(GObject *, GParamSpec *, gpointer);
+static gboolean download_handle(WebKitWebView *, WebKitDownload *, gpointer);
static gboolean download_request(WebKitWebView *, WebKitWebFrame *,
WebKitNetworkRequest *, gchar *,
WebKitWebPolicyDecision *, gpointer);
static gboolean download_request(WebKitWebView *, WebKitWebFrame *,
WebKitNetworkRequest *, gchar *,
WebKitWebPolicyDecision *, gpointer);
-static gboolean download_wget(WebKitWebView *, WebKitDownload *, gpointer);
static gchar *ensure_url_scheme(const gchar *);
static void grab_environment_configuration(void);
static void hover_web_view(WebKitWebView *, gchar *, gchar *, gpointer);
static gchar *ensure_url_scheme(const gchar *);
static void grab_environment_configuration(void);
static void hover_web_view(WebKitWebView *, gchar *, gchar *, gpointer);
"mime-type-policy-decision-requested",
G_CALLBACK(download_request), NULL);
g_signal_connect(G_OBJECT(c->web_view), "download-requested",
"mime-type-policy-decision-requested",
G_CALLBACK(download_request), NULL);
g_signal_connect(G_OBJECT(c->web_view), "download-requested",
- G_CALLBACK(download_wget), NULL);
+ G_CALLBACK(download_handle), NULL);
g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
G_CALLBACK(key_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
G_CALLBACK(key_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
-download_request(WebKitWebView *web_view, WebKitWebFrame *frame,
- WebKitNetworkRequest *request, gchar *mime_type,
- WebKitWebPolicyDecision *policy_decision, gpointer data)
+download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
- (void)frame;
- (void)request;
+ gchar *path, *path2 = NULL, *uri;
+ gboolean ret;
+ int suffix = 1;
+
+ (void)web_view;
- if (!webkit_web_view_can_show_mime_type(web_view, mime_type))
+ path = g_build_filename(download_dir,
+ webkit_download_get_suggested_filename(download),
+ NULL);
+ path2 = g_strdup(path);
+ while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
- webkit_web_policy_decision_download(policy_decision);
- return TRUE;
+ g_free(path2);
+
+ path2 = g_strdup_printf("%s.%d", path, suffix);
+ suffix++;
+
+ if (suffix == 1000)
+ {
+ fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
+ ret = FALSE;
+ }
+ else
+ {
+ uri = g_filename_to_uri(path2, NULL, NULL);
+ webkit_download_set_destination_uri(download, uri);
+ ret = TRUE;
+ g_free(uri);
+ }
+
+ g_free(path);
+ g_free(path2);
+
+ return ret;
-download_wget(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
+download_request(WebKitWebView *web_view, WebKitWebFrame *frame,
+ WebKitNetworkRequest *request, gchar *mime_type,
+ WebKitWebPolicyDecision *policy_decision, gpointer data)
- const gchar *uri;
- char id[16] = "";
- gint ret;
-
- (void)web_view;
+ (void)frame;
+ (void)request;
- uri = webkit_download_get_uri(download);
- if (fork() == 0)
+ if (!webkit_web_view_can_show_mime_type(web_view, mime_type))
- chdir(download_dir);
- if (embed == 0)
- ret = execlp("xterm", "xterm", "-hold", "-e", "wget", uri, NULL);
- else
- {
- if (snprintf(id, 16, "%ld", embed) >= 16)
- {
- fprintf(stderr, __NAME__": id for xterm embed truncated!\n");
- exit(EXIT_FAILURE);
- }
- ret = execlp("xterm", "xterm", "-hold", "-into", id, "-e", "wget",
- uri, NULL);
- }
-
- if (ret == -1)
- {
- fprintf(stderr, __NAME__": exec'ing xterm for download");
- perror(" failed");
- exit(EXIT_FAILURE);
- }
+ webkit_web_policy_decision_download(policy_decision);
+ return TRUE;