CEF 76, MacOS. How to set cookies storage directory?

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.

CEF 76, MacOS. How to set cookies storage directory?

Postby coder678 » Tue Sep 10, 2019 12:08 am

During execution of the app, there are different users, and each user shouldn't have access to cookies of other users. Before, there was a class allowing to set cookie storage directory. In CEF 76, there is no method
Code: Select all
mCookieManager = CefCookieManager::CreateManager(CefString(cookieStorageDirectory), persist_session_cookies, callback);

Please help.

Class that was used before:
Code: Select all
class ContextHandler : public CefRequestContextHandler
{
public:
    ContextHandler(const std::string cookieStorageDirectory)
    {
        bool persist_session_cookies = true;
        CefRefPtr<CefCompletionCallback> callback = nullptr;
       
        mCookieManager = CefCookieManager::CreateManager(CefString(cookieStorageDirectory), persist_session_cookies, callback);
    }
   
    CefRefPtr<CefCookieManager> GetCookieManager() override
    {
        return mCookieManager;
    }
   
private:
    CefRefPtr<CefCookieManager> mCookieManager;
   
    IMPLEMENT_REFCOUNTING(ContextHandler);
};
coder678
Techie
 
Posts: 35
Joined: Sun Jun 26, 2016 10:03 pm

Re: CEF 76, MacOS. How to set cookies storage directory?

Postby salvadordf » Tue Sep 10, 2019 2:15 am

That was one of the API changes introduced with the Network Service and as far as I know, you can't set the cookies storage path at runtime now.

This information is available in the CEF project :
Remove methods that modify cookie storage at runtime (see issue #2622).

This change removes cookie and request handler functionality that will not supported by the NetworkService. Specifically, it is no longer possible to change cookie storage locations at runime by returning a different CefCookieManager for an already initialized CefRequestContext. After this change you will need to use a separate CefRequestContext when creating a CefBrowser if you require separate cookie storage.

The following methods have been removed: - CefCookieManager::CreateManager - CefCookieManager::GetBlockingManager - CefCookieManager::SetStoragePath - CefRequestContextHandler::GetCookieManager

The following methods have been renamed: - CefRequestContext::GetDefaultCookieManager to GetCookieManager.

This change substantially simplifies the network implementation in CEF because it is no longer necessary to proxy objects that are normally owned by Chromium. Chromium patches that are no longer necessary will be removed as a follow-up commit.

To test: Verify that ceftests --gtest_filter=-PluginTest.* pass with NetworkService disabled. Plugin tests will be fixed in a follow-up commit.

https://bitbucket.org/chromiumembedded/ ... orkservice

As suggested by Marshall in that comment, you can use a separate CefRequestContext for each user.
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: CEF 76, MacOS. How to set cookies storage directory?

Postby coder678 » Wed Jan 22, 2020 8:28 pm

If to close the app and then reopen, will cookies be lost?
Is there any way to save and restore cookies for a given CefRequestContext ?
coder678
Techie
 
Posts: 35
Joined: Sun Jun 26, 2016 10:03 pm

Re: CEF 76, MacOS. How to set cookies storage directory?

Postby salvadordf » Thu Jan 23, 2020 4:21 am

Use a "cache_path" setting when you create the CefRequestContext to keep the cookies.
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 34 guests