Global CefCookieManager vs Create new cookiemanager

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Global CefCookieManager vs Create new cookiemanager

Postby sunswam » Sat Sep 02, 2017 2:12 am

Hi,
I am asking a naive question as i am still exploring CEF framework.. When do we use CefCookieManager::GetGlobalManager to visit all cookies versus when do we create our CookieManager using CreateManager method?. When i set a path in SetStoragePath for the global cookie manager, CEF writes a Cookie file and journal file in that location. In my use case, i just need to cache the cookies coming from server and send it back later in another request. Will the Global cookie manager is sufficient here?. I am trying to get the list of cookies in OnBeforeResourceLoad or OnLoadEnd method. Please correct me if am wrong.

Thanks
sunswam
sunswam
Newbie
 
Posts: 7
Joined: Fri Jan 13, 2017 5:35 pm

Re: Global CefCookieManager vs Create new cookiemanager

Postby magreenblatt » Sat Sep 02, 2017 1:39 pm

The global cookie manager is fine for your use case. CreateManager is used to customize the cookie storage location for a RequestContext.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Global CefCookieManager vs Create new cookiemanager

Postby sunswam » Mon Sep 04, 2017 11:15 pm

That clarifies. Thank you very much
sunswam
Newbie
 
Posts: 7
Joined: Fri Jan 13, 2017 5:35 pm

Re: Global CefCookieManager vs Create new cookiemanager

Postby sunswam » Fri Sep 08, 2017 7:14 pm

I have a follow up question of using the global cookiemanager. I have a situation where i need to cache the cookies in a file that our application has defined and restore the cookies back to the CEF cookie manager next time when the application is started. If i use the SetStoragePath API, then CEF cookie file is handling nicely all of the scenarios i wanted. But i am constrained because other components in our application which doesn't use CEF has to have the cookies information shared ( single sign-on/sign off implementation across different components ).

When i restore the cookies i read array of cookies ( json ) format and try to set it using the following in the browser process ( IO thread ):
//array of CefCookie objects are read ( from JSON file )
//following is called in a loop.

CefPostTask(TID_IO, CefCreateClosureTask(base::Bind(base::IgnoreResult(&CefCookieManager::SetCookie),
manager,
CefString("https://test.url.com"), // There is a initial URL that gets loaded but then this page redirects to several other pages before success page.
cookie,
nullptr)));

Can i set the cookies based on domain that i got from CefCookie object or do i have to know each URL that it navigates to be set it in the Setcookie function?. Please clarify.
sunswam
Newbie
 
Posts: 7
Joined: Fri Jan 13, 2017 5:35 pm

Re: Global CefCookieManager vs Create new cookiemanager

Postby magreenblatt » Fri Sep 08, 2017 7:29 pm

Cookies are always associated with a particular domain or host. You don't need a full URL. See https://developer.mozilla.org/en-US/doc ... Set-Cookie
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Global CefCookieManager vs Create new cookiemanager

Postby sunswam » Mon Sep 11, 2017 8:58 pm

Thank you for the clarification. I had to fully form the URL using the domain value and add the prefix scheme "https://" to be set in the SetCookie URL value, then it works fine.
sunswam
Newbie
 
Posts: 7
Joined: Fri Jan 13, 2017 5:35 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 50 guests