mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-30 14:20:21 +00:00
LibWeb: Add initial CookieStore support
This commit is contained in:
parent
4a8c70b3a5
commit
d6c2893663
Notes:
github-actions[bot]
2025-08-08 17:12:40 +00:00
Author: https://github.com/IdanHo
Commit: d6c2893663
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5766
Reviewed-by: https://github.com/trflynn89 ✅
19 changed files with 134 additions and 2 deletions
|
@ -80,6 +80,7 @@ set(SOURCES
|
|||
ContentSecurityPolicy/Violation.cpp
|
||||
Cookie/Cookie.cpp
|
||||
Cookie/ParsedCookie.cpp
|
||||
CookieStore/CookieStore.cpp
|
||||
CredentialManagement/Credential.cpp
|
||||
CredentialManagement/CredentialsContainer.cpp
|
||||
CredentialManagement/FederatedCredential.cpp
|
||||
|
|
26
Libraries/LibWeb/CookieStore/CookieStore.cpp
Normal file
26
Libraries/LibWeb/CookieStore/CookieStore.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/CookieStorePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CookieStore/CookieStore.h>
|
||||
|
||||
namespace Web::CookieStore {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(CookieStore);
|
||||
|
||||
CookieStore::CookieStore(JS::Realm& realm)
|
||||
: DOM::EventTarget(realm)
|
||||
{
|
||||
}
|
||||
|
||||
void CookieStore::initialize(JS::Realm& realm)
|
||||
{
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(CookieStore);
|
||||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
}
|
24
Libraries/LibWeb/CookieStore/CookieStore.h
Normal file
24
Libraries/LibWeb/CookieStore/CookieStore.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
|
||||
namespace Web::CookieStore {
|
||||
|
||||
// https://cookiestore.spec.whatwg.org/#cookiestore
|
||||
class CookieStore final : public DOM::EventTarget {
|
||||
WEB_PLATFORM_OBJECT(CookieStore, DOM::EventTarget);
|
||||
GC_DECLARE_ALLOCATOR(CookieStore);
|
||||
|
||||
private:
|
||||
CookieStore(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
21
Libraries/LibWeb/CookieStore/CookieStore.idl
Normal file
21
Libraries/LibWeb/CookieStore/CookieStore.idl
Normal file
|
@ -0,0 +1,21 @@
|
|||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
#import <HTML/Window.idl>
|
||||
#import <ServiceWorker/ServiceWorkerGlobalScope.idl>
|
||||
|
||||
// https://cookiestore.spec.whatwg.org/#cookiestore
|
||||
[Exposed=(ServiceWorker,Window), SecureContext]
|
||||
interface CookieStore : EventTarget {
|
||||
|
||||
};
|
||||
|
||||
// https://cookiestore.spec.whatwg.org/#Window
|
||||
[SecureContext]
|
||||
partial interface Window {
|
||||
[SameObject] readonly attribute CookieStore cookieStore;
|
||||
};
|
||||
|
||||
// https://cookiestore.spec.whatwg.org/#ServiceWorkerGlobalScope
|
||||
partial interface ServiceWorkerGlobalScope {
|
||||
[SameObject] readonly attribute CookieStore cookieStore;
|
||||
};
|
|
@ -173,6 +173,12 @@ enum class Source;
|
|||
|
||||
}
|
||||
|
||||
namespace Web::CookieStore {
|
||||
|
||||
class CookieStore;
|
||||
|
||||
}
|
||||
|
||||
namespace Web::CredentialManagement {
|
||||
|
||||
class Credential;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <LibWeb/CSS/MediaQueryList.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/Screen.h>
|
||||
#include <LibWeb/CookieStore/CookieStore.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
|
@ -130,6 +131,7 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(m_pdf_viewer_plugin_objects);
|
||||
visitor.visit(m_pdf_viewer_mime_type_objects);
|
||||
visitor.visit(m_close_watcher_manager);
|
||||
visitor.visit(m_cookie_store);
|
||||
visitor.visit(m_locationbar);
|
||||
visitor.visit(m_menubar);
|
||||
visitor.visit(m_personalbar);
|
||||
|
@ -1121,6 +1123,17 @@ GC::Ref<CloseWatcherManager> Window::close_watcher_manager()
|
|||
return GC::Ref { *m_close_watcher_manager };
|
||||
}
|
||||
|
||||
// https://cookiestore.spec.whatwg.org/#Window
|
||||
GC::Ref<CookieStore::CookieStore> Window::cookie_store()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
// The cookieStore getter steps are to return this’s associated CookieStore.
|
||||
if (!m_cookie_store)
|
||||
m_cookie_store = realm.create<CookieStore::CookieStore>(realm);
|
||||
return *m_cookie_store;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-alert
|
||||
void Window::alert(String const& message)
|
||||
{
|
||||
|
|
|
@ -194,6 +194,7 @@ public:
|
|||
|
||||
[[nodiscard]] GC::Ref<Navigator> navigator();
|
||||
[[nodiscard]] GC::Ref<CloseWatcherManager> close_watcher_manager();
|
||||
[[nodiscard]] GC::Ref<CookieStore::CookieStore> cookie_store();
|
||||
|
||||
void alert(String const& message = {});
|
||||
bool confirm(Optional<String> const& message);
|
||||
|
@ -310,6 +311,7 @@ private:
|
|||
GC::Ptr<Navigator> m_navigator;
|
||||
GC::Ptr<Location> m_location;
|
||||
GC::Ptr<CloseWatcherManager> m_close_watcher_manager;
|
||||
GC::Ptr<CookieStore::CookieStore> m_cookie_store;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#window-navigation-api
|
||||
GC::Ptr<Navigation> m_navigation;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#import <CookieStore/CookieStore.idl>
|
||||
#import <CSS/MediaQueryList.idl>
|
||||
#import <CSS/Screen.idl>
|
||||
#import <CSS/VisualViewport.idl>
|
||||
|
|
|
@ -109,6 +109,8 @@ public:
|
|||
protected:
|
||||
explicit WorkerGlobalScope(JS::Realm&, GC::Ref<Web::Page>);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
virtual void initialize_web_interfaces_impl();
|
||||
|
||||
void close_a_worker();
|
||||
|
@ -120,8 +122,6 @@ protected:
|
|||
private:
|
||||
virtual bool is_window_or_worker_global_scope_mixin() const final { return true; }
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
GC::Ptr<WorkerLocation> m_location;
|
||||
GC::Ptr<WorkerNavigator> m_navigator;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CookieStore/CookieStore.h>
|
||||
#include <LibWeb/ServiceWorker/EventNames.h>
|
||||
#include <LibWeb/ServiceWorker/ServiceWorkerGlobalScope.h>
|
||||
|
||||
|
@ -18,6 +19,13 @@ ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(JS::Realm& realm, GC::Ref<Web
|
|||
{
|
||||
}
|
||||
|
||||
void ServiceWorkerGlobalScope::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
||||
visitor.visit(m_cookie_store);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-oninstall
|
||||
void ServiceWorkerGlobalScope::set_oninstall(GC::Ptr<WebIDL::CallbackType> value)
|
||||
{
|
||||
|
@ -78,4 +86,15 @@ GC::Ptr<WebIDL::CallbackType> ServiceWorkerGlobalScope::onmessageerror()
|
|||
return event_handler_attribute(EventNames::messageerror);
|
||||
}
|
||||
|
||||
// https://cookiestore.spec.whatwg.org/#ServiceWorkerGlobalScope
|
||||
GC::Ref<CookieStore::CookieStore> ServiceWorkerGlobalScope::cookie_store()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
// The cookieStore getter steps are to return this’s associated CookieStore.
|
||||
if (!m_cookie_store)
|
||||
m_cookie_store = realm.create<CookieStore::CookieStore>(realm);
|
||||
return *m_cookie_store;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,8 +33,15 @@ public:
|
|||
void set_onmessageerror(GC::Ptr<WebIDL::CallbackType>);
|
||||
GC::Ptr<WebIDL::CallbackType> onmessageerror();
|
||||
|
||||
[[nodiscard]] GC::Ref<CookieStore::CookieStore> cookie_store();
|
||||
|
||||
protected:
|
||||
explicit ServiceWorkerGlobalScope(JS::Realm&, GC::Ref<Web::Page>);
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
GC::Ptr<CookieStore::CookieStore> m_cookie_store;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#import <CookieStore/CookieStore.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
// https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope
|
||||
|
|
|
@ -13,6 +13,7 @@ libweb_js_bindings(Clipboard/ClipboardItem)
|
|||
libweb_js_bindings(ContentSecurityPolicy/SecurityPolicyViolationEvent)
|
||||
libweb_js_bindings(Compression/CompressionStream)
|
||||
libweb_js_bindings(Compression/DecompressionStream)
|
||||
libweb_js_bindings(CookieStore/CookieStore)
|
||||
libweb_js_bindings(CredentialManagement/Credential)
|
||||
libweb_js_bindings(CredentialManagement/CredentialsContainer)
|
||||
libweb_js_bindings(CredentialManagement/FederatedCredential)
|
||||
|
|
|
@ -4816,6 +4816,7 @@ static void generate_using_namespace_definitions(SourceGenerator& generator)
|
|||
using namespace Web::Animations;
|
||||
using namespace Web::Clipboard;
|
||||
using namespace Web::ContentSecurityPolicy;
|
||||
using namespace Web::CookieStore;
|
||||
using namespace Web::CredentialManagement;
|
||||
using namespace Web::Crypto;
|
||||
using namespace Web::CSS;
|
||||
|
|
|
@ -17,6 +17,7 @@ static constexpr Array libweb_interface_namespaces = {
|
|||
"Clipboard"sv,
|
||||
"Compression"sv,
|
||||
"ContentSecurityPolicy"sv,
|
||||
"CookieStore"sv,
|
||||
"Crypto"sv,
|
||||
"DOM"sv,
|
||||
"DOMURL"sv,
|
||||
|
|
|
@ -333,6 +333,7 @@ shared_library("LibWeb") {
|
|||
"CSS",
|
||||
"Clipboard",
|
||||
"Cookie",
|
||||
"CookieStore",
|
||||
"Crypto",
|
||||
"DOM",
|
||||
"DOMURL",
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
source_set("CookieStore") {
|
||||
configs += [ "//Userland/Libraries/LibWeb:configs" ]
|
||||
deps = [ "//Userland/Libraries/LibWeb:all_generated" ]
|
||||
sources = [ "CookieStore.cpp" ]
|
||||
}
|
|
@ -30,6 +30,7 @@ standard_idl_files = [
|
|||
"//Userland/Libraries/LibWeb/Animations/KeyframeEffect.idl",
|
||||
"//Userland/Libraries/LibWeb/Clipboard/Clipboard.idl",
|
||||
"//Userland/Libraries/LibWeb/Clipboard/ClipboardEvent.idl",
|
||||
"//Userland/Libraries/LibWeb/CookieStore/CookieStore.idl",
|
||||
"//Userland/Libraries/LibWeb/Crypto/Crypto.idl",
|
||||
"//Userland/Libraries/LibWeb/Crypto/CryptoKey.idl",
|
||||
"//Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl",
|
||||
|
|
|
@ -79,6 +79,7 @@ Comment
|
|||
CompositionEvent
|
||||
CompressionStream
|
||||
ConstantSourceNode
|
||||
CookieStore
|
||||
CountQueuingStrategy
|
||||
Credential
|
||||
CredentialsContainer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue