Esempio n. 1
0
        /// <summary>
        /// 清除cookies
        /// </summary>
        /// <param name="urls"></param>
        /// <param name="names"></param>
        public static void DelectCookie(string domain, List <string> names)
        {
            CefCookieManager manager = CefCookieManager.GetGlobal(null);
            string           url     = "http://" + domain;

            foreach (var name in names)
            {
                manager.DeleteCookies(url, name, null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The on before close.
        /// </summary>
        public void OnBeforeClose()
        {
            BeforeClose?.Invoke(this, null);

            // Flush cache
            // This is needed since there is some delay from when a cookie
            // has been set/deleted before it is actually persisted to disk.
            // This ensures all cookies is written to disk before exit.
            var cookieManager = CefCookieManager.GetGlobal(null);

            cookieManager?.FlushStore(null);
        }
Esempio n. 3
0
        public static async Task <Cookie[]> GetCookies(string domainEnding)
        {
            var manager = CefCookieManager.GetGlobal(null);
            var visitor = new CookieVisitor();

            if (!manager.VisitAllCookies(visitor))
            {
                return(new Cookie[0]);
            }
            var cc = await visitor.Task;

            return((await visitor.Task).Where(c => c.Domain.EndsWith(domainEnding)).ToArray());
        }
Esempio n. 4
0
        /// <summary>
        /// 设置cookies
        /// </summary>
        /// <param name="urls"></param>
        /// <param name="cookies"></param>
        /// <param name="domain"></param>
        public static void SetCookie(string domain, Dictionary <string, string> cookies)
        {
            CefCookieManager manager = CefCookieManager.GetGlobal(null);
            string           url     = "http://" + domain;

            foreach (var c in cookies)
            {
                CefCookie cookie = new CefCookie();
                cookie.Name     = c.Key;
                cookie.Value    = c.Value;
                cookie.Domain   = domain;
                cookie.Path     = "/";
                cookie.HttpOnly = false;
                //cookie.Expires = DateTime.Now.AddDays(100);
                //cookie.expires.year = 2200;
                //cookie.expires.month = 4;
                //cookie.expires.day_of_week = 5;
                //cookie.expires.day_of_month = 11;
                // BSCookieTask bt = new BSCookieTask(url, cookie);
                //CefRuntime.PostTask(CefThreadId.IO, bt);
                manager.SetCookie(url, cookie, null);
            }
        }
        public bool SetCookie(string name, string value, string domain, string path, bool httpOnly, bool secure, DateTime?expires, bool global)
        {
            // Reset the wait event.
            _setCookieEvent.Reset();

            var success = false;

            // Set the cookie on the IO thread.
            CefRuntime.PostTask(CefThreadId.IO, new ActionCallbackTask(() =>
            {
                try
                {
                    // Create a cookie in the Chromium cookie manager.
                    success = CefCookieManager.GetGlobal(null).SetCookie(
                        "http://gs.com",
                        new CefCookie
                    {
                        Name     = name,
                        Value    = value,
                        Domain   = domain,
                        Path     = path,
                        HttpOnly = httpOnly,
                        Secure   = secure,
                        Expires  = expires
                    }, null);
                }
                finally
                {
                    _setCookieEvent.Set();
                }
            }));

            // Wait for the call to SetCookie to complete.
            _setCookieEvent.WaitOne(5000);
            return(success);
        }
 protected override void OnContextInitialized()
 {
     CefCookieManager.GetGlobal(null).SetSupportedSchemes(CefBrowserApplication.AllowedProtocols, null);
     base.OnContextInitialized();
 }
Esempio n. 7
0
 protected override void Execute()
 {
     bool tmp  = CefCookieManager.GetGlobal(null).SetCookie(url, cookie, null);
     bool temp = CefCookieManager.GetGlobal(null).VisitUrlCookies(url, false, new CefWebCookieVisitor(cookie));
 }