summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/dwb.144
-rwxr-xr-xexamples/scheme_handler10
-rw-r--r--src/config.h6
-rw-r--r--src/dwb.c59
-rw-r--r--src/dwb.h1
-rw-r--r--src/view.c23
-rw-r--r--util/settings.in3
7 files changed, 108 insertions, 38 deletions
diff --git a/doc/dwb.1 b/doc/dwb.1
index 6e7d53c0..133ac7af 100644
--- a/doc/dwb.1
+++ b/doc/dwb.1
@@ -1628,12 +1628,6 @@ The font used for tablabels without focus and completion items without focus. Po
string,
default value:
.TP
-.BR ftp-client
-Program to open ftp://.
-.IR dwb_uri
-will be replaced with the ftp-url. Default value:
-.IR xterm\ -e\ ncftp\ 'dwb_uri' .
-.TP
.BR hint-active-color
The background color for active link, i.e. the link followed when Return is
pressed. Possible values: a rgb color string,
@@ -1709,12 +1703,6 @@ default value:
Whether to allow loading javascript snippets with scheme 'javascript',
default value:
.IR true .
-.TP
-.BR mail-client
-The email program that is used for mailto:-urls.
-.IR dwb_uri
-will be replaced with the mail-url. Default value:
-.IR xterm\ -e\ mutt\ 'dwb_uri'.
.TP
.BR message-delay
The duration messages are shown. Possible values: duration in seconds (integer),
@@ -1769,6 +1757,38 @@ invoking dwb. Possible values: true/false,
default value:
.IR false .
.TP
+.BR scheme-handler
+A script or application that handles uris that cannot be loaded by dwb. dwb only
+loads uris with scheme
+.BR http ,
+.BR https ,
+.B about
+and
+.BR dwb ;
+support for e.g. ftp is provided through a scheme handler. The scheme handler
+can either be an application or a script. The first command line argument will
+be the uri for your application, so you can simply set this to
+.IR xdg-open .
+There are also the environment variables
+.IR DWB_URI ,
+.IR DWB_SCHEME ,
+.IR DWB_COOKIES ,
+.IR DWB_USER_AGENT ,
+and
+.I DWB_REFERER
+available which can be used in a script, for example:
+
+.nf
+ #!/bin/sh
+
+ case ${DWB_SCHEME} in
+ mailto) xterm -e "mutt ${DWB_URI}";;
+ ftp) xterm -e "ncftp ${DWB_URI}";;
+ *) xdg-open ${DWB_URI}
+ esac
+.fi
+
+.TP
.BR scroll-step
The step-increment in pixels for scrolling. If set to a value lower or equal 0,
the default step-increment will be used.
diff --git a/examples/scheme_handler b/examples/scheme_handler
new file mode 100755
index 00000000..7901bf4f
--- /dev/null
+++ b/examples/scheme_handler
@@ -0,0 +1,10 @@
+#!/bin/sh
+# The environment variables DWB_URI, DWB_SCHEME, DWB_COOKIES, DWB_USER_AGENT and
+# DWB_REFERER can be used
+
+case ${DWB_SCHEME} in
+ mailto) xterm -e "mutt ${DWB_URI}";;
+ ftp) xterm -e "ncftp ${DWB_URI}";;
+ *) xdg-open ${DWB_URI}
+esac
+
diff --git a/src/config.h b/src/config.h
index a0685766..be20d520 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1022,10 +1022,8 @@ static WebSettings DWB_SETTINGS[] = {
SETTING_GLOBAL, INTEGER, { .i = 500 }, (S_Func) NULL, },
{ { "scrollbars", "Whether scrollbars should be enabled", },
SETTING_GLOBAL, BOOLEAN, { .b = false }, NULL, },
- { { "mail-client", "Program used for mailto:-urls", },
- SETTING_GLOBAL, CHAR, { .p = "xterm -e mutt 'dwb_uri'" }, NULL, },
- { { "ftp-client", "Program used for ftp", },
- SETTING_GLOBAL, CHAR, { .p = "xterm -e ncftp 'dwb_uri'" }, NULL, },
+ { { "scheme-handler", "Handler script for unsupported schemes", },
+ SETTING_GLOBAL, CHAR, { .p = NULL }, NULL, },
{ { "editor", "External editor", },
SETTING_GLOBAL, CHAR, { .p = "xterm -e vim dwb_uri" }, NULL, },
{ { "adblocker", "Whether to block advertisements via a filterlist", },
diff --git a/src/dwb.c b/src/dwb.c
index 23c85f89..9c942800 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -148,7 +148,7 @@ dwb_set_adblock(GList *gl, WebSettings *s) {
}
}/*}}}*/
-/* dwb_set_cookies */
+/* dwb_set_cookies {{{ */
static DwbStatus
dwb_set_cookies(GList *gl, WebSettings *s) {
dwb.state.cookie_store_policy = dwb_soup_get_cookie_store_policy(s->arg.p);
@@ -174,7 +174,8 @@ dwb_set_private_browsing(GList *gl, WebSettings *s) {
dwb_webkit_setting(gl, s);
return STATUS_OK;
}/*}}}*/
-/* dwb_set_new_tab_position_policy */
+
+/* dwb_set_new_tab_position_policy {{{ */
static DwbStatus
dwb_set_new_tab_position_policy(GList *gl, WebSettings *s) {
if (!g_strcmp0(s->arg.p, "right"))
@@ -214,11 +215,12 @@ dwb_set_sync_interval(GList *gl, WebSettings *s) {
return STATUS_OK;
}/*}}}*/
+/* dwb_set_scroll_step {{{*/
static DwbStatus
dwb_set_scroll_step(GList *gl, WebSettings *s) {
dwb.misc.scroll_step = s->arg.d;
return STATUS_OK;
-}
+}/*}}}*/
/* dwb_set_startpage(GList *l, WebSettings *){{{*/
static DwbStatus
@@ -517,6 +519,53 @@ dwb_update_status_text(GList *gl, GtkAdjustment *a) {
/*}}}*/
/* FUNCTIONS {{{*/
+
+DwbStatus
+dwb_scheme_handler(GList *gl, WebKitNetworkRequest *request) {
+ const char *handler = GET_CHAR("scheme-handler");
+ if (handler == NULL) {
+ dwb_set_error_message(gl, "No scheme handler defined");
+ return STATUS_ERROR;
+ }
+ GError *error = NULL;
+ char **scheme_handler = g_strsplit(handler, " ", -1);
+ int l = g_strv_length(scheme_handler);
+ char **argv = g_malloc0_n(l + 2, sizeof(char*));
+ GSList *list = NULL;
+ const char *uri = webkit_network_request_get_uri(request);
+ int i=0;
+ for (; i<l; i++) {
+ argv[i] = scheme_handler[i];
+ }
+ argv[i++] = (char*)uri;
+ argv[i++] = NULL;
+ list = g_slist_append(list, dwb_navigation_new("DWB_URI", uri));
+ list = g_slist_prepend(list, dwb_navigation_new("DWB_COOKIES", dwb.files.cookies));
+
+ char *scheme = g_uri_parse_scheme(uri);
+ if (scheme) {
+ list = g_slist_append(list, dwb_navigation_new("DWB_SCHEME", scheme));
+ g_free(scheme);
+ }
+ const char *referer = soup_get_header_from_request(request, "Referer");
+ if (referer)
+ list = g_slist_append(list, dwb_navigation_new("DWB_REFERER", uri));
+ const char *user_agent = soup_get_header_from_request(request, "User-Agent");
+ if (user_agent)
+ list = g_slist_append(list, dwb_navigation_new("DWB_USER_AGENT", uri));
+ if (g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, (GSpawnChildSetupFunc)dwb_setup_environment, list, NULL, &error)) {
+ return STATUS_OK;
+ }
+ else {
+ dwb_set_error_message(gl, "Spawning scheme handler failed");
+ return STATUS_ERROR;
+ }
+ for (int i=0; i<l; i++)
+ g_free(argv[i]);
+ g_free(scheme_handler);
+ g_free(argv);
+}
+
/* dwb_glist_prepend_unique(GList **list, char *text) {{{*/
void
dwb_glist_prepend_unique(GList **list, char *text) {
@@ -678,6 +727,7 @@ clean:
g_free(info);
}/*}}}*/
+/* dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error) {{{*/
gboolean
dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error) {
WebKitDOMNode *parent = webkit_dom_node_get_parent_node(node);
@@ -686,7 +736,8 @@ dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error) {
return true;
}
return false;
-}
+}/*}}}*/
+
/* dwb_get_editable(WebKitDOMElement *) {{{*/
static gboolean
dwb_get_editable(WebKitDOMElement *element) {
diff --git a/src/dwb.h b/src/dwb.h
index 2d26347d..97b7ea9b 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -865,6 +865,7 @@ void dwb_version();
DwbStatus dwb_pack(const char *layout, gboolean rebuild);
void dwb_init_signals(void);
void dwb_parse_commands(const char *line);
+DwbStatus dwb_scheme_handler(GList *gl, WebKitNetworkRequest *request);
gboolean dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error);
diff --git a/src/view.c b/src/view.c
index d6bf4aff..619dac08 100644
--- a/src/view.c
+++ b/src/view.c
@@ -317,6 +317,13 @@ view_navigation_policy_cb(WebKitWebView *web, WebKitWebFrame *frame, WebKitNetwo
gboolean ret = false;
WebKitWebNavigationReason reason = webkit_web_navigation_action_get_reason(action);
+ if (!g_str_has_prefix(uri, "http:") && !g_str_has_prefix(uri, "https:") && !g_str_has_prefix(uri, "about:") && !g_str_has_prefix(uri, "dwb:")) {
+ if (dwb_scheme_handler(gl, request) == STATUS_OK) {
+ webkit_web_policy_decision_ignore(policy);
+ return true;
+ }
+ }
+
/* Check if tab is locked */
if (LP_LOCKED_URI(VIEW(gl))) {
const char *initial_uri = webkit_web_view_get_uri(web);
@@ -400,22 +407,6 @@ view_navigation_policy_cb(WebKitWebView *web, WebKitWebFrame *frame, WebKitNetwo
default: break;
}
-
- /* mailto, ftp */
- char *scheme = g_uri_parse_scheme(uri);
- if (scheme) {
- if (!g_strcmp0(scheme, "mailto")) {
- dwb_spawn(gl, "mail-client", uri);
- webkit_web_policy_decision_ignore(policy);
- ret = true;
- }
- else if (!g_strcmp0(scheme, "ftp")) {
- dwb_spawn(gl, "ftp-client", uri);
- webkit_web_policy_decision_ignore(policy);
- ret = true;
- }
- g_free(scheme);
- }
return ret;
}/*}}}*/
diff --git a/util/settings.in b/util/settings.in
index 5b413843..9127eb61 100644
--- a/util/settings.in
+++ b/util/settings.in
@@ -135,10 +135,9 @@ enable-site-specific-quirks checkbox Enable site specific compatibility workarou
enable-spatial-navigation checkbox Enable spatial navigation
enable-universal-access-from-file-uris checkbox Whether to allow files loaded through file:
enable-xss-auditor checkbox Whether to enable the xss auditor
-ftp-client text Application used for ftp
history-length text Length of the browsing history
-mail-client text Application used for mailto:-urls
navigation-history-max Length of the navigation history
print-backgrounds checkbox Whether background images should be printed
+scheme-handler Application or script that handles uris with schemes that cannot be handled by dwb
sync-history text Interval to save history to disk, 0 means save immediately
tab-key-cycles-through-elements checkbox Tab cycles through elements in insert mode