[webkit-gtk] Trapping URL access from inside WebKit

Andrew Wood a.j.w at me.com
Sun Sep 18 08:19:29 PDT 2011


Ive got a strange bug in the call back function for this which I cant 
understand.

When the callback is called I check the requestd url to see if it is one 
that I want to permit, but on certain sites (Wikipedia search is a prim 
example) the url returned is null which then causes a segmentation fault 
when I try to access it. I dont understand why sometimes it comes back 
as null.  the code is as follows:


      gchar *url=NULL;
      g_object_get (navigation_action,"original-uri", &url,NULL);
      std::string requestedurl=std::string(url); //needs to be a C++ 
string so I can do a validation check later
      g_free(url);
      g_print("url is: ");
      g_print(requestedurl.c_str());
       .....carry on here to do validation

When run (on certain sites) it crashes with the following output:
url is:
Program received signal SIGSEGV, Segmentation fault.
0xf643e4c1 in ?? () from /lib/i686/cmov/libc.so.6


Ive tried various ways of accessing the url:

std::string requestedurl 
=std::string(webkit_network_request_get_uri(request));
std::string requestedurl 
=std::string(webkit_web_navigation_action_get_original_uri(navigation_action));
std::string requestedurl=std::string(webkit_web_frame_get_uri(frame));

But they all result in the same problem.

The prototype for the callback function is:
gboolean trapNavigationRequested(WebKitWebView *webView, WebKitWebFrame 
*frame,WebKitNetworkRequest *request,WebKitWebNavigationAction 
*navigation_action, WebKitWebPolicyDecision *policy_decision,gpointer 
user_data)

As I say its only clicking links on certain sites that cause this, other 
sites it works fine leaving me totally puzzled.

Any ideas?

Thanks
Andrew


On 07/09/11 21:44, Emmanuel Rodriguez wrote:
> On Wed, Sep 7, 2011 at 18:12, Andrew Wood<a.j.w at me.com>  wrote:
>> How do I intercept a request to load a URL which has come from within
>> webkit, such as a user clicking a link on a page, a redirect (either via
>> HTTP or using the meta refresh tag), or a page which is using frames to load
>> URLs other than the one typed by the user?
> The signal "navigation-policy-decision-requested" that's emitted by
> the WebKitWebView can help you. With it you can detect users requests
> for iframes and clicked links. You'll have to test how it handles
> redirects.
>



More information about the webkit-gtk mailing list