It is currently Sun May 27, 2018 8:38 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: NavigationCallback for WebGadget in Linux + MacOS
PostPosted: Tue Mar 19, 2013 11:52 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1502
Location: Germany
Currently the navigation callback for the WebGadget
Code:
SetGadgetAttribute(#WebGadget, #PB_Web_NavigationCallback, @Callback())
is only implemented for Windows. It would be nice to have it also available cross-platform for Linux and MacOS X. The following two code examples demonstrate how it might be done (doing the same as the second example from PB help for the WebGadget, i.e. blocking the switching to the News hyperlink on the PB website).

Linux version (works in ASCII and Unicode mode):
Code:
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


MacOS X version (Cocoa framework):
Code:
EnableExplicit

ImportC ""
  sel_registerName(str.p-ascii)
  class_addMethod(class, selector, imp, types.p-ascii)
EndImport

Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
Global delegateClass = CocoaMessage(0, appDelegate, "class")

ProcedureC PolicyDecisionMaker(obj, sel, webView, actionInformation, request, frameName, listener)
  Protected URL = CocoaMessage(0, request, "URL")
  Protected URLString.s = PeekS(CocoaMessage(0, CocoaMessage(0, URL, "absoluteString"), "UTF8String"), -1, #PB_UTF8)

  If URLString = "http://www.purebasic.com/news.php"
    MessageRequester("", "No news today!")
  Else
    CocoaMessage(0, listener, "use")
  EndIf
EndProcedure

class_addMethod(delegateClass, sel_registerName("webView:decidePolicyForNavigationAction:request:frame:decisionListener:"), @PolicyDecisionMaker(), "v@:@@@@@")

If OpenWindow(0, 270, 100, 600, 300, "WebGadget")
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")
  CocoaMessage(0, GadgetID(0), "setPolicyDelegate:", appDelegate)
 
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye