====== Using the OpenInsight 10 Browser Control (Web) ======
====== ======
==== Created at 28 MAY 2019 01:28PM ====
Using the OpenInsight 10 Browser Control
The OpenInsight 10 Browser Control is based on the Chromium browser engine, used by most of the major desktop browsers. The OI 10 version has been embedded in a COM object for easier control from inside the OpenInsight environment.
To use the Browser Control, you must add it to your form. In the form designer, add an OLE control:
{{kb1084_1.png}}
{{kb1084_2.png}}
Set its class id (CLSID) to ChromeOI_10.CEFBrowser:
I{{kb1084_3.png}}
You may name the control anything you wish; for the purposes of this document, we will use the name OLE_WB for our examples. You may wish to set the AutosizeWidth and AutosizeHeight properties to true:
{{kb1084_4.png}}
Be sure to also set the 'OLE' event in the Events tab - this should be set as a quick event to "Call Commuter Module (@Window)":
{{kb1084_5.png}}
{{kb1084_6.png}}
{{kb1084_7.png}}
{{kb1084_8.png}}
You'll also (most likely) need to set the events for Create to call your commuter module in the same way.
In your commuter module, you must mark the events you wish to be notified about. You may wish to catch all OLE events for the web control:
call exec_Method( atWindow : ".OLE_WB", |
"QUALIFY_EVENT", |
"ALL_OLES", |
TRUE$ )
In your handler for the OLE events, you can use the utility function RTI_CEF_OLE_EVENTS which can process many of the browser control's events for you (such as download requests, opening new tabs, etc.):
* param1, param2: passed from the OLE event
* atWindow: the window ID that contains the control
* statusLine : control ID of the status line, if any
* UNUSED: pass null
* titleLine: control ID of the title, if any
* ctlID: control ID of the browser control
StatusLine = atWindow:".STATUSTEXT" ;* where to put the status messages
titleLine = atWindow
ctlID = atWindow:".OLE_WB"
RTI_CEF_OLE_EVENTS(param1, param2, atWindow, statusLine, unused, titleLine, ctlID)
* update the toolbar buttons as appropriate
canGoBack = Get_Property(atWindow, "@GOBACK")
canGoFwd = Get_Property(atWindow, "@GOFWD")
call Set_Property(atWindow:".BTN_BACK", "ENABLED", canGoBack+0)
call Set_Property(atWindow:".BTN_FWD", "ENABLED", canGoFwd+0)
Note that if a link inside the web page hosted by the browser control starts with "oi:%%//%%" (instead of a normal http:%%//%% or https:%%//%%), a special "browserOIEvent" event will be raised and passed back to OpenInsight. Your code in the OLE handler can look for this and use the information passed back to perform any desired action. For example:
Case ( param1 _eqc "browserOIEvent" )
realURL = param2[6, Len(param2)] ;* remove oi:%%//%% prefix
oiEventID = oconv(realURL, "[URL_FORMAT,COMPONENT]")
oiEventName = trim(oiEventID[1,","])
oiEventName[-1,1] = "" ;* remove trailing slash
oiEventParam1 = oiEventID[col2()+1,","]
To initialize the control, you must first wait until it is ready and you can then send it HTML or a URL:
Loop
isReady = Get_Property(atWindow:".OLE_WB", "isReady")
While isReady = "0"
call yield()
repeat
call exec_Method( atWindow : ".OLE_WB", "Navigate2", url )
or
Loop
rs = Get_Property(atWindow: WEB_CONTROL$, "isReady")
While rs = "0"
call yield()
repeat
call exec_method( atWindow : WEB_CONTROL$, "setHTML", startHTML, "file:%%//%%":drive():"/")
An example of a very simple commuter module would be:
Function BROWSER_TEST_FORM( CtrlEntId, Method, Param1, Param2, Param3, Param4, Param5, Param6, Param7)
Declare Function exec_method, Set_Property, Get_Property
Declare Subroutine rti_cef_ole_events, set_property
$Insert Logical
If Assigned( CtrlEntID ) Else CtrlEntID = Null$
If Assigned( Method ) Else Method = Null$
If Assigned( Param1 ) Else Param1 = Null$
If Assigned( Param2 ) Else Param2 = Null$
If Assigned( Param3 ) Else Param3 = Null$
If Assigned( Param4 ) Else Param4 = Null$
If Assigned( Param5 ) Else Param5 = Null$
If Assigned( Param6 ) Else Param6 = Null$
if assigned( Param7 ) else param7 = Null$
RetVal = False$
WinID = CtrlEntID[1,'.']
BrowserCtl = WinID:".OLE_WB"
statusLine = WinID:".StatusLine"
Begin Case
Case method _eqc "CREATE" ; Gosub WinCreate
Case method _eqc "OLE" ; Gosub handleOLE
End Case
Return RetVal
// --------------------------------------------------------------------------------------------
WinCreate:
// This Sub Handles Window Creation.
title = "Browser Test Control"
// Qualify OLE Events
eventOp = ''
eventOp<1> = True$
eventOp<4> = False$ ; * synch
eventOp<7> = False$ ; * single param
OleEvent = 'ALL_OLES'
x = exec_method( BrowserCtl, 'QUALIFY_EVENT', OleEvent, eventOp )
Set_Property( BrowserCtl, "isSecure", "0")
If title <> "" then
x = Set_Property( WinID, "TEXT", title)
End
Loop
rs = Get_Property(BrowserCtl, "isReady")
While rs = "0"
call yield()
Repeat
baseFileURL = "file://":drive():"/"
html = "Hello, world, I am the Chromium Browser Control!"
call exec_method( BrowserCtl, "setHTML", html, baseFileURL)
Return
// --------------------------------------------------------------------------------------------
handleOLE:
* handle OLE events
RTI_CEF_OLE_EVENTS(param1, param2, winID, statusLine)
Return
For more information, see the descriptions for the properties and methods below.
Properties of the Web Control
isReady (read only)
Example: rs = Get_Property(atWindow: WEB_CONTROL$, "isReady")
returns 0 if the browser control is not yet fully initialized, 1 otherwise
History (read only)
Example: rs = Get_Property(atWindow: WEB_CONTROL$, "History")
returns @FM delimited list of pages visited by the control
DefaultURL
Example: rs = Get_Property(atWindow: WEB_CONTROL$, "DefaultURL")
Example: rs = Set_Property(atWindow: WEB_CONTROL$, "DefaultURL", “https:%%//%%www.revelation.com�)
gets or sets the default URL used by the browser control (default is about:blank)
HTML
Example: rs = Get_Property(atWindow: WEB_CONTROL$, "HTML")
Example: rs = Set_Property(atWindow: WEB_CONTROL$, "HTML", “