Example #1
0
        protected void OnItemChange(BrowserNative.ChangeType type, string arg1)
        {
            //Debug.Log("ChangeType " + name + " " + type + " arg " + arg1 + " loaded " + IsLoaded);
            switch (type)
            {
            case BrowserNative.ChangeType.CHT_CURSOR:
                UpdateCursor();
                break;

            case BrowserNative.ChangeType.CHT_BROWSER_CLOSE:
                //handled directly on the calling thread, nothing to do here
                break;

            case BrowserNative.ChangeType.CHT_FETCH_FINISHED:
                onFetch(JSONNode.Parse(arg1));
                break;

            case BrowserNative.ChangeType.CHT_FETCH_FAILED:
                onFetchError(JSONNode.Parse(arg1));
                break;

            case BrowserNative.ChangeType.CHT_LOAD_FINISHED:
                if (skipNextLoad)
                {
                    //deal with extra step we have to do to load HTML to an empty page
                    skipNextLoad = false;
                    return;
                }

                loadPending = false;

                if (onloadActions.Count != 0)
                {
                    foreach (var action in onloadActions)
                    {
                        action();
                    }
                    onloadActions.Clear();
                }

                onLoad(JSONNode.Parse(arg1));
                break;

            case BrowserNative.ChangeType.CHT_CERT_ERROR:
                onCertError(JSONNode.Parse(arg1));
                break;

            case BrowserNative.ChangeType.CHT_SAD_TAB:
                onSadTab();
                break;
            }
        }
Example #2
0
        private static void CB_ChangeFunc(int browserId, BrowserNative.ChangeType changeType, string arg1)
        {
            //Note: we may have been Object.Destroy'd at this point, so guard against that.
            //That means we can't trust that `browser == null` means we don't have a browser, we may have an object that
            //is destroyed, but not actually null.
            Browser browser;

            lock (allBrowsers) {
                if (!allBrowsers.TryGetValue(browserId, out browser))
                {
                    return;
                }
            }

            if (changeType == BrowserNative.ChangeType.CHT_BROWSER_CLOSE)
            {
                //We can't continue if the browser is closed, so goodbye.

                //At this point, we may or may not be destroyed, but if not, become destroyed.
                //Debug.Log("Got close notification for " + unsafeBrowserId);
                if (browser)
                {
                    //Need to be destroyed.
                    lock (browser.thingsToDo) browser.thingsToDo.Add(() => {
                            Destroy(browser.gameObject);
                        });
                }
                else
                {
                    //If we are (Unity) destroyed, we won't get another update, so we can't rely on thingsToDo
                    //That said, there's not anything else for us to do but step out of allThingsToRemember.
                }

                //The native side has acknowledged it's done, now we can finally let the native trampolines be GC'd
                lock (allThingsToRemember) allThingsToRemember.Remove(browser.unsafeBrowserId);

                //Now that we know we can allow ourselves to be GC'd and destroyed (without leaking to allThingsToRemember)
                //go ahead and allow it. (And we won't get any more native callbacks at this point.)
                lock (allBrowsers) allBrowsers.Remove(browserId);

                //Just in case someone tries to call something, make sure CheckSanity and such fail.
                browser.browserId = 0;
            }
            else if (browser)
            {
                lock (browser.thingsToDo) browser.thingsToDo.Add(() => browser.OnItemChange(changeType, arg1));
            }
        }