Example #1
0
    /// <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);
    }
Example #2
0
        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();
            }
        }
Example #3
0
    /// <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);
        }
    }
Example #4
0
 /// <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);
 }
Example #5
0
 /// <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);
 }
Example #6
0
 /// <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));
 }
Example #7
0
 /// <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);
 }
Example #8
0
 /// <summary>
 /// Sets alpha-blending value in current webview window.
 /// </summary>
 public static void SetAlpha(string name, float alpha)
 {
     WWebViewWin32.SetAlpha(name, alpha);
 }
Example #9
0
 /// <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));
 }
Example #10
0
 /// <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)));
 }
Example #11
0
 /// <summary>
 /// Sets the background of webview to transparent.
 /// Compatibility Level: UniWebView2
 /// </summary>
 public static void TransparentBackground(string name, bool transparent)
 {
     WWebViewWin32.Transparent(name, transparent);
 }
Example #12
0
 /// <summary>
 /// Add some javascript to the web page.
 /// </summary>
 public static void AddJavaScript(string name, string script)
 {
     WWebViewWin32.AddJavaScript(name, script);
 }
Example #13
0
 /// <summary>
 /// Retrieves current navigating url.
 /// </summary>
 public static string GetCurrentUrl(string name)
 {
     return(Marshal.PtrToStringAuto(WWebViewWin32.CurrentUrl(name)));
 }
Example #14
0
 /// <summary>
 /// Reload current page.
 /// </summary>
 public static void Reload(string name)
 {
     WWebViewWin32.Refresh(name);
 }
Example #15
0
 /// <summary>
 /// Navigate an HTML string in current webview.
 /// </summary>
 public static void LoadHTMLString(string name, string html, string baseUrl)
 {
     WWebViewWin32.NavigateToString(name, html);
 }
Example #16
0
 /// <summary>
 /// Navigate a url in current webview.
 /// </summary>
 public static void Load(string name, string url)
 {
     WWebViewWin32.Navigate(name, url);
 }
Example #17
0
 /// <summary>
 /// Remove a url scheme from WWebView message interpreter.
 /// </summary>
 public static void RemoveUrlScheme(string name, string scheme)
 {
     WWebViewWin32.RemoveUrlScheme(name, scheme);
 }
Example #18
0
 /// <summary>
 /// Adds a url scheme to WWebview message interpreter.
 /// </summary>
 public static void AddUrlScheme(string name, string scheme)
 {
     WWebViewWin32.AddUrlScheme(name, scheme);
 }
Example #19
0
 /// <summary>
 /// Hides the webview window.
 /// </summary>
 public static bool Hide(string name, bool fade, int direction, float duration)
 {
     WWebViewWin32.Show(name, false);
     return(true);
 }
Example #20
0
 /// <summary>
 /// Clears all caches. This will removes cached local data of webview.
 /// </summary>
 public static void CleanCache(string name)
 {
     WWebViewWin32.CleanCache();
 }
Example #21
0
 /// <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);
 }
Example #22
0
 /// <summary>
 /// Clears all cookies from webview.
 /// </summary>
 public static void CleanCookie(string name, string key)
 {
     WWebViewWin32.CleanCookie(name);
 }
Example #23
0
 /// <summary>
 /// Gets alpha-blending value in current webview window.
 /// </summary>
 public static float GetAlpha(string name)
 {
     return(WWebViewWin32.GetAlpha(name));
 }
Example #24
0
 /// <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)));
 }
Example #25
0
 /// <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));
 }
Example #26
0
 /// <summary>
 /// Sets a cookie for a certain url.
 /// </summary>
 public static void SetCookie(string url, string cookie)
 {
     WWebViewWin32.SetCookie(url, cookie);
 }
Example #27
0
 /// <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));
 }
Example #28
0
 /// <summary>
 /// Destroy the webview instance.
 /// </summary>
 public static void Destroy(string name)
 {
     WWebViewWin32.Destroy(name);
 }
Example #29
0
 /// <summary>
 /// Set the header field.
 /// Compatibility Level: UniWebView2
 /// </summary>
 public static void SetHeaderField(string name, string key, string value)
 {
     WWebViewWin32.SetHeaderField(name, key, value);
 }
Example #30
0
 /// <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);
 }