From 5f4a723e51529d8e572f7d626d596e32e0c401c8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 26 Sep 2021 02:25:02 +0200 Subject: [PATCH] LibWeb: Implement more of "completely finish loading the document" --- Userland/Libraries/LibWeb/DOM/Document.cpp | 24 +++++++++++++++++-- .../LibWeb/HTML/HTMLIFrameElement.cpp | 20 ++++++++++++++++ .../Libraries/LibWeb/HTML/HTMLIFrameElement.h | 2 ++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 451165ff42..5b7f40dc07 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -920,10 +921,29 @@ EventTarget* Document::get_parent(const Event& event) return &window(); } +// https://html.spec.whatwg.org/multipage/browsing-the-web.html#completely-finish-loading void Document::completely_finish_loading() { - // FIXME: This needs to handle iframes. - dispatch_event(DOM::Event::create(HTML::EventNames::load)); + // 1. Assert: document's browsing context is non-null. + VERIFY(browsing_context()); + + // FIXME: 2. Set document's completely loaded time to the current time. + + // 3. Let container be document's browsing context's container. + auto* container = browsing_context()->container(); + + // If container is an iframe element, then queue an element task on the DOM manipulation task source given container to run the iframe load event steps given container. + if (container && is(*container)) { + container->queue_an_element_task(HTML::Task::Source::DOMManipulation, [container]() mutable { + run_iframe_load_event_steps(static_cast(*container)); + }); + } + // Otherwise, if container is non-null, then queue an element task on the DOM manipulation task source given container to fire an event named load at container. + else if (container) { + container->queue_an_element_task(HTML::Task::Source::DOMManipulation, [container]() mutable { + container->dispatch_event(DOM::Event::create(HTML::EventNames::load)); + }); + } } String Document::cookie(Cookie::Source source) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 8a33217a15..7af50c7cf7 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -63,4 +64,23 @@ void HTMLIFrameElement::load_src(const String& value) m_nested_browsing_context->loader().load(url, FrameLoader::Type::IFrame); } +// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#iframe-load-event-steps +void run_iframe_load_event_steps(HTML::HTMLIFrameElement& element) +{ + // 1. Assert: element's nested browsing context is not null. + VERIFY(element.nested_browsing_context()); + + // 2. Let childDocument be the active document of element's nested browsing context. + [[maybe_unused]] auto* child_document = element.nested_browsing_context()->active_document(); + + // FIXME: 3. If childDocument has its mute iframe load flag set, then return. + + // FIXME: 4. Set childDocument's iframe load in progress flag. + + // 5. Fire an event named load at element. + element.dispatch_event(DOM::Event::create(HTML::EventNames::load)); + + // FIXME: 6. Unset childDocument's iframe load in progress flag. +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h index e8f3d1561a..50d22bad7c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h @@ -26,4 +26,6 @@ private: void load_src(const String&); }; +void run_iframe_load_event_steps(HTML::HTMLIFrameElement&); + }