1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:27:45 +00:00

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.
This commit is contained in:
Luke Wilde 2022-09-14 15:50:47 +01:00 committed by Andreas Kling
parent 6290a25224
commit 6a4934a030
4 changed files with 37 additions and 0 deletions

View file

@ -1831,4 +1831,24 @@ JS::NonnullGCPtr<HTML::History> Document::history()
return *m_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);
}
} }

View file

@ -353,6 +353,9 @@ public:
bool is_initial_about_blank() const { return m_is_initial_about_blank; } 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; } void set_is_initial_about_blank(bool b) { m_is_initial_about_blank = b; }
String domain() const;
void set_domain(String const& domain);
protected: protected:
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;

View file

@ -27,6 +27,7 @@ interface Document : Node {
// FIXME: These attributes currently don't do anything. // FIXME: These attributes currently don't do anything.
[PutForwards=href, LegacyUnforgeable] readonly attribute Location? location; [PutForwards=href, LegacyUnforgeable] readonly attribute Location? location;
attribute USVString domain;
readonly attribute DOMImplementation implementation; readonly attribute DOMImplementation implementation;

View file

@ -92,6 +92,19 @@ public:
return result.to_string(); 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); }
bool operator!=(Origin const& other) const { return !is_same_origin(other); } bool operator!=(Origin const& other) const { return !is_same_origin(other); }