Merge revision 534 changes:

- Add CefCookieManager interface and CefRequestHandler::GetCookieManager for custom cookie handling (issue #542).

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/963@536 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-03-15 22:40:45 +00:00
parent 542e115b9b
commit 6a23cfd5c6
23 changed files with 1516 additions and 757 deletions

View File

@ -487,6 +487,8 @@
'libcef_dll/cpptoc/browser_cpptoc.h',
'libcef_dll/cpptoc/command_line_cpptoc.cc',
'libcef_dll/cpptoc/command_line_cpptoc.h',
'libcef_dll/cpptoc/cookie_manager_cpptoc.cc',
'libcef_dll/cpptoc/cookie_manager_cpptoc.h',
'libcef_dll/cpptoc/cpptoc.h',
'libcef_dll/cpptoc/domdocument_cpptoc.cc',
'libcef_dll/cpptoc/domdocument_cpptoc.h',
@ -824,6 +826,8 @@
'libcef/cef_time.cc',
'libcef/cef_time_util.h',
'libcef/command_line_impl.cc',
'libcef/cookie_impl.cc',
'libcef/cookie_impl.h',
'libcef/drag_data_impl.cc',
'libcef/drag_data_impl.h',
'libcef/drag_download_file.cc',

View File

@ -194,6 +194,8 @@
'libcef_dll/ctocpp/browser_ctocpp.h',
'libcef_dll/ctocpp/command_line_ctocpp.cc',
'libcef_dll/ctocpp/command_line_ctocpp.h',
'libcef_dll/ctocpp/cookie_manager_ctocpp.cc',
'libcef_dll/ctocpp/cookie_manager_ctocpp.h',
'libcef_dll/ctocpp/ctocpp.h',
'libcef_dll/ctocpp/domdocument_ctocpp.cc',
'libcef_dll/ctocpp/domdocument_ctocpp.h',

View File

@ -59,6 +59,7 @@ class CefApp;
class CefBrowser;
class CefClient;
class CefContentFilter;
class CefCookieManager;
class CefCookieVisitor;
class CefDOMDocument;
class CefDOMEvent;
@ -371,54 +372,6 @@ bool CefParseURL(const CefString& url,
bool CefCreateURL(const CefURLParts& parts,
CefString& url);
///
// Visit all cookies. The returned cookies are ordered by longest path, then by
// earliest creation date. Returns false if cookies cannot be accessed.
///
/*--cef()--*/
bool CefVisitAllCookies(CefRefPtr<CefCookieVisitor> visitor);
///
// Visit a subset of cookies. 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()--*/
bool CefVisitUrlCookies(const CefString& url, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor);
///
// Sets a cookie given a valid URL and explicit user-provided cookie attributes.
// This function expects each attribute to be well-formed. It will check for
// disallowed characters (e.g. the ';' character is disallowed within the cookie
// value attribute) and will return false without setting the cookie if such
// characters are found. This method must be called on the IO thread.
///
/*--cef()--*/
bool CefSetCookie(const CefString& url, const CefCookie& cookie);
///
// Delete all cookies that match the specified parameters. If both |url| and
// |cookie_name| are specified all host and domain cookies matching both values
// will be deleted. If only |url| is specified all host cookies (but not domain
// cookies) irrespective of path will be deleted. If |url| is empty all cookies
// for all hosts and domains will be deleted. Returns false if a non-empty
// invalid URL is specified or if cookies cannot be accessed. This method must
// be called on the IO thread.
///
/*--cef(optional_param=url,optional_param=cookie_name)--*/
bool CefDeleteCookies(const CefString& url, const CefString& cookie_name);
///
// Sets the directory path that will be used for storing cookie data. If |path|
// is empty data will be stored in memory only. By default the cookie path is
// the same as the cache path. Returns false if cookies cannot be accessed.
///
/*--cef(optional_param=path)--*/
bool CefSetCookiePath(const CefString& path);
typedef cef_storage_type_t CefStorageType;
@ -583,6 +536,80 @@ public:
};
///
// Class used for managing cookies. The methods of this class may be called on
// any thread unless otherwise indicated.
///
/*--cef(source=library)--*/
class CefCookieManager : public virtual CefBase
{
public:
///
// Returns the global cookie manager. By default data will be stored at
// CefSettings.cache_path if specified or in memory otherwise.
///
/*--cef()--*/
static CefRefPtr<CefCookieManager> GetGlobalManager();
///
// Creates a new cookie manager. If |path| is empty data will be stored in
// memory only. Returns NULL if creation fails.
///
/*--cef(optional_param=path)--*/
static CefRefPtr<CefCookieManager> CreateManager(const CefString& path);
///
// Visit all cookies. 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. 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;
///
// Sets a cookie given a valid URL and explicit user-provided cookie
// attributes. This function expects each attribute to be well-formed. It will
// check for disallowed characters (e.g. the ';' character is disallowed
// within the cookie value attribute) and will return false without setting
// the cookie if such characters are found. This method must be called on the
// IO thread.
///
/*--cef()--*/
virtual bool SetCookie(const CefString& url, const CefCookie& cookie) =0;
///
// Delete all cookies that match the specified parameters. If both |url| and
// values |cookie_name| are specified all host and domain cookies matching
// both will be deleted. If only |url| is specified all host cookies (but not
// domain cookies) irrespective of path will be deleted. If |url| is empty all
// cookies for all hosts and domains will be deleted. Returns false if a non-
// empty invalid URL is specified or if cookies cannot be accessed. This
// method must be called on the IO thread.
///
/*--cef(optional_param=url,optional_param=cookie_name)--*/
virtual bool DeleteCookies(const CefString& url,
const CefString& cookie_name) =0;
///
// Sets the directory path that will be used for storing cookie data. If
// |path| is empty data will be stored in memory only. Returns false if
// cookies cannot be accessed.
///
/*--cef(optional_param=path)--*/
virtual bool SetStoragePath(const CefString& path) =0;
};
///
// Interface to implement for visiting cookie values. The methods of this class
// will always be called on the IO thread.
@ -1343,6 +1370,15 @@ public:
const CefString& scheme,
CefString& username,
CefString& password) { return false; }
///
// Called on the UI thread to retrieve the cookie manager. Cookies managers
// can be unique per browser or shared across multiple browsers. The global
// cookie manager will be used if this method returns NULL.
///
/*--cef()--*/
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser) { return NULL; }
};

View File

@ -310,51 +310,6 @@ CEF_EXPORT int cef_parse_url(const cef_string_t* url,
CEF_EXPORT int cef_create_url(const struct _cef_urlparts_t* parts,
cef_string_t* url);
///
// Visit all cookies. The returned cookies are ordered by longest path, then by
// earliest creation date. Returns false (0) if cookies cannot be accessed.
///
CEF_EXPORT int cef_visit_all_cookies(struct _cef_cookie_visitor_t* visitor);
///
// Visit a subset of cookies. The results are filtered by the given url scheme,
// host, domain and path. If |includeHttpOnly| is true (1) 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 (0) if cookies
// cannot be accessed.
///
CEF_EXPORT int cef_visit_url_cookies(const cef_string_t* url,
int includeHttpOnly, struct _cef_cookie_visitor_t* visitor);
///
// Sets a cookie given a valid URL and explicit user-provided cookie attributes.
// This function expects each attribute to be well-formed. It will check for
// disallowed characters (e.g. the ';' character is disallowed within the cookie
// value attribute) and will return false (0) without setting the cookie if such
// characters are found. This function must be called on the IO thread.
///
CEF_EXPORT int cef_set_cookie(const cef_string_t* url,
const struct _cef_cookie_t* cookie);
///
// Delete all cookies that match the specified parameters. If both |url| and
// |cookie_name| are specified all host and domain cookies matching both values
// will be deleted. If only |url| is specified all host cookies (but not domain
// cookies) irrespective of path will be deleted. If |url| is NULL all cookies
// for all hosts and domains will be deleted. Returns false (0) if a non-NULL
// invalid URL is specified or if cookies cannot be accessed. This function must
// be called on the IO thread.
///
CEF_EXPORT int cef_delete_cookies(const cef_string_t* url,
const cef_string_t* cookie_name);
///
// Sets the directory path that will be used for storing cookie data. If |path|
// is NULL data will be stored in memory only. By default the cookie path is the
// same as the cache path. Returns false (0) if cookies cannot be accessed.
///
CEF_EXPORT int cef_set_cookie_path(const cef_string_t* path);
///
// Visit storage of the specified type. If |origin| is non-NULL only data
// matching that origin will be visited. If |key| is non-NULL only data matching
@ -437,6 +392,81 @@ typedef struct _cef_task_t
} cef_task_t;
///
// Structure used for managing cookies. The functions of this structure may be
// called on any thread unless otherwise indicated.
///
typedef struct _cef_cookie_manager_t
{
// Base structure.
cef_base_t base;
///
// Visit all cookies. The returned cookies are ordered by longest path, then
// by earliest creation date. Returns false (0) if cookies cannot be accessed.
///
int (CEF_CALLBACK *visit_all_cookies)(struct _cef_cookie_manager_t* self,
struct _cef_cookie_visitor_t* visitor);
///
// Visit a subset of cookies. The results are filtered by the given url
// scheme, host, domain and path. If |includeHttpOnly| is true (1) 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 (0)
// if cookies cannot be accessed.
///
int (CEF_CALLBACK *visit_url_cookies)(struct _cef_cookie_manager_t* self,
const cef_string_t* url, int includeHttpOnly,
struct _cef_cookie_visitor_t* visitor);
///
// Sets a cookie given a valid URL and explicit user-provided cookie
// attributes. This function expects each attribute to be well-formed. It will
// check for disallowed characters (e.g. the ';' character is disallowed
// within the cookie value attribute) and will return false (0) without
// setting the cookie if such characters are found. This function must be
// called on the IO thread.
///
int (CEF_CALLBACK *set_cookie)(struct _cef_cookie_manager_t* self,
const cef_string_t* url, const struct _cef_cookie_t* cookie);
///
// Delete all cookies that match the specified parameters. If both |url| and
// values |cookie_name| are specified all host and domain cookies matching
// both will be deleted. If only |url| is specified all host cookies (but not
// domain cookies) irrespective of path will be deleted. If |url| is NULL all
// cookies for all hosts and domains will be deleted. Returns false (0) if a
// non- NULL invalid URL is specified or if cookies cannot be accessed. This
// function must be called on the IO thread.
///
int (CEF_CALLBACK *delete_cookies)(struct _cef_cookie_manager_t* self,
const cef_string_t* url, const cef_string_t* cookie_name);
///
// Sets the directory path that will be used for storing cookie data. If
// |path| is NULL data will be stored in memory only. Returns false (0) if
// cookies cannot be accessed.
///
int (CEF_CALLBACK *set_storage_path)(struct _cef_cookie_manager_t* self,
const cef_string_t* path);
} cef_cookie_manager_t;
///
// Returns the global cookie manager. By default data will be stored at
// CefSettings.cache_path if specified or in memory otherwise.
///
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_global_manager();
///
// Creates a new cookie manager. If |path| is NULL data will be stored in memory
// only. Returns NULL if creation fails.
///
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_create_manager(
const cef_string_t* path);
///
// Structure to implement for visiting cookie values. The functions of this
// structure will always be called on the IO thread.
@ -1159,6 +1189,14 @@ typedef struct _cef_request_handler_t
int port, const cef_string_t* realm, const cef_string_t* scheme,
cef_string_t* username, cef_string_t* password);
///
// Called on the UI thread to retrieve the cookie manager. Cookies managers
// can be unique per browser or shared across multiple browsers. The global
// cookie manager will be used if this function returns NULL.
///
struct _cef_cookie_manager_t* (CEF_CALLBACK *get_cookie_manager)(
struct _cef_request_handler_t* self, struct _cef_browser_t* browser);
} cef_request_handler_t;

