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"
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class NullCookieChangeDispatcher : public net::CookieChangeDispatcher {
|
|
|
|
public:
|
|
|
|
NullCookieChangeDispatcher() {}
|
|
|
|
~NullCookieChangeDispatcher() override {}
|
|
|
|
|
|
|
|
// net::CookieChangeDispatcher
|
|
|
|
std::unique_ptr<net::CookieChangeSubscription> AddCallbackForCookie(
|
|
|
|
const GURL& url,
|
|
|
|
const std::string& name,
|
2018-04-19 17:44:42 +02:00
|
|
|
net::CookieChangeCallback callback) override {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<net::CookieChangeSubscription> AddCallbackForUrl(
|
|
|
|
const GURL& url,
|
|
|
|
net::CookieChangeCallback callback) override {
|
2018-03-20 21:15:08 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<net::CookieChangeSubscription> AddCallbackForAllChanges(
|
2018-04-19 17:44:42 +02:00
|
|
|
net::CookieChangeCallback callback) override {
|
2018-03-20 21:15:08 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(NullCookieChangeDispatcher);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
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));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run(false);
|
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));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run(false);
|
2016-02-05 01:49:19 +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();
|
2018-03-15 02:40:37 +01:00
|
|
|
if (cookie_store) {
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->GetCookieListWithOptionsAsync(url, options,
|
|
|
|
std::move(callback));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run(net::CookieList());
|
|
|
|
}
|
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();
|
2018-03-15 02:40:37 +01:00
|
|
|
if (cookie_store) {
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->GetAllCookiesAsync(std::move(callback));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run(net::CookieList());
|
|
|
|
}
|
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();
|
2018-03-15 02:40:37 +01:00
|
|
|
if (cookie_store) {
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->DeleteCookieAsync(url, cookie_name, std::move(callback));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run();
|
|
|
|
}
|
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();
|
2018-03-15 02:40:37 +01:00
|
|
|
if (cookie_store) {
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->DeleteCanonicalCookieAsync(cookie, std::move(callback));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run(0);
|
|
|
|
}
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2018-05-16 11:28:49 +02:00
|
|
|
void CefCookieStoreProxy::DeleteAllCreatedInTimeRangeAsync(
|
2018-05-20 15:51:42 +02:00
|
|
|
const net::CookieDeletionInfo::TimeRange& creation_range,
|
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) {
|
2018-05-16 11:28:49 +02:00
|
|
|
cookie_store->DeleteAllCreatedInTimeRangeAsync(creation_range,
|
|
|
|
std::move(callback));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run(0);
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-16 11:28:49 +02:00
|
|
|
void CefCookieStoreProxy::DeleteAllMatchingInfoAsync(
|
2018-05-20 15:51:42 +02:00
|
|
|
net::CookieDeletionInfo delete_info,
|
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) {
|
2018-05-16 11:28:49 +02:00
|
|
|
cookie_store->DeleteAllMatchingInfoAsync(delete_info, std::move(callback));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run(0);
|
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();
|
2018-03-15 02:40:37 +01:00
|
|
|
if (cookie_store) {
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->DeleteSessionCookiesAsync(std::move(callback));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run(0);
|
|
|
|
}
|
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();
|
2018-03-15 02:40:37 +01:00
|
|
|
if (cookie_store) {
|
2017-07-27 01:19:27 +02:00
|
|
|
cookie_store->FlushStore(std::move(callback));
|
2018-03-15 02:40:37 +01:00
|
|
|
} else if (!callback.is_null()) {
|
|
|
|
std::move(callback).Run();
|
|
|
|
}
|
2016-02-05 01:49:19 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
net::CookieChangeDispatcher& CefCookieStoreProxy::GetChangeDispatcher() {
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore* cookie_store = GetCookieStore();
|
2018-03-20 21:15:08 +01:00
|
|
|
if (cookie_store)
|
|
|
|
return cookie_store->GetChangeDispatcher();
|
2017-09-06 23:40:58 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
if (!null_dispatcher_)
|
|
|
|
null_dispatcher_.reset(new NullCookieChangeDispatcher());
|
|
|
|
return *null_dispatcher_;
|
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();
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefCookieManager> manager = handler_->GetCookieManager();
|
|
|
|
if (manager.get()) {
|
2018-03-15 02:40:37 +01:00
|
|
|
// Use the cookie store provided by the manager. May be nullptr if the
|
|
|
|
// cookie manager is blocking.
|
|
|
|
return reinterpret_cast<CefCookieManagerImpl*>(manager.get())
|
|
|
|
->GetExistingCookieStore();
|
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.
|
2018-03-15 02:40:37 +01:00
|
|
|
net::CookieStore* 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";
|
2018-03-15 02:40:37 +01:00
|
|
|
return cookie_store;
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2018-03-15 02:40:37 +01:00
|
|
|
return nullptr;
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|