2012-04-03 03:34:16 +02:00
|
|
|
// 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/browser/cookie_manager_impl.h"
|
|
|
|
|
2012-08-04 02:59:58 +02:00
|
|
|
#include <set>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
2012-08-04 02:59:58 +02:00
|
|
|
#include <vector>
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "libcef/browser/browser_context.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/context.h"
|
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
#include "libcef/browser/url_request_context_getter.h"
|
|
|
|
#include "libcef/common/time_util.h"
|
|
|
|
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/file_util.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "base/format_macros.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/logging.h"
|
2012-05-18 17:04:56 +02:00
|
|
|
#include "base/threading/thread_restrictions.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "content/browser/net/sqlite_persistent_cookie_store.h"
|
2013-12-17 23:04:35 +01:00
|
|
|
#include "content/public/browser/cookie_crypto_delegate.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "net/cookies/cookie_util.h"
|
2012-08-04 02:59:58 +02:00
|
|
|
#include "net/cookies/parsed_cookie.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/url_request/url_request_context.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "url/gurl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-03-12 21:23:24 +01:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
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) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
int total = list.size(), count = 0;
|
|
|
|
|
|
|
|
net::CookieList::const_iterator it = list.begin();
|
|
|
|
for (; it != list.end(); ++it, ++count) {
|
|
|
|
CefCookie cookie;
|
2012-08-04 02:59:58 +02:00
|
|
|
const net::CanonicalCookie& cc = *(it);
|
2012-06-19 18:29:49 +02:00
|
|
|
CefCookieManagerImpl::GetCefCookie(cc, cookie);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
// Methods extracted from net/cookies/cookie_monster.cc
|
|
|
|
|
|
|
|
// Determine the cookie domain to use for setting the specified cookie.
|
|
|
|
bool GetCookieDomain(const GURL& url,
|
2012-08-04 02:59:58 +02:00
|
|
|
const net::ParsedCookie& pc,
|
2012-06-19 18:29:49 +02:00
|
|
|
std::string* result) {
|
|
|
|
std::string domain_string;
|
|
|
|
if (pc.HasDomain())
|
|
|
|
domain_string = pc.Domain();
|
|
|
|
return net::cookie_util::GetCookieDomainWithString(url, domain_string,
|
|
|
|
result);
|
|
|
|
}
|
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
void RunCompletionOnIOThread(CefRefPtr<CefCompletionCallback> callback) {
|
2013-02-13 20:53:41 +01:00
|
|
|
CEF_POST_TASK(CEF_IOT,
|
2014-02-05 21:35:45 +01:00
|
|
|
base::Bind(&CefCompletionCallback::OnComplete, callback.get()));
|
2013-02-13 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
CefCookieManagerImpl::CefCookieManagerImpl(bool is_global)
|
|
|
|
: is_global_(is_global) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CefCookieManagerImpl::~CefCookieManagerImpl() {
|
|
|
|
}
|
|
|
|
|
2013-02-13 20:53:41 +01:00
|
|
|
void CefCookieManagerImpl::Initialize(
|
|
|
|
const CefString& path,
|
|
|
|
bool persist_session_cookies) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (is_global_)
|
|
|
|
SetGlobal();
|
|
|
|
else
|
2013-02-13 20:53:41 +01:00
|
|
|
SetStoragePath(path, persist_session_cookies);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-04-04 00:14:28 +02:00
|
|
|
void CefCookieManagerImpl::SetSupportedSchemes(
|
|
|
|
const std::vector<CefString>& schemes) {
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!cookie_monster_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (is_global_) {
|
|
|
|
// Global changes are handled by the request context.
|
2013-02-23 01:43:28 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> getter =
|
2012-06-19 18:29:49 +02:00
|
|
|
static_cast<CefURLRequestContextGetter*>(
|
2013-09-03 18:43:31 +02:00
|
|
|
CefContentBrowserClient::Get()->request_context().get());
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
std::vector<std::string> scheme_vec;
|
|
|
|
std::vector<CefString>::const_iterator it = schemes.begin();
|
|
|
|
for (; it != schemes.end(); ++it)
|
|
|
|
scheme_vec.push_back(it->ToString());
|
|
|
|
|
|
|
|
getter->SetCookieSupportedSchemes(scheme_vec);
|
2012-04-04 00:14:28 +02:00
|
|
|
return;
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
supported_schemes_ = schemes;
|
|
|
|
|
|
|
|
if (supported_schemes_.empty()) {
|
|
|
|
supported_schemes_.push_back("http");
|
|
|
|
supported_schemes_.push_back("https");
|
|
|
|
}
|
2012-04-04 00:14:28 +02:00
|
|
|
|
|
|
|
std::set<std::string> scheme_set;
|
2012-06-19 18:29:49 +02:00
|
|
|
std::vector<CefString>::const_iterator it = supported_schemes_.begin();
|
|
|
|
for (; it != supported_schemes_.end(); ++it)
|
2012-04-04 00:14:28 +02:00
|
|
|
scheme_set.insert(*it);
|
|
|
|
|
|
|
|
const char** arr = new const char*[scheme_set.size()];
|
|
|
|
std::set<std::string>::const_iterator it2 = scheme_set.begin();
|
|
|
|
for (int i = 0; it2 != scheme_set.end(); ++it2, ++i)
|
|
|
|
arr[i] = it2->c_str();
|
|
|
|
|
|
|
|
cookie_monster_->SetCookieableSchemes(arr, scheme_set.size());
|
|
|
|
|
|
|
|
delete [] arr;
|
|
|
|
} else {
|
|
|
|
// Execute on the IO thread.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefCookieManagerImpl::SetSupportedSchemes,
|
|
|
|
this, schemes));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefCookieManagerImpl::VisitAllCookies(
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor) {
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!cookie_monster_)
|
|
|
|
return false;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
scoped_refptr<VisitCookiesCallback> callback(
|
|
|
|
new VisitCookiesCallback(cookie_monster_, visitor));
|
|
|
|
|
|
|
|
cookie_monster_->GetAllCookiesAsync(
|
|
|
|
base::Bind(&VisitCookiesCallback::Run, callback.get()));
|
|
|
|
} else {
|
|
|
|
// Execute on the IO thread.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::VisitAllCookies),
|
|
|
|
this, visitor));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::VisitUrlCookies(
|
|
|
|
const CefString& url, bool includeHttpOnly,
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor) {
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!cookie_monster_)
|
|
|
|
return false;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
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.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::VisitUrlCookies),
|
|
|
|
this, url, includeHttpOnly, visitor));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::SetCookie(const CefString& url,
|
|
|
|
const CefCookie& cookie) {
|
|
|
|
CEF_REQUIRE_IOT_RETURN(false);
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!cookie_monster_)
|
|
|
|
return false;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
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);
|
|
|
|
|
2014-01-06 20:59:48 +01:00
|
|
|
cookie_monster_->SetCookieWithDetailsAsync(
|
|
|
|
gurl, name, value, domain, path,
|
|
|
|
expiration_time,
|
|
|
|
cookie.secure ? true : false,
|
|
|
|
cookie.httponly ? true : false,
|
2013-05-07 23:48:34 +02:00
|
|
|
net::COOKIE_PRIORITY_DEFAULT,
|
2012-04-03 03:34:16 +02:00
|
|
|
net::CookieStore::SetCookiesCallback());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::DeleteCookies(const CefString& url,
|
|
|
|
const CefString& cookie_name) {
|
|
|
|
CEF_REQUIRE_IOT_RETURN(false);
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!cookie_monster_)
|
|
|
|
return false;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-13 20:53:41 +01:00
|
|
|
bool CefCookieManagerImpl::SetStoragePath(
|
|
|
|
const CefString& path,
|
|
|
|
bool persist_session_cookies) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath new_path;
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!path.empty())
|
2013-02-23 01:43:28 +01:00
|
|
|
new_path = base::FilePath(path);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (is_global_) {
|
|
|
|
// Global path changes are handled by the request context.
|
2013-02-23 01:43:28 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> getter =
|
2012-04-03 03:34:16 +02:00
|
|
|
static_cast<CefURLRequestContextGetter*>(
|
2013-09-03 18:43:31 +02:00
|
|
|
CefContentBrowserClient::Get()->request_context().get());
|
2013-02-13 20:53:41 +01:00
|
|
|
getter->SetCookieStoragePath(new_path, persist_session_cookies);
|
2012-04-03 03:34:16 +02:00
|
|
|
cookie_monster_ = getter->GetURLRequestContext()->cookie_store()->
|
|
|
|
GetCookieMonster();
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-04 02:59:58 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if (cookie_monster_ && ((storage_path_.empty() && path.empty()) ||
|
|
|
|
storage_path_ == new_path)) {
|
|
|
|
// The path has not changed so don't do anything.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-16 00:16:01 +02:00
|
|
|
scoped_refptr<content::SQLitePersistentCookieStore> persistent_store;
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!new_path.empty()) {
|
2012-05-18 17:04:56 +02:00
|
|
|
// TODO(cef): Move directory creation to the blocking pool instead of
|
|
|
|
// allowing file IO on this thread.
|
2012-05-18 22:32:28 +02:00
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
2013-07-24 22:15:18 +02:00
|
|
|
if (base::DirectoryExists(new_path) ||
|
2013-12-17 23:04:35 +01:00
|
|
|
base::CreateDirectory(new_path)) {
|
2013-02-23 01:43:28 +01:00
|
|
|
const base::FilePath& cookie_path = new_path.AppendASCII("Cookies");
|
2012-05-31 17:19:33 +02:00
|
|
|
persistent_store =
|
2013-04-16 00:16:01 +02:00
|
|
|
new content::SQLitePersistentCookieStore(
|
2013-03-12 21:23:24 +01:00
|
|
|
cookie_path,
|
|
|
|
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
|
|
|
|
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
|
|
|
|
persist_session_cookies,
|
2013-12-17 23:04:35 +01:00
|
|
|
NULL,
|
2014-02-05 21:35:45 +01:00
|
|
|
NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
} 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);
|
2013-02-13 20:53:41 +01:00
|
|
|
if (persistent_store.get() && persist_session_cookies)
|
|
|
|
cookie_monster_->SetPersistSessionCookies(true);
|
2012-04-03 03:34:16 +02:00
|
|
|
storage_path_ = new_path;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
// Restore the previously supported schemes.
|
|
|
|
SetSupportedSchemes(supported_schemes_);
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
// Execute on the IO thread.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::SetStoragePath),
|
2013-02-13 20:53:41 +01:00
|
|
|
this, path, persist_session_cookies));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
bool CefCookieManagerImpl::FlushStore(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2013-02-13 20:53:41 +01:00
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
|
|
|
if (!cookie_monster_) {
|
2014-02-05 21:35:45 +01:00
|
|
|
if (callback.get())
|
|
|
|
RunCompletionOnIOThread(callback);
|
2013-02-13 20:53:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
base::Closure flush_callback;
|
|
|
|
if (callback.get())
|
|
|
|
flush_callback = base::Bind(RunCompletionOnIOThread, callback);
|
2013-02-13 20:53:41 +01:00
|
|
|
else
|
2014-02-05 21:35:45 +01:00
|
|
|
flush_callback = base::Bind(&base::DoNothing);
|
2013-02-13 20:53:41 +01:00
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
cookie_monster_->FlushStore(flush_callback);
|
2013-02-13 20:53:41 +01:00
|
|
|
} else {
|
|
|
|
// Execute on the IO thread.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::FlushStore),
|
2014-02-05 21:35:45 +01:00
|
|
|
this, callback));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCookieManagerImpl::SetGlobal() {
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2013-09-03 18:43:31 +02:00
|
|
|
if (CefContentBrowserClient::Get()->request_context()) {
|
|
|
|
cookie_monster_ = CefContentBrowserClient::Get()->request_context()->
|
|
|
|
GetURLRequestContext()->cookie_store()->GetCookieMonster();
|
2012-06-19 18:29:49 +02:00
|
|
|
DCHECK(cookie_monster_);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
// Execute on the IO thread.
|
|
|
|
CEF_POST_TASK(CEF_IOT, base::Bind(&CefCookieManagerImpl::SetGlobal, this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// static
|
2012-08-04 02:59:58 +02:00
|
|
|
bool CefCookieManagerImpl::GetCefCookie(const net::CanonicalCookie& cc,
|
|
|
|
CefCookie& cookie) {
|
2012-06-19 18:29:49 +02:00
|
|
|
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);
|
2012-08-04 02:59:58 +02:00
|
|
|
cookie.has_expires = cc.IsPersistent();
|
2012-06-19 18:29:49 +02:00
|
|
|
if (cookie.has_expires)
|
|
|
|
cef_time_from_basetime(cc.ExpiryDate(), cookie.expires);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool CefCookieManagerImpl::GetCefCookie(const GURL& url,
|
|
|
|
const std::string& cookie_line,
|
|
|
|
CefCookie& cookie) {
|
|
|
|
// Parse the cookie.
|
2012-08-04 02:59:58 +02:00
|
|
|
net::ParsedCookie pc(cookie_line);
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!pc.IsValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string cookie_domain;
|
|
|
|
if (!GetCookieDomain(url, pc, &cookie_domain))
|
|
|
|
return false;
|
|
|
|
|
2012-08-04 02:59:58 +02:00
|
|
|
std::string cookie_path = net::CanonicalCookie::CanonPath(url, pc);
|
2012-06-19 18:29:49 +02:00
|
|
|
base::Time creation_time = base::Time::Now();
|
2012-08-04 02:59:58 +02:00
|
|
|
base::Time cookie_expires =
|
2012-11-05 21:18:20 +01:00
|
|
|
net::CanonicalCookie::CanonExpiration(pc, creation_time, creation_time);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
CefString(&cookie.name).FromString(pc.Name());
|
|
|
|
CefString(&cookie.value).FromString(pc.Value());
|
|
|
|
CefString(&cookie.domain).FromString(cookie_domain);
|
|
|
|
CefString(&cookie.path).FromString(cookie_path);
|
|
|
|
cookie.secure = pc.IsSecure();
|
|
|
|
cookie.httponly = pc.IsHttpOnly();
|
|
|
|
cef_time_from_basetime(creation_time, cookie.creation);
|
|
|
|
cef_time_from_basetime(creation_time, cookie.last_access);
|
|
|
|
cookie.has_expires = !cookie_expires.is_null();
|
|
|
|
if (cookie.has_expires)
|
|
|
|
cef_time_from_basetime(cookie_expires, cookie.expires);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefCookieManagerImpl> manager(new CefCookieManagerImpl(true));
|
2013-02-13 20:53:41 +01:00
|
|
|
manager->Initialize(CefString(), false);
|
2012-04-03 03:34:16 +02:00
|
|
|
return manager.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
|
2013-02-13 20:53:41 +01:00
|
|
|
const CefString& path,
|
|
|
|
bool persist_session_cookies) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefCookieManagerImpl> manager(new CefCookieManagerImpl(false));
|
2013-02-13 20:53:41 +01:00
|
|
|
manager->Initialize(path, persist_session_cookies);
|
2012-04-03 03:34:16 +02:00
|
|
|
return manager.get();
|
|
|
|
}
|