View File

@ -57,7 +57,6 @@
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
#include "net/base/auth.h"
#include "net/base/cookie_store.h"
#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
@ -1112,61 +1111,6 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge {
RequestProxy* proxy_;
};
//-----------------------------------------------------------------------------
class CookieSetter : public base::RefCountedThreadSafe<CookieSetter> {
public:
void Set(const GURL& url, const std::string& cookie) {
REQUIRE_IOT();
net::CookieStore* cookie_store =
_Context->request_context()->cookie_store();
if (cookie_store) {
cookie_store->SetCookieWithOptionsAsync(
url, cookie, net::CookieOptions(),
net::CookieStore::SetCookiesCallback());
}
}
private:
friend class base::RefCountedThreadSafe<CookieSetter>;
~CookieSetter() {}
};
class CookieGetter : public base::RefCountedThreadSafe<CookieGetter> {
public:
CookieGetter() : event_(false, false) {
}
void Get(const GURL& url) {
REQUIRE_IOT();
net::CookieStore* cookie_store =
_Context->request_context()->cookie_store();
if (cookie_store) {
cookie_store->GetCookiesWithOptionsAsync(
url, net::CookieOptions(),
base::Bind(&CookieGetter::OnGetCookies, this));
}
}
std::string GetResult() {
event_.Wait();
return result_;
}
private:
void OnGetCookies(const std::string& cookie_line) {
result_ = cookie_line;
event_.Signal();
}
friend class base::RefCountedThreadSafe<CookieGetter>;
~CookieGetter() {}
base::WaitableEvent event_;
std::string result_;
};
} // anonymous namespace
//-----------------------------------------------------------------------------
@ -1181,36 +1125,6 @@ webkit_glue::ResourceLoaderBridge* BrowserResourceLoaderBridge::Create(
//-----------------------------------------------------------------------------
// static
void BrowserResourceLoaderBridge::SetCookie(const GURL& url,
const GURL& first_party_for_cookies,
const std::string& cookie) {
// Proxy to IO thread to synchronize w/ network loading.
scoped_refptr<CookieSetter> cookie_setter = new CookieSetter();
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
&CookieSetter::Set, cookie_setter.get(), url, cookie));
}
// static
std::string BrowserResourceLoaderBridge::GetCookies(
const GURL& url, const GURL& first_party_for_cookies) {
// Proxy to IO thread to synchronize w/ network loading.
scoped_refptr<CookieGetter> cookie_getter = new CookieGetter();
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
&CookieGetter::Get, cookie_getter.get(), url));
// Blocks until the result is available.
return cookie_getter->GetResult();
}
// static
void BrowserResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) {
// Proxy to IO thread to synchronize w/ network loading.
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
&BrowserRequestContext::SetAcceptAllCookies,
_Context->request_context().get(), accept_all_cookies));
}
// static
CefRefPtr<CefBrowser> BrowserResourceLoaderBridge::GetBrowserForRequest(
net::URLRequest* request) {

View File

@ -16,14 +16,6 @@ class GURL;
class BrowserResourceLoaderBridge {
public:
// May only be called after Init.
static void SetCookie(const GURL& url,
const GURL& first_party_for_cookies,
const std::string& cookie);
static std::string GetCookies(const GURL& url,
const GURL& first_party_for_cookies);
static void SetAcceptAllCookies(bool accept_all_cookies);
// Return the CefBrowser associated with the specified request. The browser
// will be NULL in cases where the request was initiated using the
// CefWebURLRequest API.

View File

@ -1,25 +1,152 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 the Chromium Embedded Framework authors.
// Portions copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "browser_webcookiejar_impl.h"
#include "browser_resource_loader_bridge.h"
#include "libcef/browser_webcookiejar_impl.h"
#include <string>
#include "libcef/browser_resource_loader_bridge.h"
#include "libcef/browser_impl.h"
#include "libcef/cookie_impl.h"
#include "libcef/cef_context.h"
#include "libcef/cef_thread.h"
#include "base/synchronization/waitable_event.h"
#include "net/base/cookie_store.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
using WebKit::WebString;
using WebKit::WebURL;
namespace {
class CookieSetter : public base::RefCountedThreadSafe<CookieSetter> {
public:
void Set(net::CookieStore* cookie_store,
const GURL& url,
const std::string& cookie) {
REQUIRE_IOT();
cookie_store->SetCookieWithOptionsAsync(
url, cookie, net::CookieOptions(),
net::CookieStore::SetCookiesCallback());
}
private:
friend class base::RefCountedThreadSafe<CookieSetter>;
~CookieSetter() {}
};
class CookieGetter : public base::RefCountedThreadSafe<CookieGetter> {
public:
CookieGetter() : event_(false, false) {
}
void Get(net::CookieStore* cookie_store, const GURL& url) {
REQUIRE_IOT();
cookie_store->GetCookiesWithOptionsAsync(
url, net::CookieOptions(),
base::Bind(&CookieGetter::OnGetCookies, this));
}
std::string GetResult() {
event_.Wait();
return result_;
}
private:
void OnGetCookies(const std::string& cookie_line) {
result_ = cookie_line;
event_.Signal();
}
friend class base::RefCountedThreadSafe<CookieGetter>;
~CookieGetter() {}
base::WaitableEvent event_;
std::string result_;
};
} // namespace
BrowserWebCookieJarImpl::BrowserWebCookieJarImpl()
: browser_(NULL) {
}
BrowserWebCookieJarImpl::BrowserWebCookieJarImpl(CefBrowserImpl* browser)
: browser_(browser) {
}
void BrowserWebCookieJarImpl::setCookie(const WebURL& url,
const WebURL& first_party_for_cookies,
const WebString& value) {
BrowserResourceLoaderBridge::SetCookie(
url, first_party_for_cookies, value.utf8());
const WebURL& first_party_for_cookies,
const WebString& value) {
GURL gurl = url;
std::string cookie = value.utf8();
scoped_refptr<net::CookieStore> cookie_store;
if (browser_) {
CefRefPtr<CefClient> client = browser_->GetClient();
if (client.get()) {
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
if (handler.get()) {
// Get the manager from the handler.
CefRefPtr<CefCookieManager> manager =
handler->GetCookieManager(browser_);
if (manager.get()) {
cookie_store =
reinterpret_cast<CefCookieManagerImpl*>(
manager.get())->cookie_monster();
}
}
}
}
if (!cookie_store) {
// Use the global cookie store.
cookie_store = _Context->request_context()->cookie_store();
}
// Proxy to IO thread to synchronize w/ network loading.
scoped_refptr<CookieSetter> cookie_setter = new CookieSetter();
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
&CookieSetter::Set, cookie_setter.get(), cookie_store, gurl, cookie));
}
WebString BrowserWebCookieJarImpl::cookies(
const WebURL& url,
const WebURL& first_party_for_cookies) {
return WebString::fromUTF8(
BrowserResourceLoaderBridge::GetCookies(url, first_party_for_cookies));
GURL gurl = url;
scoped_refptr<net::CookieStore> cookie_store;
if (browser_) {
CefRefPtr<CefClient> client = browser_->GetClient();
if (client.get()) {
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
if (handler.get()) {
// Get the manager from the handler.
CefRefPtr<CefCookieManager> manager =
handler->GetCookieManager(browser_);
if (manager.get()) {
cookie_store =
reinterpret_cast<CefCookieManagerImpl*>(
manager.get())->cookie_monster();
}
}
}
}
if (!cookie_store) {
// Use the global cookie store.
cookie_store = _Context->request_context()->cookie_store();
}
// Proxy to IO thread to synchronize w/ network loading.
scoped_refptr<CookieGetter> cookie_getter = new CookieGetter();
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
&CookieGetter::Get, cookie_getter.get(), cookie_store, gurl));
// Blocks until the result is available.
return WebString::fromUTF8(cookie_getter->GetResult());
}

