From 02004b70557deaf930d74772fe58c6a21aed4cf7 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Thu, 24 Mar 2022 22:10:38 +0200 Subject: [PATCH] LibWeb: Handle XML MIME types in HTMLObjectElement --- .../Libraries/LibWeb/HTML/HTMLObjectElement.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index 5c5aa9f219..0b324c3f05 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace Web::HTML { @@ -187,6 +188,19 @@ void HTMLObjectElement::resource_did_load() run_object_representation_handler_steps(move(resource_type)); } +static bool is_xml_mime_type(StringView resource_type) +{ + auto mime_type = MimeSniff::MimeType::from_string(resource_type); + if (!mime_type.has_value()) + return false; + + // An XML MIME type is any MIME type whose subtype ends in "+xml" or whose essence is "text/xml" or "application/xml". [RFC7303] + if (mime_type->subtype().ends_with("+xml")) + return true; + + return mime_type->essence().is_one_of("text/xml"sv, "application/xml"sv); +} + // 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) { @@ -198,8 +212,7 @@ void HTMLObjectElement::run_object_representation_handler_steps(Optional // Otherwise, the user agent should use the plugin that supports resource type and pass the content of the resource to that plugin. If the plugin reports an error, then jump to the step below labeled fallback. // * If the resource type is an XML MIME type, or if the resource type does not start with "image/" - // FIXME: Handle XML MIME types. - if (resource_type.has_value() && !resource_type->starts_with("image/"sv)) { + if (resource_type.has_value() && (is_xml_mime_type(*resource_type) || !resource_type->starts_with("image/"sv))) { // If the object element's nested browsing context is null, then create a new nested browsing context for the element. if (!m_nested_browsing_context) create_new_nested_browsing_context();