Esempio n. 1
0
    void OnGUI()
    {
        var x = 10;

        GUI.enabled = webViewObject.CanGoBack();
        if (GUI.Button(new Rect(x, 10, 80, 80), "<"))
        {
            webViewObject.GoBack();
        }
        GUI.enabled = true;
        x          += 90;

        GUI.enabled = webViewObject.CanGoForward();
        if (GUI.Button(new Rect(x, 10, 80, 80), ">"))
        {
            webViewObject.GoForward();
        }
        GUI.enabled = true;
        x          += 90;

        if (GUI.Button(new Rect(x, 10, 80, 80), "r"))
        {
            webViewObject.Reload();
        }
        x += 90;

        GUI.TextField(new Rect(x, 10, 180, 80), "" + webViewObject.Progress());
        x += 190;

        if (GUI.Button(new Rect(x, 10, 80, 80), "*"))
        {
            var g = GameObject.Find("WebViewObject");
            if (g != null)
            {
                Destroy(g);
            }
            else
            {
                StartCoroutine(Start());
            }
        }
        x += 90;

        if (GUI.Button(new Rect(x, 10, 80, 80), "c"))
        {
            Debug.Log(webViewObject.GetCookies(Url));
        }
        x += 90;

        if (GUI.Button(new Rect(x, 10, 80, 80), "x"))
        {
            webViewObject.ClearCookies();
        }
        x += 90;
    }
 static int QPYX_ClearCookies_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 1);
         WebViewObject QPYX_obj_YXQP = (WebViewObject)ToLua.CheckObject <WebViewObject>(L_YXQP, 1);
         QPYX_obj_YXQP.ClearCookies();
         return(0);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Esempio n. 3
0
    public void ClearCookies()
    {
#if UNITY_EDITOR
#elif UNITY_ANDROID || UNITY_IOS
        Debug.Log("Clear Cookies()");
        BG.SetActive(true);
        if (webViewObject == null)
        {
            webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
            webViewObject.Init(enableWKWebView: true);
        }
        webViewObject.ClearCookies();

        Destroy(webViewObject.gameObject);
        BG.SetActive(false);
#endif

        PlayerStats.instance.playerSettings = ("", "");
    }
Esempio n. 4
0
 public void ClearCookies()
 {
     webViewObject.ClearCookies();
 }
Esempio n. 5
0
    IEnumerator Start()
    {
        Screen.orientation = ScreenOrientation.Portrait;
        webViewObject      = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init(
            cb: (msg) =>
        {
            Debug.Log(string.Format("cb : CallFromJS[{0}]", msg));
            //status.text = msg;
            //status.GetComponent<Animation>().Play();


            // Try validating with cookie
            if (!string.IsNullOrEmpty(msg))
            {
                string authToken;
                bool success = TryGetToken(msg, out authToken);
                if (success)
                {
                    FinishLogin(authToken);
                    return;
                }
            }
        },
            err: (msg) =>
        {
            Debug.Log(string.Format("CallOnError[{0}]", msg));
            //status.text = msg;
            //status.GetComponent<Animation>().Play();
        },
            started: (msg) =>
        {
            Debug.Log(string.Format("started : CallOnStarted[{0}]", msg));
        },
            ld: (msg) =>
        {
            string currentUrl = msg;

            Debug.Log(string.Format("CallOnLoaded[{0}]", msg));

            canvas.SetActive(false);
            loginPage.SetActive(false);
            webViewObject.SetVisibility(true);

            if (!currentUrl.Contains(AUTH_TOKEN_URL))
            {
                return;
            }

            string cookieValue = webViewObject.GetCookies(AUTH_TOKEN_URL);
            Debug.LogFormat("Cookies from {0}: {1}", currentUrl, cookieValue);

            // Try validating with cookie
            if (!string.IsNullOrEmpty(cookieValue))
            {
                string authToken;
                bool success = TryGetToken(cookieValue, out authToken);
                if (success)
                {
                    FinishLogin(authToken);
                    return;
                }
            }

#if UNITY_EDITOR_OSX || !UNITY_ANDROID
            // NOTE: depending on the situation, you might prefer
            // the 'iframe' approach.
            // cf. https://github.com/gree/unity-webview/issues/189
#if true
            webViewObject.EvaluateJS(@"
                  if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
                    window.Unity = {
                      call: function(msg) {
                        window.webkit.messageHandlers.unityControl.postMessage(msg);
                      }
                    }
                  } else {
                    window.Unity = {
                      call: function(msg) {
                        window.location = 'unity:' + msg;
                      }
                    }
                  }
                ");
#else
            webViewObject.EvaluateJS(@"
                  if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
                    window.Unity = {
                      call: function(msg) {
                        window.webkit.messageHandlers.unityControl.postMessage(msg);
                      }
                    }
                  } else {
                    window.Unity = {
                      call: function(msg) {
                        var iframe = document.createElement('IFRAME');
                        iframe.setAttribute('src', 'unity:' + msg);
                        document.documentElement.appendChild(iframe);
                        iframe.parentNode.removeChild(iframe);
                        iframe = null;
                      }
                    }
                  }
                ");
#endif
#endif
            // Try getting cookie from js
            webViewObject.EvaluateJS(@"Unity.call(document.cookie)");
        },
            //ua: "custom user agent string",
            enableWKWebView: true);
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
        webViewObject.bitmapRefreshCycle = 1;
#endif
        webViewObject.SetMargins(Screen.width / 8, Screen.height / 4, Screen.width / 8, Screen.height / 4);
        //webViewObject.SetVisibility(true);
        webViewObject.ClearCookies();

#if !UNITY_WEBPLAYER
        if (Url.StartsWith("http") || Url.StartsWith("https"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            var exts = new string[] {
                ".jpg",
                ".js",
                ".html"  // should be last
            };
            foreach (var ext in exts)
            {
                var    url    = Url.Replace(".html", ext);
                var    src    = System.IO.Path.Combine(Application.streamingAssetsPath, url);
                var    dst    = System.IO.Path.Combine(Application.persistentDataPath, url);
                byte[] result = null;
                if (src.Contains("://"))    // for Android
                {
                    var www = new WWW(src);
                    yield return(www);

                    result = www.bytes;
                }
                else
                {
                    result = System.IO.File.ReadAllBytes(src);
                }
                System.IO.File.WriteAllBytes(dst, result);
                if (ext == ".html")
                {
                    webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
                    break;
                }
            }
        }
#else
        if (Url.StartsWith("http") || Url.StartsWith("https"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
        }
        webViewObject.EvaluateJS(
            "parent.$(function() {" +
            "   window.Unity = {" +
            "       call:function(msg) {" +
            "           parent.unityWebView.sendMessage('WebViewObject', msg)" +
            "       }" +
            "   };" +
            "});");
#endif
        yield break;
    }