View File

@ -1,22 +1,31 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 the Chromium Embedded Framework authors.
// Portions copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef _BROWSER_SIMPLE_WEBCOOKIEJAR_IMPL_H
#define _BROWSER_SIMPLE_WEBCOOKIEJAR_IMPL_H
#ifndef CEF_LIBCEF_BROWSER_WEBCOOKIEJAR_IMPL_H_
#define CEF_LIBCEF_BROWSER_WEBCOOKIEJAR_IMPL_H_
#pragma once
// TODO(darin): WebCookieJar.h is missing a WebString.h include!
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCookieJar.h"
class CefBrowserImpl;
class BrowserWebCookieJarImpl : public WebKit::WebCookieJar {
public:
BrowserWebCookieJarImpl();
explicit BrowserWebCookieJarImpl(CefBrowserImpl* browser);
// WebKit::WebCookieJar methods:
virtual void setCookie(
const WebKit::WebURL& url, const WebKit::WebURL& first_party_for_cookies,
const WebKit::WebString& cookie);
virtual WebKit::WebString cookies(
const WebKit::WebURL& url, const WebKit::WebURL& first_party_for_cookies);
private:
// May be NULL for the global implementation.
CefBrowserImpl* browser_;
};
#endif // _BROWSER_SIMPLE_WEBCOOKIEJAR_IMPL_H
#endif // CEF_LIBCEF_BROWSER_WEBCOOKIEJAR_IMPL_H_

View File

@ -496,7 +496,7 @@ bool BrowserWebViewDelegate::allowScriptExtension(
// WebPluginPageDelegate -----------------------------------------------------
WebCookieJar* BrowserWebViewDelegate::GetCookieJar() {
return WebKit::webKitPlatformSupport()->cookieJar();
return &cookie_jar_;
}
// WebWidgetClient -----------------------------------------------------------
@ -675,6 +675,10 @@ WebApplicationCacheHost* BrowserWebViewDelegate::createApplicationCacheHost(
return BrowserAppCacheSystem::CreateApplicationCacheHost(client);
}
WebKit::WebCookieJar* BrowserWebViewDelegate::cookieJar(WebFrame* frame) {
return &cookie_jar_;
}
void BrowserWebViewDelegate::willClose(WebFrame* frame) {
browser_->UIT_BeforeFrameClosed(frame);
}
@ -994,7 +998,8 @@ BrowserWebViewDelegate::BrowserWebViewDelegate(CefBrowserImpl* browser)
#else
select_trailing_whitespace_enabled_(false),
#endif
block_redirects_(false) {
block_redirects_(false),
cookie_jar_(browser) {
}
BrowserWebViewDelegate::~BrowserWebViewDelegate() {

View File

@ -27,6 +27,7 @@
#include "webkit/glue/webcursor.h"
#include "webkit/plugins/npapi/webplugin_page_delegate.h"
#include "browser_navigation_controller.h"
#include "browser_webcookiejar_impl.h"
#if defined(OS_MACOSX)
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
@ -145,6 +146,7 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient,
virtual WebKit::WebApplicationCacheHost* createApplicationCacheHost(
WebKit::WebFrame* frame, WebKit::WebApplicationCacheHostClient* client)
OVERRIDE;
virtual WebKit::WebCookieJar* cookieJar(WebKit::WebFrame*) OVERRIDE;
virtual void willClose(WebKit::WebFrame*) OVERRIDE;
virtual void loadURLExternally(
WebKit::WebFrame*, const WebKit::WebURLRequest&,
@ -367,6 +369,8 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient,
std::string edit_command_name_;
std::string edit_command_value_;
BrowserWebCookieJarImpl cookie_jar_;
DISALLOW_COPY_AND_ASSIGN(BrowserWebViewDelegate);
};

View File

@ -18,7 +18,6 @@
#include "base/string_split.h"
#include "base/synchronization/waitable_event.h"
#include "base/utf_string_conversions.h"
#include "net/base/cookie_monster.h"
#include "webkit/plugins/npapi/plugin_list.h"
#if defined(OS_MACOSX) || defined(OS_WIN)
@ -96,105 +95,6 @@ int GetThreadId(CefThreadId threadId)
return -1;
}
// Callback class for visiting cookies.
class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
public:
VisitCookiesCallback(CefRefPtr<CefCookieVisitor> visitor)
: visitor_(visitor)
{
}
void Run(const net::CookieList& list)
{
REQUIRE_IOT();
net::CookieMonster* cookie_monster = static_cast<net::CookieMonster*>(
_Context->request_context()->cookie_store());
if (!cookie_monster)
return;
int total = list.size(), count = 0;
net::CookieList::const_iterator it = list.begin();
for (; it != list.end(); ++it, ++count) {
CefCookie cookie;
const net::CookieMonster::CanonicalCookie& cc = *(it);
CefString(&cookie.name).FromString(cc.Name());
CefString(&cookie.value).FromString(cc.Value());
CefString(&cookie.domain).FromString(cc.Domain());
CefString(&cookie.path).FromString(cc.Path());
cookie.secure = cc.IsSecure();
cookie.httponly = cc.IsHttpOnly();
cef_time_from_basetime(cc.CreationDate(), cookie.creation);
cef_time_from_basetime(cc.LastAccessDate(), cookie.last_access);
cookie.has_expires = cc.DoesExpire();
if (cookie.has_expires)
cef_time_from_basetime(cc.ExpiryDate(), cookie.expires);
bool deleteCookie = false;
bool keepLooping = visitor_->Visit(cookie, count, total, deleteCookie);
if (deleteCookie) {
cookie_monster->DeleteCanonicalCookieAsync(cc,
net::CookieMonster::DeleteCookieCallback());
}
if (!keepLooping)
break;
}
}
private:
CefRefPtr<CefCookieVisitor> visitor_;
};
void IOT_VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor)
{
REQUIRE_IOT();
net::CookieMonster* cookie_monster = static_cast<net::CookieMonster*>(
_Context->request_context()->cookie_store());
if (!cookie_monster)
return;
scoped_refptr<VisitCookiesCallback> callback(
new VisitCookiesCallback(visitor));
cookie_monster->GetAllCookiesAsync(
base::Bind(&VisitCookiesCallback::Run, callback.get()));
}
void IOT_VisitUrlCookies(const GURL& url, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor)
{
REQUIRE_IOT();
net::CookieMonster* cookie_monster = static_cast<net::CookieMonster*>(
_Context->request_context()->cookie_store());
if (!cookie_monster)
return;
net::CookieOptions options;
if (includeHttpOnly)
options.set_include_httponly();
scoped_refptr<VisitCookiesCallback> callback(
new VisitCookiesCallback(visitor));
cookie_monster->GetAllCookiesForURLWithOptionsAsync(url, options,
base::Bind(&VisitCookiesCallback::Run, callback.get()));
}
void IOT_SetCookiePath(const CefString& path)
{
REQUIRE_IOT();
FilePath cookie_path;
if (!path.empty())
cookie_path = FilePath(path);
_Context->request_context()->SetCookieStoragePath(cookie_path);
}
// Used in multi-threaded message loop mode to observe shutdown of the UI
// thread.
class DestructionObserver : public MessageLoop::DestructionObserver
@ -560,134 +460,6 @@ bool CefCreateURL(const CefURLParts& parts,
return false;
}
bool CefVisitAllCookies(CefRefPtr<CefCookieVisitor> visitor)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return false;
}
return CefThread::PostTask(CefThread::IO, FROM_HERE,
NewRunnableFunction(IOT_VisitAllCookies, visitor));
}
bool CefVisitUrlCookies(const CefString& url, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return false;
}
std::string urlStr = url;
GURL gurl = GURL(urlStr);
if (!gurl.is_valid())
return false;
return CefThread::PostTask(CefThread::IO, FROM_HERE,
NewRunnableFunction(IOT_VisitUrlCookies, gurl, includeHttpOnly, visitor));
}
bool CefSetCookie(const CefString& url, const CefCookie& cookie)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return false;
}
// Verify that this function is being called on the IO thread.
if (!CefThread::CurrentlyOn(CefThread::IO)) {
NOTREACHED() << "called on invalid thread";
return false;
}
net::CookieMonster* cookie_monster = static_cast<net::CookieMonster*>(
_Context->request_context()->cookie_store());
if (!cookie_monster)
return false;
std::string urlStr = url;
GURL gurl = GURL(urlStr);
if (!gurl.is_valid())
return false;
std::string name = CefString(&cookie.name).ToString();
std::string value = CefString(&cookie.value).ToString();
std::string domain = CefString(&cookie.domain).ToString();
std::string path = CefString(&cookie.path).ToString();
base::Time expiration_time;
if (cookie.has_expires)
cef_time_to_basetime(cookie.expires, expiration_time);
cookie_monster->SetCookieWithDetailsAsync(gurl, name, value, domain, path,
expiration_time, cookie.secure, cookie.httponly,
net::CookieStore::SetCookiesCallback());
return true;
}
bool CefDeleteCookies(const CefString& url, const CefString& cookie_name)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return false;
}
// Verify that this function is being called on the IO thread.
if (!CefThread::CurrentlyOn(CefThread::IO)) {
NOTREACHED() << "called on invalid thread";
return false;
}
net::CookieMonster* cookie_monster = static_cast<net::CookieMonster*>(
_Context->request_context()->cookie_store());
if (!cookie_monster)
return false;
if (url.empty()) {
// Delete all cookies.
cookie_monster->DeleteAllAsync(net::CookieMonster::DeleteCallback());
return true;
}
std::string urlStr = url;
GURL gurl = GURL(urlStr);
if (!gurl.is_valid())
return false;
if (cookie_name.empty()) {
// Delete all matching host cookies.
cookie_monster->DeleteAllForHostAsync(gurl,
net::CookieMonster::DeleteCallback());
} else {
// Delete all matching host and domain cookies.
cookie_monster->DeleteCookieAsync(gurl, cookie_name, base::Closure());
}
return true;
}
bool CefSetCookiePath(const CefString& path)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return false;
}
if (CefThread::CurrentlyOn(CefThread::IO)) {
IOT_SetCookiePath(path);
} else {
CefThread::PostTask(CefThread::IO, FROM_HERE,
base::Bind(&IOT_SetCookiePath, path));
}
return true;
}
bool CefVisitStorage(CefStorageType type, const CefString& origin,
const CefString& key,
CefRefPtr<CefStorageVisitor> visitor)

