简介

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 这个类:

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

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

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

class CCookieVisitor : public CefCookieVisitor
{
public:
CCookieVisitor() {};
~CCookieVisitor() {}; bool Visit(const CefCookie& cookie, int count, int total,
bool& deleteCookie);
//这是一个宏
//所有的框架类从CefBase继承,实例指针由CefRefPtr管理,CefRefPtr通过调用AddRef()和Release()方法自动管理引用计数。
IMPLEMENT_REFCOUNTING(CookieVisitor);
};
//作为类的成员变量
CefRefPtr<CCookieVisitor> m_CookieVisitor;
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 bool CookieVisitor::Visit(const CefCookie & cookie, int count, int total, bool & deleteCookie)
2 {
3 if (count == total)
4 {
5 return false;
6 }
7 if (cookie.name.str && cookie.value.str)
8 {
9 string strName = cookie.name.str;
10 string strValue = cookie.value.str;
11 }
12 return true;
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. easyUI中datagrid的使用

    easyUI中的datagrid数据表格经常被用到,结合项目中的使用情况,总结一下datagrid使用中需要注意的一些问题.使用datagrid展示数据,需要在html.css.js中都要编写代码,h ...

  2. SpringMVC结合ajaxfileupload文件无刷新上传

    jQuery没有提供ajax的文件上传,我们可以通过ajaxfileupload实现ajax文件的上传.其实ajaxfileupload文件上传特别的简单.下面就演示一下在SpringMVC中实现aj ...

  3. 阿里云centos 安装和配置 DokuWiki

    安装 1) 添加虚拟主机:由于我的 阿里云CentOs服务器 安装了oneinstack的一键部署PHP.JAVA.Nginx等环境,所以域名配置很方便,照着文档一步一步做就可以了 cd /root/ ...

  4. TypeScript入门-枚举、类型推论

    枚举 使用枚举可以定义一些具有名字的数字常量,和在C语言中一样都是使用关键字enum enum Direction { Up = 1, Down = 1<<2, Left, Right } ...

  5. CAS单点登录(SSO)服务端的部署和配置---连接MySQL进行身份认证

    一.修改系统host,加入 127.0.0.1 server.test.com127.0.0.1 client1.test.com127.0.0.1 client2.test.com 二.安装grad ...

  6. 走进javascript——类型

    ECMAScript语言类型对应于使用ECMAScript语言的ECMAScript程序员直接操作的值.ECMAScript语言类型有以下几种Undefined,Null,Boolean,String ...

  7. [笔记]scanf的使用(主要是针对char)

    学的是C++,用cin cout也用的很顺溜,写自己的类时重载"<<"与">>"运算符也很爽,但是发现在刷算法竞赛题时,cin cout ...

  8. 关于TOE(TCP/IP Offload Engine)

    前言 昨天在电脑上抓取的报文,想进行回话,但是发现全部被设备丢弃了,没有debug信息,查看了抓包文件,原来是IP头和TCP.UDP头的检验和全部为0,也就是TOE(TCP/IP Offload En ...

  9. robotframe 学习笔记(之一)

    在robot framework中,通过 Set variable关键字来定义变量 连接对象: 通过Catenate关键字可以连接多个信息 加上"SEPARATOR=",可以对多个 ...

  10. kotlin 语言入门指南一

    基于官网的Getting Start部分,翻译如下: 基础语法 定义一个包 包的声明必须放在文件头部: package my.demo import java.util.* // ... 不需要加上p ...