// %BANNER_BEGIN%
// ---------------------------------------------------------------------
// %COPYRIGHT_BEGIN%
// Copyright (c) (2018-2022) Magic Leap, Inc. All Rights Reserved.
// Use of this file is governed by the Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2
// Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein.
// %COPYRIGHT_END%
// ---------------------------------------------------------------------
// %BANNER_END%
namespace UnityEngine.XR.MagicLeap
{
using System;
using System.Runtime.InteropServices;
using UnityEngine.XR.MagicLeap.Native;
///
/// 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 partial class MLWebView
{
///
/// See ml_webview.h for additional comments.
///
private class NativeBindings : Native.MagicLeapNativeBindings
{
///
/// The delegate for the before reasource loaded event.
///
/// The url of the resource about to be loaded.
/// User defined data.
public delegate void OnBeforeResourceLoadCallback([MarshalAs(UnmanagedType.LPStr)] string resourceUrl, IntPtr userData);
///
/// The delegate for the reasource loaded event.
///
/// Whether this event was for the main frame.
/// The standard http status code.
/// User defined data.
public delegate void OnLoadEndCallback([MarshalAs(UnmanagedType.I1)] bool isMainFrame, int httpStatusCode, IntPtr userData);
///
/// The delegate for the reasource load error event.
///
/// True if this event was for the main frame.
/// Http status code for the URL load failure.
/// The stringified version of the error code.
/// The url that caused the load error.
/// User defined data.
public delegate void OnLoadErrorCallback([MarshalAs(UnmanagedType.I1)] bool isMainFrame, int httpStatusCode, [MarshalAs(UnmanagedType.LPStr)] string errorStr, [MarshalAs(UnmanagedType.LPStr)] string failedUrl, IntPtr userData);
///
/// The delegate for the certificate error event.
///
/// Error code for ssl error.
/// The url associated to the certificate error.
/// Certificate error short description.
/// Certificate error details.
/// User defined data.
[return: MarshalAs(UnmanagedType.I1)]
public delegate bool OnCertificateErrorCallback(int errorCode, [MarshalAs(UnmanagedType.LPStr)] string url, [MarshalAs(UnmanagedType.LPStr)] string errorMessage, [MarshalAs(UnmanagedType.LPStr)] string details, IntPtr userData);
///
/// The delegate for the keyboard show event.
///
/// Horizontal position of the input field.
/// Vertical position of the input field.
/// Width of the input field.
/// Height of the input field.
/// One or combination of TextInputFlags.
/// One of TextInputType.
/// User defined data.
public delegate void OnShowKeyboardCallback(int x, int y, int width, int height, TextInputFlags textInputFlags, TextInputType textInputType, IntPtr userData);
///
/// The delegate for the keyboard dismiss event.
///
/// User defined data.
public delegate void OnKeyboardDismissCallback(IntPtr userData);
///
/// The delegate for the webview destroy event.
///
/// User defined data.
public delegate void OnDestroyCallback(IntPtr userData);
///
/// The delegate for the webview service connected event.
///
public delegate void OnServiceConnectedCallback(IntPtr userData);
///
/// The delegate for the webview service disconnected event.
///
public delegate void OnServiceDisconnectedCallback(IntPtr userData);
///
/// The delegate for the webview service failed event.
///
public delegate void OnServiceFailedCallback(MLResult result, IntPtr userData);
///
/// The delegate for the webview before popup event.
///
public delegate bool OnBeforePopupCallback([MarshalAs(UnmanagedType.LPStr)] string url, IntPtr userData);
///
/// The delegate for the webview popup opened event.
///
public delegate void OnPopupOpenedCallback(ulong popupID, [MarshalAs(UnmanagedType.LPStr)] string url, IntPtr userData);
///
/// The delegate for the webview popup closed event.
/// This callback is used to notify the application of a popup that is being closed.
/// For example, this can happen if window.close() is used. This is not always called.
/// If the application closes the popup itself, then this function is not called.
/// An application should call MLWebViewDestroy as soon as possible on the popup's
/// handle after receiving this callback.
///
public delegate void OnPopupClosedCallback(ulong handle, IntPtr userData);
///
/// Struct to define the cursor's state.
///
[StructLayout(LayoutKind.Sequential)]
public struct CursorState
{
///
/// Version of this struct.
///
public uint Version;
///
/// Horizontal position of the cursor.
///
public uint XPosition;
///
/// Vertical position of the cursor.
///
public uint YPosition;
///
/// Should be one or combination of #MLWebViewEventFlags.
///
public EventFlags Modifiers;
///
/// Create and return an initialized version of this struct.
///
/// A new instance of this struct.
public static CursorState Create(uint xPosition, uint yPosition, EventFlags modifiers)
{
return new CursorState()
{
Version = 1,
XPosition = xPosition,
YPosition = yPosition,
Modifiers = modifiers
};
}
};
///
/// Struct to define webview initialization.
///
[StructLayout(LayoutKind.Sequential)]
public struct Settings
{
///
/// Version of this struct.
///
public uint Version;
///
/// Horizontal size of webview in pixels.
///
public uint Width;
///
/// Vertical size of webview in pixels.
///
public uint Height;
///
/// JavaVM* pointer to use for Android up-calls.
///
public IntPtr ApplicationVm;
///
/// jobject to android. content. Context instance for Android up-calls.
///
public IntPtr Context;
///
/// Event callbacks for interacting with webview.
///
public EventCallbacks Callbacks;
///
/// Is this a popup?
///
public bool IsPopup;
///
/// Popup identifier used to create a webview.
///
public ulong PopupID;
///
/// Create and return an initialized version of this struct.
///
/// A new instance of this struct.
public static Settings Create(GCHandle gcHandle, uint width, uint height, bool isPopup, ulong popupID)
{
return new Settings()
{
Version = 3,
Width = width,
Height = height,
ApplicationVm = GetJavaVM(),
Context = GetAppContext(),
Callbacks = EventCallbacks.Create(gcHandle),
IsPopup = isPopup,
PopupID = popupID
};
}
};
///
/// Event handler for MLWebView callbacks. This structure must be initialized by calling #MLWebViewEventCallbacksInit
/// before use.
///
[StructLayout(LayoutKind.Sequential)]
public struct EventCallbacks
{
///
/// Version of this struct
///
public uint Version;
///
/// User data passed to every callback.
///
public IntPtr UserData;
///
/// Called to notify when a resource will loadeded.
///
public OnBeforeResourceLoadCallback OnBeforeResourceLoad;
///
/// Called to notify load completion.
///
public OnLoadEndCallback OnLoadEnd;
///
/// Called if there was any error during loading. These errors could be due to connectivity, certificate errors etc.
///
public OnLoadErrorCallback OnLoadError;
///
/// Called when there is any certificate error.
///
public OnCertificateErrorCallback OnCertificateError;
///
/// Called when user selects an input field.
///
public OnShowKeyboardCallback OnShowKeyboard;
///
/// Called when user deselects an input field and the keyboard should be dismissed.
///
public OnKeyboardDismissCallback OnKeyboardDismiss;
///
/// Called when webview is destroyed.
///
public OnDestroyCallback OnDestroy;
///
/// This callback is used to pass notify user of service connection.
///
public OnServiceConnectedCallback OnServiceConnected;
///
/// This callback is used to notify user that service is disconnect.
///
public OnServiceDisconnectedCallback OnServiceDisconnected;
///
/// This callback is used to notify user that service failed to connect.
///
public OnServiceFailedCallback OnServiceFailed;
///
/// This callback is used to ask the application if is OK to load a URL.
///
public OnBeforePopupCallback OnBeforePopup;
///
/// This callback is used to notify application that popup is opened.
///
public OnPopupOpenedCallback OnPopupOpened;
///
/// This callback is used to notify the application of a closing popup.
///
public OnPopupClosedCallback OnPopupClosed;
///
/// Create and return an initialized version of this struct.
/// Pointer to user data to be used to reference the originating web view tab
///
/// A new instance of this struct.
public static EventCallbacks Create(GCHandle gcHandle)
{
return new EventCallbacks()
{
Version = 3u,
UserData = GCHandle.ToIntPtr(gcHandle),
OnBeforeResourceLoad = HandleOnBeforeResourceLoad,
OnLoadEnd = HandleOnLoadEnd,
OnLoadError = HandleOnLoadError,
OnCertificateError = HandleOnCertificateError,
OnShowKeyboard = HandleOnShowKeyboard,
OnKeyboardDismiss = HandleOnKeyboardDismiss,
OnDestroy = HandleOnDestroy,
OnServiceConnected = HandleServiceConnected,
OnServiceDisconnected = HandleServiceDisconnected,
OnServiceFailed = HandleServiceFailed,
OnBeforePopup = HandleBeforePopup,
OnPopupOpened = HandlePopupOpened,
OnPopupClosed = HandlePopupClosed
};
}
};
///
/// Returns pointer to JavaVM that is required by WebView API.
///
/// pointer to JavaVM
[DllImport(CUtilsDLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetJavaVM();
///
/// Returns pointer to App Context that is required by WebView API.
///
/// pointer to JavaVM
[DllImport(CUtilsDLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetAppContext();
///
/// Create a MLWebView. The MLWebView will be ready to use once this function returns with MLResult_OK.
///
/// Handle that is ready to use with all other MLWebView API calls.
/// The initialization paramaters for the webview.
/// MLResult.Code.Ok if the MLWebView is ready for use.
/// MLResult.Code.UnspecifiedFailure if Unable to create the MLWebView.
/// MLResult.Code.InvalidParam if the parameter was null pointer.
/// MLResult.Code.PermissionDenied its missing the permission(s).
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewCreate(out ulong handle, ref Settings settings);
///
/// Destroy a MLWebView. The MLWebView will be terminated by this function call and the handle shall no longer be valid.
///
///
/// 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 handle.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewDestroy(ulong handle);
///
/// Specify the event handler for an MLWebView.
///
/// The MLWebView to link the event handler.
/// The event handler to link to the MLWebView.
/// Data that will be passed to your event handler when triggered.
/// MLResult.Code.Ok if event handler was set.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewSetEventCallbacks(ulong handle, EventCallbacks callbacks, IntPtr userData);
///
/// Acquires next available frame buffer for rendering.
///
/// The webview being accessed.
/// The buffer that is ready to be rendered. A value of 0 indicates no frame is ready.
/// MLResult.Code.Ok if frame is ready.
/// MLResult.Code.InvalidParam if its nable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewAcquireNextAvailableFrame(ulong handle, out IntPtr hwBuffer);
///
/// Release a frame acquired by #MLWebViewAcquireNextAvailableFrame.
///
/// The webview being accessed.<
/// The frame being released.
/// MLResult.Code.Ok if frame was successfully released.
/// MLResult.Code.UnspecifiedFailure if error occurred releasing the frame.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewReleaseFrame(ulong handle, IntPtr hwBuffer);
///
/// 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 handler on_load_error.
///
/// The webview being accessed.
/// URL that will be loaded.
/// MLResult.Code.Ok if WebView is attempting to load the specified URL.
/// MLResult.Code.IllegalState if WebView was paused. MLWebViewResume should be called before this function.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewGoTo(ulong handle, [MarshalAs(UnmanagedType.LPStr)] string url);
///
/// 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.
///
/// The webview being accessed.
/// MLResult.Code.Ok if WebView Back action was initiated or cannot go back any further.
/// MLResult.Code.IllegalState if WebView was paused. MLWebViewResume should be called before this function.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewGoBack(ulong handle);
///
/// 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.
///
/// The webview being accessed.
/// MLResult.Code.Ok if WebView Forward action was initiated or cannot go forward any further.
/// MLResult.Code.IllegalState if WebView was paused. MLWebViewResume should be called before this function.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewGoForward(ulong handle);
///
/// Trigger a "Reload" action in the MLWebView.
///
/// The webview being accessed.
/// MLResult.Code.Ok if WebView Reload action was initiated.
/// MLResult.Code.IllegalState if WebView was paused. MLWebViewResume should be called before this function.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewReload(ulong handle);
///
/// Get the current URL. Set outUrl to NULL to get the length of the current URL.
///
/// The webview being accessed.
/// The size that has been allocated in outUrl to hold the URL. This will be set to the actual length of URL if inoutSize and size needed for the URL are different.
/// The URL up to inoutSize of characters.
/// MLResult.Code.Ok if WebView URL was acquired.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewGetUrl(ulong handle, out uint inoutSize, IntPtr outUrl);
///
/// Checks if the "Back" action is currently valid.
///
/// The webview being accessed.
/// True if "Back" has a valid page to go to.
/// MLResult.Code.Ok if status of going "Back" was acquired.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewCanGoBack(ulong handle, [MarshalAs(UnmanagedType.I1)] out bool outCanGoBack);
///
/// Checks if the "Forward" action is currently valid.
///
/// The webview being accessed.
/// True if "Forward" has a valid page to go to.
/// MLResult.Code.Ok if status of going "Forward" was acquired.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewCanGoForward(ulong handle, [MarshalAs(UnmanagedType.I1)] out bool outCanGoForward);
///
/// Moves the WebView mouse.
///
/// The webview being accessed.
/// Information about the mouse movement.
/// MLResult.Code.Ok if internal mouse was moved.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewInjectMouseMove(ulong handle, ref CursorState cursorState);
///
/// Sends a mouse button down/pressed event on a specific location on screen.
///
/// The webview being accessed.
/// Information about the mouse button event.
/// MLResult.Code.Ok if successful.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewInjectMouseButtonDown(ulong handle, ref CursorState cursorState);
///
/// Sends a mouse button up/released event on a specific location on screen.
///
/// The webview being accessed.
/// Information about the mouse button event.
/// MLResult.Code.Ok if successful.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewInjectMouseButtonUp(ulong handle, ref CursorState cursorState);
///
/// Sends a printable char keyboard event to MLWebView.
///
/// The webview being accessed.
/// printable char utf code
/// MLResult.Code.Ok if key event was injected.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewInjectChar(ulong handle, uint charUtf32);
///
/// Sends a key down/pressed event to MLWebView.
///
/// The webview being accessed.
/// MLWebView.KeyCode.
/// Should be one or combination of MLWebView.EventFlags.
/// MLResult.Code.Ok if key event was injected.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewInjectKeyDown(ulong handle, MLWebView.KeyCode keyCode, uint modifierMask);
///
/// Sends a key up/release event to MLWebView.
///
/// The webview being accessed.
/// MLWebView.KeyCode.
/// Should be one or combination of MLWebView.EventFlags.
/// MLResult.Code.Ok if key event was injected.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewInjectKeyUp(ulong handle, MLWebView.KeyCode keyCode, uint modifierMask);
///
/// Reset zoom level to 1.0.
///
/// The webview being accessed.
/// MLResult.Code.Ok if MLWebView zoom was reset.
/// 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 it failed to reset zoom due to an internal error.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewResetZoom(ulong handle);
///
/// Zoom in one level.
///
/// The webview being accessed.
/// MLResult.Code.Ok if MLWebView zoomed in.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.WebViewResultZoomLimitReached if cannot zoom in any further.
/// MLResult.Code.UnspecifiedFailure if it failed to reset zoom due to an internal error.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewZoomIn(ulong handle);
///
/// Zoom out one level.
///
/// The webview being accessed.
/// MLResult.Code.Ok if MLWebView zoomed out.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.WebViewResultZoomLimitReached if cannot zoom out any further.
/// MLResult.Code.UnspecifiedFailure if it failed to reset zoom due to an internal error.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewZoomOut(ulong handle);
///
/// Get the current zoom factor. The default zoom factor is 1.0.
///
/// The webview being accessed.
/// Current numeric value for zoom factor.
/// MLResult.Code.Ok if outZoomFactor parameter was updated with the current zoom value.
/// 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 to get the zoom factor due to an internal error.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewGetZoomFactor(ulong handle, out double outZoomFactor);
///
/// Triggers a mouse "Scroll" event.
///
/// The webview being accessed.
/// The number of pixels to scroll on the x axis.
/// The number of pixels to scroll on the y axis.
/// MLResult.Code.Ok if MLWebView was scrolled.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewScrollBy(ulong handle, uint xPixels, uint yPixels);
///
/// Get the entire scrollable size of the webview.
/// This should be typically called afer HandleOnLoadEnd 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.
///
/// The webview being accessed.
/// The number representing the entire width of the webview, in pixels.
/// The number representing the entire height of the webview, in pixels.
/// MLResult.Code.Ok if MLWebView scroll size values were retrieved.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
/// TODO: To be removed due to deprecation.
public static extern MLResult.Code MLWebViewGetScrollSize(ulong handle, out int width, out int height);
///
/// Get the scroll offset of the webview.
///
/// The webview being accessed.
/// The number representing the horizontal offset of the webview, in pixels.
/// The number representing the vertical offset of the webview, in pixels.
/// MLResult.Code.Ok if MLWebView scroll offset values were retrieved.
/// MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
/// TODO: To be removed due to deprecation.
public static extern MLResult.Code MLWebViewGetScrollOffset(ulong handle, out int x, out int y);
///
/// Retrieves the 4x4 texture coordinate transform matrix used by all MLWebView frames. This transform matrix maps 2D
/// homogeneous texture coordinates of the form (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture coordinate
/// that should be used to sample that location from the texture. Sampling the texture outside of the range of this
/// transform is undefined. The matrix is stored in column-major order so that it may be passed directly to OpenGL ES via the
/// glLoadMatrixf or glUniformMatrix4fv functions.
///
/// The webview being accessed.
/// The retrieved matrix.
/// MLResult.Code.Ok if constant matrix was retrieved.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewGetFrameTransformMatrix(ulong handle, out MLMat4f outMtx);
///
/// Remove all webview cookies.
///
/// The webview being accessed.
/// MLResult.Code.Ok if all cookies removed 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 removing all cookies failed due to an internal error.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewRemoveAllCookies(ulong handle);
///
/// Pause the webview. Call MLWebViewResume to resume.
/// This method provides a multiple pause types to the webview.
///
/// The webview being accessed.
/// The type of pause to be used.
/// 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.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewPause(ulong handle, MLWebView.PauseType pauseType);
///
/// Resumes a webview after a previous call of the MLWebViewPause.
/// Resume webview to the normal operation for all webview pause types.
///
/// The webview being accessed.
/// 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.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewResume(ulong handle);
///
/// Clear the webview cache.
///
/// The webview being accessed.
/// MLResult.Code.Ok if cache cleared 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 clearing cache failed due to an internal error.
/// MLResult.Code.Pending if the MLWebView handle is not ready to use.
[DllImport(MLWebViewDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebViewClearCache(ulong handle);
///
/// Callback from the native code to notify when a resource will loadeded.
///
/// The url of the resource about to be loaded.
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnBeforeResourceLoadCallback))]
private static void HandleOnBeforeResourceLoad([MarshalAs(UnmanagedType.LPStr)] string resourceUrl, IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, resourceUrl, webView.OnBeforeResourceLoaded);
}
///
/// Callback from the native code to notify load completion.
///
/// Whether this event was for the main frame.
/// The standard http status code.
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnLoadEndCallback))]
private static void HandleOnLoadEnd([MarshalAs(UnmanagedType.I1)] bool isMainFrame, int httpStatusCode, IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, isMainFrame, httpStatusCode, webView.OnLoadEnded);
}
///
/// Callback from the native code to notify that there was an error during loading.
///
/// If this event was for the main frame.
/// Http status code for the URL load failure.
/// The stringified version of the error code.
/// The url that caused the load error.
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnLoadErrorCallback))]
private static void HandleOnLoadError([MarshalAs(UnmanagedType.I1)] bool isMainFrame, int httpStatusCode, [MarshalAs(UnmanagedType.LPStr)] string errorStr, [MarshalAs(UnmanagedType.LPStr)] string failedUrl, IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, isMainFrame, httpStatusCode, errorStr, failedUrl, webView.OnErrorLoaded);
}
///
/// Callback from the native code whenever there is any certificate error.
///
/// Error code for ssl error.
/// The url associated to the certificate error.
/// Certificate error short description.
/// Certificate error details.
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnCertificateErrorCallback))]
private static bool HandleOnCertificateError(int errorCode, [MarshalAs(UnmanagedType.LPStr)] string url, [MarshalAs(UnmanagedType.LPStr)] string errorMessage, [MarshalAs(UnmanagedType.LPStr)] string details, IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, errorCode, url, errorMessage, details, webView.IgnoreCertificateError, webView.OnCertificateErrorLoaded);
return webView.IgnoreCertificateError;
}
///
/// Callback from the native code when user selects an input field.
///
/// Horizontal position of the input field.
/// Vertical position of the input field.
/// Width of the input field.
/// Height of the input field.
/// One or combination of TextInputFlags.
/// One of TextInputType.
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnShowKeyboardCallback))]
private static void HandleOnShowKeyboard(int x, int y, int width, int height, TextInputFlags textInputFlags, TextInputType textInputType, IntPtr userData)
{
InputFieldData keyboardShowData = new InputFieldData()
{
X = x,
Y = y,
Width = width,
Height = height,
TextInputFlags = textInputFlags,
TextInputType = textInputType
};
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, keyboardShowData, webView.OnKeyboardShown);
}
///
/// Callback from the native code when user deselects an input field and the keyboard should be dismissed.
///
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnKeyboardDismissCallback))]
private static void HandleOnKeyboardDismiss(IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, webView.OnKeyboardDismissed);
}
///
/// Callback from the native code when webview is destroyed.
///
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnDestroyCallback))]
private static void HandleOnDestroy(IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, webView.OnWebViewDestroyed);
}
///
/// Callback from the native code when Service is connected.
///
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnServiceConnectedCallback))]
private static void HandleServiceConnected(IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, webView.OnServiceConnected);
}
///
/// Callback from the native code when Service is disconnected.
///
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnServiceDisconnectedCallback))]
private static void HandleServiceDisconnected(IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, webView.OnServiceDisconnected);
}
///
/// Callback from the native code when Service failed to connect.
///
/// The MLResult code associated with the failure.
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnServiceFailedCallback))]
private static void HandleServiceFailed(MLResult result, IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, result, webView.OnServiceFailed);
}
///
/// Callback from the native code to check if URL is OK to load in a popup.
///
/// The URL for the popup to load.
/// User defined data, typically a pointer to the originating MLWebView object.
/// The application should return true if it accepts the popup and false otherwise.
[AOT.MonoPInvokeCallback(typeof(OnBeforePopupCallback))]
private static bool HandleBeforePopup([MarshalAs(UnmanagedType.LPStr)] string url, IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, url, webView.AcceptPopup, webView.OnBeforePopup);
return webView.AcceptPopup;
}
///
/// Callback from the native code when a popup is opened.
///
/// The ID of the popup.
/// The URL associated with the popup.
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnPopupOpenedCallback))]
private static void HandlePopupOpened(ulong popupID, [MarshalAs(UnmanagedType.LPStr)] string url, IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, popupID, url, webView.OnPopupOpened);
}
///
/// Callback from the native code when a popup is closing.
///
/// The webview handle of the popup being closed.
/// User defined data, typically a pointer to the originating MLWebView object.
[AOT.MonoPInvokeCallback(typeof(OnPopupClosedCallback))]
private static void HandlePopupClosed(ulong handle, IntPtr userData)
{
GCHandle gcHandle = GCHandle.FromIntPtr(userData);
MLWebView webView = gcHandle.Target as MLWebView;
MLThreadDispatch.Call(webView, handle, webView.OnPopupClosed);
}
}
}
}