CEF3的CefCookieManager的正确用法?

ForgotThePain 2014-12-19 02:02:14
研究过CEF3的大牛们,怎样使用CefCookieManager::CreateManager来为浏览器实例分配单独的CookieManager?
我本来以为很简单:
首先生成一个CefRequestContextHandler,重载GetCookieManager,象这样:


```
 class WXRequestContextHandler :public CefRequestContextHandler
{
public:
WXRequestContextHandler(){};
~WXRequestContextHandler(){};
CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE{

return CefCookieManager::CreateManager("F:\\CefCookie", FALSE)
}
private:
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(WXRequestContextHandler);
};

```
然后用CefRequestContext::CreateContext来创建一个CefRequestContext实例。
像这样:
 CefRefPtr<CefRequestContext> rc = CefRequestContext::CreateContext(new WXRequestContextHandler


());

然后创建BROWSER:


```
CefBrowserHost::CreateBrowser(window_info, handler.get(), url,
browser_settings, rc);

```

结果一运行代码就出现EXCEPTION 访问冲突。只有getCookieManager返回NULL
才正常

我想肯定是我的用法错了,那么正确的用法是什么?求指教。
我测试代码是用的CEF3下载包中的cefSimple应用程序,只改了两行代码:



```
void SimpleApp::OnContextInitialized() {
REQUIRE_UI_THREAD();

// Information used when creating the native window.
CefWindowInfo window_info;

#if defined(OS_WIN)
// On Windows we need to specify certain flags that will be passed to
// CreateWindowEx().
window_info.SetAsPopup(NULL, "cefsimple");
#endif

// SimpleHandler implements browser-level callbacks.
CefRefPtr<SimpleHandler> handler(new SimpleHandler());

// Specify CEF browser settings here.
CefBrowserSettings browser_settings;

std::string url;

// Check if a "--url=" value was provided via the command-line. If so, use
// that instead of the default URL.
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
url = command_line->GetSwitchValue("url");
if (url.empty())
url = "http://www.google.com";

CefRefPtr<CefRequestContext> rc = CefRequestContext::CreateContext(new WXRequestContextHandler

());

// Create the first browser window.
CefBrowserHost::CreateBrowser(window_info, handler.get(), url,
browser_settings, rc);
}

```

我是用的CEF3.175,VS2013,WIN7。
...全文
5693 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞翔的薄荷 2015-07-03
  • 打赏
  • 举报
回复
只能返回一个,不能多次创建。 class SimpleContextHandler : public CefRequestContextHandler { public: virtual CefRefPtr<CefCookieManager> GetCookieManager() override { if (coke_) { return coke_; } coke_ = CefCookieManager::CreateManager("F:\\CefCookie", false); return coke_; } public: CefRefPtr<CefCookieManager> coke_ = nullptr; private: // Include the default reference counting implementation. IMPLEMENT_REFCOUNTING(SimpleContextHandler); };
ForgotThePain 2014-12-19
  • 打赏
  • 举报
回复

3,056

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