mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibWeb: Run <object> fallback steps if data type is not supported
Progress on fixing regressed Acid2.
This commit is contained in:
parent
d5cddd4696
commit
768b1455d6
Notes:
sideshowbarker
2024-07-18 00:41:35 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/768b1455d6 Pull-request: https://github.com/SerenityOS/serenity/pull/23977
5 changed files with 42 additions and 10 deletions
|
@ -0,0 +1 @@
|
|||
Fallback
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="include.js"></script>
|
||||
<object id="object" data="data:application/x-unknown,ERROR">
|
||||
<div id="fallback">Fallback</div>
|
||||
</object>
|
||||
<script>
|
||||
test(() => {});
|
||||
</script>
|
|
@ -414,6 +414,30 @@ static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOM::Document>> 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<DOM::Document> load_document(HTML::NavigationParams const& navigation_params)
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Web {
|
|||
|
||||
bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optional<String> content_encoding);
|
||||
JS::GCPtr<DOM::Document> 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<typename MutateDocument>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/DocumentLoading.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/HTML/DecodedImageData.h>
|
||||
#include <LibWeb/HTML/HTMLMediaElement.h>
|
||||
|
@ -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<ByteString> resource_type)
|
||||
{
|
||||
|
@ -252,8 +244,14 @@ void HTMLObjectElement::run_object_representation_handler_steps(Optional<ByteStr
|
|||
// If plugins are being sandboxed, then jump to the step below labeled fallback.
|
||||
// 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 (!resource_type.has_value()) {
|
||||
run_object_representation_fallback_steps();
|
||||
return;
|
||||
}
|
||||
auto mime_type = MimeSniff::MimeType::parse(*resource_type).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// * If the resource type is an XML MIME type, or if the resource type does not start with "image/"
|
||||
if (resource_type.has_value() && (is_xml_mime_type(*resource_type) || !resource_type->starts_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());
|
||||
|
|
Loading…
Reference in a new issue