简介

Chromium Embedded Framework (CEF)是由 Marshall Greenblatt 在2008年创办的开源项目,致力于基于Google Chromium项目开发一个Web控件。 CEF目前已支持多种编程语言和操作系统,能方便地集成到现有或者新的应用程序中,设计上,它追求高性能的同时,也追求易于使用,它的基本框架通过原生库提供C和C++的编程接口,这些接口将宿主程序与Chromium与WebKit的实现细节隔离,能让浏览器与应用程序无缝集成,并支持自定义插件、协议、Javascript对象与扩展。宿主程序还能根据需要控制资源加载、页面跳转、上下文菜单、打印等等。这些好处都是在支持Google Chrome同等效率与HTML5技术可用的基本上提供的。现在很多主流的客户端都使用了CEF来显示Web页面:网易云音乐、QQ、豌豆荚等(安装目录下可以找到libcef.dll)。

正文

首先从cef_cookie.h 源码中看到CefCookieManager 这个类:

  1. // Visit all cookies on the IO thread. The returned cookies are ordered by
  2. // longest path, then by earliest creation date. Returns false if cookies
  3. // cannot be accessed.
  4. ///
  5. /*--cef()--*/
  6. virtual bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) =0;
  7.  
  8. ///
  9. // Visit a subset of cookies on the IO thread. The results are filtered by the
  10. // given url scheme, host, domain and path. If |includeHttpOnly| is true
  11. // HTTP-only cookies will also be included in the results. The returned
  12. // cookies are ordered by longest path, then by earliest creation date.
  13. // Returns false if cookies cannot be accessed.
  14. ///
  15. /*--cef()--*/
  16. virtual bool VisitUrlCookies(const CefString& url,
  17. bool includeHttpOnly,
  18. CefRefPtr<CefCookieVisitor> visitor) =0;
  1. 1 class CefCookieVisitor : public virtual CefBase {
  2. 2 public:
  3. 3 ///
  4. 4 // Method that will be called once for each cookie. |count| is the 0-based
  5. 5 // index for the current cookie. |total| is the total number of cookies.
  6. 6 // Set |deleteCookie| to true to delete the cookie currently being visited.
  7. 7 // Return false to stop visiting cookies. This method may never be called if
  8. 8 // no cookies are found.
  9. 9 ///
  10. 10 /*--cef()--*/
  11. 11 virtual bool Visit(const CefCookie& cookie, int count, int total,
  12. 12 bool& deleteCookie) =0;
  13. 13 };

可以通过VisitAllCookies获取所有cookies;VisitUrlCookies获取域名下的所有cookies。

看到VisitUrlCookies的参数是CefCookieVisitor;所以实现一个类用于回调读取cookies;

  1. class CCookieVisitor : public CefCookieVisitor
  2. {
  3. public:
  4. CCookieVisitor() {};
  5. ~CCookieVisitor() {};
  6.  
  7. bool Visit(const CefCookie& cookie, int count, int total,
  8. bool& deleteCookie);
  9. //这是一个宏
  10. //所有的框架类从CefBase继承,实例指针由CefRefPtr管理,CefRefPtr通过调用AddRef()和Release()方法自动管理引用计数。
  11. IMPLEMENT_REFCOUNTING(CookieVisitor);
  12. };
  1. //作为类的成员变量
    CefRefPtr<CCookieVisitor> m_CookieVisitor;
  2. m_CookieVisitor(new CCookieVisitor());

 //以下代码执行 即回调Visit

 CefRefPtr<CefCookieManager> cefCookieManager = CefCookieManager::GetGlobalManager(nullptr);

if (cefCookieManager)
  {
    cefCookieManager->VisitUrlCookies(url ,true , m_visitor);
  }

回调进行读取,count为当前cookie total为总数。具体看CefCookieVisitor的注释,接下来便可以Visit读取到数据

  1. 1 bool CookieVisitor::Visit(const CefCookie & cookie, int count, int total, bool & deleteCookie)
  2. 2 {
  3. 3 if (count == total)
  4. 4 {
  5. 5 return false;
  6. 6 }
  7. 7 if (cookie.name.str && cookie.value.str)
  8. 8 {
  9. 9 string strName = cookie.name.str;
  10. 10 string strValue = cookie.value.str;
  11. 11 }
  12. 12 return true;
  13. 13 }

备注:CEF远程调试地址 chrome://inspect/#devices

结束!

