How to Isolate browser cookies? new session to each browser

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

How to Isolate browser cookies? new session to each browser

Postby agitech » Wed Jun 19, 2013 10:15 pm

Hi, i am using CEF3 in multi-process mode.
How to use CefCookieManager to give every browser of same application a different session?
agitech
Techie
 
Posts: 16
Joined: Sun Jun 16, 2013 12:37 pm

Re: How to Isolate browser cookies? new session to each brow

Postby Czarek » Thu Jun 20, 2013 10:41 am

agitech wrote:Hi, i am using CEF3 in multi-process mode.
How to use CefCookieManager to give every browser of same application a different session?

See CefRequestHandler::GetCookieManager():

Code: Select all
  ///
  // Called on the IO thread to retrieve the cookie manager. |main_url| is the
  // URL of the top-level frame. Cookies managers can be unique per browser or
  // shared across multiple browsers. The global cookie manager will be used if
  // this method returns NULL.
  ///
  /*--cef()--*/
  virtual CefRefPtr<CefCookieManager> GetCookieManager(
      CefRefPtr<CefBrowser> browser,
      const CefString& main_url) { return NULL; }


Return CefCookieManager::CreateManager() for each browser.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How to Isolate browser cookies? new session to each brow

Postby agitech » Thu Jun 20, 2013 10:44 am

Thanks a lot :)
agitech
Techie
 
Posts: 16
Joined: Sun Jun 16, 2013 12:37 pm

Re: How to Isolate browser cookies? new session to each brow

Postby agitech » Thu Jun 20, 2013 12:04 pm

Code: Select all
 CefRefPtr<CefCookieManager> ClientHandler::GetCookieManager(
      CefRefPtr<CefBrowser> browser,
      const CefString& main_url){
        std::string cache_path = "K:/cef_cache/";// should be retrived from browser host setting, but i will find how later
        CefString cookie_path = cache_path+ "cookie_"+std::to_string((long double)browser->GetIdentifier());         
        return CefCookieManager::CreateManager( cookie_path, false);
   }


This code create a cookie path for every browser with the cache_path like : K:/cef_cache/cookie_1 , K:/cef_cache/cookie_2 , K:/cef_cache/cookie_3 ...

But it crach just after the return , any idea ?
agitech
Techie
 
Posts: 16
Joined: Sun Jun 16, 2013 12:37 pm

Re: How to Isolate browser cookies? new session to each brow

Postby Czarek » Thu Jun 20, 2013 12:18 pm

agitech wrote:This code create a cookie path for every browser with the cache_path like : K:/cef_cache/cookie_1 , K:/cef_cache/cookie_2 , K:/cef_cache/cookie_3 ...
But it crach just after the return , any idea ?

Try to return an in-memory cookie manager and see if that makes any difference.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How to Isolate browser cookies? new session to each brow

Postby agitech » Thu Jun 20, 2013 12:34 pm

Same result, i dont know what path the CefCookieManager::CreateManager is expecting.

also it's strange that the browser will create a new CefCookieManager in every request, no? the session must be the same along the user connection.

And i check the cache folder K:\cef_cache\ i found a new empty folder cookie_1 but not the others cookie_2 cookie_3 ...cookie_6
Last edited by agitech on Thu Jun 20, 2013 1:15 pm, edited 1 time in total.
agitech
Techie
 
Posts: 16
Joined: Sun Jun 16, 2013 12:37 pm

Re: How to Isolate browser cookies? new session to each brow

Postby magreenblatt » Thu Jun 20, 2013 12:48 pm

GetCookieManager will be called every time the cookie manager is needed, not just once per browser. If you wish to always return the same cookie manager for a given browser you need to manage that in your handler implementation.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to Isolate browser cookies? new session to each brow

Postby agitech » Thu Jun 20, 2013 1:07 pm

OK thanks, so you confirm that if a new CefCookieManager is returned on every request, the browser will not keep the session.

But could any one tell me how correctly return a new CefCookieManager without craching the application?
agitech
Techie
 
Posts: 16
Joined: Sun Jun 16, 2013 12:37 pm

Re: How to Isolate browser cookies? new session to each brow

Postby magreenblatt » Thu Jun 20, 2013 1:22 pm

agitech wrote:But could any one tell me how correctly return a new CefCookieManager without craching the application?

It's probably not a crash but instead a debug assertion because you're specifying the same path for multiple calls to CreateManager.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to Isolate browser cookies? new session to each brow

Postby Czarek » Thu Jun 20, 2013 1:23 pm

agitech wrote:OK thanks, so you confirm that if a new CefCookieManager is returned on every request, the browser will not keep the session.

But could any one tell me how correctly return a new CefCookieManager without craching the application?

I think that you should *not* return 2 different cookie managers for the same browser.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Next

Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 142 guests