Truly independent web browser
LibWeb: Load documents and images in embed elements
sideshowbarker3baa2b06c45f
diff --git a/Libraries/LibWeb/CSS/StyleEngineInput.cpp b/Libraries/LibWeb/CSS/StyleEngineInput.cppindex 4e63aee8a69..49f68ed88b1 100644--- a/Libraries/LibWeb/CSS/StyleEngineInput.cpp+++ b/Libraries/LibWeb/CSS/StyleEngineInput.cpp@@ -33,6 +33,7 @@#include <LibWeb/HTML/HTMLBRElement.h>#include <LibWeb/HTML/HTMLBodyElement.h>#include <LibWeb/HTML/HTMLCanvasElement.h>+#include <LibWeb/HTML/HTMLEmbedElement.h>#include <LibWeb/HTML/HTMLFrameSetElement.h>#include <LibWeb/HTML/HTMLHeadingElement.h>#include <LibWeb/HTML/HTMLImageElement.h>@@ -1612,7 +1613,7 @@ static ElementOpenFacts element_open_facts(DOM::Element const& element)set(is<SVG::SVGElement>(element), ElementOpenFacts::SvgElement);set(is_body || is<HTML::HTMLFrameSetElement>(element), ElementOpenFacts::Body);set(is<HTML::HTMLHeadingElement>(element), ElementOpenFacts::Heading);- set(is_input || is<HTML::HTMLTextAreaElement>(element) || is<HTML::HTMLImageElement>(element) || is<HTML::HTMLObjectElement>(element) || is<HTML::HTMLVideoElement>(element)+ set(is_input || is<HTML::HTMLTextAreaElement>(element) || is<HTML::HTMLImageElement>(element) || is<HTML::HTMLObjectElement>(element) || is<HTML::HTMLEmbedElement>(element) || is<HTML::HTMLVideoElement>(element)|| is<SVG::SVGImageElement>(element) || is<HTML::HTMLCanvasElement>(element),ElementOpenFacts::ReplacedContent);set(is_input || local_name == HTML::TagNames::bdi, ElementOpenFacts::OwnDirectionality);@@ -1902,6 +1903,13 @@ static void publish_element_replaced_content_input(DOM::Element& element, StyleEset_image_natural_size_input(style_engine, node, *image);return;}+ if (auto const* embed = as_if<HTML::HTMLEmbedElement>(element)) {+ if (embed->content_navigable())+ set_natural_size_input(style_engine, node, embed->natural_size_of_content_document());+ else+ set_image_natural_size_input(style_engine, node, *embed);+ return;+ }if (auto const* object = as_if<HTML::HTMLObjectElement>(element)) {// An object representing its content navigable is sized from the SVG document it shows.if (object->represents_its_content_navigable())diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.hindex 3c5042de1ba..f7bdac780cb 100644--- a/Libraries/LibWeb/DOM/Document.h+++ b/Libraries/LibWeb/DOM/Document.h@@ -209,6 +209,7 @@ enum class InvalidateLayoutTreeReason {X(EventHandlerShowContextMenu, false) \X(EventHandlerTargetNodeAtPosition, false) \X(FontFaceSetReady, false) \+ X(HTMLEmbedElement, false) \X(HTMLElementGetTheTextSteps, false) \X(HTMLElementOffsetHeight, true) \X(HTMLElementOffsetLeft, true) \diff --git a/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Libraries/LibWeb/DOM/DocumentLoading.cppindex d6c82cdb29a..274a87ce633 100644--- a/Libraries/LibWeb/DOM/DocumentLoading.cpp+++ b/Libraries/LibWeb/DOM/DocumentLoading.cpp@@ -463,7 +463,7 @@ static WebIDL::ExceptionOr<GC::Ref<DOM::Document>> load_media_document(HTML::Navif (image_element) {// INTEROP: All major engines present the image from the response that was navigated to rather than fetching it// again. A second fetch would be subject to the Content-Security-Policy of that same response.- image_element->set_resource_from_navigation_response(HTML::SharedResourceRequest::create_from_navigation_response_body(document, *navigation_params.response->body(), stop_parsing));+ image_element->set_resource_from_navigation_response(HTML::SharedResourceRequest::create_from_image_response_body(document, document->url(), *navigation_params.response->body(), false, stop_parsing));} else {navigation_params.response->body()->fully_read(realm,diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.hindex 9c702181d89..4a5ae34d53f 100644--- a/Libraries/LibWeb/DOM/Node.h+++ b/Libraries/LibWeb/DOM/Node.h@@ -87,7 +87,7 @@ enum class RootNodeComposed {X(HTMLCanvasElementWidthOrHeightChange) \X(HTMLImageElementReactToChangesInTheEnvironment) \X(HTMLImageElementUpdateTheImageData) \- X(HTMLObjectElementContentDocumentResized) \+ X(EmbeddedDocumentResized) \X(HTMLVideoElementNaturalDimensionsChanged) \X(HTMLVideoElementSetVideoTrack) \X(ImplicitAnchorChange) \@@ -116,6 +116,7 @@ enum class SetNeedsLayoutReason {X(HTMLImageElementUpdateTheImageData) \X(HTMLInputElementSrcAttribute) \X(HTMLInputElementTypeAttribute) \+ X(HTMLEmbedElementRepresentationChanged) \X(HTMLObjectElementUpdateLayoutAndChildObjects) \X(KeyframeEffect) \X(LanguageChangeUnderCasingTextTransform) \diff --git a/Libraries/LibWeb/HTML/EventLoop/Task.h b/Libraries/LibWeb/HTML/EventLoop/Task.hindex f299f6e830a..afaaa11b311 100644--- a/Libraries/LibWeb/HTML/EventLoop/Task.h+++ b/Libraries/LibWeb/HTML/EventLoop/Task.h@@ -104,6 +104,9 @@ public:// https://storage.spec.whatwg.org/#task-sourceStorage,+ // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#embed-task-source+ Embed,+// !!! IMPORTANT: Keep this field last!// This serves as the base value of all unique task sources.// Some elements, such as the HTMLMediaElement, must have a unique task source per instance.diff --git a/Libraries/LibWeb/HTML/HTMLEmbedElement.cpp b/Libraries/LibWeb/HTML/HTMLEmbedElement.cppindex 748295c4d15..4456ae4af3d 100644--- a/Libraries/LibWeb/HTML/HTMLEmbedElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLEmbedElement.cpp@@ -4,23 +4,431 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibWeb/CSS/ElementBoxKind.h>#include <LibWeb/CSS/PropertyID.h>+#include <LibWeb/CSS/StyleEngineInput.h>#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>+#include <LibWeb/DOM/Document.h>+#include <LibWeb/DOM/DocumentLoading.h>+#include <LibWeb/DOM/DocumentObserver.h>+#include <LibWeb/DOM/Event.h>+#include <LibWeb/Fetch/Fetching/Checks.h>+#include <LibWeb/Fetch/Fetching/Fetching.h>+#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>+#include <LibWeb/Fetch/Infrastructure/FetchController.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>+#include <LibWeb/HTML/DecodedImageData.h>#include <LibWeb/HTML/HTMLEmbedElement.h>+#include <LibWeb/HTML/HTMLMediaElement.h>+#include <LibWeb/HTML/HTMLObjectElement.h>+#include <LibWeb/HTML/Navigable.h>#include <LibWeb/HTML/Parser/HTMLParser.h>+#include <LibWeb/HTML/PolicyContainers.h>+#include <LibWeb/HTML/Scripting/Environments.h>+#include <LibWeb/HTML/SharedResourceRequest.h>+#include <LibWeb/HighResolutionTime/TimeOrigin.h>+#include <LibWebCommon/Fetch/Infrastructure/URL.h>+#include <LibWebCommon/MimeSniff/MimeType.h>namespace Web::HTML {GC_DEFINE_ALLOCATOR(HTMLEmbedElement);HTMLEmbedElement::HTMLEmbedElement(DOM::Document& document, DOM::QualifiedName qualified_name)- : HTMLElement(document, move(qualified_name))+ : NavigableContainer(document, move(qualified_name)){}HTMLEmbedElement::~HTMLEmbedElement() = default;+void HTMLEmbedElement::visit_edges(Cell::Visitor& visitor)+{+ Base::visit_edges(visitor);+ visitor.visit(m_image_request);+ visitor.visit(m_fetch_controller);+ visitor.visit(m_document_observer);+}++// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-embed-element-setup-steps+// Whenever an embed element that was not potentially active becomes potentially active, and whenever a potentially+// active embed element that is remaining potentially active has its src attribute set, changed, or removed or its type+// attribute set, changed, or removed, the user agent must queue an element task on the embed task source given the+// element to run the embed element setup steps for that element.+// NB: Whether the element is potentially active depends on its layout, so these hooks queue the setup steps whenever it+// may have become potentially active, and the setup steps check that it is (see is_potentially_active()):+// - initialize_element() and adopted_from(): Its node document becomes fully active, or stops being fully active.+// - post_connection() and removed_from(): It's inserted into a document, or removed from one.+// - attribute_changed(): Its src or type attribute is set, changed, or removed.+// - rendering_changed(): It starts or stops being rendered.+// - ancestor_object_started_showing_fallback_content(): An ancestor object element starts showing its fallback+// content.+void HTMLEmbedElement::initialize_element()+{+ m_document_observer = DOM::DocumentObserver::create(document());+ m_document_observer->set_document_became_active(GC::create_function(heap(), GC::captures(*this), [](auto& self) {+ self.queue_setup_steps();+ }));+ m_document_observer->set_document_became_inactive(GC::create_function(heap(), GC::captures(*this), [](auto& self) {+ self.stop_loading();+ }));+}++void HTMLEmbedElement::adopted_from(DOM::Document& old_document)+{+ Base::adopted_from(old_document);+ m_document_observer->retarget_for_adoption(document());+}++void HTMLEmbedElement::post_connection()+{+ Base::post_connection();+ queue_setup_steps();+}++void HTMLEmbedElement::removed_from(IsSubtreeRoot is_subtree_root, DOM::Node* old_ancestor, DOM::Node& old_root)+{+ Base::removed_from(is_subtree_root, old_ancestor, old_root);+ stop_loading();+}++void HTMLEmbedElement::attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_)+{+ Base::attribute_changed(name, old_value, value, namespace_);+ if (!namespace_.has_value() && first_is_one_of(name, AttributeNames::src, AttributeNames::type))+ queue_setup_steps();+}++// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#display-no-plugin+// Whenever an embed element that was potentially active stops being potentially active, any plugin that had been+// instantiated for that element must be unloaded.+// NB: This displays no plugin for the element, and stops whatever it was loading or showing: Its fetch, its image, and+// its content navigable.+void HTMLEmbedElement::stop_loading()+{+ ++m_setup_generation;+ if (m_fetch_controller)+ m_fetch_controller->abort(relevant_realm(*this), {});+ m_fetch_controller = nullptr;+ m_load_event_delayer.clear();+ if (!m_image_request && !m_content_navigable)+ return;++ // NB: An image that is still being decoded from the response body delays the load event until it ends, so end it.+ if (m_image_request)+ m_image_request->response_body_fetch_was_stopped();+ m_image_request = nullptr;++ // 1. Destroy a child navigable given element.+ destroy_the_child_navigable();++ // FIXME: 2. Display an indication that no plugin could be found for element, as the contents of element.++ // 3. element now represents nothing.+ m_natural_size = {};+ update_representation();+}++CSS::ElementBoxKind HTMLEmbedElement::box_kind() const+{+ if (content_navigable())+ return CSS::ElementBoxKind::NavigableContainerViewport;+ if (m_image_request && m_image_request->image_data())+ return CSS::ElementBoxKind::Image;+ return Base::box_kind();+}++GC::Ptr<DecodedImageData> HTMLEmbedElement::decoded_image_data() const+{+ return m_image_request ? m_image_request->image_data() : nullptr;+}++void HTMLEmbedElement::set_natural_size_of_content_document(CSS::SizeWithAspectRatio const& size)+{+ m_natural_size = size;+ CSS::record_element_replaced_content_input(*this);+ set_needs_layout_update(DOM::SetNeedsLayoutReason::EmbeddedDocumentResized);+}++void HTMLEmbedElement::update_representation()+{+ CSS::record_element_box_kind(*this);+ CSS::record_element_replaced_content_input(*this);+ // NB: The parent is a shadow root for an embed at the top of a shadow tree, so it's not always an element.+ if (auto parent = this->parent())+ parent->set_needs_layout_tree_update(true, DOM::SetNeedsLayoutTreeUpdateReason::HTMLEmbedElementRepresentationChanged);+}++// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-embed-element-setup-steps+void HTMLEmbedElement::queue_setup_steps()+{+ if (!is_connected() || !document().is_fully_active())+ return;+ auto generation = ++m_setup_generation;++ // The embed element potentially delays the load event.+ // NB: The delay starts when the setup steps are queued, so that the load event can't fire between now and the fetch+ // those steps start, and it ends once the steps have nothing more to load.+ m_load_event_delayer.emplace(document());+ queue_an_element_task(Task::Source::Embed, GC::create_function(heap(), GC::captures(*this, generation), [](auto& self, auto generation) {+ // 1. If another task has since been queued to run the embed element setup steps for element, then return.+ if (self.m_setup_generation != generation)+ return;+ self.run_setup_steps(generation);+ }),+ GC::create_function(heap(), GC::captures(*this, generation), [](auto& self, auto generation) {+ if (self.m_setup_generation == generation)+ self.m_load_event_delayer.clear();+ }));+}++// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#concept-embed-active+bool HTMLEmbedElement::is_potentially_active()+{+ // An embed element is said to be potentially active when the following conditions are all met simultaneously:+ // - The element is in a document or was in a document the last time the event loop reached step 1.+ // AD-HOC: "In a document" is a legacy term, and the spec's use of it hasn't been updated for shadow trees:+ // https://dom.spec.whatwg.org/#in-a-document+ // So an embed in a shadow tree counts once it's connected, the same as one in the document tree.+ // - The element's node document is fully active.+ if (!is_connected() || !document().is_fully_active())+ return false;++ // - The element has either a src attribute set or a type attribute set (or both).+ auto src = get_attribute(AttributeNames::src);+ if (!src.has_value() && !has_attribute(AttributeNames::type))+ return false;++ // - The element's src attribute is either absent or its value is not the empty string.+ if (src.has_value() && src->is_empty())+ return false;++ // - The element is being rendered, or was being rendered the last time the event loop reached step 1.+ // NB: This is checked ahead of the ancestor conditions, so that the rendering state that rendering_changed()+ // compares against is current, even when an ancestor keeps the element from being potentially active.+ document().update_layout(DOM::UpdateLayoutReason::HTMLEmbedElement);+ m_was_rendered = has_layout_box();+ if (!m_was_rendered)+ return false;++ // - The element is not a descendant of a media element.+ // - The element is not a descendant of an object element that is not showing its fallback content.+ for (auto ancestor = parent(); ancestor; ancestor = ancestor->parent()) {+ if (is<HTMLMediaElement>(*ancestor) || (is<HTMLObjectElement>(*ancestor) && !as<HTMLObjectElement>(*ancestor).shows_fallback_content()))+ return false;+ }+ return true;+}++// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-embed-element-setup-steps+void HTMLEmbedElement::run_setup_steps(u64 generation)+{+ // NB: Step 1 is done by the task that runs these steps. And since the steps are queued whenever the element may+ // have become potentially active, they check here that it is, and unload what it shows if it isn't.+ if (!is_potentially_active()) {+ stop_loading();+ return;+ }++ // 2. If element has a src attribute set:+ auto src = get_attribute(AttributeNames::src);+ if (!src.has_value()) {+ // 3. Otherwise, display no plugin for element.+ stop_loading();+ return;+ }++ // 1. Let url be the result of encoding-parsing a URL given element's src attribute's value, relative to element's+ // node document.+ auto url = document().encoding_parse_url(*src);++ // 2. If url is failure, then return.+ // AD-HOC: The spec leaves whatever a previous src loaded in place. Instead, display no plugin, as the element no+ // longer names anything to show.+ if (!url.has_value()) {+ stop_loading();+ return;+ }++ // 3. Let request be a new request whose URL is url, client is element's node document's relevant settings object,+ // destination is "embed", credentials mode is "include", mode is "navigate", initiator type is "embed", and+ // whose use-URL-credentials flag is set.+ using Request = Fetch::Infrastructure::Request;+ auto request = Request::create();+ request->set_url(url.release_value());+ request->set_client(document().relevant_settings_object().address());+ request->set_destination(Request::Destination::Embed);+ request->set_credentials_mode(Request::CredentialsMode::Include);+ request->set_mode(Request::Mode::Navigate);+ request->set_initiator_type(Request::InitiatorType::Embed);+ request->set_use_url_credentials(true);++ // 4. Fetch request, with processResponse set to the following steps given response response:+ // NB: A fetch from an earlier run of these steps is no longer wanted, so abort it.+ if (m_fetch_controller)+ m_fetch_controller->abort(relevant_realm(*this), {});+ Fetch::Infrastructure::FetchAlgorithms::Input algorithms { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };+ algorithms.process_response = GC::create_function(heap(), GC::captures(*this, generation), [](auto& self, auto generation, GC::Ref<Fetch::Infrastructure::ResponseView> response) {+ // 1. If another task has since been queued to run the embed element setup steps for element, then return.+ if (generation == self.m_setup_generation)+ self.handle_response(response, generation);+ });+ m_fetch_controller = Fetch::Fetching::fetch(relevant_realm(*this), request, Fetch::Infrastructure::FetchAlgorithms::create(move(algorithms)));++ // Fetching the resource must delay the load event of element's node document.+ // NB: The delay that queue_setup_steps() started lasts until the response has been handled.++ // AD-HOC: A stopped fetch, such as one of a document that was stopped, never processes its response. Stop delaying+ // the load event on it then, as if the user agent had given up on loading it.+ m_fetch_controller->set_stop_steps(GC::create_function(heap(), GC::captures(GC::Weak { *this }, generation), [](auto& weak_this, auto generation) {+ auto embed = weak_this.ptr();+ if (!embed || embed->m_setup_generation != generation)+ return;+ embed->m_fetch_controller = nullptr;+ embed->m_load_event_delayer.clear();++ // NB: An image that is being decoded from the response body won't get the rest of it either.+ if (auto image_request = embed->m_image_request)+ image_request->response_body_fetch_was_stopped();+ }));+}++// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-embed-element-setup-steps+// NB: These are the processResponse steps of step 2.4 of the embed element setup steps, from step 2 on.+void HTMLEmbedElement::handle_response(Fetch::Infrastructure::ResponseView& response, u64 generation)+{+ // 2. If response is a network error, then fire an event named load at element, and return.+ // AD-HOC: The spec leaves whatever a previous src loaded in place. Instead, display no plugin, as nothing loaded.+ auto handle_network_error = [&] {+ stop_loading();+ dispatch_event(DOM::Event::create(EventNames::load, HighResolutionTime::current_high_resolution_time(relevant_global_object(*this))));+ };+ // NB: A response without a URL has nothing to navigate to, so it's handled as a network error.+ if (response.is_network_error() || !response.url().has_value()) {+ handle_network_error();+ return;+ }++ // 3. Let type be the result of determining the type of content given element and response.+ // AD-HOC: The spec determines the type of the content only for a plugin, and otherwise returns null, so that the+ // element displays no plugin for an HTML or SVG document, or for an image. Instead, take the type from the+ // response's Content-Type, or from a type attribute that names an image type or a type of document that+ // can be loaded, and show documents and images, as the web expects:+ // https://github.com/whatwg/html/issues/513+ auto type = Fetch::Infrastructure::extract_mime_type(response.header_list());+ if (auto declared = get_attribute(AttributeNames::type); declared.has_value()) {+ if (auto mime = MimeSniff::MimeType::parse(*declared); mime.has_value() && (mime->is_image() || can_load_document_with_type(*mime)))+ type = move(mime);+ }++ // 4. Switch on type:+ // null+ // 1. Display no plugin for element.+ if (!type.has_value()) {+ stop_loading();+ return;+ }++ // AD-HOC: The spec has no case for an image. Rather than navigating the content navigable to an image document,+ // show a raster image as the element's own image:+ // https://github.com/whatwg/html/issues/7939+ if (type->is_image() && !type->is_xml() && response.body()) {+ // NB: The setup fetch uses navigation mode, but the raster response is consumed as an image subresource, so it+ // gets the cross-origin resource policy check of one.+ // https://fetch.spec.whatwg.org/#cross-origin-resource-policy-check+ if (Fetch::Infrastructure::is_http_or_https_scheme(response.url()->scheme())+ && Fetch::Fetching::cross_origin_resource_policy_check(document().origin(), document().policy_container()->embedder_policy, *response.record()) == Fetch::Infrastructure::RequestOrResponseBlocking::Blocked) {+ handle_network_error();+ return;+ }+ destroy_the_child_navigable();+ m_natural_size = {};+ m_image_request = SharedResourceRequest::create_from_image_response_body(document(), *response.url(), *response.body(), !document().origin().is_same_origin(response.url()->origin()), {});+ auto complete = GC::create_function(heap(), GC::captures(*this, generation), [](auto& self, auto generation) {+ if (generation != self.m_setup_generation)+ return;+ self.update_representation();+ self.m_load_event_delayer.clear();+ self.m_fetch_controller = nullptr;+ self.dispatch_event(DOM::Event::create(EventNames::load, HighResolutionTime::current_high_resolution_time(relevant_global_object(self))));+ });+ auto discard = GC::create_function(heap(), GC::captures(*this, generation), [](auto& self, auto generation) {+ if (generation == self.m_setup_generation)+ self.stop_loading();+ });+ m_image_request->add_callbacks(complete, discard, discard);+ update_representation();+ return;+ }++ // NB: A type that names neither an image nor a type of document that can be loaded is null, as above.+ if (!can_load_document_with_type(*type)) {+ stop_loading();+ return;+ }++ // AD-HOC: The spec does not stop an embed from embedding the document that contains it, so the nesting never ends+ // and the load event never fires. As for an object element, allow one level of self-reference, and display+ // no plugin at the second.+ size_t matching_ancestors = 0;+ for (auto const& ancestor : document().inclusive_ancestor_navigables()) {+ auto ancestor_url = ancestor->active_document_url();+ if (ancestor_url.has_value() && ancestor_url->equals(*response.url(), URL::ExcludeFragment::Yes) && ++matching_ancestors >= 2) {+ stop_loading();+ return;+ }+ }++ // Otherwise+ m_image_request = nullptr;+ m_natural_size = {};++ // 1. If element's content navigable is null, then create a new child navigable for element.+ if (!m_content_navigable)+ create_new_child_navigable();++ // 2. Navigate element's content navigable to response's URL using element's node document, with response set+ // to response, and historyHandling set to "replace".+ // FIXME: Navigate with response set to response, rather than fetching the document a second time.+ if (m_content_navigable) {+ MUST(m_content_navigable->navigate({+ .url = *response.url(),+ .source_document = document(),+ .history_handling = NavigationHistoryBehavior::Replace,+ }));+ }++ // NB: The content navigable delays the load event while it loads the document, so the element no longer needs to.+ // And the navigation fetches the document itself, so this fetch can stop.+ m_load_event_delayer.clear();+ if (m_fetch_controller)+ m_fetch_controller->abort(relevant_realm(*this), {});+ m_fetch_controller = nullptr;++ // 3. element now represents its content navigable.+ update_representation();+}++void HTMLEmbedElement::rendering_changed()+{+ if (!has_attribute(AttributeNames::src) || !is_connected())+ return;+ queue_an_element_task(Task::Source::Embed, GC::create_function(heap(), GC::captures(*this), [](auto& self) {+ if (self.has_layout_box() != self.m_was_rendered)+ self.queue_setup_steps();+ }));+}++void HTMLEmbedElement::ancestor_object_started_showing_fallback_content()+{+ // NB: The embed may start being rendered now, but it gets its layout box only at the next layout update, which can+ // come after the object's fetch stops delaying the document's load event. Queueing the setup steps right away+ // delays that load event until the embed has loaded.+ if (has_attribute(AttributeNames::src))+ queue_setup_steps();+}+bool HTMLEmbedElement::is_presentational_hint(Utf16FlyString const& name) const{if (Base::is_presentational_hint(name))diff --git a/Libraries/LibWeb/HTML/HTMLEmbedElement.h b/Libraries/LibWeb/HTML/HTMLEmbedElement.hindex 28d79db365f..97906d56b4d 100644--- a/Libraries/LibWeb/HTML/HTMLEmbedElement.h+++ b/Libraries/LibWeb/HTML/HTMLEmbedElement.h@@ -6,23 +6,58 @@#pragma once-#include <LibWeb/HTML/HTMLElement.h>+#include <LibWeb/CSS/Sizing.h>+#include <LibWeb/DOM/DocumentLoadEventDelayer.h>+#include <LibWeb/HTML/NavigableContainer.h>+#include <LibWeb/Layout/ImageProvider.h>namespace Web::HTML {-class HTMLEmbedElement final : public HTMLElement {- WEB_WRAPPABLE(HTMLEmbedElement, HTMLElement);+class HTMLEmbedElement final+ : public NavigableContainer+ , public Layout::ImageProvider {+ WEB_WRAPPABLE(HTMLEmbedElement, NavigableContainer);GC_DECLARE_ALLOCATOR(HTMLEmbedElement);public:virtual ~HTMLEmbedElement() override;+ CSS::SizeWithAspectRatio const& natural_size_of_content_document() const { return m_natural_size; }+ void set_natural_size_of_content_document(CSS::SizeWithAspectRatio const&);+ void rendering_changed();+ void ancestor_object_started_showing_fallback_content();+private:HTMLEmbedElement(DOM::Document&, DOM::QualifiedName);virtual bool is_html_embed_element() const override { return true; }virtual bool is_presentational_hint(Utf16FlyString const&) const override;virtual void apply_presentational_hints(Vector<CSS::StyleProperty>&) const override;++ virtual void visit_edges(Cell::Visitor&) override;+ virtual void initialize_element() override;+ virtual void adopted_from(DOM::Document&) override;+ virtual void post_connection() override;+ virtual bool has_post_connection_steps() const override { return true; }+ virtual void removed_from(IsSubtreeRoot, DOM::Node* old_ancestor, DOM::Node& old_root) override;+ virtual void attribute_changed(Utf16FlyString const&, Optional<Utf16String> const&, Optional<Utf16String> const&, Optional<Utf16FlyString> const&) override;+ virtual CSS::ElementBoxKind box_kind() const override;+ virtual GC::Ptr<DecodedImageData> decoded_image_data() const override;++ void queue_setup_steps();+ bool is_potentially_active();+ void run_setup_steps(u64 generation);+ void handle_response(Fetch::Infrastructure::ResponseView&, u64 generation);+ void stop_loading();+ void update_representation();++ u64 m_setup_generation { 0 };+ bool m_was_rendered { false };+ CSS::SizeWithAspectRatio m_natural_size;+ GC::Ptr<SharedResourceRequest> m_image_request;+ GC::Ptr<DOM::DocumentObserver> m_document_observer;+ GC::Ptr<Fetch::Infrastructure::FetchController> m_fetch_controller;+ Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer;};}diff --git a/Libraries/LibWeb/HTML/HTMLEmbedElement.idl b/Libraries/LibWeb/HTML/HTMLEmbedElement.idlindex 2b8cb10fc6a..b548ca1d4b1 100644--- a/Libraries/LibWeb/HTML/HTMLEmbedElement.idl+++ b/Libraries/LibWeb/HTML/HTMLEmbedElement.idl@@ -8,7 +8,7 @@ interface HTMLEmbedElement : HTMLElement {[CEReactions, Reflect] attribute DOMString type;[CEReactions, Reflect] attribute DOMString width;[CEReactions, Reflect] attribute DOMString height;- [FIXME] Document? getSVGDocument();+ Document? getSVGDocument();// Obsolete[CEReactions, Reflect] attribute DOMString align;diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cppindex 9c6f07aa79e..2feadde8096 100644--- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp@@ -26,6 +26,7 @@#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/BrowsingContext.h>#include <LibWeb/HTML/DecodedImageData.h>+#include <LibWeb/HTML/HTMLEmbedElement.h>#include <LibWeb/HTML/HTMLMediaElement.h>#include <LibWeb/HTML/HTMLObjectElement.h>#include <LibWeb/HTML/ImageRequest.h>@@ -608,6 +609,12 @@ void HTMLObjectElement::update_layout_and_child_objects(Representation representobject.queue_element_task_to_run_object_representation_steps();return IterationDecision::Continue;});+ if (m_representation != Representation::Children) {+ for_each_in_subtree_of_type<HTMLEmbedElement>([](auto& embed) {+ embed.ancestor_object_started_showing_fallback_content();+ return TraversalDecision::Continue;+ });+ }}m_representation = representation;@@ -630,7 +637,7 @@ void HTMLObjectElement::set_natural_size_of_content_document(CSS::SizeWithAspect{m_natural_size_of_content_document = natural_size;CSS::record_element_replaced_content_input(*this);- set_needs_layout_update(DOM::SetNeedsLayoutReason::HTMLObjectElementContentDocumentResized);+ set_needs_layout_update(DOM::SetNeedsLayoutReason::EmbeddedDocumentResized);}GC::Ptr<DecodedImageData> HTMLObjectElement::image_data() constdiff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Libraries/LibWeb/HTML/HTMLObjectElement.hindex bcb8516b468..b4a91e66235 100644--- a/Libraries/LibWeb/HTML/HTMLObjectElement.h+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.h@@ -36,6 +36,8 @@ public:Utf16String type() const { return get_attribute_value(HTML::AttributeNames::type); }+ bool shows_fallback_content() const { return m_representation == Representation::Children; }+bool represents_its_content_navigable() const { return m_representation == Representation::ContentNavigable; }// The natural size of the <svg> document element of the document the element shows as its content navigable's,diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 62a867f9715..b295c91691d 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -2791,9 +2791,10 @@ static void create_navigation_params_by_fetching(// The referenced issue suggests that it is a no-op to retrieve the browsing context scope origin.// 2. Set request's destination to navigable's container's local name.- // FIXME: Are there other container types? If so, we need a helper here+ auto container_is_embed = *container_local_name == HTML::TagNames::embed;auto container_is_iframe = *container_local_name == HTML::TagNames::iframe;request->set_destination(container_is_iframe ? Web::Fetch::Infrastructure::Request::Destination::IFrame+ : container_is_embed ? Web::Fetch::Infrastructure::Request::Destination::Embed: Web::Fetch::Infrastructure::Request::Destination::Object);// 3. If sourceSnapshotParams's fetch client is navigable's container document's relevant settings object,@@ -2803,8 +2804,8 @@ static void create_navigation_params_by_fetching(// is that process's, so its resource timing is not told of the navigation.auto fetch_client = settings_object_of_fetch_client(source_snapshot_params->fetch_client);if (auto container_document = navigable->container_document(); container_document && fetch_client.ptr() == &container_document->relevant_settings_object()) {- // FIXME: Are there other container types? If so, we need a helper hererequest->set_initiator_type(container_is_iframe ? Web::Fetch::Infrastructure::Request::InitiatorType::IFrame+ : container_is_embed ? Web::Fetch::Infrastructure::Request::InitiatorType::Embed: Web::Fetch::Infrastructure::Request::InitiatorType::Object);}diff --git a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp b/Libraries/LibWeb/HTML/SharedResourceRequest.cppindex e882ae78f0e..952773c2a0f 100644--- a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp+++ b/Libraries/LibWeb/HTML/SharedResourceRequest.cpp@@ -59,26 +59,28 @@ GC::Ref<SharedResourceRequest> SharedResourceRequest::get_or_create(DOM::Documenreturn get_or_create(document, { request.url(), request.mode(), request.credentials_mode(), request.integrity_metadata(), request.referrer_policy() });}-GC::Ref<SharedResourceRequest> SharedResourceRequest::create_from_navigation_response_body(DOM::Document& document, Fetch::Infrastructure::Body const& body, GC::Ref<GC::Function<void()>> on_body_read)+GC::Ref<SharedResourceRequest> SharedResourceRequest::create_from_image_response_body(DOM::Document& document, URL::URL const& url, Fetch::Infrastructure::Body const& body, bool is_cors_cross_origin, GC::Ptr<GC::Function<void()>> on_body_read){using Request = Fetch::Infrastructure::Request;- auto request = GC::Heap::the().allocate<SharedResourceRequest>(document.page(), Key { document.url(), Request::Mode::NoCORS, Request::CredentialsMode::Include, {}, ReferrerPolicy::ReferrerPolicy::EmptyString }, document);+ auto request = GC::Heap::the().allocate<SharedResourceRequest>(document.page(), Key { url, Request::Mode::NoCORS, Request::CredentialsMode::Include, {}, ReferrerPolicy::ReferrerPolicy::EmptyString }, document);request->m_can_be_shared = false;request->m_state = State::Fetching;// NB: The element that presents the image may start to wait for it only after the body has been read.request->m_load_event_delayer.emplace(document);GC::Weak weak_request { *request };- auto process_body = GC::create_function(GC::Heap::the(), GC::captures(weak_request, on_body_read), [](auto& weak_request, auto& on_body_read, ByteBuffer data) {+ auto process_body = GC::create_function(GC::Heap::the(), GC::captures(weak_request, on_body_read, is_cors_cross_origin), [](auto& weak_request, auto& on_body_read, auto is_cors_cross_origin, ByteBuffer data) {// NB: A document for an SVG image is an XML document, so this is never an SVG image.if (auto request = weak_request.ptr())- request->handle_successful_fetch(request->url(), IsSVGImage::No, move(data), false);- on_body_read->function()();+ request->handle_successful_fetch(request->url(), IsSVGImage::No, move(data), is_cors_cross_origin);+ if (on_body_read)+ on_body_read->function()();});auto process_body_error = GC::create_function(GC::Heap::the(), GC::captures(weak_request, on_body_read), [](auto& weak_request, auto& on_body_read, JS::Value) {if (auto request = weak_request.ptr())request->handle_failed_fetch();- on_body_read->function()();+ if (on_body_read)+ on_body_read->function()();});auto& realm = HTML::relevant_realm(document);@@ -400,6 +402,11 @@ void SharedResourceRequest::handle_failed_fetch()// NB: A stopped fetch never responds, so nothing waits on it anymore, and a later request for the URL// fetches it again.+void SharedResourceRequest::response_body_fetch_was_stopped()+{+ handle_stopped_fetch();+}+void SharedResourceRequest::handle_stopped_fetch(){if (m_state != State::Fetching)diff --git a/Libraries/LibWeb/HTML/SharedResourceRequest.h b/Libraries/LibWeb/HTML/SharedResourceRequest.hindex a7c50e6b226..518c4f3bf25 100644--- a/Libraries/LibWeb/HTML/SharedResourceRequest.h+++ b/Libraries/LibWeb/HTML/SharedResourceRequest.h@@ -38,11 +38,15 @@ public:[[nodiscard]] static GC::Ref<SharedResourceRequest> get_or_create(DOM::Document&, URL::URL const&, CORSSettingAttribute);[[nodiscard]] static GC::Ref<SharedResourceRequest> get_or_create(DOM::Document&, Fetch::Infrastructure::Request const&);- // Creates a request that loads the resource from the body of the response that the document was navigated to,+ // Creates a private request that decodes a raster image from the body of a response,// instead of fetching it. No fetch checks this resource against the policies of the document, so it is only for// the element that presents it, and get_or_create() never returns it.// Calls on_body_read once reading the body has ended, whether or not that succeeded.- [[nodiscard]] static GC::Ref<SharedResourceRequest> create_from_navigation_response_body(DOM::Document&, Fetch::Infrastructure::Body const&, GC::Ref<GC::Function<void()>> on_body_read);+ [[nodiscard]] static GC::Ref<SharedResourceRequest> create_from_image_response_body(DOM::Document&, URL::URL const&, Fetch::Infrastructure::Body const&, bool is_cors_cross_origin, GC::Ptr<GC::Function<void()>> on_body_read);++ // Ends a request created from a response body whose fetch was stopped or is no longer wanted, as that body will+ // never be read to its end. Does nothing once the request has finished.+ void response_body_fetch_was_stopped();virtual ~SharedResourceRequest() override;diff --git a/Libraries/LibWeb/Layout/Box.cpp b/Libraries/LibWeb/Layout/Box.cppindex d245041bc25..ff43fb50513 100644--- a/Libraries/LibWeb/Layout/Box.cpp+++ b/Libraries/LibWeb/Layout/Box.cpp@@ -6,6 +6,7 @@*/#include <LibWeb/DOM/Document.h>+#include <LibWeb/HTML/HTMLEmbedElement.h>#include <LibWeb/HTML/HTMLImageElement.h>#include <LibWeb/HTML/HTMLInputElement.h>#include <LibWeb/HTML/HTMLObjectElement.h>@@ -30,6 +31,8 @@ static ImageProvider const* image_provider_for_element(DOM::Element const& elemereturn image;if (auto const* input = as_if<HTML::HTMLInputElement>(element))return input;+ if (auto const* embed = as_if<HTML::HTMLEmbedElement>(element))+ return embed;if (auto const* object = as_if<HTML::HTMLObjectElement>(element))return object;return nullptr;diff --git a/Libraries/LibWeb/Layout/NodeArena.cpp b/Libraries/LibWeb/Layout/NodeArena.cppindex f446f36152c..136eb95de1f 100644--- a/Libraries/LibWeb/Layout/NodeArena.cpp+++ b/Libraries/LibWeb/Layout/NodeArena.cpp@@ -8,6 +8,7 @@#include <LibWeb/CSS/StyleComputer.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/Node.h>+#include <LibWeb/HTML/HTMLEmbedElement.h>#include <LibWeb/Layout/Node.h>#include <LibWeb/Layout/NodeArena.h>#include <LibWeb/Painting/BoxViews.h>@@ -41,8 +42,13 @@ void NodeArena::start_reporting_box_presence(Badge<DOM::Document>)GC::Ptr<DOM::Node> node = &document;if (style_node != 0)node = document.style_computer().node_for_style_node(CSS::StyleNodeID { style_node });- if (node)- node->set_box_presence({}, bits & RustFFI::BOX_PRESENCE_HAS_LAYOUT_BOX, bits & RustFFI::BOX_PRESENCE_HAS_COMMITTED_BOX);+ if (node) {+ bool has_layout_box = bits & RustFFI::BOX_PRESENCE_HAS_LAYOUT_BOX;+ bool changed = node->has_layout_box() != has_layout_box;+ node->set_box_presence({}, has_layout_box, bits & RustFFI::BOX_PRESENCE_HAS_COMMITTED_BOX);+ if (changed && is<HTML::HTMLEmbedElement>(*node))+ as<HTML::HTMLEmbedElement>(*node).rendering_changed();+ }});}diff --git a/Libraries/LibWeb/Layout/UpdateLayout.cpp b/Libraries/LibWeb/Layout/UpdateLayout.cppindex b977c0f69d7..b7cc275404e 100644--- a/Libraries/LibWeb/Layout/UpdateLayout.cpp+++ b/Libraries/LibWeb/Layout/UpdateLayout.cpp@@ -17,6 +17,7 @@#include <LibWeb/DOM/ShadowRoot.h>#include <LibWeb/HTML/AttributeNames.h>#include <LibWeb/HTML/EventLoop/EventLoop.h>+#include <LibWeb/HTML/HTMLEmbedElement.h>#include <LibWeb/HTML/HTMLObjectElement.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/Layout/LayoutRustFFI.h>@@ -279,13 +280,17 @@ void Document::update_style_and_layout_once(Layout::BegunRead const& read, Updat// An <object> showing this document is sized from its <svg> document element, whose natural size only this// document's layout works out. Hand it over as it changes.- if (auto* object = as_if<HTML::HTMLObjectElement>(navigable->container().ptr())) {+ auto container = navigable->container();+ if (container && (is<HTML::HTMLObjectElement>(*container) || is<HTML::HTMLEmbedElement>(*container))) {Layout::RustFFI::FfiNaturalSize natural_size {};if (Layout::RustFFI::render_state_take_changed_document_svg_root_natural_size(arena.host(), &read, &natural_size)) {CSS::SizeWithAspectRatio size { natural_size.width, natural_size.height, {} };if (natural_size.has_aspect_ratio)size.aspect_ratio = CSSPixelFraction(natural_size.aspect_ratio_numerator, natural_size.aspect_ratio_denominator);- object->set_natural_size_of_content_document(size);+ if (auto* embed = as_if<HTML::HTMLEmbedElement>(*container))+ embed->set_natural_size_of_content_document(size);+ else+ as<HTML::HTMLObjectElement>(*container).set_natural_size_of_content_document(size);}}}diff --git a/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-hidden-attribute-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-hidden-attribute-ref.htmlnew file mode 100644index 00000000000..1b7e47f823f--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-hidden-attribute-ref.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<title>The hidden global presentation attribute within the embed element</title>++This embed should be visible (green box):+<embed src='../../../../images/green-256x256.png' type='image/png'>++These should not be visible (no red):++<style>+ embed {+ display:block;+ }+</style>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/images/green-256x256.png b/Tests/LibWeb/Ref/expected/wpt-import/images/green-256x256.pngnew file mode 100644index 00000000000..b06945c3101Binary files /dev/null and b/Tests/LibWeb/Ref/expected/wpt-import/images/green-256x256.png differdiff --git a/Tests/LibWeb/Ref/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-hidden-attribute.html b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-hidden-attribute.htmlnew file mode 100644index 00000000000..3cafc9d9616--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-hidden-attribute.html@@ -0,0 +1,20 @@+<!DOCTYPE html>+<title>The hidden global presentation attribute within the embed element</title>+<link rel="author" href="mailto:[email protected]">+<link rel=match href="../../../../../../expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-hidden-attribute-ref.html">++This embed should be visible (green box):+<embed src='../../../../images/green-256x256.png' type='image/png'>++These should not be visible (no red):+<embed hidden src='../../../../images/fail.gif' type='image/png'>+<embed hidden="" src='../../../../images/fail.gif' type='image/png'>+<embed hidden="hidden" src='../../../../images/fail.gif' type='image/png'>+<embed hidden="true" src='../../../../images/fail.gif' type='image/png'>+<embed hidden="yes" src='../../../../images/fail.gif' type='image/png'>++<style>+embed {+ display:block;+}+</style>diff --git a/Tests/LibWeb/Ref/input/wpt-import/images/fail.gif b/Tests/LibWeb/Ref/input/wpt-import/images/fail.gifnew file mode 100644index 00000000000..c4addcf0090Binary files /dev/null and b/Tests/LibWeb/Ref/input/wpt-import/images/fail.gif differdiff --git a/Tests/LibWeb/Ref/input/wpt-import/images/green-256x256.png b/Tests/LibWeb/Ref/input/wpt-import/images/green-256x256.pngnew file mode 100644index 00000000000..b06945c3101Binary files /dev/null and b/Tests/LibWeb/Ref/input/wpt-import/images/green-256x256.png differdiff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 8f2121dd058..cbb7c590d10 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -5,6 +5,15 @@ Text/input/PDF/viewer-does-not-take-over-initial-about-blank-window.html[LoadFromHttpServer]Text/input/fragment-scroll-after-stylesheet.html+Text/input/replaced/embed-raster-resource-policy.html+Text/input/replaced/embed-representations.html+Text/input/replaced/embed-window-stop-during-fetch.html+Text/input/replaced/embed-window-stop-during-body.html+Text/input/replaced/embed-removed-during-body.html+Text/input/replaced/embed-in-shadow-tree.html+Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html+Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-document.html+Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback.htmlText/input/MediaSession/active-session-duration.html; Site-compatibility rules match the site of the page, and a file: page has none.Text/input/Fetch/site-compatibility-user-agent-change-during-fetch.html@@ -1360,6 +1369,8 @@ Text/input/wpt-import/speech-api/SpeechRecognition-non-secure-context.http.htmlText/input/wpt-import/credential-management/require_securecontext.html[Skipped]+Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback-subdocument.html+Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-iframe.html; Need position-visibility: no-overflow to hide a target that overflows after scrollingRef/input/wpt-import/css/css-anchor-position/position-visibility-no-overflow-scroll.html; Need absolutely positioned boxes fragmented across columnsdiff --git a/Tests/LibWeb/Text/expected/replaced/embed-in-shadow-tree.txt b/Tests/LibWeb/Text/expected/replaced/embed-in-shadow-tree.txtnew file mode 100644index 00000000000..9df81f5f8c1--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/embed-in-shadow-tree.txt@@ -0,0 +1 @@+image embed in a shadow tree: 16x16diff --git a/Tests/LibWeb/Text/expected/replaced/embed-object-fallback-transition.txt b/Tests/LibWeb/Text/expected/replaced/embed-object-fallback-transition.txtnew file mode 100644index 00000000000..686e82baad3--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/embed-object-fallback-transition.txt@@ -0,0 +1,5 @@+initial fallback: 16x16+parent shows image: true+restored fallback: 16x16+parent shows image: true+restored fallback: 16x16diff --git a/Tests/LibWeb/Text/expected/replaced/embed-raster-resource-policy.txt b/Tests/LibWeb/Text/expected/replaced/embed-raster-resource-policy.txtnew file mode 100644index 00000000000..27c4b925dfc--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/embed-raster-resource-policy.txt@@ -0,0 +1,2 @@+same-origin: 100x50+cross-origin: 100x50diff --git a/Tests/LibWeb/Text/expected/replaced/embed-removed-during-body.txt b/Tests/LibWeb/Text/expected/replaced/embed-removed-during-body.txtnew file mode 100644index 00000000000..c51ad8dd679--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/embed-removed-during-body.txt@@ -0,0 +1 @@+readyState: completediff --git a/Tests/LibWeb/Text/expected/replaced/embed-representations.txt b/Tests/LibWeb/Text/expected/replaced/embed-representations.txtnew file mode 100644index 00000000000..367036023ed--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/embed-representations.txt@@ -0,0 +1,5 @@+invalid PNG fired load: false+PNG: 133x106, 0 child windows+SVG: 100x50, 1 child windows+svg+second PNG: 16x16, 0 child windowsdiff --git a/Tests/LibWeb/Text/expected/replaced/embed-window-stop-during-body.txt b/Tests/LibWeb/Text/expected/replaced/embed-window-stop-during-body.txtnew file mode 100644index 00000000000..c51ad8dd679--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/embed-window-stop-during-body.txt@@ -0,0 +1 @@+readyState: completediff --git a/Tests/LibWeb/Text/expected/replaced/embed-window-stop-during-fetch.txt b/Tests/LibWeb/Text/expected/replaced/embed-window-stop-during-fetch.txtnew file mode 100644index 00000000000..c51ad8dd679--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/embed-window-stop-during-fetch.txt@@ -0,0 +1 @@+readyState: completediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-change-src-2.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-change-src-2.txtnew file mode 100644index 00000000000..db7fe20d50b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-change-src-2.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass The embed element update with new content when the src attribute is setdiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-dimension.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-dimension.txtnew file mode 100644index 00000000000..5bf2ea0ff96--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-dimension.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass Check the actual length of the embed element's height+Pass Check the actual length of the embed element's widthdiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-document.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-document.txtnew file mode 100644index 00000000000..161ed308fe7--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-document.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Test document type embeddingdiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.txtnew file mode 100644index 00000000000..ba2a6cd3cf3--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Test embed being ignored inside media elementdiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback.txtnew file mode 100644index 00000000000..1380fe3ef9c--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass We have the right embed element+Pass Check that the right things loadeddiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-svg-navigation-resets-size.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-svg-navigation-resets-size.txtnew file mode 100644index 00000000000..7cabc748b4b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-embed-element/embed-svg-navigation-resets-size.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Intrinsic sizing of SVG embedded via <embed> should disappear on navigationdiff --git a/Tests/LibWeb/Text/input/replaced/embed-in-shadow-tree.html b/Tests/LibWeb/Text/input/replaced/embed-in-shadow-tree.htmlnew file mode 100644index 00000000000..5f92610ea6a--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/embed-in-shadow-tree.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<div id="host"></div>+<script>+ promiseTest(async () => {+ const root = host.attachShadow({ mode: "open" });+ const embed = document.createElement("embed");+ const loaded = new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));+ embed.src = "../wpt-import/images/green-16x16.png";+ root.append(embed);+ await loaded;+ println(`image embed in a shadow tree: ${embed.offsetWidth}x${embed.offsetHeight}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/replaced/embed-object-fallback-transition.html b/Tests/LibWeb/Text/input/replaced/embed-object-fallback-transition.htmlnew file mode 100644index 00000000000..839bc274c48--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/embed-object-fallback-transition.html@@ -0,0 +1,27 @@+<!doctype html>+<script src="../include.js"></script>+<object id="object" data="data:application/x-unsupported,initial">+ <div><embed id="image" src="../wpt-import/images/green-16x16.png"></div>+</object>+<script>+ promiseTest(async () => {+ const object = document.getElementById("object");+ const image = document.getElementById("image");+ await new Promise(resolve => window.addEventListener("load", resolve, { once: true }));+ println(`initial fallback: ${image.offsetWidth}x${image.offsetHeight}`);++ for (const source of ["data:application/x-unsupported,fallback", ""]) {+ const objectLoaded = new Promise(resolve => object.addEventListener("load", resolve, { once: true }));+ object.data = "../wpt-import/images/blue.png";+ await objectLoaded;+ await animationFrame();+ println(`parent shows image: ${image.getClientRects().length === 0}`);+ await animationFrame();++ const embedLoaded = new Promise(resolve => image.addEventListener("load", resolve, { once: true }));+ object.data = source;+ await embedLoaded;+ println(`restored fallback: ${image.offsetWidth}x${image.offsetHeight}`);+ }+ });+</script>diff --git a/Tests/LibWeb/Text/input/replaced/embed-raster-resource-policy.html b/Tests/LibWeb/Text/input/replaced/embed-raster-resource-policy.htmlnew file mode 100644index 00000000000..d12f6bd9d9e--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/embed-raster-resource-policy.html@@ -0,0 +1,19 @@+<!doctype html>+<script src="../include.js"></script>+<script>+ promiseTest(async () => {+ const url = new URL("../wpt-import/fetch/cross-origin-resource-policy/resources/image.py", location.href);+ url.searchParams.set("type", "image/png");+ const embed = document.createElement("embed");+ document.body.append(embed);+ for (const policy of ["same-origin", "cross-origin"]) {+ if (policy === "cross-origin")+ url.hostname = location.hostname === "localhost" ? "127.0.0.1" : "localhost";+ url.searchParams.set("corp", policy);+ const loaded = new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));+ embed.src = url.href;+ await loaded;+ println(`${policy}: ${embed.offsetWidth}x${embed.offsetHeight}`);+ }+ });+</script>diff --git a/Tests/LibWeb/Text/input/replaced/embed-raster-resource-policy.html.headers b/Tests/LibWeb/Text/input/replaced/embed-raster-resource-policy.html.headersnew file mode 100644index 00000000000..6604450991a--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/embed-raster-resource-policy.html.headers@@ -0,0 +1 @@+Cross-Origin-Embedder-Policy: require-corpdiff --git a/Tests/LibWeb/Text/input/replaced/embed-removed-during-body.html b/Tests/LibWeb/Text/input/replaced/embed-removed-during-body.htmlnew file mode 100644index 00000000000..8d63bbb240a--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/embed-removed-during-body.html@@ -0,0 +1,22 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<embed id="embed" src="../wpt-import/images/green-256x256.png?pipe=trickle(100:d3)">+<script>+ asyncTest(done => {+ // The embed's fetch starts in a queued task, and its body is held back for 3 seconds after the first 100 bytes.+ setTimeout(() => {+ // Removing the embed while its body is still arriving leaves nothing to delay the load event.+ document.getElementById("embed").remove();+ let frames = 0;+ const check = () => {+ if (document.readyState === "complete" || ++frames === 60) {+ println(`readyState: ${document.readyState}`);+ done();+ return;+ }+ requestAnimationFrame(check);+ };+ check();+ }, 100);+ });+</script>diff --git a/Tests/LibWeb/Text/input/replaced/embed-representations.html b/Tests/LibWeb/Text/input/replaced/embed-representations.htmlnew file mode 100644index 00000000000..9424dea97f2--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/embed-representations.html@@ -0,0 +1,27 @@+<!doctype html>+<script src="../include.js"></script>+<embed id="picture" src="../wpt-import/images/blue.png">+<embed id="invalid" type="image/png" src="data:text/html,not%20an%20image" onload="this.dataset.loaded = 1">+<script>+ promiseTest(async () => {+ const picture = document.getElementById("picture");+ await new Promise(resolve => window.addEventListener("load", resolve, { once: true }));++ function report(label) {+ println(`${label}: ${picture.offsetWidth}x${picture.offsetHeight}, ${frames.length} child windows`);+ }++ println(`invalid PNG fired load: ${document.getElementById("invalid").hasAttribute("data-loaded")}`);+ report("PNG");+ const svgLoaded = new Promise(resolve => picture.addEventListener("load", resolve, { once: true }));+ picture.src = "../wpt-import/images/green.svg";+ await svgLoaded;+ report("SVG");+ println(picture.getSVGDocument()?.documentElement.localName);++ const imageLoaded = new Promise(resolve => picture.addEventListener("load", resolve, { once: true }));+ picture.src = "../wpt-import/images/green-16x16.png";+ await imageLoaded;+ report("second PNG");+ });+</script>diff --git a/Tests/LibWeb/Text/input/replaced/embed-window-stop-during-body.html b/Tests/LibWeb/Text/input/replaced/embed-window-stop-during-body.htmlnew file mode 100644index 00000000000..f0b40635c50--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/embed-window-stop-during-body.html@@ -0,0 +1,22 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<embed id="embed" src="../wpt-import/images/green-256x256.png?pipe=trickle(100:d3)">+<script>+ asyncTest(done => {+ // The embed's fetch starts in a queued task, and its body is held back for 3 seconds after the first 100 bytes.+ setTimeout(() => {+ // Stopping the document stops the embed's fetch while its body is still arriving.+ window.stop();+ let frames = 0;+ const check = () => {+ if (document.readyState === "complete" || ++frames === 60) {+ println(`readyState: ${document.readyState}`);+ done();+ return;+ }+ requestAnimationFrame(check);+ };+ check();+ }, 100);+ });+</script>diff --git a/Tests/LibWeb/Text/input/replaced/embed-window-stop-during-fetch.html b/Tests/LibWeb/Text/input/replaced/embed-window-stop-during-fetch.htmlnew file mode 100644index 00000000000..734917e8968--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/embed-window-stop-during-fetch.html@@ -0,0 +1,22 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<embed id="embed" src="../wpt-import/xhr/resources/delay.py?ms=3000">+<script>+ asyncTest(done => {+ // The embed's fetch starts in a queued task, and the server holds back its response headers for 3 seconds.+ setTimeout(() => {+ // Stopping the document stops the embed's fetch before it has a response.+ window.stop();+ let frames = 0;+ const check = () => {+ if (document.readyState === "complete" || ++frames === 60) {+ println(`readyState: ${document.readyState}`);+ done();+ return;+ }+ requestAnimationFrame(check);+ };+ check();+ }, 100);+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/resources/should-not-load.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/resources/should-not-load.htmlnew file mode 100644index 00000000000..6281b2da553--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/resources/should-not-load.html@@ -0,0 +1,5 @@+<script>+ parent.nestingTest.step(function() {+ parent.assert_unreached(window.frameElement.getAttribute("test-description"));+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-change-src-2.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-change-src-2.htmlnew file mode 100644index 00000000000..068dad0022e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-change-src-2.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>The embed element update with new content when the src attribute is set</title>+<link rel="help" href="https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-embed-element">+<link rel="help" href="https://crbug.com/479233864">+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<body>+<script>+promise_test(async () => {+ const embed = document.body.appendChild(document.createElement('embed'));++ const boundsBefore = embed.getBoundingClientRect();+ assert_equals(boundsBefore.width, 0, 'represents nothing');++ const loadPromise = new Promise(resolve => embed.onload = resolve);+ embed.src = 'data:image/svg+xml,<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg"><rect height="100" width="100" fill="green"/></svg>';++ await loadPromise;++ const boundsAfter = embed.getBoundingClientRect();+ assert_equals(boundsAfter.width, 100, 'represents its content navigable');+});+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-dimension.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-dimension.htmlnew file mode 100644index 00000000000..cd0405a8f4a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-dimension.html@@ -0,0 +1,20 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>HTML Test: dimension</title>+<link rel="author" title="Intel" href="http://www.intel.com">+<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-embed-element">+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<div id="log"></div>+<embed src="../../../../images/blue.png" height="100" width="100" id="test">+<script>+ test(function () {+ var height = getComputedStyle(document.getElementById("test"))["height"];+ assert_equals(height, "100px", "The height of the embed element should be 100px.");+ }, "Check the actual length of the embed element's height");++ test(function () {+ var width = getComputedStyle(document.getElementById("test"))["width"];+ assert_equals(width, "100px", "The width of the embed element should be 100px.");+ }, "Check the actual length of the embed element's width");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-document.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-document.htmlnew file mode 100644index 00000000000..370a835e771--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-document.html@@ -0,0 +1,17 @@+<!doctype html>+<meta charset="utf-8">+<title>HTML Test: The embed element represents a document</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<meta name="assert" content="Check if the embed element represents a document when a text/html resource source is used">+<body>+ <script type="application/javascript">+ window.childLoaded = false;+ async_test(function() {+ addEventListener("load", this.step_func_done(function() {+ assert_true(window.childLoaded);+ }));+ }, "Test document type embedding");+ </script>+ <embed src="embed-iframe.html">+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-iframe.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-iframe.htmlnew file mode 100644index 00000000000..f9b1bfdb57f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-iframe.html@@ -0,0 +1,7 @@+<!DOCTYPE html>+<meta charset="utf-8">+<body>+ <script type="application/javascript">+ parent.childLoaded = true;+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.htmlnew file mode 100644index 00000000000..d9850931487--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html@@ -0,0 +1,22 @@+<!doctype html>+<meta charset="utf-8">+<title>HTML Test: The embed element represents a document</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<meta name="assert" content="Check if the embed element is ignored when used inside a media element">+<script type="application/javascript">+ var nestingTest = async_test("Test embed being ignored inside media element");+ onload = nestingTest.step_func_done(function() {+ assert_true(true, "We got to a load event without loading things we should not load");+ });+</script>+<body>+ <video>+ <embed type="text/html" src="../resources/should-not-load.html"+ test-description="<embed> in <video>">+ </video>+ <audio>+ <embed type="text/html" src="../resources/should-not-load.html"+ test-description="<embed> in <audio>">+ </audio>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback-subdocument.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback-subdocument.htmlnew file mode 100644index 00000000000..a2c2a93992b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback-subdocument.html@@ -0,0 +1,4 @@+<script>+ var varName = location.search.substr(1);+ parent[varName] = true;+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback.htmlnew file mode 100644index 00000000000..4ecf5d5d534--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-in-object-fallback.html@@ -0,0 +1,38 @@+<!doctype html>+<meta charset=utf-8>+<title>Ensure that embed elements inside object elements load when the objects+ fall back but not otherwise</title>+<script src=../../../../resources/testharness.js></script>+<script src=../../../../resources/testharnessreport.js></script>+<script>+ var child1Loaded = false;+ var child2Loaded = false;+ var child3Loaded = false;+ var parent3Loaded = false;+</script>+<object>+ <embed src="embed-in-object-fallback-subdocument.html?child1Loaded">+</object>+<object>+ <embed id="two" src="embed-in-object-fallback-subdocument.html?child2Loaded">+ <!-- Something that forces the embed to be in the tree before the <object>+ is done parsing -->+ <script>+ test(function() {+ assert_equals(document.getElementById("two").localName,+ "embed");+ }, "We have the right embed element");+ </script>+</object>+<object data="embed-in-object-fallback-subdocument.html?parent3Loaded">+ <embed src="embed-in-object-fallback-subdocument.html?child3Loaded">+</object>+<script>+ var t = async_test("Check that the right things loaded");+ onload = t.step_func_done(function() {+ assert_true(child1Loaded, "child 1 should load");+ assert_true(child2Loaded, "child 2 should load");+ assert_false(child3Loaded, "child 3 should not load");+ assert_true(parent3Loaded, "parent 3 should load");+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-svg-navigation-resets-size.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-svg-navigation-resets-size.htmlnew file mode 100644index 00000000000..28ed872a970--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-svg-navigation-resets-size.html@@ -0,0 +1,31 @@+<!doctype html>+<meta charset=utf-8>+<title>Intrinsic sizing of SVG embedded via <embed> should disappear on navigation</title>+<script src=../../../../resources/testharness.js></script>+<script src=../../../../resources/testharnessreport.js></script>+<embed id="element" name="embed" src='data:image/svg+xml,+ <svg xmlns="http://www.w3.org/2000/svg"+ xmlns:xlink="http://www.w3.org/1999/xlink"+ viewBox="0 0 1000 1000"+ width="400"+ height="400"+ font-size="100">+ </svg>'>+<script>+promise_test(async () => {+ await new Promise(resolve => {+ onload = resolve;+ });++ assert_equals(element.scrollWidth, 400, "The width should be determined by the embedded SVG");+ assert_equals(element.scrollHeight, 400, "The height should be determined by the embedded SVG");++ await new Promise(resolve => {+ element.onload = resolve;+ element.src = "about:blank";+ });++ assert_equals(element.scrollWidth, 300, "The width should be the default");+ assert_equals(element.scrollHeight, 150, "The height should be the default");+});+</script>