diff options
author | Devin J. Pohly <djpohly@gmail.com> | 2011-10-27 12:06:16 -0400 |
---|---|---|
committer | Devin J. Pohly <djpohly@gmail.com> | 2011-10-27 13:24:45 -0400 |
commit | 38fd1f02bbdc5edda7daf8210a0d2b241bc9b412 (patch) | |
tree | e3c39acd94349ac78d982d7fc290a48ddde7435c /src/callbacks.c | |
parent | 4e9672c31ee7790cb4a0453b7d45d3e89613c035 (diff) |
add request_handler hook
This creates a handler `request_handler' in the same vein as
scheme_handler, download_handler, etc., which is called whenever the
page requests a URI. (Possible applications include Adblock and SSL
enforcement.) The handler should get the URI from $1 and print the URI
of the resource that should be loaded instead, or print nothing to allow
the request unmodified.
Diffstat (limited to 'src/callbacks.c')
-rw-r--r-- | src/callbacks.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/callbacks.c b/src/callbacks.c index f939454..23b8d55 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -358,7 +358,31 @@ request_starting_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitWebRes (void) response; (void) user_data; + const gchar* uri = webkit_network_request_get_uri (request); + + if (uzbl.state.verbose) + printf("Request starting -> %s\n", uri); send_event (REQUEST_STARTING, NULL, TYPE_STR, webkit_network_request_get_uri(request), NULL); + + if (uzbl.behave.request_handler) { + GString *result = g_string_new (""); + GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); + const CommandInfo *c = parse_command_parts(uzbl.behave.request_handler, a); + + if(c) { + g_array_append_val(a, uri); + run_parsed_command(c, a, result); + } + g_array_free(a, TRUE); + + if(result->len > 0) { + char *p = strchr(result->str, '\n' ); + if ( p != NULL ) *p = '\0'; + webkit_network_request_set_uri(request, result->str); + } + + g_string_free(result, TRUE); + } } void |