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

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@534 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2012-03-15 22:38:02 +00:00
parent 97d6924f7e
commit ef43df264a
24 changed files with 1324 additions and 576 deletions

View File

@@ -51,13 +51,11 @@
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/synchronization/waitable_event.h"
#include "base/time.h"
#include "base/timer.h"
#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"
@@ -1113,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
//-----------------------------------------------------------------------------
@@ -1182,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

@@ -19,14 +19,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 "libcef/browser_webcookiejar_impl.h"
#include "libcef/browser_resource_loader_bridge.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,4 +1,5 @@
// 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.
@@ -6,18 +7,25 @@
#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 // CEF_LIBCEF_BROWSER_WEBCOOKIEJAR_IMPL_H_

View File

@@ -510,7 +510,7 @@ bool BrowserWebViewDelegate::allowScriptExtension(
// WebPluginPageDelegate -----------------------------------------------------
WebCookieJar* BrowserWebViewDelegate::GetCookieJar() {
return WebKit::webKitPlatformSupport()->cookieJar();
return &cookie_jar_;
}
// WebWidgetClient -----------------------------------------------------------
@@ -688,6 +688,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);
}
@@ -1007,7 +1011,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

@@ -16,6 +16,7 @@
#include <vector>
#include "libcef/browser_navigation_controller.h"
#include "libcef/browser_webcookiejar_impl.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
@@ -157,6 +158,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&,
@@ -384,6 +386,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

@@ -1,32 +1,33 @@
// 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 "include/cef_cookie.h"
#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 "net/base/cookie_monster.h"
#include "base/logging.h"
namespace {
// Callback class for visiting cookies.
class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
public:
explicit VisitCookiesCallback(CefRefPtr<CefCookieVisitor> visitor)
: visitor_(visitor) {
explicit VisitCookiesCallback(net::CookieMonster* cookie_monster,
CefRefPtr<CefCookieVisitor> visitor)
: cookie_monster_(cookie_monster),
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();
@@ -49,7 +50,7 @@ class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
bool deleteCookie = false;
bool keepLooping = visitor_->Visit(cookie, count, total, deleteCookie);
if (deleteCookie) {
cookie_monster->DeleteCanonicalCookieAsync(cc,
cookie_monster_->DeleteCanonicalCookieAsync(cc,
net::CookieMonster::DeleteCookieCallback());
}
if (!keepLooping)
@@ -58,104 +59,78 @@ class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
}
private:
scoped_refptr<net::CookieMonster> cookie_monster_;
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);
}
} // namespace
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,
base::Bind(IOT_VisitAllCookies, visitor));
CefCookieManagerImpl::CefCookieManagerImpl()
: is_global_(true) {
cookie_monster_ =
static_cast<net::CookieMonster*>(
_Context->request_context()->cookie_store());
DCHECK(cookie_monster_);
}
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,
base::Bind(IOT_VisitUrlCookies, gurl, includeHttpOnly, visitor));
// Creates a new cookie monster with storage at the specified |path|.
CefCookieManagerImpl::CefCookieManagerImpl(const CefString& path)
:is_global_(false) {
SetStoragePath(path);
}
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;
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;
}
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);
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
return false;
@@ -168,65 +143,110 @@ bool CefSetCookie(const CefString& url, const CefCookie& cookie) {
if (cookie.has_expires)
cef_time_to_basetime(cookie.expires, expiration_time);
cookie_monster->SetCookieWithDetailsAsync(gurl, name, value, domain, path,
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;
}
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;
}
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());
cookie_monster_->DeleteAllAsync(net::CookieMonster::DeleteCallback());
return true;
}
std::string urlStr = url;
GURL gurl = GURL(urlStr);
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
return false;
if (cookie_name.empty()) {
// Delete all matching host cookies.
cookie_monster->DeleteAllForHostAsync(gurl,
cookie_monster_->DeleteAllForHostAsync(gurl,
net::CookieMonster::DeleteCallback());
} else {
// Delete all matching host and domain cookies.
cookie_monster->DeleteCookieAsync(gurl, cookie_name, base::Closure());
cookie_monster_->DeleteCookieAsync(gurl, cookie_name, base::Closure());
}
return true;
}
bool CefSetCookiePath(const CefString& path) {
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 false;
return NULL;
}
if (CefThread::CurrentlyOn(CefThread::IO)) {
IOT_SetCookiePath(path);
} else {
CefThread::PostTask(CefThread::IO, FROM_HERE,
base::Bind(&IOT_SetCookiePath, path));
}
return true;
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_cookie.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_