252
libcef/cookie_impl.cc Normal file
View File

@ -0,0 +1,252 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
#include "libcef/cookie_impl.h"
#include <string>
#include "libcef/browser_persistent_cookie_store.h"
#include "libcef/cef_context.h"
#include "libcef/cef_thread.h"
#include "libcef/cef_time_util.h"
#include "base/bind.h"
#include "base/logging.h"
namespace {
// Callback class for visiting cookies.
class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
public:
explicit VisitCookiesCallback(net::CookieMonster* cookie_monster,
CefRefPtr<CefCookieVisitor> visitor)
: cookie_monster_(cookie_monster),
visitor_(visitor) {
}
void Run(const net::CookieList& list) {
REQUIRE_IOT();
int total = list.size(), count = 0;
net::CookieList::const_iterator it = list.begin();
for (; it != list.end(); ++it, ++count) {
CefCookie cookie;
const net::CookieMonster::CanonicalCookie& cc = *(it);
CefString(&cookie.name).FromString(cc.Name());
CefString(&cookie.value).FromString(cc.Value());
CefString(&cookie.domain).FromString(cc.Domain());
CefString(&cookie.path).FromString(cc.Path());
cookie.secure = cc.IsSecure();
cookie.httponly = cc.IsHttpOnly();
cef_time_from_basetime(cc.CreationDate(), cookie.creation);
cef_time_from_basetime(cc.LastAccessDate(), cookie.last_access);
cookie.has_expires = cc.DoesExpire();
if (cookie.has_expires)
cef_time_from_basetime(cc.ExpiryDate(), cookie.expires);
bool deleteCookie = false;
bool keepLooping = visitor_->Visit(cookie, count, total, deleteCookie);
if (deleteCookie) {
cookie_monster_->DeleteCanonicalCookieAsync(cc,
net::CookieMonster::DeleteCookieCallback());
}
if (!keepLooping)
break;
}
}
private:
scoped_refptr<net::CookieMonster> cookie_monster_;
CefRefPtr<CefCookieVisitor> visitor_;
};
} // namespace
CefCookieManagerImpl::CefCookieManagerImpl()
: is_global_(true) {
cookie_monster_ =
static_cast<net::CookieMonster*>(
_Context->request_context()->cookie_store());
DCHECK(cookie_monster_);
}
// Creates a new cookie monster with storage at the specified |path|.
CefCookieManagerImpl::CefCookieManagerImpl(const CefString& path)
:is_global_(false) {
SetStoragePath(path);
}
bool CefCookieManagerImpl::VisitAllCookies(
CefRefPtr<CefCookieVisitor> visitor) {
if (CefThread::CurrentlyOn(CefThread::IO)) {
scoped_refptr<VisitCookiesCallback> callback(
new VisitCookiesCallback(cookie_monster_, visitor));
cookie_monster_->GetAllCookiesAsync(
base::Bind(&VisitCookiesCallback::Run, callback.get()));
} else {
// Execute on the IO thread.
CefThread::PostTask(CefThread::IO, FROM_HERE,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::VisitAllCookies),
this, visitor));
}
return true;
}
bool CefCookieManagerImpl::VisitUrlCookies(
const CefString& url, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) {
if (CefThread::CurrentlyOn(CefThread::IO)) {
net::CookieOptions options;
if (includeHttpOnly)
options.set_include_httponly();
scoped_refptr<VisitCookiesCallback> callback(
new VisitCookiesCallback(cookie_monster_, visitor));
GURL gurl = GURL(url.ToString());
cookie_monster_->GetAllCookiesForURLWithOptionsAsync(gurl, options,
base::Bind(&VisitCookiesCallback::Run, callback.get()));
} else {
// Execute on the IO thread.
CefThread::PostTask(CefThread::IO, FROM_HERE,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::VisitUrlCookies),
this, url, includeHttpOnly, visitor));
}
return true;
}
bool CefCookieManagerImpl::SetCookie(const CefString& url,
const CefCookie& cookie) {
// Verify that this function is being called on the IO thread.
if (!CefThread::CurrentlyOn(CefThread::IO)) {
NOTREACHED() << "called on invalid thread";
return false;
}
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
return false;
std::string name = CefString(&cookie.name).ToString();
std::string value = CefString(&cookie.value).ToString();
std::string domain = CefString(&cookie.domain).ToString();
std::string path = CefString(&cookie.path).ToString();
base::Time expiration_time;
if (cookie.has_expires)
cef_time_to_basetime(cookie.expires, expiration_time);
cookie_monster_->SetCookieWithDetailsAsync(gurl, name, value, domain, path,
expiration_time, cookie.secure, cookie.httponly,
net::CookieStore::SetCookiesCallback());
return true;
}
bool CefCookieManagerImpl::DeleteCookies(const CefString& url,
const CefString& cookie_name) {
// Verify that this function is being called on the IO thread.
if (!CefThread::CurrentlyOn(CefThread::IO)) {
NOTREACHED() << "called on invalid thread";
return false;
}
if (url.empty()) {
// Delete all cookies.
cookie_monster_->DeleteAllAsync(net::CookieMonster::DeleteCallback());
return true;
}
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
return false;
if (cookie_name.empty()) {
// Delete all matching host cookies.
cookie_monster_->DeleteAllForHostAsync(gurl,
net::CookieMonster::DeleteCallback());
} else {
// Delete all matching host and domain cookies.
cookie_monster_->DeleteCookieAsync(gurl, cookie_name, base::Closure());
}
return true;
}
bool CefCookieManagerImpl::SetStoragePath(const CefString& path) {
if (CefThread::CurrentlyOn(CefThread::IO)) {
FilePath new_path;
if (!path.empty())
new_path = FilePath(path);
if (is_global_) {
// Global path changes are handled by the request context.
_Context->request_context()->SetCookieStoragePath(new_path);
cookie_monster_ =
static_cast<net::CookieMonster*>(
_Context->request_context()->cookie_store());
return true;
}
if (cookie_monster_ && ((storage_path_.empty() && path.empty()) ||
storage_path_ == new_path)) {
// The path has not changed so don't do anything.
return true;
}
scoped_refptr<BrowserPersistentCookieStore> persistent_store;
if (!new_path.empty()) {
if (file_util::CreateDirectory(new_path)) {
const FilePath& cookie_path = new_path.AppendASCII("Cookies");
persistent_store = new BrowserPersistentCookieStore(cookie_path, false);
} else {
NOTREACHED() << "The cookie storage directory could not be created";
storage_path_.clear();
}
}
// Set the new cookie store that will be used for all new requests. The old
// cookie store, if any, will be automatically flushed and closed when no
// longer referenced.
cookie_monster_ = new net::CookieMonster(persistent_store.get(), NULL);
storage_path_ = new_path;
} else {
// Execute on the IO thread.
CefThread::PostTask(CefThread::IO, FROM_HERE,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::SetStoragePath),
this, path));
}
return true;
}
// CefCookieManager methods ----------------------------------------------------
// static
CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager() {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return NULL;
}
return new CefCookieManagerImpl();
}
// static
CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
const CefString& path) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return NULL;
}
return new CefCookieManagerImpl(path);
}

41
libcef/cookie_impl.h Normal file
View File

@ -0,0 +1,41 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
#ifndef CEF_LIBCEF_COOKIE_IMPL_H_
#define CEF_LIBCEF_COOKIE_IMPL_H_
#include "include/cef.h"
#include "base/file_path.h"
#include "net/base/cookie_monster.h"
// Implementation of the CefCookieManager interface.
class CefCookieManagerImpl : public CefCookieManager {
public:
// Creates a new reference to the existing global cookie monster.
CefCookieManagerImpl();
// Creates a new cookie monster with storage at the specified |path|.
explicit CefCookieManagerImpl(const CefString& path);
// CefCookieManager methods.
virtual bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) OVERRIDE;
virtual bool VisitUrlCookies(const CefString& url, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) OVERRIDE;
virtual bool SetCookie(const CefString& url,
const CefCookie& cookie) OVERRIDE;
virtual bool DeleteCookies(const CefString& url,
const CefString& cookie_name) OVERRIDE;
virtual bool SetStoragePath(const CefString& path) OVERRIDE;
net::CookieMonster* cookie_monster() { return cookie_monster_; }
private:
scoped_refptr<net::CookieMonster> cookie_monster_;
bool is_global_;
FilePath storage_path_;
IMPLEMENT_REFCOUNTING(CefCookieManagerImpl);
};
#endif // CEF_LIBCEF_COOKIE_IMPL_H_

View File

