// 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 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 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 };
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 m_COOKIEVisitor;
m_COOKIEVisitor(new CCOOKIEVisitor());
//以下代码执行 即回调Visit
CefRefPtr cefCOOKIEManager = CefCOOKIEManager::GetGlobalManager(nullptr);
if (cefCOOKIEManager)
{
cefCOOKIEManager->VisitUrlCOOKIEs(url ,true , m_visitor);
}
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 }