Sharing context with CefCookieManager

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.

Sharing context with CefCookieManager

Postby sjaved » Fri May 26, 2017 4:38 am

Hi,
Scenario:
open two urls in two separate cef browser instances (e.g. bitbucket.com), And login to one of the page.

Problem:
They do not share the context, meaning if I login into one page, the other one does not get the logged in information.

Causes:
This happens when i am creating my own CefCookieManager, if i do not create it. everything remains fine.

//code snippet (Browser Creation)
CefRefPtr<CefRequestContext> requestContext = CefRequestContext::CreateContext(CefRequestContext::GetGlobalContext(), m_clientHandler);
CefBrowserHost::CreateBrowser(info, m_clientHandler, cefStartupUrl, browserSettings, requestContext);

//code snippet ClientHandler::GetCookieManager() //overriding CefRequestContextHandler::GetCookieManager()
return CefCookieManager::CreateManager(CefString("cookie_storage_path"), false, NULL); // => in this case context is not shared
//return NULL; // => everything works fine

i saw that internally CefCookieManager::CreateManager is doing something like this
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
cookie_manager->Initialize(NULL, path, persist_session_cookies, callback); // => first parameter request_context is NULL

My Questions:
Is there a way to create CefCookieManager with the context?
Is there anyway that the context gets shared and i still use my own CefCookieManager not the global one?
or any other suggestions?

OS: Windows-7
CEF: CEF-2623

Regards,
sjaved
Techie
 
Posts: 15
Joined: Wed Jun 15, 2016 3:47 am

Re: Sharing context with CefCookieManager

Postby Czarek » Fri May 26, 2017 5:02 am

From your code I can see you create a new manager each time GetCookieManager is called -> you should create it only once and save it if you want to share it.
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: Sharing context with CefCookieManager

Postby sjaved » Fri May 26, 2017 7:23 am

Those are just sample snippets, each browser has its own CookieManager; which is created only first time when GetCookieManager() is called.
The actual code is something like this
if (!mCookieManager.get()) {
mCookieManager = CefCookieManager::CreateManager(CefString("cookie_storage_path"), false, NULL);
}
return mCookieManager;

Regards,
sjaved
Techie
 
Posts: 15
Joined: Wed Jun 15, 2016 3:47 am

Re: Sharing context with CefCookieManager

Postby HarmlessDave » Fri May 26, 2017 3:08 pm

each browser has its own CookieManager; which is created only first time when GetCookieManager() is called.


You should make this cookie pointer application global not part of each browser.

If browser 1 and browser 2 have different manager objects then they have separate cookie stores.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Sharing context with CefCookieManager

Postby sjaved » Mon May 29, 2017 4:03 am

Does this means that there is no possibility to share the cookie store of two browsers?
sjaved
Techie
 
Posts: 15
Joined: Wed Jun 15, 2016 3:47 am

Re: Sharing context with CefCookieManager

Postby magreenblatt » Mon May 29, 2017 7:55 am

sjaved wrote:Does this means that there is no possibility to share the cookie store of two browsers?

If you either (a) return the same CefCookieManager instance or (b) use the same CefRequestContext then browsers running in the same CEF instance will share the same cookie store. You cannot share the cookie store between browsers running in different CEF instances.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Sharing context with CefCookieManager

Postby sjaved » Tue May 30, 2017 7:04 am

I was assuming that by passing CefRequestContext::GetGlobalContext() while creating the CefRequestContext would help. but that does not seems to be the case.
Both the CefCookieManager and CefRequestContext were being created each time a browser is created, which means that they have different cookie store and they will not share the context.

Thanks for the answer.
sjaved
Techie
 
Posts: 15
Joined: Wed Jun 15, 2016 3:47 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 41 guests

cron