From 5deb8ba2f819bb145fac67033084cdd1257e564d Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 15 Jun 2025 19:04:02 +1200 Subject: [PATCH] LibWeb: Explicitly set Document's origin As part of the effort of removing the default constructor of Origin, since document has the origin set after construction, port Document's origin over to an Optional. This exposes that we were never setting the origin of the document during fragment parsing. For now, to maintain previous behaviour, let's explicitly set it to an opaque origin. --- Libraries/LibWeb/DOM/Document.cpp | 2 +- Libraries/LibWeb/DOM/Document.h | 2 +- Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 8f5e387a71b..c274b06d646 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -840,7 +840,7 @@ GC::Ptr Document::default_view() const URL::Origin const& Document::origin() const { - return m_origin; + return m_origin.value(); } void Document::set_origin(URL::Origin const& origin) diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 1c030d453aa..c704c5d80f7 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -1103,7 +1103,7 @@ private: String m_referrer; // https://dom.spec.whatwg.org/#concept-document-origin - URL::Origin m_origin; + Optional m_origin; GC::Ptr m_applets; GC::Ptr m_anchors; diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 325d461c176..ffedc4cf340 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -4570,6 +4570,11 @@ Vector> HTMLParser::parse_html_fragment(DOM::Element& contex // This is required for Document::parse_url() to work inside iframe srcdoc documents. temp_document->set_about_base_url(context_element.document().about_base_url()); + // AD-HOC: The origin is not otherwise set for the document, but it may be accessed during parsing + // script. For now, let's just use an opaque origin, but it is likely that the spec is + // missing setting this origin. + temp_document->set_origin(URL::Origin {}); + // 2. If context's node document is in quirks mode, then set document's mode to "quirks". if (context_element.document().in_quirks_mode()) temp_document->set_quirks_mode(DOM::QuirksMode::Yes);