/** * Returns a list of all cookies in the browser across all domains. * * Note that cookies are shared between browser instances. * * If the browser is not ready yet (browser.IsReady or WhenReady()) this will return an empty list. * * This method is not reentrant! You must wait for the returned promise to resolve before calling it again, * even on a differnet object. */ public IPromise <List <Cookie> > GetCookies() { if (currentFetch != null) { //This method Wait for the previous promise to resolve, then make your call. //If this limitation actually affects you, let me know. throw new InvalidOperationException("GetCookies is not reentrant"); } Cookie.Init(); var result = new List <Cookie>(); if (!browser.IsReady || !browser.enabled) { return(Promise <List <Cookie> > .Resolved(result)); } var promise = new Promise <List <Cookie> >(); BrowserNative.GetCookieFunc cookieFunc = CB_GetCookieFunc; BrowserNative.zfb_getCookies(browser.browserId, cookieFunc); currentFetch = new CookieFetch { promise = promise, nativeCB = cookieFunc, manager = this, result = result, }; return(promise); }
/** * Returns a list of all cookies in the browser across all domains. * * Note that cookies are shared between browser instances. * * If the browser is not ready yet (browser.IsReady or WhenReady()) this will return an empty list. */ public IPromise <List <Cookie> > GetCookies() { Cookie.Init(); var ret = new List <Cookie>(); if (!browser.IsReady || !browser.enabled) { return(Promise <List <Cookie> > .Resolved(ret)); } var promise = new Promise <List <Cookie> >(); BrowserNative.GetCookieFunc cookieFunc = cookie => { try { if (cookie == null) { browser.RunOnMainThread(() => promise.Resolve(ret)); cookieFuncs.Remove(promise); return; } ret.Add(new Cookie(this, cookie)); } catch (Exception ex) { Debug.LogException(ex); } }; BrowserNative.zfb_getCookies(browser.browserId, cookieFunc); cookieFuncs[promise] = cookieFunc; return(promise); }
public IPromise <List <Cookie> > GetCookies() { Cookie.Init(); List <Cookie> ret = new List <Cookie>(); if (!browser.IsReady || !browser.enabled) { return(Promise <List <Cookie> > .Resolved(ret)); } Promise <List <Cookie> > promise = new Promise <List <Cookie> >(); BrowserNative.GetCookieFunc getCookieFunc = delegate(BrowserNative.NativeCookie cookie) { try { if (cookie == null) { browser.RunOnMainThread(delegate { promise.Resolve(ret); }); cookieFuncs.Remove(promise); } else { ret.Add(new Cookie(this, cookie)); } } catch (Exception exception) { Debug.LogException(exception); } }; BrowserNative.zfb_getCookies(browser.browserId, getCookieFunc); cookieFuncs[promise] = getCookieFunc; return(promise); }