MLWebView
NameSpace: MagicLeap
API for MLWebView that allows an application to instantiate a hardware accelerated WebView and interact with it(via "mouse" and "keyboard" events). More...
Inherits from:
MLAPIBase
Detailed Description
public class MLWebView : MLAPIBase
Details*
MLWebView class exposes static functions that allows an application to instantiate a hardware accelerated WebView and interact with it(via "mouse" and "keyboard" events).
Public Fields
AcceptPopup
Flag to indicate if the application accepts the popup
public bool AcceptPopup = false { get; set; }
IgnoreCertificateError
Flag to indicate if urls issuing certificate errors should be loaded or not
public bool IgnoreCertificateError { get; set; }
WebViewHandle
Retrieves the assigned web view handle.
public ulong WebViewHandle { get; set; }
Returns: The assigned web view handle, MagicLeapNativeBindings.InvalidHandle if it has not been created.
Public Methods
bool CanGoBack
Checks if the "Back" action is currently valid.
public bool CanGoBack()
Returns: True if can use the "Back" action.
bool CanGoForward
Checks if the "Forward" action is currently valid.
public bool CanGoForward()
Returns: True if can use the "Forward" action.
MLResult ClearCache
Clear the webview cache.
public MLResult ClearCache()
Returns: MLResult.Code.Ok if cache cleared successfully
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult.Code.UnspecifiedFailure if clearing cache failed due to an internal error.
MLWebView Create
Create a MLWebView. The MLWebView will be ready to use once this function returns with MLResult_OK.
public static MLWebView Create(
uint width,
uint height,
bool isPopup =false,
ulong popupId =0
)
Parameters
Type | Name | Description |
---|---|---|
uint | width | Width of the WebView in pixels. |
uint | height | Height of the WebView in pixels. |
bool | isPopup | |
ulong | popupId |
Returns: MLWebView instance if creation was successful, null otherwise.
MLResult Destroy
Destroy a MLWebView. The MLWebView will be terminated by this function call and the shall no longer be valid.
public MLResult Destroy()
Returns: MLResult.Code.Ok if was destroyed successfully.
MLResult.Code.UnspecifiedFailure if an error occurred destroying the MLWebView.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
Vector2Int GetScrollOffset
Get the scroll offset of the webview.
public Vector2Int GetScrollOffset()
Returns: Vector2Int representing the horizontal and vertical offset of the webview, in pixels.
Vector2Int GetScrollSize
Get the entire scrollable size of the webview. This should be typically called afer OnLoadEnd to determine the scollable size of the main frame of the loaded page.Some pages might dynamically resize and this should be called before each frame draw to correctly determine the scrollable size of the webview.
public Vector2Int GetScrollSize()
Returns: Vector2Int representing the entire width and height of the webview, in pixels.
string GetURL
Get the current URL.
public string GetURL()
Returns: Current URL.
double GetZoomFactor
Get the current zoom factor. The default zoom factor is 1.0.
public double GetZoomFactor()
Returns: Current numeric value for zoom factor.
MLResult GoBack
Trigger a "Back" action in the MLWebView. Query #MLWebViewCanGoBack before calling this method. If there is no valid page to go back to, this method will be no-op.
public MLResult GoBack()
Returns: MLResult.Code.Ok if WebView Back action was initiated or cannot go back any further.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult GoForward
Trigger a "Forward" action in the MLWebView. Query MLWebViewCanGoForward before calling this method. If there is no valid page to go forward to, this method will be no-op.
public MLResult GoForward()
Returns: MLResult.Code.Ok if WebView Forward action was initiated or cannot go forward any further.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult GoTo
Go to a URL with the specified MLWebView. Note that success with this call only indicates that a load will be attempted. Caller can be notified about issues loading the URL via the event r on_load_error.
public MLResult GoTo(
string url
)
Parameters
Type | Name | Description |
---|---|---|
string | url | URL that will be loaded. |
Returns: MLResult.Code.Ok if WebView is attempting to load the specified URL.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult InjectChar
Sends a printable char keyboard event to MLWebView.
public MLResult InjectChar(
char charUtf
)
Parameters
Type | Name | Description |
---|---|---|
char | charUtf32 | printable char utf code |
Returns: MLResult.Code.Ok if key event was injected.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult InjectKeyDown
Sends a key down/pressed event to MLWebView.
public MLResult InjectKeyDown(
MLWebView.KeyCode keyCode,
uint modifierMask
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView.KeyCode | keyCode | MLWebView.KeyCode. |
uint | modifierMask | Should be one or combination of MLWebView.EventFlags. |
Returns: MLResult.Code.Ok if key event was injected.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult InjectKeyUp
Sends a key up/release event to MLWebView.
public MLResult InjectKeyUp(
MLWebView.KeyCode keyCode,
uint modifierMask
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView.KeyCode | keyCode | MLWebView.KeyCode. |
uint | modifierMask | Should be one or combination of MLWebView.EventFlags. |
Returns: MLResult.Code.Ok if key event was injected.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult InjectMouseButtonDown
Sends a mouse button down/pressed event on a specific location on screen.
public MLResult InjectMouseButtonDown(
uint xPosition,
uint yPosition,
EventFlags modifiers
)
Parameters
Type | Name | Description |
---|---|---|
uint | xPosition | Horizontal position of the cursor. |
uint | yPosition | Vertical position of the cursor. |
EventFlags | modifiers | Should be one or combination of EventFlags. |
Returns: MLResult.Code.Ok if successful.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult InjectMouseButtonUp
Sends a mouse button up/released event on a specific location on screen.
public MLResult InjectMouseButtonUp(
uint xPosition,
uint yPosition,
EventFlags modifiers
)
Parameters
Type | Name | Description |
---|---|---|
uint | xPosition | Horizontal position of the cursor. |
uint | yPosition | Vertical position of the cursor. |
EventFlags | modifiers | Should be one or combination of EventFlags. |
Returns: MLResult.Code.Ok if successful.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult InjectMouseMove
Moves the WebView mouse.
public MLResult InjectMouseMove(
uint xPosition,
uint yPosition,
EventFlags modifiers
)
Parameters
Type | Name | Description |
---|---|---|
uint | xPosition | Horizontal position of the cursor. |
uint | yPosition | Vertical position of the cursor. |
EventFlags | modifiers | Should be one or combination of EventFlags. |
Returns: MLResult.Code.Ok if internal mouse was moved.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
delegate void OnBeforePopupDelegate
The delegate for the webview before popup event.
public delegate void OnBeforePopupDelegate(
MLWebView webView,
string url,
bool popupAccepted
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
string | url | The URL for the popup to load. |
bool | popupAccepted |
delegate void OnBeforeResourceLoadDelegate
The delegate for the before reasource loaded event.
public delegate void OnBeforeResourceLoadDelegate(
MLWebView webView,
string resourceURL
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
string | resourceURL | The url of the resource about to be loaded. |
delegate void OnCertificateErrorDelegate
The delegate for the certificate error event.
public delegate void OnCertificateErrorDelegate(
MLWebView webView,
int errorCode,
string url,
string errorMessage,
string details,
bool certificateErrorIgnored
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
int | errorCode | Error code for ssl error. |
string | url | The url associated to the certificate error. |
string | errorMessage | Certificate error short description. |
string | details | Certificate error details. |
bool | certificateErrorIgnored |
delegate void OnDestroyDelegate
The delegate for the webview destroy event.
public delegate void OnDestroyDelegate(
MLWebView webView
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
delegate void OnKeyboardDismissDelegate
The delegate for the keyboard dismiss event.
public delegate void OnKeyboardDismissDelegate(
MLWebView webView
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
delegate void OnLoadEndDelegate
The delegate for the reasource loaded event.
public delegate void OnLoadEndDelegate(
MLWebView webView,
bool isMainFrame,
int httpStatusCode
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
bool | isMainFrame | Whether this event was for the main frame. |
int | httpStatusCode | The standard http status code. |
delegate void OnLoadErrorDelegate
The delegate for the reasource load error event.
public delegate void OnLoadErrorDelegate(
MLWebView webView,
bool isMainFrame,
int httpStatusCode,
string errorStr,
string failedUrl
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
bool | isMainFrame | True if this event was for the main frame. |
int | httpStatusCode | Http status code for the URL load failure. |
string | errorStr | The stringified version of the error code. |
string | failedUrl | The url that caused the load error. |
delegate void OnPopupClosedDelegate
The delegate fpr the webview popup closed event.
public delegate void OnPopupClosedDelegate(
MLWebView webView,
ulong handle
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
ulong | handle | The webview handle of the popup being closed. |
delegate void OnPopupOpenedDelegate
The delegate for the webview popup opened event.
public delegate void OnPopupOpenedDelegate(
MLWebView webView,
ulong popupID,
string url
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
ulong | popupID | The ID of the popup. |
string | url | The URL associated with the popup. |
delegate void OnServiceConnectedDelegate
The delegate for the webview service connected event.
public delegate void OnServiceConnectedDelegate(
MLWebView webView
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
delegate void OnServiceDisconnectedDelegate
The delegate for the webview service disconnected event.
public delegate void OnServiceDisconnectedDelegate(
MLWebView webView
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
delegate void OnServiceFailedDelegate
The delegate for the webview service failed event.
public delegate void OnServiceFailedDelegate(
MLWebView webView,
MLResult result
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
MLResult | result | The MLResult code associated with the failure. |
delegate void OnShowKeyboardDelegate
The delegate for the keyboard show event.
public delegate void OnShowKeyboardDelegate(
MLWebView webView,
InputFieldData keyboardShowData
)
Parameters
Type | Name | Description |
---|---|---|
MLWebView | webView | The MLWebView associated with this callback. |
InputFieldData | keyboardShowData | Data about the clicked input field. |
MLResult Pause
Pause the webview. Call MLWebViewResume to resume. This method provides a multiple pause types to the webview.
public MLResult Pause(
PauseType pauseType
)
Parameters
Type | Name | Description |
---|---|---|
PauseType | pauseType | The type of pause to be used. |
Returns: MLResult.Code.Ok if paused successfully.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle or PauseType value.
MLResult.Code.UnspecifiedFailure if failed due to an internal error.
MLResult.Code.Pending if the MLWebView handle is not ready to use. See an asynchronous mode of MLWebViewCreate.
MLResult Reload
Trigger a "Reload" action in the MLWebView.
public MLResult Reload()
Returns: MLResult.Code.Ok if WebView Reload action was initiated.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult RemoveAllCookies
Remove all webview cookies.
public MLResult RemoveAllCookies()
Returns: MLResult.Code.Ok if all cookies removed successfully.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult.Code.UnspecifiedFailure if removing all cookies failed due to an internal error.
MLResult ResetZoom
Reset zoom level to 1.0.
public MLResult ResetZoom()
Returns: MLResult.Code.Ok if MLWebView zoom was reset.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult.Code.UnspecifiedFailure if it failed to reset zoom due to an internal error.
MLResult Resume
Resumes a webview after a previous call of Pause. Resume webview to the normal operation for all webview pause types.
public MLResult Resume()
Parameters
Type | Name | Description |
---|---|---|
handle | The webview being accessed. |
Returns: MLResult.Code.Ok if resumed successfully.
MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
MLResult.Code.UnspecifiedFailure if failed due to an internal error.
MLResult.Code.Pending if the MLWebView handle is not ready to use. See an asynchronous mode of MLWebViewCreate.
MLResult ScrollBy
Triggers a mouse "Scroll" event.
public MLResult ScrollBy(
uint xPixels,
uint yPixels
)
Parameters
Type | Name | Description |
---|---|---|
uint | xPixels | The number of pixels to scroll on the x axis. |
uint | yPixels | The number of pixels to scroll on the y axis. |
Returns: MLResult.Code.Ok if MLWebView was scrolled.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult ZoomIn
Zoom in one level.
public MLResult ZoomIn()
Returns: MLResult.Code.Ok if MLWebView zoomed in.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult.Code.WebViewResultZoomLimitReached if cannot zoom in any further.
MLResult.Code.UnspecifiedFailure if it failed to reset zoom due to an internal error.
MLResult ZoomOut
Zoom out one level.
public MLResult ZoomOut()
Returns: MLResult.Code.Ok if MLWebView zoomed out.
MLResult.Code.InvalidParam if its unable to find the specified MLWebView .
MLResult.Code.WebViewResultZoomLimitReached if cannot zoom out any further.
MLResult.Code.UnspecifiedFailure if it failed to reset zoom due to an internal error.
Public Events
OnBeforePopup
Event raised when WebView checks if a URL is OK to load in a popup.
public OnBeforePopupDelegate OnBeforePopup()
OnBeforeResourceLoaded
Event raised just before resources are loaded.
public OnBeforeResourceLoadDelegate OnBeforeResourceLoaded()
OnCertificateErrorLoaded
Event raised when there was an error during certification loading.
public OnCertificateErrorDelegate OnCertificateErrorLoaded()
OnErrorLoaded
Event raised when there was an error during loading.
public OnLoadErrorDelegate OnErrorLoaded()
OnKeyboardDismissed
Event rasied if Keyboard should be dismissed.
public OnKeyboardDismissDelegate OnKeyboardDismissed()
OnKeyboardShown
Event raised if user clicked inputfield and keyboard should be displayed.
public OnShowKeyboardDelegate OnKeyboardShown()
OnLoadEnded
Event raised when resources finish loading.
public OnLoadEndDelegate OnLoadEnded()
OnPopupClosed
Event raised when Webview is closing a popup.
public OnPopupClosedDelegate OnPopupClosed()
OnPopupOpened
Event raised when WebView opened a popup.
public OnPopupOpenedDelegate OnPopupOpened()
OnServiceConnected
Event raised when WebView service is connected.
public OnServiceConnectedDelegate OnServiceConnected()
OnServiceDisconnected
Event raised when WebView service is disconnected.
public OnServiceDisconnectedDelegate OnServiceDisconnected()
OnServiceFailed
Event raised when WebView service fails to connect.
public OnServiceFailedDelegate OnServiceFailed()
OnWebViewDestroyed
Event raised when WebView is destroyed.
public OnDestroyDelegate OnWebViewDestroyed()
Public Enums
EventFlags
Flags to set special key states during input.
Enumerator | Value | Description |
---|---|---|
None | 0 | No flag is applied. |
CapsLockOn | 1 << 0 | Caps Lock is on. |
ShiftDown | 1 << 1 | Shift is pressed. |
ControlDown | 1 << 2 | Control is pressed. |
AltDown | 1 << 3 | Alt is pressed. |
LeftMouseButton | 1 << 4 | Left mouse button is pressed. |
MiddleMouseButton | 1 << 5 | Middle mouse button is pressed. |
RightMouseButton | 1 << 6 | Right mouse button is pressed. |
CommandDown | 1 << 7 | Command key is pressed. |
NumLockOn | 1 << 8 | NumLock is on. |
IsKeyPad | 1 << 9 | Was key struck on KeyPad. |
IsLeft | 1 << 10 | Is left key. |
IsRight | 1 << 11 | Is right key. |
AltGRDown | 1 << 12 | AltGR is pressed. |
KeyCode
Enums for all possible ML Key Codes.
Enumerator | Value | Description |
---|---|---|
Unknown | 0 | |
Home | 3 | |
Back | 4 | |
DpadLeft | 21 | |
DpadRight | 22 | |
Delete | 67 | |
Focus | 80 | |
Plus | 81 | |
Menu | 82 | |
Forward | 125 | |
Trigger | 500 | |
Capture | 501 | |
Bumper | 502 | |
Reality | 503 | |
Battery | 504 | |
MLBack | 508 | |
HomeTap | MLBack | |
HomeMediumTap | 509 | |
Popple | 510 | |
MouseLeft | 511 | |
MouseRight | 512 | |
MouseWheel | 513 | |
MouseExtra | 514 | |
MouseSide | 515 | |
VkbCancel | 1001 | |
VkbSubmit | 1002 | |
VkbPrevious | 1003 | |
VkbNext | 1004 | |
VkbClear | 1005 | |
VkbClose | 1006 | |
VkbCustom1 | 1007 | |
VkbCustom2 | 1008 | |
VkbCustom3 | 1009 | |
VkbCustom4 | 1010 | |
VkbHidePassword | 1012 | |
VkbShowPassword | 1013 |
PauseType
The type of the webview pause.
Enumerator | Value | Description |
---|---|---|
MultiMedia | Pause all multimedia activities of the webview. | |
Timers | Pause javascript timers of the webview. | |
Discard | Pause and discard the webview rendering process. But keep alive the MLWebView handle. |
TextInputFlags
Flags related to a text entry field passed when on_show_keyboard is called.
Enumerator | Value | Description |
---|---|---|
None | 0 | Nonne of flasg are applied. |
AutocompleteOn | 1 << 0 | Autocompletion is on. |
AutocompleteOff | 1 << 1 | Autocompletion is off. |
AutocorrectOn | 1 << 2 | Autocorrection is on. |
AutocorrectOff | 1 << 3 | Autocorrection is off. |
SpellcheckOn | 1 << 4 | Spellcheck is on. |
SpellcheckOff | 1 << 5 | Spellcheck is of. |
AutocapitalizeNone | 1 << 6 | Autocapitalize is off. |
AutocapitalizeCharacters | 1 << 7 | Autocapitalize characters. |
AutocapitalizeWords | 1 << 8 | Autocapitalize words. |
AutocapitalizeSentences | 1 << 9 | Autocapitalize sentences. |
HaveNextFocusableElement | 1 << 10 | Have next focusable element. |
HavePreviousFocusableElement | 1 << 11 | Have previous focusable element. |
HasBeenPasswordField | 1 << 12 | has been a password field. |
TextInputType
The type of text entry selected when onShowKeyboard is called.
Enumerator | Value | Description |
---|---|---|
None | None. | |
Text | Text. | |
Password | Password. | |
Search | Search. | |
Email. | ||
Number | Number | |
Telephone | Telephone. | |
URL | URL. | |
Date | Date. | |
DateTime | Date Time. | |
DateTimeLocal | Date Time Local. | |
Month | Month. | |
Time | Time. | |
Week | Week. | |
TextArea | Text Area. | |
ContentEditable | Content Editable. | |
DateTimeField | Date Time Field. |