CEF3 获取Cookie例子 CefCookieManager C++
简介
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++的更多相关文章
- js获取cookie中存储的值
最近看了试卷题目发现自己会的十分的匮乏, 第一题就把自己难住了,知道有这个东西,但是实际上没有操作过. ========================================= cookie ...
- 在jsp中怎么使用Cookie?el表达式中获取cookie的问题
初学jsp,不清楚cookie的使用方法,希望高手指点一下! 一般来说有两种办法,在JSP中使用Java的嵌入脚本. 例如: 写入Cookie <html> <head>. ...
- Springboot使用Cookie,生成cookie,获取cookie信息(注解与非注解方式)
先 创建一个控制类吧, 其实我没有分层啊,随便做个例子: MyGetCookieController: @RestControllerpublic class MyGetCookieControlle ...
- Cookie的使用、Cookie详解、HTTP cookies 详解、获取cookie的方法、客户端获取Cookie、深入解析cookie
Cookie是指某些网站为了辨别用户身份.进行session跟踪而存储在用户本地终端上的数据(通常经过加密),比如说有些网站需要登录才能访问某个页面,在登录之前,你想抓取某个页面内容是不允许的.那么我 ...
- js获取cookie
js获取cookie 之前用jQuery.cookie来获取cookie,虽然简单,但是项目上又多引用了一个插件,总觉得不太好,下面是我封装的js原生获取cookie的函数. function get ...
- javascript设置和获取cookie的通用方法
//获取cookie function getCookieValue(cookieName) { var cookieValue = document.cookie; var co ...
- 通过js获取cookie的实例及简单分析
今天碰到一个在firefox下swfupload 上传时session不一致问题 在一个项目遇到多文件上传时,firefox下,服务器端的session获取不一致问题. 解决办法: 解决办法:将ses ...
- ASP.NET后台获取cookie中文乱码解决办法
项目中有一功能,需要从一个页面前台使用cookie保存json数据,并传递到第二个页面.要在第二个页面中获取cookie中的json的值,没有任何处理情况下,获取的字符串为乱码,就连符号都是乱码的.百 ...
- js创建和获取cookie
创建cookie document.cookie='like=1'; //创建 cookie键名和值 var str = document.cookie; 获取cookie 读取cookiefunct ...
随机推荐
- 清北Day 2
清北第二天,感受到了来自这个世界的不友善,大概把没听过不会的"名词"记录下来就已经一面了,然后被大佬说这都是最基础的东西,就很皮,那就趁别人练习字符串的题的时候,来写波博客了,倒不 ...
- 【算法系列学习】状压dp [kuangbin带你飞]专题十二 基础DP1 D - Doing Homework
https://vjudge.net/contest/68966#problem/D http://blog.csdn.net/u010489389/article/details/19218795 ...
- Java数据类型(基本数据类型)学习
Java数据类型(基本数据类型)学习 与其他语言一样,Java编程同样存在,比如int a,float b等.在学习变量之前我就必须先了解Java的数据类型啦. Java的数据类型包括基本数据类型和引 ...
- 为什么要用Handler ?
我的理解,Handler的好处之一就是配合子线程处理数据之后控制UI的显示. 如下是http://www.cnblogs.com/sydeveloper/p/3312865.html的完美解释: 当应 ...
- Could not find a valid gem 'compass' (>= 0) in any repository compass安装失败解决方案
安装完成ruby gem 之后,通过 gem install compass 安装compass~~ 出现如下报错 Could not find a valid gem 'compass' (> ...
- UserManager
刚刚学习servlet,打算学做一个小项目把前边学到的知识做一个总结. 由于只是实现了一些简单的功能,所以美工就凑合着看吧(美工其实也不太会). 首先项目整体架构如图 项目准备工作: 要用到mysql ...
- NSString类
创建一个字符串 ) NSString *s = @"aaaa"; ) NSString *s1=[NSString new]; s1=@"bbb"; )格式化创 ...
- maven的三大生命周期
一.Maven的生命周期 Maven的生命周期就是对所有的构建过程进行抽象和统一.包含了项目的清理.初始化.编译.测试.打包.集成测试.验证.部署和站点生成等几乎所有的构建步骤. Maven的生命周期 ...
- [刷题]算法竞赛入门经典(第2版) 4-2/UVa201 - Squares
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,20 ms) #include<iostream> #include<cs ...
- Jdk1.6 JUC源码解析(12)-ArrayBlockingQueue
功能简介: ArrayBlockingQueue是一种基于数组实现的有界的阻塞队列.队列中的元素遵循先入先出(FIFO)的规则.新元素插入到队列的尾部,从队列头部取出元素. 和普通队列有所不同,该队列 ...