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 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题