Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/HTMLViewer Mac/WebPolicyDelegate
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/HTMLViewer Mac/WebPolicyDelegate
This example is the version from Sun, 23th Sep 2017.
Project "WebPolicyDelegate.rbp"
FileTypes
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control Info Inherits Label
ControlInstance Info Inherits Label
End Control
Control web Inherits HTMLViewer
ControlInstance web Inherits HTMLViewer
End Control
Control RadioButton1 Inherits RadioButton
ControlInstance RadioButton1 Inherits RadioButton
End Control
Control RadioButton2 Inherits RadioButton
ControlInstance RadioButton2 Inherits RadioButton
End Control
Control RadioButton3 Inherits RadioButton
ControlInstance RadioButton3 Inherits RadioButton
End Control
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
EventHandler Sub Close() if wui<>nil then wui.w=nil end if End EventHandler
EventHandler Sub Open() wui=new MyUIEvents wui.w=self web.InstallWebPolicyDelegateMBS wui if not me.Composite then MsgBox "This window must be composite!" end if End EventHandler
Property Protected wui As myuIEvents
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() if TargetMachO then // ok else MsgBox "This project works only as MachO target on Mac OS X." end if MainWindow.show MainWindow.web.LoadURL "http://www.apple.com" End EventHandler
End Class
Class MyUIEvents Inherits WebPolicyDelegateMBS
EventHandler Sub Close() 'MsgBox "Close" End EventHandler
EventHandler Sub Open() 'MsgBox "Open" End EventHandler
EventHandler Function decidePolicyForMIMEType(type as string,request as NSURLRequestMBS, frame as WebFrameMBS, decisionListener as WebPolicyDecisionListenerMBS) As boolean System.DebugLog "decide policy for mime type "+type if w.RadioButton1.Value then w.List.InsertRow 0,"use "+type decisionListener.use elseif w.RadioButton2.Value then w.List.InsertRow 0,"download "+type decisionListener.download elseif w.RadioButton3.Value then w.List.InsertRow 0,"ignore "+type decisionListener.ignore end if Return true // disable old handler from Xojo End EventHandler
EventHandler Function decidePolicyForNavigationAction(request as NSURLRequestMBS, frame as WebFrameMBS, decisionListener as WebPolicyDecisionListenerMBS, NavigationType as integer, ModifierFlags as integer, OriginalURL as string) As boolean System.DebugLog "decide policy for navigation "+request.URL if w.RadioButton1.Value then w.List.InsertRow 0,"use "+request.URL decisionListener.use elseif w.RadioButton2.Value then w.List.InsertRow 0,"download "+request.URL decisionListener.download elseif w.RadioButton3.Value then w.List.InsertRow 0,"ignore "+request.URL decisionListener.ignore end if Return true // disable old handler from Xojo End EventHandler
EventHandler Function decidePolicyForNewWindowAction(request as NSURLRequestMBS, framename as string, decisionListener as WebPolicyDecisionListenerMBS, NavigationType as integer, ModifierFlags as integer, OriginalURL as string) As boolean System.DebugLog "decide policy for new window "+request.URL if w.RadioButton1.Value then w.List.InsertRow 0,"use "+request.URL decisionListener.use elseif w.RadioButton2.Value then w.List.InsertRow 0,"download "+request.URL decisionListener.download elseif w.RadioButton3.Value then w.List.InsertRow 0,"ignore "+request.URL decisionListener.ignore end if Return true // disable old handler from Xojo End EventHandler
EventHandler Function unableToImplementPolicyWithError(errorString as string, frame as WebFrameMBS) As boolean System.DebugLog "unable to implement policy error "+errorString End EventHandler
Property w As mainwindow
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacControls Plugin.





Links
MBS Xojo PDF Plugins