/// <summary> /// Initialize the WWebView. /// </summary> public static bool Init(string name, int top, int left, int bottom, int right, int width, int height) { if (initialize == false) { IntPtr module = Kernel32.GetModuleHandle(null); if (module == IntPtr.Zero) { Debug.LogError("Can't find process module."); return(false); } IntPtr window = WWebViewWin32.FindUnityPlayerWindow(); if (window == IntPtr.Zero) { Debug.LogError("Can't find Unity player window handle."); return(false); } // Version description. // 11001: IE11. Webpages are displayed in IE11 edge mode, regardless of the declared !DOCTYPE directive. // 11000: IE11. Webpages containing standards - based !DOCTYPE directives are displayed in IE11 edge mode. // 10001: IE10. Webpages are displayed in IE10 Standards mode, regardless of the !DOCTYPE directive. // 10000: IE10. Webpages containing standards - based !DOCTYPE directives are displayed in IE10 Standards mode. // 9999: IE9. Webpages are displayed in IE9 Standards mode, regardless of the declared !DOCTYPE directive. // 9000: IE9. Webpages containing standards - based !DOCTYPE directives are displayed in IE9 mode. // 8888: IE8. Webpages are displayed in IE8 Standards mode, regardless of the declared !DOCTYPE directive. // 8000: IE8. Webpages containing standards - based !DOCTYPE directives are displayed in IE8 mode. // 7000: IE7. Webpages containing standards - based !DOCTYPE directives are displayed in IE7 Standards mode. // REFER: https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx WWebViewWin32.Initialize(module, IntPtr.Zero, null, 0, window, Screen.width, Screen.height, 11000); WWebViewSystem.Instance.Initialize(); documentComplete = new WWebViewWin32.ActionDocumentComplete(OnDocumentComplete); beforeNavigate = new WWebViewWin32.ActionBeforeNavigate(OnBeforeNavigate); windowClosing = new WWebViewWin32.ActionWindowClosing(OnWindowClosing); titleChange = new WWebViewWin32.ActionTitleChange(OnTitleChange); newWindow = new WWebViewWin32.ActionNewWindow(OnNewWindow); navigateComplete = new WWebViewWin32.ActionNavigateComplete(OnNavigateComplete); initialize = true; } WWebViewWin32.Create( name, documentComplete, beforeNavigate, windowClosing, titleChange, newWindow, navigateComplete, left, top, right, bottom, width, height, false); #if UNIWEBVIEW2_SUPPORTED || UNIWEBVIEW3_SUPPORTED WWebViewWin32.AddUrlScheme(name, "uniwebview"); #endif WWebViewWin32.AddUrlScheme(name, "wwebview"); return(true); }
private IEnumerator DispatchMessage() { // Whenever Win32 window has run in editor mode, the window message loop is gradually frozen. // I'm not exactly sure how this works. I can only guess the Unity3D is trying to consume more resources // on the renderer in editor mode. It seems to be a sort of optimization. // so, I just tried to dispatch window messages by force. while (true) { yield return(new WaitForFixedUpdate()); WWebViewWin32.DispatchMessage(); } }
/// <summary> /// Evaluate a JavaScript string on current page. /// </summary> public static void EvaluatingJavaScript(string name, string script) { GameObject webView = GameObject.Find(name); if (webView != null) { string result = Marshal.PtrToStringAuto( WWebViewWin32.EvaluateJavaScript(name, script)); #if UNIWEBVIEW3_SUPPORTED result = "{\"data\":\"" + WWebViewSystem.EscapeJsonText(result) + "\",\"resultCode\":\"0\",\"identifier\":\"\"}"; #endif webView.SendMessage("EvalJavaScriptFinished", result, SendMessageOptions.DontRequireReceiver); } }
/// <summary> /// Navigates the webview to the next page in the navigation history, if one is available. /// </summary> public static void GoForward(string name) { WWebViewWin32.GoForward(name); }
/// <summary> /// Cancels any pending navigation and stops any dynamic page elements, such as background sounds and animations. /// </summary> public static void Stop(string name) { WWebViewWin32.Stop(name); }
/// <summary> /// Gets a value indicating whether a subsequent page in navigation history is available, /// which allows the GoForward method to succeed. /// </summary> public static bool CanGoForward(string name) { return(WWebViewWin32.CanGoForward(name)); }
/// <summary> /// Sets the visibility of vertical scroll bar for the webview. /// Compatibility Level: UniWebView2 /// </summary> public static void SetVerticalScrollBarShow(string name, bool show) { WWebViewWin32.ShowScrollY(name, show); }
/// <summary> /// Sets alpha-blending value in current webview window. /// </summary> public static void SetAlpha(string name, float alpha) { WWebViewWin32.SetAlpha(name, alpha); }
/// <summary> /// Get the webview's height, as a value in device-independent units (1/96th inch per unit). /// The default is 0. The default might be encountered if the webview has not been loaded /// and hasn't yet been involved in a layout pass that renders the UI. /// </summary> public static int GetActualHeight(string name) { return(WWebViewWin32.GetActualHeight(name)); }
/// <summary> /// Gets the user-agent string currently used in webview. /// If a customized user-agent is not set, the default user-agent in current platform will be returned. /// </summary> public static string GetUserAgent(string name) { return(Marshal.PtrToStringAuto(WWebViewWin32.GetUserAgent(name))); }
/// <summary> /// Sets the background of webview to transparent. /// Compatibility Level: UniWebView2 /// </summary> public static void TransparentBackground(string name, bool transparent) { WWebViewWin32.Transparent(name, transparent); }
/// <summary> /// Add some javascript to the web page. /// </summary> public static void AddJavaScript(string name, string script) { WWebViewWin32.AddJavaScript(name, script); }
/// <summary> /// Retrieves current navigating url. /// </summary> public static string GetCurrentUrl(string name) { return(Marshal.PtrToStringAuto(WWebViewWin32.CurrentUrl(name))); }
/// <summary> /// Reload current page. /// </summary> public static void Reload(string name) { WWebViewWin32.Refresh(name); }
/// <summary> /// Navigate an HTML string in current webview. /// </summary> public static void LoadHTMLString(string name, string html, string baseUrl) { WWebViewWin32.NavigateToString(name, html); }
/// <summary> /// Navigate a url in current webview. /// </summary> public static void Load(string name, string url) { WWebViewWin32.Navigate(name, url); }
/// <summary> /// Remove a url scheme from WWebView message interpreter. /// </summary> public static void RemoveUrlScheme(string name, string scheme) { WWebViewWin32.RemoveUrlScheme(name, scheme); }
/// <summary> /// Adds a url scheme to WWebview message interpreter. /// </summary> public static void AddUrlScheme(string name, string scheme) { WWebViewWin32.AddUrlScheme(name, scheme); }
/// <summary> /// Hides the webview window. /// </summary> public static bool Hide(string name, bool fade, int direction, float duration) { WWebViewWin32.Show(name, false); return(true); }
/// <summary> /// Clears all caches. This will removes cached local data of webview. /// </summary> public static void CleanCache(string name) { WWebViewWin32.CleanCache(); }
/// <summary> /// Sets the user-agent used in the webview. /// Compatibility Level: UniWebView3 /// </summary> public static void SetUserAgent(string name, string userAgent) { WWebViewWin32.SetUserAgent(name, userAgent); }
/// <summary> /// Clears all cookies from webview. /// </summary> public static void CleanCookie(string name, string key) { WWebViewWin32.CleanCookie(name); }
/// <summary> /// Gets alpha-blending value in current webview window. /// </summary> public static float GetAlpha(string name) { return(WWebViewWin32.GetAlpha(name)); }
/// <summary> /// Gets the cookie value under a url and key. /// </summary> public static string GetCookie(string url, string key) { return(Marshal.PtrToStringAuto(WWebViewWin32.GetCookie(url, key))); }
/// <summary> /// Get the webview's width, as a value in device-independent units (1/96th inch per unit). /// The default is 0. The default might be encountered if the webview has not been loaded /// and hasn't yet been involved in a layout pass that renders the UI. /// </summary> public static int GetActualWidth(string name) { return(WWebViewWin32.GetActualWidth(name)); }
/// <summary> /// Sets a cookie for a certain url. /// </summary> public static void SetCookie(string url, string cookie) { WWebViewWin32.SetCookie(url, cookie); }
/// <summary> /// Gets a value indicating whether a previous page in navigation history is available, /// which allows the GoBack method to succeed. /// </summary> public static bool CanGoBack(string name) { return(WWebViewWin32.CanGoBack(name)); }
/// <summary> /// Destroy the webview instance. /// </summary> public static void Destroy(string name) { WWebViewWin32.Destroy(name); }
/// <summary> /// Set the header field. /// Compatibility Level: UniWebView2 /// </summary> public static void SetHeaderField(string name, string key, string value) { WWebViewWin32.SetHeaderField(name, key, value); }
/// <summary> /// Navigates the webview to the previous page in the navigation history, if one is available. /// </summary> public static void GoBack(string name) { WWebViewWin32.GoBack(name); }