CEF3 获取Cookie例子 CefCookieManager C++的更多相关文章

  1. js获取cookie中存储的值

    最近看了试卷题目发现自己会的十分的匮乏, 第一题就把自己难住了,知道有这个东西,但是实际上没有操作过. ========================================= cookie ...

  2. 在jsp中怎么使用Cookie?el表达式中获取cookie的问题

    初学jsp,不清楚cookie的使用方法,希望高手指点一下!   一般来说有两种办法,在JSP中使用Java的嵌入脚本. 例如: 写入Cookie <html> <head>. ...

  3. Springboot使用Cookie,生成cookie,获取cookie信息(注解与非注解方式)

    先 创建一个控制类吧, 其实我没有分层啊,随便做个例子: MyGetCookieController: @RestControllerpublic class MyGetCookieControlle ...

  4. Cookie的使用、Cookie详解、HTTP cookies 详解、获取cookie的方法、客户端获取Cookie、深入解析cookie

    Cookie是指某些网站为了辨别用户身份.进行session跟踪而存储在用户本地终端上的数据(通常经过加密),比如说有些网站需要登录才能访问某个页面,在登录之前,你想抓取某个页面内容是不允许的.那么我 ...

  5. js获取cookie

    js获取cookie 之前用jQuery.cookie来获取cookie,虽然简单,但是项目上又多引用了一个插件,总觉得不太好,下面是我封装的js原生获取cookie的函数. function get ...

  6. javascript设置和获取cookie的通用方法

    //获取cookie  function getCookieValue(cookieName)  {     var cookieValue = document.cookie;     var co ...

  7. 通过js获取cookie的实例及简单分析

    今天碰到一个在firefox下swfupload 上传时session不一致问题 在一个项目遇到多文件上传时,firefox下,服务器端的session获取不一致问题. 解决办法: 解决办法:将ses ...

  8. ASP.NET后台获取cookie中文乱码解决办法

    项目中有一功能,需要从一个页面前台使用cookie保存json数据,并传递到第二个页面.要在第二个页面中获取cookie中的json的值,没有任何处理情况下,获取的字符串为乱码,就连符号都是乱码的.百 ...

  9. js创建和获取cookie

    创建cookie document.cookie='like=1'; //创建 cookie键名和值 var str = document.cookie; 获取cookie 读取cookiefunct ...

随机推荐

  1. golang环境

    Golang是谷歌开发的一款开源性语言,暂时比较方便的IDE有Inteillj Idea.LiteIDE.Eclipse(Golipse)等,使用起来比较方便的IDE:LiteIDE和Inteillj ...

  2. 【2017-04-20】Sql字符串注入式攻击与防御

    一.攻击 所谓sql字符串注入式攻击就是在用户输入界面输入一串sql语句,来改变C#中连接数据库要执行的sql语句 通过你写的程序,直接来执行我想要执行的sql语句 例如:在这么一个程序中,sname ...

  3. 【BFS + Hash】拼图——携程2017春招编程题2

    写在前面 前天参加了携程的网测--还是感觉自己太!渣!了!    _(:з」∠)_ 时光匆匆啊,已经到了开始思考人生的时候了(算了不矫情了)--总之写个博客来督促一下自己.之前太懒了,很多时候都是输在 ...

  4. Python -堆的实现

    最小(大)堆是按完全二叉树的排序顺序的方式排布堆中元素的,并且满足:ai  >a(2i+1)  and ai>a(2i+2)( ai  <a(2i+1)  and ai<a(2 ...

  5. C#如何向word文档插入一个新段落及隐藏段落

    编辑Word文档时,我们有时会突然想增加一段新内容:而将word文档给他人浏览时,有些信息我们是不想让他人看到的.那么如何运用C#编程的方式巧妙地插入或隐藏段落呢?本文将与大家分享一种向Word文档插 ...

  6. DirectFB 之 环境配置

    1. 准备 directFB下载地址:http://www.directfb.org/index.php?path=Main%2FDownloads 本人采用的版本是DirectFB-1.5.3.ta ...

  7. [内存管理]linux内存管理 之 内存节点和内存分区

    Linux支持多种硬件体系结构,因此Linux必须采用通用的方法来描述内存,以方便对内存进行管理.为此,Linux有了内存节点.内存区.页框的概念,这些概念也是一目了然的. 内存节点:主要依据CPU访 ...

  8. poj3320尺取法

    Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is co ...

  9. UI基础控件—UIView

    1. 什么是UIView?     UIView :代表屏幕上的一个矩形区域,管理界面上的内容; 2. 创建UIview a.开辟空间并初始化视图(初始化时,给出视图位置和大小) b.对视图做一些设置 ...

  10. vue视频学习笔记07

    video 7 vue问题:论坛http://bbs.zhinengshe.com------------------------------------------------UI组件别人提供好一堆 ...