/// <summary>
    /// Called from the native webview when JavaScript evaluating is finished.
    /// </summary>
    private static void OnEvaluatingJavaScriptFinished(WebViewClient sender, string result)
    {
        GameObject webView = GameObject.Find(sender.Name);

        if (webView != null)
        {
#if UNIWEBVIEW3_SUPPORTED
            result =
                "{\"data\":\"" +
                WWebViewSystem.EscapeJsonText(result) +
                "\",\"resultCode\":\"0\",\"identifier\":\"\"}";
#endif
            webView.SendMessage("EvalJavaScriptFinished", result, SendMessageOptions.DontRequireReceiver);
        }
    }
    /// <summary>
    /// Invoked when the navigation is failed.
    /// </summary>
    private static void OnNavigationFailed(WebViewClient sender, WebViewNavigationFailedEventArgs args)
    {
        GameObject webView = GameObject.Find(sender.Name);

        if (webView != null)
        {
            webView.SendMessage(
#if UNIWEBVIEW3_SUPPORTED
                "PageErrorReceived",
                "{\"data\":\"" + WWebViewSystem.EscapeJsonText(args.Uri.ToString()) +
                "\",\"resultCode\":\"" + args.WebErrorStatus.ToString() + "\",\"identifier\":\"\"}",
#else
                "LoadComplete", args.WebErrorStatus.ToString(),
#endif
                SendMessageOptions.DontRequireReceiver);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Fired from native webview when a page is completely loaded.
    /// </summary>
    /// <param name="name">Target(event dispatcher) identifier.</param>
    /// <param name="url">Navigated url</param>
    private static void OnDocumentComplete(IntPtr name, IntPtr url)
    {
        GameObject webView = GameObject.Find(Marshal.PtrToStringAuto(name));

        if (webView != null)
        {
            webView.SendMessage(
#if UNIWEBVIEW3_SUPPORTED
                "PageFinished",
                "{\"data\":\"" + WWebViewSystem.EscapeJsonText(Marshal.PtrToStringAuto(url)) + "\",\"resultCode\":\"200\",\"identifier\":\"\"}",
#elif UNIWEBVIEW2_SUPPORTED
                "LoadComplete", string.Empty,
#else
                "LoadComplete", Marshal.PtrToStringAuto(url),
#endif
                SendMessageOptions.DontRequireReceiver);
        }
    }
Beispiel #4
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);
        }
    }