I have an application for OSX with a multi tabbed browser view. It needs to set a cache path separately for each tab. Here is the code.
- Code: Select all
-(void)addTab
{
CefRefPtr<SimpleHandler> handler(cHandler);
CefBrowserSettings browser_settings;
browser_settings.application_cache = STATE_ENABLED;
CefRequestContextSettings contextSettings;
mContextHandler = new ContextHandler("/Users/directory/for/cookies");
CefRefPtr<CefRequestContext> request_context2 = CefRequestContext::CreateContext(contextSettings, mContextHandler);
// !!! here it needs to set a custom cache_path. How???
NSRect f = self.view.frame;
NSView *cefView = [[NSView alloc] initWithFrame:(NSMakeRect(0, 70, f.size.width - 10, f.size.height - 70))];
CefWindowInfo window_info;
window_info.SetAsChild(cefView, 0, 0, [cefView frame].size.width, [cefView frame].size.height);
CefBrowserHost::CreateBrowser(window_info, handler, "some url here", browser_settings, request_context2);
}
// a custom request context to set directory for cookies at runtime
class ContextHandler : public CefRequestContextHandler
{
public:
ContextHandler(const std::string cookieStorageDirectory)
{
bool persist_session_cookies = true; // was false
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);
};
I've searched in the forum but couldn't find a working solution. Please help.