2019-03-25 19:14:23 +01:00
|
|
|
// Copyright (c) 2019 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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/net_service/cookie_manager_impl.h"
|
2019-03-25 19:14:23 +01:00
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/functional/bind.h"
|
2019-03-25 19:14:23 +01:00
|
|
|
#include "base/logging.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/net_service/net_service_util.h"
|
|
|
|
#include "cef/libcef/common/time_util.h"
|
2019-03-25 19:14:23 +01:00
|
|
|
#include "content/public/browser/browser_context.h"
|
|
|
|
#include "content/public/browser/storage_partition.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "services/network/public/mojom/cookie_manager.mojom.h"
|
2019-03-25 19:14:23 +01:00
|
|
|
#include "url/gurl.h"
|
|
|
|
|
|
|
|
using network::mojom::CookieManager;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-03-27 21:00:36 +01:00
|
|
|
// Do not keep a reference to the object returned by this method.
|
|
|
|
CefBrowserContext* GetBrowserContext(const CefBrowserContext::Getter& getter) {
|
2019-03-25 19:14:23 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2020-03-27 21:00:36 +01:00
|
|
|
DCHECK(!getter.is_null());
|
|
|
|
|
2022-01-10 22:11:16 +01:00
|
|
|
// Will return nullptr if the BrowserContext has been shut down.
|
2020-03-27 21:00:36 +01:00
|
|
|
return getter.Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not keep a reference to the object returned by this method.
|
|
|
|
CookieManager* GetCookieManager(CefBrowserContext* browser_context) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2021-06-04 03:34:56 +02:00
|
|
|
return browser_context->AsBrowserContext()
|
|
|
|
->GetDefaultStoragePartition()
|
2019-03-25 19:14:23 +01:00
|
|
|
->GetCookieManagerForBrowserProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always execute the callback asynchronously.
|
2019-03-25 19:35:51 +01:00
|
|
|
void RunAsyncCompletionOnUIThread(CefRefPtr<CefCompletionCallback> callback) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!callback.get()) {
|
2019-03-25 19:14:23 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefCompletionCallback::OnComplete,
|
|
|
|
callback.get()));
|
2019-03-25 19:14:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Always execute the callback asynchronously.
|
|
|
|
void SetCookieCallbackImpl(CefRefPtr<CefSetCookieCallback> callback,
|
2020-08-29 00:39:23 +02:00
|
|
|
net::CookieAccessResult access_result) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!callback.get()) {
|
2019-03-25 19:14:23 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-08-29 00:39:23 +02:00
|
|
|
const bool is_include = access_result.status.IsInclude();
|
|
|
|
if (!is_include) {
|
|
|
|
LOG(WARNING) << "SetCookie failed with reason: "
|
|
|
|
<< access_result.status.GetDebugString();
|
2020-04-24 23:48:16 +02:00
|
|
|
}
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefSetCookieCallback::OnComplete,
|
|
|
|
callback.get(), is_include));
|
2019-03-25 19:14:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Always execute the callback asynchronously.
|
|
|
|
void DeleteCookiesCallbackImpl(CefRefPtr<CefDeleteCookiesCallback> callback,
|
|
|
|
uint32_t num_deleted) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!callback.get()) {
|
2019-03-25 19:14:23 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefDeleteCookiesCallback::OnComplete,
|
|
|
|
callback.get(), num_deleted));
|
2019-03-25 19:14:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExecuteVisitor(CefRefPtr<CefCookieVisitor> visitor,
|
2020-03-27 21:00:36 +01:00
|
|
|
const CefBrowserContext::Getter& browser_context_getter,
|
2019-03-25 19:14:23 +01:00
|
|
|
const std::vector<net::CanonicalCookie>& cookies) {
|
2019-03-25 19:35:51 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2020-03-27 21:00:36 +01:00
|
|
|
auto browser_context = GetBrowserContext(browser_context_getter);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2020-03-27 21:00:36 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-03-27 21:00:36 +01:00
|
|
|
|
|
|
|
auto cookie_manager = GetCookieManager(browser_context);
|
2019-03-25 19:14:23 +01:00
|
|
|
|
|
|
|
int total = cookies.size(), count = 0;
|
|
|
|
for (const auto& cc : cookies) {
|
|
|
|
CefCookie cookie;
|
2019-04-24 04:50:25 +02:00
|
|
|
net_service::MakeCefCookie(cc, cookie);
|
2019-03-25 19:14:23 +01:00
|
|
|
|
|
|
|
bool deleteCookie = false;
|
|
|
|
bool keepLooping = visitor->Visit(cookie, count, total, deleteCookie);
|
|
|
|
if (deleteCookie) {
|
2019-03-25 19:35:51 +01:00
|
|
|
cookie_manager->DeleteCanonicalCookie(
|
|
|
|
cc, CookieManager::DeleteCanonicalCookieCallback());
|
2019-03-25 19:14:23 +01:00
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!keepLooping) {
|
2019-03-25 19:14:23 +01:00
|
|
|
break;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-03-25 19:14:23 +01:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always execute the callback asynchronously.
|
2020-03-27 21:00:36 +01:00
|
|
|
void GetAllCookiesCallbackImpl(
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor,
|
|
|
|
const CefBrowserContext::Getter& browser_context_getter,
|
|
|
|
const net::CookieList& cookies) {
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&ExecuteVisitor, visitor,
|
|
|
|
browser_context_getter, cookies));
|
2019-03-25 19:14:23 +01:00
|
|
|
}
|
|
|
|
|
2020-03-27 21:00:36 +01:00
|
|
|
void GetCookiesCallbackImpl(
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor,
|
|
|
|
const CefBrowserContext::Getter& browser_context_getter,
|
2020-07-08 19:23:29 +02:00
|
|
|
const net::CookieAccessResultList& include_cookies,
|
|
|
|
const net::CookieAccessResultList&) {
|
2019-10-01 15:55:16 +02:00
|
|
|
net::CookieList cookies;
|
|
|
|
for (const auto& status : include_cookies) {
|
|
|
|
cookies.push_back(status.cookie);
|
|
|
|
}
|
2020-03-27 21:00:36 +01:00
|
|
|
GetAllCookiesCallbackImpl(visitor, browser_context_getter, cookies);
|
2019-06-05 16:15:45 +02:00
|
|
|
}
|
|
|
|
|
2019-03-25 19:14:23 +01:00
|
|
|
} // namespace
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefCookieManagerImpl::CefCookieManagerImpl() = default;
|
2019-03-25 19:14:23 +01:00
|
|
|
|
|
|
|
void CefCookieManagerImpl::Initialize(
|
2020-03-27 21:00:36 +01:00
|
|
|
CefBrowserContext::Getter browser_context_getter,
|
2019-03-25 19:14:23 +01:00
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2020-03-27 21:00:36 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2021-04-15 01:28:22 +02:00
|
|
|
DCHECK(!initialized_);
|
2020-03-27 21:00:36 +01:00
|
|
|
DCHECK(!browser_context_getter.is_null());
|
|
|
|
DCHECK(browser_context_getter_.is_null());
|
|
|
|
browser_context_getter_ = browser_context_getter;
|
2021-04-15 01:28:22 +02:00
|
|
|
|
|
|
|
initialized_ = true;
|
|
|
|
if (!init_callbacks_.empty()) {
|
2022-09-26 21:30:45 +02:00
|
|
|
for (auto& init_callback : init_callbacks_) {
|
|
|
|
std::move(init_callback).Run();
|
2021-04-15 01:28:22 +02:00
|
|
|
}
|
|
|
|
init_callbacks_.clear();
|
|
|
|
}
|
|
|
|
|
2019-03-25 19:35:51 +01:00
|
|
|
RunAsyncCompletionOnUIThread(callback);
|
2019-03-25 19:14:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::VisitAllCookies(
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!visitor.get()) {
|
2019-03-25 19:14:23 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-03-25 19:14:23 +01:00
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
if (!ValidContext()) {
|
|
|
|
StoreOrTriggerInitCallback(base::BindOnce(
|
|
|
|
base::IgnoreResult(&CefCookieManagerImpl::VisitAllCookiesInternal),
|
|
|
|
this, visitor));
|
2019-03-25 19:14:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
return VisitAllCookiesInternal(visitor);
|
2019-03-25 19:14:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::VisitUrlCookies(
|
|
|
|
const CefString& url,
|
|
|
|
bool includeHttpOnly,
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!visitor.get()) {
|
2019-03-25 19:14:23 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-03-25 19:14:23 +01:00
|
|
|
|
|
|
|
GURL gurl = GURL(url.ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!gurl.is_valid()) {
|
2019-03-25 19:14:23 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-03-25 19:14:23 +01:00
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
if (!ValidContext()) {
|
|
|
|
StoreOrTriggerInitCallback(base::BindOnce(
|
|
|
|
base::IgnoreResult(&CefCookieManagerImpl::VisitUrlCookiesInternal),
|
|
|
|
this, gurl, includeHttpOnly, visitor));
|
2019-03-25 19:14:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
return VisitUrlCookiesInternal(gurl, includeHttpOnly, visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::SetCookie(const CefString& url,
|
|
|
|
const CefCookie& cookie,
|
|
|
|
CefRefPtr<CefSetCookieCallback> callback) {
|
|
|
|
GURL gurl = GURL(url.ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!gurl.is_valid()) {
|
2021-04-15 01:28:22 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-15 01:28:22 +02:00
|
|
|
|
|
|
|
if (!ValidContext()) {
|
|
|
|
StoreOrTriggerInitCallback(base::BindOnce(
|
|
|
|
base::IgnoreResult(&CefCookieManagerImpl::SetCookieInternal), this,
|
|
|
|
gurl, cookie, callback));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetCookieInternal(gurl, cookie, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::DeleteCookies(
|
|
|
|
const CefString& url,
|
|
|
|
const CefString& cookie_name,
|
|
|
|
CefRefPtr<CefDeleteCookiesCallback> callback) {
|
|
|
|
// Empty URLs are allowed but not invalid URLs.
|
|
|
|
GURL gurl = GURL(url.ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!gurl.is_empty() && !gurl.is_valid()) {
|
2021-04-15 01:28:22 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-15 01:28:22 +02:00
|
|
|
|
|
|
|
if (!ValidContext()) {
|
|
|
|
StoreOrTriggerInitCallback(base::BindOnce(
|
|
|
|
base::IgnoreResult(&CefCookieManagerImpl::DeleteCookiesInternal), this,
|
|
|
|
gurl, cookie_name, callback));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DeleteCookiesInternal(gurl, cookie_name, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::FlushStore(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
|
|
|
if (!ValidContext()) {
|
|
|
|
StoreOrTriggerInitCallback(base::BindOnce(
|
|
|
|
base::IgnoreResult(&CefCookieManagerImpl::FlushStoreInternal), this,
|
|
|
|
callback));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FlushStoreInternal(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::VisitAllCookiesInternal(
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor) {
|
|
|
|
DCHECK(ValidContext());
|
|
|
|
DCHECK(visitor);
|
|
|
|
|
|
|
|
auto browser_context = GetBrowserContext(browser_context_getter_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2021-04-15 01:28:22 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-15 01:28:22 +02:00
|
|
|
|
|
|
|
GetCookieManager(browser_context)
|
2021-06-04 03:34:56 +02:00
|
|
|
->GetAllCookies(base::BindOnce(&GetAllCookiesCallbackImpl, visitor,
|
|
|
|
browser_context_getter_));
|
2021-04-15 01:28:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::VisitUrlCookiesInternal(
|
|
|
|
const GURL& url,
|
|
|
|
bool includeHttpOnly,
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor) {
|
|
|
|
DCHECK(ValidContext());
|
|
|
|
DCHECK(visitor);
|
|
|
|
DCHECK(url.is_valid());
|
|
|
|
|
2019-03-25 19:14:23 +01:00
|
|
|
net::CookieOptions options;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (includeHttpOnly) {
|
2019-03-25 19:14:23 +01:00
|
|
|
options.set_include_httponly();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-04-24 23:48:16 +02:00
|
|
|
options.set_same_site_cookie_context(
|
|
|
|
net::CookieOptions::SameSiteCookieContext::MakeInclusive());
|
2019-03-25 19:14:23 +01:00
|
|
|
|
2020-03-27 21:00:36 +01:00
|
|
|
auto browser_context = GetBrowserContext(browser_context_getter_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2020-03-27 21:00:36 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-03-27 21:00:36 +01:00
|
|
|
|
|
|
|
GetCookieManager(browser_context)
|
2021-12-16 23:35:54 +01:00
|
|
|
->GetCookieList(url, options, net::CookiePartitionKeyCollection(),
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(&GetCookiesCallbackImpl, visitor,
|
|
|
|
browser_context_getter_));
|
2019-03-25 19:14:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
bool CefCookieManagerImpl::SetCookieInternal(
|
|
|
|
const GURL& url,
|
|
|
|
const CefCookie& cookie,
|
|
|
|
CefRefPtr<CefSetCookieCallback> callback) {
|
|
|
|
DCHECK(ValidContext());
|
|
|
|
DCHECK(url.is_valid());
|
2019-03-25 19:14:23 +01:00
|
|
|
|
|
|
|
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;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cookie.has_expires) {
|
2022-05-31 22:28:43 +02:00
|
|
|
expiration_time = CefBaseTime(cookie.expires);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-03-25 19:14:23 +01:00
|
|
|
|
2020-04-24 23:48:16 +02:00
|
|
|
net::CookieSameSite same_site =
|
|
|
|
net_service::MakeCookieSameSite(cookie.same_site);
|
|
|
|
net::CookiePriority priority =
|
|
|
|
net_service::MakeCookiePriority(cookie.priority);
|
|
|
|
|
2019-03-25 19:14:23 +01:00
|
|
|
auto canonical_cookie = net::CanonicalCookie::CreateSanitizedCookie(
|
2021-04-15 01:28:22 +02:00
|
|
|
url, name, value, domain, path,
|
2023-12-06 21:16:15 +01:00
|
|
|
/*creation_time=*/base::Time(), expiration_time,
|
|
|
|
/*last_access_time=*/base::Time(), cookie.secure ? true : false,
|
|
|
|
cookie.httponly ? true : false, same_site, priority,
|
2024-04-23 22:06:00 +02:00
|
|
|
/*partition_key=*/std::nullopt, /*status=*/nullptr);
|
2019-03-25 19:14:23 +01:00
|
|
|
|
2019-05-08 20:12:21 +02:00
|
|
|
if (!canonical_cookie) {
|
2020-07-08 19:23:29 +02:00
|
|
|
SetCookieCallbackImpl(
|
2020-08-29 00:39:23 +02:00
|
|
|
callback, net::CookieAccessResult(net::CookieInclusionStatus(
|
|
|
|
net::CookieInclusionStatus::EXCLUDE_UNKNOWN_ERROR)));
|
2019-05-08 20:12:21 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-16 16:38:48 +02:00
|
|
|
net::CookieOptions options;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cookie.httponly) {
|
2019-04-16 16:38:48 +02:00
|
|
|
options.set_include_httponly();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-04-24 23:48:16 +02:00
|
|
|
options.set_same_site_cookie_context(
|
|
|
|
net::CookieOptions::SameSiteCookieContext::MakeInclusive());
|
2019-04-16 16:38:48 +02:00
|
|
|
|
2020-03-27 21:00:36 +01:00
|
|
|
auto browser_context = GetBrowserContext(browser_context_getter_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2020-03-27 21:00:36 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-03-27 21:00:36 +01:00
|
|
|
|
|
|
|
GetCookieManager(browser_context)
|
2021-04-15 01:28:22 +02:00
|
|
|
->SetCanonicalCookie(*canonical_cookie, url, options,
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(SetCookieCallbackImpl, callback));
|
2019-03-25 19:14:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
bool CefCookieManagerImpl::DeleteCookiesInternal(
|
|
|
|
const GURL& url,
|
2019-03-25 19:14:23 +01:00
|
|
|
const CefString& cookie_name,
|
|
|
|
CefRefPtr<CefDeleteCookiesCallback> callback) {
|
2021-04-15 01:28:22 +02:00
|
|
|
DCHECK(ValidContext());
|
|
|
|
DCHECK(url.is_empty() || url.is_valid());
|
2019-03-25 19:14:23 +01:00
|
|
|
|
|
|
|
network::mojom::CookieDeletionFilterPtr deletion_filter =
|
|
|
|
network::mojom::CookieDeletionFilter::New();
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
if (url.is_empty()) {
|
2019-03-25 19:14:23 +01:00
|
|
|
// Delete all cookies.
|
|
|
|
} else if (cookie_name.empty()) {
|
|
|
|
// Delete all matching host cookies.
|
2021-04-15 01:28:22 +02:00
|
|
|
deletion_filter->host_name = url.host();
|
2019-03-25 19:14:23 +01:00
|
|
|
} else {
|
|
|
|
// Delete all matching host and domain cookies.
|
2021-04-15 01:28:22 +02:00
|
|
|
deletion_filter->url = url;
|
2019-03-25 19:14:23 +01:00
|
|
|
deletion_filter->cookie_name = cookie_name;
|
|
|
|
}
|
|
|
|
|
2020-03-27 21:00:36 +01:00
|
|
|
auto browser_context = GetBrowserContext(browser_context_getter_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2020-03-27 21:00:36 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-03-27 21:00:36 +01:00
|
|
|
|
|
|
|
GetCookieManager(browser_context)
|
2019-03-25 19:14:23 +01:00
|
|
|
->DeleteCookies(std::move(deletion_filter),
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(DeleteCookiesCallbackImpl, callback));
|
2019-03-25 19:14:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
bool CefCookieManagerImpl::FlushStoreInternal(
|
2019-03-25 19:14:23 +01:00
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2021-04-15 01:28:22 +02:00
|
|
|
DCHECK(ValidContext());
|
2019-03-25 19:14:23 +01:00
|
|
|
|
2020-03-27 21:00:36 +01:00
|
|
|
auto browser_context = GetBrowserContext(browser_context_getter_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2020-03-27 21:00:36 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-03-27 21:00:36 +01:00
|
|
|
|
|
|
|
GetCookieManager(browser_context)
|
2021-06-04 03:34:56 +02:00
|
|
|
->FlushCookieStore(
|
|
|
|
base::BindOnce(RunAsyncCompletionOnUIThread, callback));
|
2019-03-25 19:14:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
void CefCookieManagerImpl::StoreOrTriggerInitCallback(
|
|
|
|
base::OnceClosure callback) {
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
|
|
|
base::BindOnce(&CefCookieManagerImpl::StoreOrTriggerInitCallback, this,
|
|
|
|
std::move(callback)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initialized_) {
|
|
|
|
std::move(callback).Run();
|
|
|
|
} else {
|
|
|
|
init_callbacks_.emplace_back(std::move(callback));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCookieManagerImpl::ValidContext() const {
|
|
|
|
return CEF_CURRENTLY_ON_UIT() && initialized_;
|
|
|
|
}
|
|
|
|
|
2019-03-25 19:14:23 +01:00
|
|
|
// CefCookieManager methods ----------------------------------------------------
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
|
|
|
CefRefPtr<CefRequestContext> context = CefRequestContext::GetGlobalContext();
|
|
|
|
return context ? context->GetCookieManager(callback) : nullptr;
|
|
|
|
}
|