diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-09-14 15:50:47 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-15 09:46:04 +0200 |
commit | 6a4934a03070b22aac1b9b30283133c4bb395d95 (patch) | |
tree | 791c4e83c1ee8293a74207f3957095ee363b3084 /Userland | |
parent | 6290a252246be79f2d757022734d1c20f0cc6478 (diff) | |
download | serenity-6a4934a03070b22aac1b9b30283133c4bb395d95.zip |
LibWeb: Implement document.domain getter
The document.domain setter is currently stubbed as that is a doozy to
implement, given how much restrictions there are in place to try and
prevent use of it and potential multi-process implications.
This was the only thing preventing us from being able to start
displaying ads delivered via Google Syndication.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.idl | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Origin.h | 13 |
4 files changed, 37 insertions, 0 deletions
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<HTML::History> 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<String> effective_domain() const + { + // 1. If origin is an opaque origin, then return null. + if (is_opaque()) + return Optional<String> {}; + + // 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); } |