ForgotThePain 2014-12-19 05:54 采纳率: 0%
浏览 4202

Cef3 CefCookieManager的正确用法?

研究过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 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。

  • 写回答

2条回答

  • ForgotThePain 2014-12-19 12:25
    关注

    问题解决了。
    答案
    有遇到同样问题的兄弟们可以参考下

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题