From 768b1455d6041e8bc278de021e247e4ac4dfd15b Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 16 Apr 2024 11:23:48 +0200 Subject: [PATCH] LibWeb: Run fallback steps if data type is not supported Progress on fixing regressed Acid2. --- ...ith-unsupported-type-in-data-attribute.txt | 1 + ...th-unsupported-type-in-data-attribute.html | 8 +++++++ .../Libraries/LibWeb/DOM/DocumentLoading.cpp | 24 +++++++++++++++++++ .../Libraries/LibWeb/DOM/DocumentLoading.h | 1 + .../LibWeb/HTML/HTMLObjectElement.cpp | 18 +++++++------- 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/object-with-unsupported-type-in-data-attribute.txt create mode 100644 Tests/LibWeb/Text/input/object-with-unsupported-type-in-data-attribute.html diff --git a/Tests/LibWeb/Text/expected/object-with-unsupported-type-in-data-attribute.txt b/Tests/LibWeb/Text/expected/object-with-unsupported-type-in-data-attribute.txt new file mode 100644 index 00000000000..c9a1bf3b3e9 --- /dev/null +++ b/Tests/LibWeb/Text/expected/object-with-unsupported-type-in-data-attribute.txt @@ -0,0 +1 @@ + Fallback diff --git a/Tests/LibWeb/Text/input/object-with-unsupported-type-in-data-attribute.html b/Tests/LibWeb/Text/input/object-with-unsupported-type-in-data-attribute.html new file mode 100644 index 00000000000..b7a0b610bdf --- /dev/null +++ b/Tests/LibWeb/Text/input/object-with-unsupported-type-in-data-attribute.html @@ -0,0 +1,8 @@ + + + +
Fallback
+
+ diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp index 73298cb435b..bc84108de0f 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp @@ -414,6 +414,30 @@ static WebIDL::ExceptionOr> load_media_document( // be true for the Document. } +bool can_load_document_with_type(MimeSniff::MimeType const& type) +{ + if (type.is_html()) + return true; + if (type.is_xml()) + return true; + if (type.is_javascript() + || type.is_json() + || type.essence() == "text/css"_string + || type.essence() == "text/plain"_string + || type.essence() == "text/vtt"_string) { + return true; + } + if (type.essence() == "multipart/x-mixed-replace"_string) + return true; + if (type.is_image() || type.is_audio_or_video()) + return true; + if (type.essence() == "application/pdf"_string || type.essence() == "text/pdf"_string) + return true; + if (type.essence() == "text/markdown"sv) + return true; + return false; +} + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#loading-a-document JS::GCPtr load_document(HTML::NavigationParams const& navigation_params) { diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.h b/Userland/Libraries/LibWeb/DOM/DocumentLoading.h index 50294f0a4ce..1fa2db3661a 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.h +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.h @@ -13,6 +13,7 @@ namespace Web { bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optional content_encoding); JS::GCPtr load_document(HTML::NavigationParams const& navigation_params); +bool can_load_document_with_type(MimeSniff::MimeType const&); // https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline template diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index 810063c2406..3c7c444c170 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -233,15 +234,6 @@ void HTMLObjectElement::resource_did_load() run_object_representation_handler_steps(resource_type.has_value() ? resource_type->to_byte_string() : ByteString::empty()); } -static bool is_xml_mime_type(StringView resource_type) -{ - auto mime_type = MimeSniff::MimeType::parse(resource_type).release_value_but_fixme_should_propagate_errors(); - if (!mime_type.has_value()) - return false; - - return mime_type->is_xml(); -} - // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-object-element:plugin-11 void HTMLObjectElement::run_object_representation_handler_steps(Optional resource_type) { @@ -252,8 +244,14 @@ void HTMLObjectElement::run_object_representation_handler_steps(Optionalstarts_with("image/"sv))) { + if (mime_type.has_value() && can_load_document_with_type(*mime_type) && (mime_type->is_xml() || !mime_type->is_image())) { // If the object element's content navigable is null, then create a new child navigable for the element. if (!m_content_navigable) { MUST(create_new_child_navigable());