NavigationCallback for WebGadget
Posted: Fri Mar 22, 2013 4:29 pm
Currently the navigation callback for the WebGadget
is only implemented for Windows. The following example code demonstrates how this might be done in Linux (tested in Kubuntu 12.04 x64 and OpenSUSE 12.3 x86 in ASCII and Unicode mode). I have also posted a feature request to ask for an implemention of this navigation callback in PureBasic natively for Linux and MacOS X (there I also posted this code example and a second one for MacOS X). The example code below does the same as the 2nd example from PB help for the Webgadget: it intercepts a click onto the hyperlink for "News" and displays a message requester.
Code: Select all
SetGadgetAttribute(#WebGadget, #PB_Web_NavigationCallback, @Callback())
Code: Select all
EnableExplicit
ImportC "-lgobject-2.0"
g_signal_connect_data(*Instance, Signal.P-UTF8, *Callback, *UserData, *ClosureNotify, ConnectFlags.I)
EndImport
ImportC "-lwebkitgtk-1.0"
webkit_web_navigation_action_get_original_uri(*NavigationAction)
webkit_web_policy_decision_ignore(*PolicyDecision)
webkit_web_policy_decision_use(*PolicyDecision)
EndImport
Enumeration
#WEBKIT_NAVIGATION_RESPONSE_ACCEPT
#WEBKIT_NAVIGATION_RESPONSE_IGNORE
EndEnumeration
ProcedureC WebGadgetCallback(*WebView, *Frame, *Request, *NavigationAction, *PolicyDecision, UserData)
If PeekS(webkit_web_navigation_action_get_original_uri(*NavigationAction), -1, #PB_UTF8) = "http://www.purebasic.com/news.php"
MessageRequester("", "No news today!")
webkit_web_policy_decision_ignore(*PolicyDecision)
Else
webkit_web_policy_decision_use(*PolicyDecision)
EndIf
EndProcedure
If OpenWindow(0, 200, 100, 600, 300, "WebGadget")
WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")
g_signal_connect_data(GadgetID(0), "navigation-policy-decision-requested", @WebGadgetCallback(), 0, 0, 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf