Skip to content

Truly independent web browser

LibWeb: Let the XML parser create script-blocking style sheets

Andreas Klingaf7953250d00
diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Libraries/LibWeb/HTML/HTMLLinkElement.h
index bf96209f3bd..81f973fcd40 100644
--- a/Libraries/LibWeb/HTML/HTMLLinkElement.h
+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.h
@@ -60,6 +60,8 @@ public:
void set_parser_document(Badge<HTMLParser>, GC::Ref<DOM::Document> document) { m_parser_document = document; }
void set_was_enabled_when_created_by_parser(Badge<HTMLParser>, bool was_enabled_when_created_by_parser) { m_was_enabled_when_created_by_parser = was_enabled_when_created_by_parser; }
+ void set_parser_document(Badge<XMLDocumentBuilder>, GC::Ref<DOM::Document> document) { m_parser_document = document; }
+ void set_was_enabled_when_created_by_parser(Badge<XMLDocumentBuilder>, bool was_enabled_when_created_by_parser) { m_was_enabled_when_created_by_parser = was_enabled_when_created_by_parser; }
void set_media(Utf16View);
Utf16String media() const;
diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
index b6c27cc1f27..6879c551431 100644
--- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
+++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
@@ -1144,8 +1144,8 @@ GC::Ref<DOM::Element> HTMLParser::create_element_for(Utf16FlyString const& local
// This is used for the render-blocking logic.
if (!m_parsing_fragment && local_name == HTML::TagNames::link && namespace_ == Namespace::HTML) {
auto& link_element = as<HTMLLinkElement>(*element);
- link_element.set_parser_document({}, document);
- link_element.set_was_enabled_when_created_by_parser({}, !attribute_value(HTML::AttributeNames::disabled).has_value());
+ link_element.set_parser_document(Badge<HTMLParser> {}, document);
+ link_element.set_was_enabled_when_created_by_parser(Badge<HTMLParser> {}, !attribute_value(HTML::AttributeNames::disabled).has_value());
}
// AD-HOC: Let style elements know which document they were originally parsed for.
diff --git a/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp
index cdbfcc2a04f..6002a3262d4 100644
--- a/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp
+++ b/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp
@@ -4,11 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/AnyOf.h>
#include <LibGC/Heap.h>
#include <LibWeb/DOM/CDATASection.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentType.h>
#include <LibWeb/DOM/ProcessingInstruction.h>
+#include <LibWeb/HTML/HTMLLinkElement.h>
#include <LibWeb/HTML/HTMLScriptElement.h>
#include <LibWeb/HTML/HTMLTemplateElement.h>
#include <LibWeb/HTML/Parser/Entities.h>
@@ -140,6 +142,15 @@ void XMLDocumentBuilder::element_start(Utf16FlyString const& name, Vector<XML::L
script_element.set_parser_document(Badge<XMLDocumentBuilder> {}, m_document);
script_element.set_force_async(Badge<XMLDocumentBuilder> {}, false);
}
+
+ // AD-HOC: Let <link> elements know which document they were originally parsed for.
+ // This is used for the script-blocking and render-blocking logic.
+ if (auto* link_element = as_if<HTML::HTMLLinkElement>(*node)) {
+ link_element->set_parser_document(Badge<XMLDocumentBuilder> {}, m_document);
+ auto has_disabled_attribute = any_of(attributes, [](auto const& attribute) { return attribute.name == "disabled"sv; });
+ link_element->set_was_enabled_when_created_by_parser(Badge<XMLDocumentBuilder> {}, !has_disabled_attribute);
+ }
+
if (m_current_node->is_html_template_element()) {
// When an XML parser would append a node to a template element, it must instead append it to the template element's template contents (a DocumentFragment node).
m_template_node_stack.append(*m_current_node);
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/106-import-xhtml.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/106-import-xhtml.txt
index b0f31846164..553eb7818ec 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/106-import-xhtml.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/106-import-xhtml.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Stylesheet in XHTML HEAD with @import blocking scripts
\ No newline at end of file
+1 Pass
+Pass Stylesheet in XHTML HEAD with @import blocking scripts
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/106-noimport-xhtml.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/106-noimport-xhtml.txt
index 801718f10fb..414ab7a1d82 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/106-noimport-xhtml.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/106-noimport-xhtml.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Stylesheet in XHTML HEAD blocking scripts
\ No newline at end of file
+1 Pass
+Pass Stylesheet in XHTML HEAD blocking scripts
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/150-import-xhtml.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/150-import-xhtml.txt
index dc62825d53b..142402eabe0 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/150-import-xhtml.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/150-import-xhtml.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Stylesheet in XHTML BODY with @import blocking scripts
\ No newline at end of file
+1 Pass
+Pass Stylesheet in XHTML BODY with @import blocking scripts
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/150-noimport-xhtml.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/150-noimport-xhtml.txt
index 60f9cd57ab2..c50cf501753 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/150-noimport-xhtml.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/execution-timing/150-noimport-xhtml.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Stylesheet in XHTML BODY blocking scripts
\ No newline at end of file
+1 Pass
+Pass Stylesheet in XHTML BODY blocking scripts
\ No newline at end of file