diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index a053421100..34493eb520 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -218,6 +218,7 @@ set(SOURCES HTML/CustomElements/CustomElementName.cpp HTML/CustomElements/CustomElementReactionNames.cpp HTML/CustomElements/CustomElementRegistry.cpp + HTML/DocumentState.cpp HTML/DOMParser.cpp HTML/DOMStringMap.cpp HTML/ErrorEvent.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index def7fcb3f2..e94465218f 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -249,6 +249,7 @@ struct CrossOriginOpenerPolicy; struct CrossOriginOpenerPolicyEnforcementResult; class CustomElementDefinition; class CustomElementRegistry; +class DocumentState; class DOMParser; class DOMStringMap; struct Environment; diff --git a/Userland/Libraries/LibWeb/HTML/DocumentState.cpp b/Userland/Libraries/LibWeb/HTML/DocumentState.cpp new file mode 100644 index 0000000000..760ce35c05 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/DocumentState.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2023, Aliaksandr Kalenik + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::HTML { + +DocumentState::DocumentState() = default; + +DocumentState::~DocumentState() = default; + +void DocumentState::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_document); +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/DocumentState.h b/Userland/Libraries/LibWeb/HTML/DocumentState.h new file mode 100644 index 0000000000..bff05961bf --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/DocumentState.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2023, Aliaksandr Kalenik + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-2 +class DocumentState final : public JS::Cell { + JS_CELL(DocumentState, JS::Cell); + +public: + virtual ~DocumentState(); + + enum class Client { + Tag, + }; + + enum class NoReferrer { + Tag, + }; + + [[nodiscard]] JS::GCPtr document() const { return m_document; } + void set_document(JS::GCPtr document) { m_document = document; } + + [[nodiscard]] Variant history_policy_container() const { return m_history_policy_container; } + void set_history_policy_container(Variant history_policy_container) { m_history_policy_container = move(history_policy_container); } + + [[nodiscard]] Variant request_referrer() const { return m_request_referrer; } + void set_request_referrer(Variant request_referrer) { m_request_referrer = move(request_referrer); } + + [[nodiscard]] ReferrerPolicy::ReferrerPolicy request_referrer_policy() const { return m_request_referrer_policy; } + void set_request_referrer_policy(ReferrerPolicy::ReferrerPolicy request_referrer_policy) { m_request_referrer_policy = move(request_referrer_policy); } + + [[nodiscard]] Optional initiator_origin() const { return m_initiator_origin; } + void set_initiator_origin(Optional initiator_origin) { m_initiator_origin = move(initiator_origin); } + + [[nodiscard]] Optional origin() const { return m_origin; } + void set_origin(Optional origin) { m_origin = move(origin); } + + [[nodiscard]] bool reload_pending() const { return m_reload_pending; } + void set_reload_pending(bool reload_pending) { m_reload_pending = reload_pending; } + + [[nodiscard]] bool ever_populated() const { return m_ever_populated; } + void set_ever_populated(bool ever_populated) { m_ever_populated = ever_populated; } + + [[nodiscard]] String ever_navigable_target_name() const { return m_navigable_target_name; } + void set_navigable_target_name(String navigable_target_name) { m_navigable_target_name = navigable_target_name; } + +private: + DocumentState(); + + void visit_edges(Cell::Visitor&) override; + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-document + JS::GCPtr m_document; + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-history-policy-container + Variant m_history_policy_container { Client::Tag }; + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-request-referrer + Variant m_request_referrer { Client::Tag }; + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-request-referrer-policy + ReferrerPolicy::ReferrerPolicy m_request_referrer_policy { ReferrerPolicy::DEFAULT_REFERRER_POLICY }; + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-initiator-origin + Optional m_initiator_origin; + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-origin + Optional m_origin; + + // FIXME: https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-nested-histories + + // FIXME: https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-resource + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-reload-pending + bool m_reload_pending { false }; + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-ever-populated + bool m_ever_populated { false }; + + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-nav-target-name + String m_navigable_target_name; +}; + +}