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 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?