@ -0,0 +1,191 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
#include "libcef_dll/ctocpp/cookie_visitor_ctocpp.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_global_manager()
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
CefRefPtr<CefCookieManager> _retval = CefCookieManager::GetGlobalManager();
// Return type: refptr_same
return CefCookieManagerCppToC::Wrap(_retval);
}
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_create_manager(
const cef_string_t* path)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: path
// Execute
CefRefPtr<CefCookieManager> _retval = CefCookieManager::CreateManager(
CefString(path));
// Return type: refptr_same
return CefCookieManagerCppToC::Wrap(_retval);
}
// MEMBER FUNCTIONS - Body may be edited by hand.
int CEF_CALLBACK cookie_manager_visit_all_cookies(
struct _cef_cookie_manager_t* self, struct _cef_cookie_visitor_t* visitor)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: visitor; type: refptr_diff
DCHECK(visitor);
if (!visitor)
return 0;
// Execute
bool _retval = CefCookieManagerCppToC::Get(self)->VisitAllCookies(
CefCookieVisitorCToCpp::Wrap(visitor));
// Return type: bool
return _retval;
}
int CEF_CALLBACK cookie_manager_visit_url_cookies(
struct _cef_cookie_manager_t* self, const cef_string_t* url,
int includeHttpOnly, struct _cef_cookie_visitor_t* visitor)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: url; type: string_byref_const
DCHECK(url);
if (!url)
return 0;
// Verify param: visitor; type: refptr_diff
DCHECK(visitor);
if (!visitor)
return 0;
// Execute
bool _retval = CefCookieManagerCppToC::Get(self)->VisitUrlCookies(
CefString(url),
includeHttpOnly?true:false,
CefCookieVisitorCToCpp::Wrap(visitor));
// Return type: bool
return _retval;
}
int CEF_CALLBACK cookie_manager_set_cookie(struct _cef_cookie_manager_t* self,
const cef_string_t* url, const struct _cef_cookie_t* cookie)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: url; type: string_byref_const
DCHECK(url);
if (!url)
return 0;
// Verify param: cookie; type: struct_byref_const
DCHECK(cookie);
if (!cookie)
return 0;
// Translate param: cookie; type: struct_byref_const
CefCookie cookieObj;
if (cookie)
cookieObj.Set(*cookie, false);
// Execute
bool _retval = CefCookieManagerCppToC::Get(self)->SetCookie(
CefString(url),
cookieObj);
// Return type: bool
return _retval;
}
int CEF_CALLBACK cookie_manager_delete_cookies(
struct _cef_cookie_manager_t* self, const cef_string_t* url,
const cef_string_t* cookie_name)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Unverified params: url, cookie_name
// Execute
bool _retval = CefCookieManagerCppToC::Get(self)->DeleteCookies(
CefString(url),
CefString(cookie_name));
// Return type: bool
return _retval;
}
int CEF_CALLBACK cookie_manager_set_storage_path(
struct _cef_cookie_manager_t* self, const cef_string_t* path)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Unverified params: path
// Execute
bool _retval = CefCookieManagerCppToC::Get(self)->SetStoragePath(
CefString(path));
// Return type: bool
return _retval;
}
// CONSTRUCTOR - Do not edit by hand.
CefCookieManagerCppToC::CefCookieManagerCppToC(CefCookieManager* cls)
: CefCppToC<CefCookieManagerCppToC, CefCookieManager, cef_cookie_manager_t>(
cls)
{
struct_.struct_.visit_all_cookies = cookie_manager_visit_all_cookies;
struct_.struct_.visit_url_cookies = cookie_manager_visit_url_cookies;
struct_.struct_.set_cookie = cookie_manager_set_cookie;
struct_.struct_.delete_cookies = cookie_manager_delete_cookies;
struct_.struct_.set_storage_path = cookie_manager_set_storage_path;
}
#ifndef NDEBUG
template<> long CefCppToC<CefCookieManagerCppToC, CefCookieManager,
cef_cookie_manager_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,37 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef _COOKIEMANAGER_CPPTOC_H
#define _COOKIEMANAGER_CPPTOC_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef.h"
#include "include/cef_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed DLL-side only.
class CefCookieManagerCppToC
: public CefCppToC<CefCookieManagerCppToC, CefCookieManager,
cef_cookie_manager_t>
{
public:
CefCookieManagerCppToC(CefCookieManager* cls);
virtual ~CefCookieManagerCppToC() {}
};
#endif // BUILDING_CEF_SHARED
#endif // _COOKIEMANAGER_CPPTOC_H

View File

@ -14,6 +14,7 @@
#include "libcef_dll/cpptoc/download_handler_cpptoc.h"
#include "libcef_dll/cpptoc/request_handler_cpptoc.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
#include "libcef_dll/ctocpp/frame_ctocpp.h"
#include "libcef_dll/ctocpp/request_ctocpp.h"
#include "libcef_dll/ctocpp/response_ctocpp.h"
@ -361,6 +362,29 @@ int CEF_CALLBACK request_handler_get_auth_credentials(
}
cef_cookie_manager_t* CEF_CALLBACK request_handler_get_cookie_manager(
struct _cef_request_handler_t* self, cef_browser_t* browser)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return NULL;
// Execute
CefRefPtr<CefCookieManager> _retval = CefRequestHandlerCppToC::Get(
self)->GetCookieManager(
CefBrowserCToCpp::Wrap(browser));
// Return type: refptr_diff
return CefCookieManagerCToCpp::Unwrap(_retval);
}
// CONSTRUCTOR - Do not edit by hand.
@ -376,6 +400,7 @@ CefRequestHandlerCppToC::CefRequestHandlerCppToC(CefRequestHandler* cls)
struct_.struct_.on_protocol_execution = request_handler_on_protocol_execution;
struct_.struct_.get_download_handler = request_handler_get_download_handler;
struct_.struct_.get_auth_credentials = request_handler_get_auth_credentials;
struct_.struct_.get_cookie_manager = request_handler_get_cookie_manager;
}
#ifndef NDEBUG

View File

@ -0,0 +1,166 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/cookie_visitor_cpptoc.h"
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
// STATIC METHODS - Body may be edited by hand.
CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager()
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_cookie_manager_t* _retval = cef_cookie_manager_get_global_manager();
// Return type: refptr_same
return CefCookieManagerCToCpp::Wrap(_retval);
}
CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
const CefString& path)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: path
// Execute
cef_cookie_manager_t* _retval = cef_cookie_manager_create_manager(
path.GetStruct());
// Return type: refptr_same
return CefCookieManagerCToCpp::Wrap(_retval);
}
// VIRTUAL METHODS - Body may be edited by hand.
bool CefCookieManagerCToCpp::VisitAllCookies(
CefRefPtr<CefCookieVisitor> visitor)
{
if (CEF_MEMBER_MISSING(struct_, visit_all_cookies))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: visitor; type: refptr_diff
DCHECK(visitor.get());
if (!visitor.get())
return false;
// Execute
int _retval = struct_->visit_all_cookies(struct_,
CefCookieVisitorCppToC::Wrap(visitor));
// Return type: bool
return _retval?true:false;
}
bool CefCookieManagerCToCpp::VisitUrlCookies(const CefString& url,
bool includeHttpOnly, CefRefPtr<CefCookieVisitor> visitor)
{
if (CEF_MEMBER_MISSING(struct_, visit_url_cookies))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: url; type: string_byref_const
DCHECK(!url.empty());
if (url.empty())
return false;
// Verify param: visitor; type: refptr_diff
DCHECK(visitor.get());
if (!visitor.get())
return false;
// Execute
int _retval = struct_->visit_url_cookies(struct_,
url.GetStruct(),
includeHttpOnly,
CefCookieVisitorCppToC::Wrap(visitor));
// Return type: bool
return _retval?true:false;
}
bool CefCookieManagerCToCpp::SetCookie(const CefString& url,
const CefCookie& cookie)
{
if (CEF_MEMBER_MISSING(struct_, set_cookie))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: url; type: string_byref_const
DCHECK(!url.empty());
if (url.empty())
return false;
// Execute
int _retval = struct_->set_cookie(struct_,
url.GetStruct(),
&cookie);
// Return type: bool
return _retval?true:false;
}
bool CefCookieManagerCToCpp::DeleteCookies(const CefString& url,
const CefString& cookie_name)
{
if (CEF_MEMBER_MISSING(struct_, delete_cookies))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: url, cookie_name
// Execute
int _retval = struct_->delete_cookies(struct_,
url.GetStruct(),
cookie_name.GetStruct());
// Return type: bool
return _retval?true:false;
}
bool CefCookieManagerCToCpp::SetStoragePath(const CefString& path)
{
if (CEF_MEMBER_MISSING(struct_, set_storage_path))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: path
// Execute
int _retval = struct_->set_storage_path(struct_,
path.GetStruct());
// Return type: bool
return _retval?true:false;
}
#ifndef NDEBUG
template<> long CefCToCpp<CefCookieManagerCToCpp, CefCookieManager,
cef_cookie_manager_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,49 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef _COOKIEMANAGER_CTOCPP_H
#define _COOKIEMANAGER_CTOCPP_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "include/cef.h"
#include "include/cef_capi.h"
#include "libcef_dll/ctocpp/ctocpp.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed wrapper-side only.
class CefCookieManagerCToCpp
: public CefCToCpp<CefCookieManagerCToCpp, CefCookieManager,
cef_cookie_manager_t>
{
public:
CefCookieManagerCToCpp(cef_cookie_manager_t* str)
: CefCToCpp<CefCookieManagerCToCpp, CefCookieManager,
cef_cookie_manager_t>(str) {}
virtual ~CefCookieManagerCToCpp() {}
// CefCookieManager methods
virtual bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) OVERRIDE;
virtual bool VisitUrlCookies(const CefString& url, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) OVERRIDE;
virtual bool SetCookie(const CefString& url,
const CefCookie& cookie) OVERRIDE;
virtual bool DeleteCookies(const CefString& url,
const CefString& cookie_name) OVERRIDE;
virtual bool SetStoragePath(const CefString& path) OVERRIDE;
};
#endif // USING_CEF_SHARED
#endif // _COOKIEMANAGER_CTOCPP_H

