#include "third_party/blink/renderer/modules/cookie_store/cookie_store.h"
#include <optional>
#include <utility>
#include "base/containers/contains.h"
#include "net/base/features.h"
#include "net/cookies/canonical_cookie.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "services/network/public/mojom/restricted_cookie_manager.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_cookie_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_cookie_list_item.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_cookie_store_delete_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_cookie_store_get_options.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/cookie_store/cookie_change_event.h"
#include "third_party/blink/renderer/modules/event_modules.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
namespace {
network::mojom::blink::CookieManagerGetOptionsPtr ToBackendOptions(
const CookieStoreGetOptions* options,
ExceptionState& exception_state) { … }
std::unique_ptr<net::CanonicalCookie> ToCanonicalCookie(
const KURL& cookie_url,
const CookieInit* options,
ExceptionState& exception_state,
net::CookieInclusionStatus& status_out) { … }
const KURL DefaultCookieURL(ExecutionContext* execution_context) { … }
KURL CookieUrlForRead(const CookieStoreGetOptions* options,
const KURL& default_cookie_url,
ScriptState* script_state,
ExceptionState& exception_state) { … }
net::SiteForCookies DefaultSiteForCookies(ExecutionContext* execution_context) { … }
const scoped_refptr<const SecurityOrigin> DefaultTopFrameOrigin(
ExecutionContext* execution_context) { … }
}
CookieStore::CookieStore(
ExecutionContext* execution_context,
HeapMojoRemote<network::mojom::blink::RestrictedCookieManager> backend)
: … { … }
CookieStore::~CookieStore() = default;
ScriptPromise<IDLSequence<CookieListItem>> CookieStore::getAll(
ScriptState* script_state,
const String& name,
ExceptionState& exception_state) { … }
ScriptPromise<IDLSequence<CookieListItem>> CookieStore::getAll(
ScriptState* script_state,
const CookieStoreGetOptions* options,
ExceptionState& exception_state) { … }
ScriptPromise<IDLNullable<CookieListItem>> CookieStore::get(
ScriptState* script_state,
const String& name,
ExceptionState& exception_state) { … }
ScriptPromise<IDLNullable<CookieListItem>> CookieStore::get(
ScriptState* script_state,
const CookieStoreGetOptions* options,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> CookieStore::set(ScriptState* script_state,
const String& name,
const String& value,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> CookieStore::set(ScriptState* script_state,
const CookieInit* options,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> CookieStore::Delete(
ScriptState* script_state,
const String& name,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> CookieStore::Delete(
ScriptState* script_state,
const CookieStoreDeleteOptions* options,
ExceptionState& exception_state) { … }
void CookieStore::Trace(Visitor* visitor) const { … }
const AtomicString& CookieStore::InterfaceName() const { … }
ExecutionContext* CookieStore::GetExecutionContext() const { … }
void CookieStore::RemoveAllEventListeners() { … }
void CookieStore::OnCookieChange(
network::mojom::blink::CookieChangeInfoPtr change) { … }
void CookieStore::AddedEventListener(
const AtomicString& event_type,
RegisteredEventListener& registered_listener) { … }
void CookieStore::RemovedEventListener(
const AtomicString& event_type,
const RegisteredEventListener& registered_listener) { … }
void CookieStore::DoRead(ScriptState* script_state,
const CookieStoreGetOptions* options,
GetAllForUrlCallback backend_result_converter,
ExceptionState& exception_state) { … }
void CookieStore::GetAllForUrlToGetAllResult(
ScriptPromiseResolver<IDLSequence<CookieListItem>>* resolver,
const Vector<network::mojom::blink::CookieWithAccessResultPtr>
backend_cookies) { … }
void CookieStore::GetAllForUrlToGetResult(
ScriptPromiseResolver<IDLNullable<CookieListItem>>* resolver,
const Vector<network::mojom::blink::CookieWithAccessResultPtr>
backend_cookies) { … }
ScriptPromise<IDLUndefined> CookieStore::DoWrite(
ScriptState* script_state,
const CookieInit* options,
ExceptionState& exception_state) { … }
void CookieStore::OnSetCanonicalCookieResult(
ScriptPromiseResolver<IDLUndefined>* resolver,
bool backend_success) { … }
void CookieStore::StartObserving() { … }
void CookieStore::StopObserving() { … }
}