diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 6d7970bc15..fd247c45b0 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1831,4 +1831,24 @@ JS::NonnullGCPtr Document::history() return *m_history; } +// https://html.spec.whatwg.org/multipage/origin.html#dom-document-domain +String Document::domain() const +{ + // 1. Let effectiveDomain be this's origin's effective domain. + auto effective_domain = origin().effective_domain(); + + // 2. If effectiveDomain is null, then return the empty string. + if (!effective_domain.has_value()) + return String::empty(); + + // 3. Return effectiveDomain, serialized. + // FIXME: Implement host serialization. + return effective_domain.release_value(); +} + +void Document::set_domain(String const& domain) +{ + dbgln("(STUBBED) Document::set_domain(domain='{}')", domain); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 6eda355046..cd1b0bf666 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -353,6 +353,9 @@ public: bool is_initial_about_blank() const { return m_is_initial_about_blank; } void set_is_initial_about_blank(bool b) { m_is_initial_about_blank = b; } + String domain() const; + void set_domain(String const& domain); + protected: virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index 81b71af855..a7d979c220 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -27,6 +27,7 @@ interface Document : Node { // FIXME: These attributes currently don't do anything. [PutForwards=href, LegacyUnforgeable] readonly attribute Location? location; + attribute USVString domain; readonly attribute DOMImplementation implementation; diff --git a/Userland/Libraries/LibWeb/HTML/Origin.h b/Userland/Libraries/LibWeb/HTML/Origin.h index 1ebe477776..e74e8eb986 100644 --- a/Userland/Libraries/LibWeb/HTML/Origin.h +++ b/Userland/Libraries/LibWeb/HTML/Origin.h @@ -92,6 +92,19 @@ public: return result.to_string(); } + // https://html.spec.whatwg.org/multipage/origin.html#concept-origin-effective-domain + Optional effective_domain() const + { + // 1. If origin is an opaque origin, then return null. + if (is_opaque()) + return Optional {}; + + // FIXME: 2. If origin's domain is non-null, then return origin's domain. + + // 3. Return origin's host. + return m_host; + } + bool operator==(Origin const& other) const { return is_same_origin(other); } bool operator!=(Origin const& other) const { return !is_same_origin(other); }