[webkit-gtk] Trapping URL access from inside WebKit

Andrew Wood a.j.w at me.com
Tue Sep 20 18:02:52 PDT 2011


Yes Ive tried that one but had the same problem. Im wondering if its a 
bug in webkit causing it to be null when navigation is initiated by a 
javascript.

On 18/09/11 20:16, Emmanuel Rodriguez wrote:
> On Sun, Sep 18, 2011 at 17:19, Andrew Wood<a.j.w at me.com>  wrote:
>> The prototype for the callback function is:
>> gboolean trapNavigationRequested(WebKitWebView *webView, WebKitWebFrame
>> *frame,WebKitNetworkRequest *request,WebKitWebNavigationAction
>> *navigation_action, WebKitWebPolicyDecision *policy_decision,gpointer
>> user_data)
> In my code I get the URL from the WebKitNetworkRequest and it always
> worked fine. Please not that I didn't do too many requests with my
> sample program.
>
> Here's the code snippet that I used, it's in Perl using GIR but you
> should be able to figure out what's going on:
>
>          # Add a callback to monitor where each URI will go and reject
> the URI if the
>          # location differs from the original website.
>          # This only blocks, iframes and clicked links. Javascript and
> CSS are not blocked.
>          $view->signal_connect("navigation-policy-decision-requested" =>  sub {
>              my ($view, $frame, $request, $action, $decision) = @_;
>
>              my $host_port = get_host_port($request->get_uri);
>
>              # We allow browsing the same site
>              return FALSE if $host_port eq $allowed_host_port;
>
>              # We block the access to an external site
>              print "Block access to $host_port\n";
>              $decision->ignore();
>              return TRUE;
>          });
>
> The full code is here https://github.com/potyl/Webkit/blob/master/nanny.pl#L70
>



More information about the webkit-gtk mailing list