[webkit-gtk] Trapping URL access from inside WebKit

Emmanuel Rodriguez emmanuel.rodriguez at gmail.com
Sun Sep 18 12:16:29 PDT 2011


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

-- 
Emmanuel Rodriguez


More information about the webkit-gtk mailing list