From 2ca8cf49ca84ea58f3de4a505e8a8d14f076b477 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Tue, 21 Feb 2023 17:08:01 +0000 Subject: [PATCH] LibWeb: Use browsing context creator URL for about:blank documents In about:blank documents, we should use the browsing context's creator URL as the base URL, if it exists and there is no element. This means that any about:blank frames will have URLs parse relative to their parent frame's URL. Fixes #17394. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 5 ++++- Userland/Libraries/LibWeb/HTML/BrowsingContext.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 940a91954f..d5be71a55d 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -777,7 +777,10 @@ JS::GCPtr Document::first_base_element_with_href_in_tree_ AK::URL Document::fallback_base_url() const { // FIXME: 1. If document is an iframe srcdoc document, then return the document base URL of document's browsing context's container document. - // FIXME: 2. If document's URL is about:blank, and document's browsing context's creator base URL is non-null, then return that creator base URL. + + // 2. If document's URL is about:blank, and document's browsing context's creator base URL is non-null, then return that creator base URL. + if (m_url == "about:blank"sv && browsing_context() && browsing_context()->creator_url().has_value()) + return browsing_context()->creator_url().value(); // 3. Return document's URL. return m_url; diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h index 8332cdc5e6..a8faa334de 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h @@ -265,6 +265,8 @@ public: // https://html.spec.whatwg.org/multipage/window-object.html#close-a-browsing-context void close(); + Optional const& creator_url() const { return m_creator_url; } + private: explicit BrowsingContext(Page&, HTML::BrowsingContextContainer*);