2015-02-14 00:17:08 +01:00
|
|
|
// Copyright (c) 2015 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.
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/cookie_store_proxy.h"
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/cookie_manager_impl.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/url_request_context_impl.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "net/url_request/url_request_context.h"
|
|
|
|
|
|
|
|
CefCookieStoreProxy::CefCookieStoreProxy(
|
|
|
|
CefURLRequestContextImpl* parent,
|
|
|
|
CefRefPtr<CefRequestContextHandler> handler)
|
2017-05-17 11:29:28 +02:00
|
|
|
: parent_(parent), handler_(handler) {
|
2015-02-14 00:17:08 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
2015-03-02 21:25:14 +01:00
|
|
|
DCHECK(parent_);
|
|
|
|
DCHECK(handler_.get());
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefCookieStoreProxy::~CefCookieStoreProxy() {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCookieStoreProxy::SetCookieWithOptionsAsync(
|
|
|
|
const GURL& url,
|
|
|
|
const std::string& cookie_line,
|
|
|
|
const net::CookieOptions& options,
|
2017-07-27 01:19:27 +02:00
|
|
|
SetCookiesCallback callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store) {
|
2015-02-14 00:17:08 +01:00
|
|
|
cookie_store->SetCookieWithOptionsAsync(url, cookie_line, options,
|
2017-07-27 01:19:27 +02:00
|
|
|
std::move(callback));
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
void CefCookieStoreProxy::SetCanonicalCookieAsync(
|
|
|
|
std::unique_ptr<net::CanonicalCookie> cookie,
|
|
|
|
bool secure_source,
|
|
|
|
bool modify_http_only,
|
|
|
|
SetCookiesCallback callback) {
|
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store) {
|
|
|
|
cookie_store->SetCanonicalCookieAsync(std::move(cookie), secure_source,
|
|
|
|
modify_http_only,
|
|
|
|
std::move(callback));
|
2016-02-05 01:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
void CefCookieStoreProxy::GetCookiesWithOptionsAsync(
|
2016-03-16 03:55:59 +01:00
|
|
|
const GURL& url,
|
|
|
|
const net::CookieOptions& options,
|
2017-07-27 01:19:27 +02:00
|
|
|
GetCookiesCallback callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->GetCookiesWithOptionsAsync(url, options, std::move(callback));
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
void CefCookieStoreProxy::GetCookieListWithOptionsAsync(
|
|
|
|
const GURL& url,
|
|
|
|
const net::CookieOptions& options,
|
2017-07-27 01:19:27 +02:00
|
|
|
GetCookieListCallback callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->GetCookieListWithOptionsAsync(url, options,
|
|
|
|
std::move(callback));
|
2016-03-16 03:55:59 +01:00
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
void CefCookieStoreProxy::GetAllCookiesAsync(GetCookieListCallback callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->GetAllCookiesAsync(std::move(callback));
|
2016-02-05 01:49:19 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefCookieStoreProxy::DeleteCookieAsync(const GURL& url,
|
|
|
|
const std::string& cookie_name,
|
2017-07-27 01:19:27 +02:00
|
|
|
base::OnceClosure callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->DeleteCookieAsync(url, cookie_name, std::move(callback));
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
void CefCookieStoreProxy::DeleteCanonicalCookieAsync(
|
|
|
|
const net::CanonicalCookie& cookie,
|
2017-07-27 01:19:27 +02:00
|
|
|
DeleteCallback callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->DeleteCanonicalCookieAsync(cookie, std::move(callback));
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefCookieStoreProxy::DeleteAllCreatedBetweenAsync(
|
|
|
|
const base::Time& delete_begin,
|
|
|
|
const base::Time& delete_end,
|
2017-07-27 01:19:27 +02:00
|
|
|
DeleteCallback callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store) {
|
2015-02-14 00:17:08 +01:00
|
|
|
cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
|
2017-07-27 01:19:27 +02:00
|
|
|
std::move(callback));
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
void CefCookieStoreProxy::DeleteAllCreatedBetweenWithPredicateAsync(
|
|
|
|
const base::Time& delete_begin,
|
|
|
|
const base::Time& delete_end,
|
|
|
|
const CookiePredicate& predicate,
|
2017-07-27 01:19:27 +02:00
|
|
|
DeleteCallback callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store) {
|
2016-05-25 01:35:43 +02:00
|
|
|
cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
|
2017-07-27 01:19:27 +02:00
|
|
|
delete_begin, delete_end, predicate, std::move(callback));
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
void CefCookieStoreProxy::DeleteSessionCookiesAsync(DeleteCallback callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->DeleteSessionCookiesAsync(std::move(callback));
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
void CefCookieStoreProxy::FlushStore(base::OnceClosure callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->FlushStore(std::move(callback));
|
2016-02-05 01:49:19 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::CookieStore::CookieChangedSubscription>
|
2015-02-14 00:17:08 +01:00
|
|
|
CefCookieStoreProxy::AddCallbackForCookie(
|
|
|
|
const GURL& url,
|
|
|
|
const std::string& name,
|
|
|
|
const CookieChangedCallback& callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
2015-02-14 00:17:08 +01:00
|
|
|
return cookie_store->AddCallbackForCookie(url, name, callback);
|
2017-09-06 23:40:58 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<net::CookieStore::CookieChangedSubscription>
|
|
|
|
CefCookieStoreProxy::AddCallbackForAllChanges(
|
|
|
|
const CookieChangedCallback& callback) {
|
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
|
|
|
return cookie_store->AddCallbackForAllChanges(callback);
|
|
|
|
return nullptr;
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
bool CefCookieStoreProxy::IsEphemeral() {
|
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
|
|
|
if (cookie_store)
|
|
|
|
return cookie_store->IsEphemeral();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
net::CookieStore* CefCookieStoreProxy::GetCookieStore() {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = nullptr;
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefCookieManager> manager = handler_->GetCookieManager();
|
|
|
|
if (manager.get()) {
|
|
|
|
// Use the cookie store provided by the manager.
|
2017-05-17 11:29:28 +02:00
|
|
|
cookie_store = reinterpret_cast<CefCookieManagerImpl*>(manager.get())
|
|
|
|
->GetExistingCookieStore();
|
2016-03-16 03:55:59 +01:00
|
|
|
DCHECK(cookie_store);
|
|
|
|
return cookie_store;
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(parent_);
|
|
|
|
if (parent_) {
|
2015-03-02 21:25:14 +01:00
|
|
|
// Use the cookie store from the parent.
|
2015-02-14 00:17:08 +01:00
|
|
|
cookie_store = parent_->cookie_store();
|
2016-03-16 03:55:59 +01:00
|
|
|
DCHECK(cookie_store);
|
|
|
|
if (!cookie_store)
|
|
|
|
LOG(ERROR) << "Cookie store does not exist";
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
return cookie_store;
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|