View File

@ -11,6 +11,7 @@
//
#include "libcef_dll/cpptoc/browser_cpptoc.h"
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
#include "libcef_dll/cpptoc/frame_cpptoc.h"
#include "libcef_dll/cpptoc/request_cpptoc.h"
#include "libcef_dll/cpptoc/response_cpptoc.h"
@ -303,6 +304,28 @@ bool CefRequestHandlerCToCpp::GetAuthCredentials(CefRefPtr<CefBrowser> browser,
}
CefRefPtr<CefCookieManager> CefRequestHandlerCToCpp::GetCookieManager(
CefRefPtr<CefBrowser> browser)
{
if (CEF_MEMBER_MISSING(struct_, get_cookie_manager))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return NULL;
// Execute
cef_cookie_manager_t* _retval = struct_->get_cookie_manager(struct_,
CefBrowserCppToC::Wrap(browser));
// Return type: refptr_diff
return CefCookieManagerCppToC::Unwrap(_retval);
}
#ifndef NDEBUG
template<> long CefCToCpp<CefRequestHandlerCToCpp, CefRequestHandler,

View File

@ -55,6 +55,8 @@ public:
const CefString& host, int port, const CefString& realm,
const CefString& scheme, CefString& username,
CefString& password) OVERRIDE;
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser) OVERRIDE;
};
#endif // BUILDING_CEF_SHARED

View File

@ -11,6 +11,7 @@
//
#include "libcef_dll/cpptoc/browser_cpptoc.h"
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
#include "libcef_dll/cpptoc/domdocument_cpptoc.h"
#include "libcef_dll/cpptoc/domevent_cpptoc.h"
#include "libcef_dll/cpptoc/domnode_cpptoc.h"
@ -100,6 +101,7 @@ CEF_EXPORT void cef_shutdown()
// Check that all wrapper objects have been destroyed
DCHECK(CefBrowserCppToC::DebugObjCt == 0);
DCHECK(CefContentFilterCToCpp::DebugObjCt == 0);
DCHECK(CefCookieManagerCppToC::DebugObjCt == 0);
DCHECK(CefCookieVisitorCToCpp::DebugObjCt == 0);
DCHECK(CefDOMDocumentCppToC::DebugObjCt == 0);
DCHECK(CefDOMEventCppToC::DebugObjCt == 0);
@ -451,110 +453,6 @@ CEF_EXPORT int cef_create_url(const struct _cef_urlparts_t* parts,
}
CEF_EXPORT int cef_visit_all_cookies(struct _cef_cookie_visitor_t* visitor)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: visitor; type: refptr_diff
DCHECK(visitor);
if (!visitor)
return 0;
// Execute
bool _retval = CefVisitAllCookies(
CefCookieVisitorCToCpp::Wrap(visitor));
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_visit_url_cookies(const cef_string_t* url,
int includeHttpOnly, struct _cef_cookie_visitor_t* visitor)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: url; type: string_byref_const
DCHECK(url);
if (!url)
return 0;
// Verify param: visitor; type: refptr_diff
DCHECK(visitor);
if (!visitor)
return 0;
// Execute
bool _retval = CefVisitUrlCookies(
CefString(url),
includeHttpOnly?true:false,
CefCookieVisitorCToCpp::Wrap(visitor));
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_set_cookie(const cef_string_t* url,
const struct _cef_cookie_t* cookie)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: url; type: string_byref_const
DCHECK(url);
if (!url)
return 0;
// Verify param: cookie; type: struct_byref_const
DCHECK(cookie);
if (!cookie)
return 0;
// Translate param: cookie; type: struct_byref_const
CefCookie cookieObj;
if (cookie)
cookieObj.Set(*cookie, false);
// Execute
bool _retval = CefSetCookie(
CefString(url),
cookieObj);
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_delete_cookies(const cef_string_t* url,
const cef_string_t* cookie_name)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: url, cookie_name
// Execute
bool _retval = CefDeleteCookies(
CefString(url),
CefString(cookie_name));
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_set_cookie_path(const cef_string_t* path)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: path
// Execute
bool _retval = CefSetCookiePath(
CefString(path));
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_visit_storage(enum cef_storage_type_t type,
const cef_string_t* origin, const cef_string_t* key,
struct _cef_storage_visitor_t* visitor)

View File

@ -42,6 +42,7 @@
#include "libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h"
#include "libcef_dll/cpptoc/write_handler_cpptoc.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
#include "libcef_dll/ctocpp/domdocument_ctocpp.h"
#include "libcef_dll/ctocpp/domevent_ctocpp.h"
#include "libcef_dll/ctocpp/domnode_ctocpp.h"
@ -102,6 +103,7 @@ CEF_GLOBAL void CefShutdown()
// Check that all wrapper objects have been destroyed
DCHECK(CefBrowserCToCpp::DebugObjCt == 0);
DCHECK(CefContentFilterCppToC::DebugObjCt == 0);
DCHECK(CefCookieManagerCToCpp::DebugObjCt == 0);
DCHECK(CefCookieVisitorCppToC::DebugObjCt == 0);
DCHECK(CefDOMDocumentCToCpp::DebugObjCt == 0);
DCHECK(CefDOMEventCToCpp::DebugObjCt == 0);
@ -421,100 +423,6 @@ CEF_GLOBAL bool CefCreateURL(const CefURLParts& parts, CefString& url)
}
CEF_GLOBAL bool CefVisitAllCookies(CefRefPtr<CefCookieVisitor> visitor)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: visitor; type: refptr_diff
DCHECK(visitor.get());
if (!visitor.get())
return false;
// Execute
int _retval = cef_visit_all_cookies(
CefCookieVisitorCppToC::Wrap(visitor));
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefVisitUrlCookies(const CefString& url, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: url; type: string_byref_const
DCHECK(!url.empty());
if (url.empty())
return false;
// Verify param: visitor; type: refptr_diff
DCHECK(visitor.get());
if (!visitor.get())
return false;
// Execute
int _retval = cef_visit_url_cookies(
url.GetStruct(),
includeHttpOnly,
CefCookieVisitorCppToC::Wrap(visitor));
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefSetCookie(const CefString& url, const CefCookie& cookie)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: url; type: string_byref_const
DCHECK(!url.empty());
if (url.empty())
return false;
// Execute
int _retval = cef_set_cookie(
url.GetStruct(),
&cookie);
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefDeleteCookies(const CefString& url,
const CefString& cookie_name)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: url, cookie_name
// Execute
int _retval = cef_delete_cookies(
url.GetStruct(),
cookie_name.GetStruct());
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefSetCookiePath(const CefString& path)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: path
// Execute
int _retval = cef_set_cookie_path(
path.GetStruct());
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefVisitStorage(CefStorageType type, const CefString& origin,
const CefString& key, CefRefPtr<CefStorageVisitor> visitor)
{

View File

@ -1,14 +1,15 @@
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "base/scoped_temp_dir.h"
#include "base/synchronization/waitable_event.h"
#include <vector>
#include "include/cef.h"
#include "include/cef_runnable.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_handler.h"
#include "test_suite.h"
#include <vector>
#include "base/scoped_temp_dir.h"
#include "base/synchronization/waitable_event.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@ -18,38 +19,36 @@ const char* kTestPath = "/path/to/cookietest";
typedef std::vector<CefCookie> CookieVector;
void IOT_Set(const CefString& url, CookieVector* cookies,
base::WaitableEvent* event)
{
void IOT_Set(CefRefPtr<CefCookieManager> manager,
const CefString& url, CookieVector* cookies,
base::WaitableEvent* event) {
CookieVector::const_iterator it = cookies->begin();
for (; it != cookies->end(); ++it)
EXPECT_TRUE(CefSetCookie(url, *it));
EXPECT_TRUE(manager->SetCookie(url, *it));
event->Signal();
}
void IOT_Delete(const CefString& url, const CefString& cookie_name,
base::WaitableEvent* event)
{
EXPECT_TRUE(CefDeleteCookies(url, cookie_name));
void IOT_Delete(CefRefPtr<CefCookieManager> manager,
const CefString& url, const CefString& cookie_name,
base::WaitableEvent* event) {
EXPECT_TRUE(manager->DeleteCookies(url, cookie_name));
event->Signal();
}
class TestVisitor : public CefCookieVisitor
{
public:
class TestVisitor : public CefCookieVisitor {
public:
TestVisitor(CookieVector* cookies, bool deleteCookies,
base::WaitableEvent* event)
: cookies_(cookies), delete_cookies_(deleteCookies), event_(event)
{
: cookies_(cookies),
delete_cookies_(deleteCookies),
event_(event) {
}
virtual ~TestVisitor()
{
virtual ~TestVisitor() {
event_->Signal();
}
virtual bool Visit(const CefCookie& cookie, int count, int total,
bool& deleteCookie)
{
bool& deleteCookie) {
cookies_->push_back(cookie);
if (delete_cookies_)
deleteCookie = true;
@ -63,11 +62,29 @@ public:
IMPLEMENT_REFCOUNTING(TestVisitor);
};
// Set the cookies.
void SetCookies(CefRefPtr<CefCookieManager> manager,
const CefString& url, CookieVector& cookies,
base::WaitableEvent& event) {
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Set, manager, url,
&cookies, &event));
event.Wait();
}
// Delete the cookie.
void DeleteCookies(CefRefPtr<CefCookieManager> manager,
const CefString& url, const CefString& cookie_name,
base::WaitableEvent& event) {
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, manager, url,
cookie_name, &event));
event.Wait();
}
// Create a test cookie. If |withDomain| is true a domain cookie will be
// created, otherwise a host cookie will be created.
void CreateCookie(CefCookie& cookie, bool withDomain,
base::WaitableEvent& event)
{
void CreateCookie(CefRefPtr<CefCookieManager> manager,
CefCookie& cookie, bool withDomain,
base::WaitableEvent& event) {
CefString(&cookie.name).FromASCII("my_cookie");
CefString(&cookie.value).FromASCII("My Value");
if (withDomain)
@ -83,28 +100,25 @@ void CreateCookie(CefCookie& cookie, bool withDomain,
CookieVector cookies;
cookies.push_back(cookie);
// Set the cookie.
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Set, kTestUrl, &cookies,
&event));
event.Wait();
SetCookies(manager, kTestUrl, cookies, event);
}
// Retrieve the test cookie. If |withDomain| is true check that the cookie
// is a domain cookie, otherwise a host cookie. if |deleteCookies| is true
// the cookie will be deleted when it's retrieved.
void GetCookie(const CefCookie& cookie, bool withDomain,
base::WaitableEvent& event, bool deleteCookies)
{
void GetCookie(CefRefPtr<CefCookieManager> manager,
const CefCookie& cookie, bool withDomain,
base::WaitableEvent& event, bool deleteCookies) {
CookieVector cookies;
// Get the cookie and delete it.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
EXPECT_TRUE(manager->VisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, deleteCookies, &event)));
event.Wait();
EXPECT_EQ((CookieVector::size_type)1, cookies.size());
const CefCookie& cookie_read = cookies[0];
EXPECT_EQ(CefString(&cookie_read.name), "my_cookie");
EXPECT_EQ(CefString(&cookie_read.value), "My Value");
@ -126,18 +140,41 @@ void GetCookie(const CefCookie& cookie, bool withDomain,
EXPECT_EQ(cookie.expires.millisecond, cookie_read.expires.millisecond);
}
// Visit URL cookies.
void VisitUrlCookies(CefRefPtr<CefCookieManager> manager,
const CefString& url,
bool includeHttpOnly,
CookieVector& cookies,
bool deleteCookies,
base::WaitableEvent& event) {
EXPECT_TRUE(manager->VisitUrlCookies(url, includeHttpOnly,
new TestVisitor(&cookies, deleteCookies, &event)));
event.Wait();
}
// Visit all cookies.
void VisitAllCookies(CefRefPtr<CefCookieManager> manager,
CookieVector& cookies,
bool deleteCookies,
base::WaitableEvent& event) {
EXPECT_TRUE(manager->VisitAllCookies(
new TestVisitor(&cookies, deleteCookies, &event)));
event.Wait();
}
// Verify that no cookies exist. If |withUrl| is true it will only check for
// cookies matching the URL.
void VerifyNoCookies(base::WaitableEvent& event, bool withUrl)
{
void VerifyNoCookies(CefRefPtr<CefCookieManager> manager,
base::WaitableEvent& event, bool withUrl) {
CookieVector cookies;
// Verify that the cookie has been deleted.
if (withUrl) {
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
EXPECT_TRUE(manager->VisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, false, &event)));
} else {
EXPECT_TRUE(CefVisitAllCookies(new TestVisitor(&cookies, false, &event)));
EXPECT_TRUE(manager->VisitAllCookies(
new TestVisitor(&cookies, false, &event)));
}
event.Wait();
@ -145,50 +182,42 @@ void VerifyNoCookies(base::WaitableEvent& event, bool withUrl)
}
// Delete all system cookies.
void DeleteAllCookies(base::WaitableEvent& event)
{
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, CefString(),
void DeleteAllCookies(CefRefPtr<CefCookieManager> manager,
base::WaitableEvent& event) {
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, manager, CefString(),
CefString(), &event));
event.Wait();
}
} // anonymous
// Test creation of a domain cookie.
TEST(CookieTest, DomainCookie)
{
void TestDomainCookie(CefRefPtr<CefCookieManager> manager) {
base::WaitableEvent event(false, false);
CefCookie cookie;
// Create a domain cookie.
CreateCookie(cookie, true, event);
CreateCookie(manager, cookie, true, event);
// Retrieve, verify and delete the domain cookie.
GetCookie(cookie, true, event, true);
GetCookie(manager, cookie, true, event, true);
// Verify that the cookie was deleted.
VerifyNoCookies(event, true);
VerifyNoCookies(manager, event, true);
}
// Test creation of a host cookie.
TEST(CookieTest, HostCookie)
{
void TestHostCookie(CefRefPtr<CefCookieManager> manager) {
base::WaitableEvent event(false, false);
CefCookie cookie;
// Create a host cookie.
CreateCookie(cookie, false, event);
CreateCookie(manager, cookie, false, event);
// Retrieve, verify and delete the host cookie.
GetCookie(cookie, false, event, true);
GetCookie(manager, cookie, false, event, true);
// Verify that the cookie was deleted.
VerifyNoCookies(event, true);
VerifyNoCookies(manager, event, true);
}
// Test creation of multiple cookies.
TEST(CookieTest, MultipleCookies)
{
void TestMultipleCookies(CefRefPtr<CefCookieManager> manager) {
base::WaitableEvent event(false, false);
std::stringstream ss;
int i;
@ -196,9 +225,9 @@ TEST(CookieTest, MultipleCookies)
CookieVector cookies;
const int kNumCookies = 4;
// Create the cookies.
for(i = 0; i < kNumCookies; i++) {
for (i = 0; i < kNumCookies; i++) {
CefCookie cookie;
ss << "my_cookie" << i;
@ -212,20 +241,16 @@ TEST(CookieTest, MultipleCookies)
}
// Set the cookies.
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Set, kTestUrl, &cookies,
&event));
event.Wait();
SetCookies(manager, kTestUrl, cookies, event);
cookies.clear();
// Get the cookies without deleting them.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, false, &event)));
event.Wait();
VisitUrlCookies(manager, kTestUrl, false, cookies, false, event);
EXPECT_EQ((CookieVector::size_type)kNumCookies, cookies.size());
CookieVector::const_iterator it = cookies.begin();
for(i = 0; it != cookies.end(); ++it, ++i) {
for (i = 0; it != cookies.end(); ++it, ++i) {
const CefCookie& cookie = *it;
ss << "my_cookie" << i;
@ -239,14 +264,10 @@ TEST(CookieTest, MultipleCookies)
cookies.clear();
// Delete the 2nd cookie.
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, kTestUrl,
CefString("my_cookie1"), &event));
event.Wait();
DeleteCookies(manager, kTestUrl, CefString("my_cookie1"), event);
// Verify that the cookie has been deleted.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, false, &event)));
event.Wait();
VisitUrlCookies(manager, kTestUrl, false, cookies, false, event);
EXPECT_EQ((CookieVector::size_type)3, cookies.size());
EXPECT_EQ(CefString(&cookies[0].name), "my_cookie0");
@ -256,19 +277,15 @@ TEST(CookieTest, MultipleCookies)
cookies.clear();
// Delete the rest of the cookies.
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, kTestUrl,
CefString(), &event));
event.Wait();
DeleteCookies(manager, kTestUrl, CefString(), event);
// Verify that the cookies have been deleted.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, false, &event)));
event.Wait();
VisitUrlCookies(manager, kTestUrl, false, cookies, false, event);
EXPECT_EQ((CookieVector::size_type)0, cookies.size());
// Create the cookies.
for(i = 0; i < kNumCookies; i++) {
for (i = 0; i < kNumCookies; i++) {
CefCookie cookie;
ss << "my_cookie" << i;
@ -282,34 +299,26 @@ TEST(CookieTest, MultipleCookies)
}
// Delete all of the cookies using the visitor.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, true, &event)));
event.Wait();
VisitUrlCookies(manager, kTestUrl, false, cookies, true, event);
cookies.clear();
// Verify that the cookies have been deleted.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, false, &event)));
event.Wait();
VisitUrlCookies(manager, kTestUrl, false, cookies, false, event);
EXPECT_EQ((CookieVector::size_type)0, cookies.size());
}
TEST(CookieTest, AllCookies)
{
void TestAllCookies(CefRefPtr<CefCookieManager> manager) {
base::WaitableEvent event(false, false);
CookieVector cookies;
// Delete all system cookies just in case something is left over from a
// different test.
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, CefString(),
CefString(), &event));
event.Wait();
DeleteCookies(manager, CefString(), CefString(), event);
// Verify that all system cookies have been deleted.
EXPECT_TRUE(CefVisitAllCookies(new TestVisitor(&cookies, false, &event)));
event.Wait();
VisitAllCookies(manager, cookies, false, event);
EXPECT_EQ((CookieVector::size_type)0, cookies.size());
@ -320,8 +329,7 @@ TEST(CookieTest, AllCookies)
CefString(&cookie1.value).FromASCII("My Value 1");
cookies.push_back(cookie1);
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Set, kUrl1, &cookies, &event));
event.Wait();
SetCookies(manager, kUrl1, cookies, event);
cookies.clear();
CefCookie cookie2;
@ -330,13 +338,11 @@ TEST(CookieTest, AllCookies)
CefString(&cookie2.value).FromASCII("My Value 2");
cookies.push_back(cookie2);
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Set, kUrl2, &cookies, &event));
event.Wait();
SetCookies(manager, kUrl2, cookies, event);
cookies.clear();
// Verify that all system cookies can be retrieved.
EXPECT_TRUE(CefVisitAllCookies(new TestVisitor(&cookies, false, &event)));
event.Wait();
VisitAllCookies(manager, cookies, false, event);
EXPECT_EQ((CookieVector::size_type)2, cookies.size());
EXPECT_EQ(CefString(&cookies[0].name), "my_cookie1");
@ -348,9 +354,7 @@ TEST(CookieTest, AllCookies)
cookies.clear();
// Verify that the cookies can be retrieved separately.
EXPECT_TRUE(CefVisitUrlCookies(kUrl1, false,
new TestVisitor(&cookies, false, &event)));
event.Wait();
VisitUrlCookies(manager, kUrl1, false, cookies, false, event);
EXPECT_EQ((CookieVector::size_type)1, cookies.size());
EXPECT_EQ(CefString(&cookies[0].name), "my_cookie1");
@ -358,9 +362,7 @@ TEST(CookieTest, AllCookies)
EXPECT_EQ(CefString(&cookies[0].domain), "www.foo.com");
cookies.clear();
EXPECT_TRUE(CefVisitUrlCookies(kUrl2, false,
new TestVisitor(&cookies, false, &event)));
event.Wait();
VisitUrlCookies(manager, kUrl2, false, cookies, false, event);
EXPECT_EQ((CookieVector::size_type)1, cookies.size());
EXPECT_EQ(CefString(&cookies[0].name), "my_cookie2");
@ -369,52 +371,314 @@ TEST(CookieTest, AllCookies)
cookies.clear();
// Delete all of the system cookies.
DeleteAllCookies(event);
DeleteAllCookies(manager, event);
// Verify that all system cookies have been deleted.
VerifyNoCookies(event, false);
VerifyNoCookies(manager, event, false);
}
TEST(CookieTest, ChangeDirectory)
{
void TestChangeDirectory(CefRefPtr<CefCookieManager> manager,
const CefString& original_dir) {
base::WaitableEvent event(false, false);
CefCookie cookie;
std::string cache_path;
CefTestSuite::GetCachePath(cache_path);
ScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
// Delete all of the system cookies.
DeleteAllCookies(event);
DeleteAllCookies(manager, event);
// Set the new temporary directory as the storage location.
EXPECT_TRUE(CefSetCookiePath(temp_dir.path().value()));
EXPECT_TRUE(manager->SetStoragePath(temp_dir.path().value()));
// Wait for the storage location change to complete on the IO thread.
WaitForIOThread();
// Verify that no cookies exist.
VerifyNoCookies(event, true);
VerifyNoCookies(manager, event, true);
// Create a domain cookie.
CreateCookie(cookie, true, event);
CreateCookie(manager, cookie, true, event);
// Retrieve and verify the domain cookie.
GetCookie(cookie, true, event, false);
GetCookie(manager, cookie, true, event, false);
// Restore the original storage location.
EXPECT_TRUE(CefSetCookiePath(cache_path));
EXPECT_TRUE(manager->SetStoragePath(original_dir));
// Wait for the storage location change to complete on the IO thread.
WaitForIOThread();
// Verify that no cookies exist.
VerifyNoCookies(event, true);
VerifyNoCookies(manager, event, true);
// Set the new temporary directory as the storage location.
EXPECT_TRUE(CefSetCookiePath(temp_dir.path().value()));
EXPECT_TRUE(manager->SetStoragePath(temp_dir.path().value()));
// Wait for the storage location change to complete on the IO thread.
WaitForIOThread();
// Retrieve and verify the domain cookie that was set previously.
GetCookie(cookie, true, event, false);
GetCookie(manager, cookie, true, event, false);
// Restore the original storage location.
EXPECT_TRUE(CefSetCookiePath(cache_path));
EXPECT_TRUE(manager->SetStoragePath(original_dir));
// Wait for the storage location change to complete on the IO thread.
WaitForIOThread();
}
} // namespace
// Test creation of a domain cookie.
TEST(CookieTest, DomainCookieGlobal) {
CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager();
EXPECT_TRUE(manager.get());
TestDomainCookie(manager);
}
// Test creation of a domain cookie.
TEST(CookieTest, DomainCookieInMemory) {
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(CefString());
EXPECT_TRUE(manager.get());
TestDomainCookie(manager);
}
// Test creation of a domain cookie.
TEST(CookieTest, DomainCookieOnDisk) {
ScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(temp_dir.path().value());
EXPECT_TRUE(manager.get());
TestDomainCookie(manager);
}
// Test creation of a host cookie.
TEST(CookieTest, HostCookieGlobal) {
CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager();
EXPECT_TRUE(manager.get());
TestHostCookie(manager);
}
// Test creation of a host cookie.
TEST(CookieTest, HostCookieInMemory) {
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(CefString());
EXPECT_TRUE(manager.get());
TestHostCookie(manager);
}
// Test creation of a host cookie.
TEST(CookieTest, HostCookieOnDisk) {
ScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(temp_dir.path().value());
EXPECT_TRUE(manager.get());
TestHostCookie(manager);
}
// Test creation of multiple cookies.
TEST(CookieTest, MultipleCookiesGlobal) {
CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager();
EXPECT_TRUE(manager.get());
TestMultipleCookies(manager);
}
// Test creation of multiple cookies.
TEST(CookieTest, MultipleCookiesInMemory) {
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(CefString());
EXPECT_TRUE(manager.get());
TestMultipleCookies(manager);
}
// Test creation of multiple cookies.
TEST(CookieTest, MultipleCookiesOnDisk) {
ScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(temp_dir.path().value());
EXPECT_TRUE(manager.get());
TestMultipleCookies(manager);
}
TEST(CookieTest, AllCookiesGlobal) {
CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager();
EXPECT_TRUE(manager.get());
TestAllCookies(manager);
}
TEST(CookieTest, AllCookiesInMemory) {
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(CefString());
EXPECT_TRUE(manager.get());
TestAllCookies(manager);
}
TEST(CookieTest, AllCookiesOnDisk) {
ScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(temp_dir.path().value());
EXPECT_TRUE(manager.get());
TestAllCookies(manager);
}
TEST(CookieTest, ChangeDirectoryGlobal) {
CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager();
EXPECT_TRUE(manager.get());
std::string cache_path;
CefTestSuite::GetCachePath(cache_path);
TestChangeDirectory(manager, cache_path);
}
TEST(CookieTest, ChangeDirectoryCreated) {
CefRefPtr<CefCookieManager> manager =
CefCookieManager::CreateManager(CefString());
EXPECT_TRUE(manager.get());
TestChangeDirectory(manager, CefString());
}
namespace {
const char* kCookieUrl1 = "http://tests/cookie1.html";
const char* kCookieUrl2 = "http://tests/cookie2.html";
class CookieTestHandler : public TestHandler {
public:
CookieTestHandler() {}
virtual void RunTest() OVERRIDE {
// Create =new in-memory managers.
manager1_ = CefCookieManager::CreateManager(CefString());
manager2_ = CefCookieManager::CreateManager(CefString());
std::string page =
"<html><head>"
"<script>"
"document.cookie='name1=value1';"
"</script>"
"</head><body>COOKIE TEST1</body></html>";
AddResource(kCookieUrl1, page, "text/html");
page =
"<html><head>"
"<script>"
"document.cookie='name2=value2';"
"</script>"
"</head><body>COOKIE TEST2</body></html>";
AddResource(kCookieUrl2, page, "text/html");
// Create the browser
CreateBrowser(kCookieUrl1);
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
std::string url = frame->GetURL();
if (url == kCookieUrl1) {
got_load_end1_.yes();
VerifyCookie(manager1_, url, "name1", "value1", got_cookie1_);
// Go to the next URL
frame->LoadURL(kCookieUrl2);
} else {
got_load_end2_.yes();
VerifyCookie(manager2_, url, "name2", "value2", got_cookie2_);
DestroyTest();
}
}
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser) OVERRIDE {
std::string url = browser->GetMainFrame()->GetURL();
if (url == kCookieUrl1) {
// Return the first cookie manager.
got_cookie_manager1_.yes();
return manager1_;
} else {
// Return the second cookie manager.
got_cookie_manager2_.yes();
return manager2_;
}
}
// Verify that the cookie was set successfully.
void VerifyCookie(CefRefPtr<CefCookieManager> manager,
const std::string& url,
const std::string& name,
const std::string& value,
TrackCallback& callback) {
base::WaitableEvent event(false, false);
CookieVector cookies;
// Get the cookie.
VisitUrlCookies(manager, url, false, cookies, false, event);
if (cookies.size() == 1 && CefString(&cookies[0].name) == name &&
CefString(&cookies[0].value) == value) {
callback.yes();
}
}
CefRefPtr<CefCookieManager> manager1_;
CefRefPtr<CefCookieManager> manager2_;
TrackCallback got_cookie_manager1_;
TrackCallback got_cookie_manager2_;
TrackCallback got_load_end1_;
TrackCallback got_load_end2_;
TrackCallback got_cookie1_;
TrackCallback got_cookie2_;
};
} // namespace
// Verify use of multiple cookie managers.
TEST(CookieTest, GetCookieManager) {
CefRefPtr<CookieTestHandler> handler = new CookieTestHandler();
handler->ExecuteTest();
EXPECT_TRUE(handler->got_cookie_manager1_);
EXPECT_TRUE(handler->got_cookie_manager2_);
EXPECT_TRUE(handler->got_load_end1_);
EXPECT_TRUE(handler->got_load_end2_);
EXPECT_TRUE(handler->got_cookie1_);
EXPECT_TRUE(handler->got_cookie2_);
}