From a20951fbc098c1a7e938eb8db63b2c3b7bc452bf Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 26 Dec 2023 12:10:21 +0000 Subject: [PATCH] LibWeb: Support making a document active after it has completely loaded So far, we always call make_active() before update_readiness (Complete), but this will soon not be the case once we implement the spec document-loading algorithms. Co-authored-by: Aliaksandr Kalenik --- Userland/Libraries/LibWeb/DOM/Document.cpp | 15 ++++++++++++--- Userland/Libraries/LibWeb/DOM/Document.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f14cd36db4..4fb59d68bd 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1934,9 +1934,13 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value) // 4. Fire an event named readystatechange at document. dispatch_event(Event::create(realm(), HTML::EventNames::readystatechange)); - if (readiness_value == HTML::DocumentReadyState::Complete && is_active() && navigable()->is_traversable()) { - HTML::HTMLLinkElement::load_fallback_favicon_if_needed(*this).release_value_but_fixme_should_propagate_errors(); - navigable()->traversable_navigable()->page().client().page_did_finish_loading(url()); + if (readiness_value == HTML::DocumentReadyState::Complete) { + if (navigable() && navigable()->is_traversable()) { + HTML::HTMLLinkElement::load_fallback_favicon_if_needed(*this).release_value_but_fixme_should_propagate_errors(); + navigable()->traversable_navigable()->page().client().page_did_finish_loading(url()); + } else { + m_needs_to_call_page_did_load = true; + } } } @@ -3093,6 +3097,11 @@ void Document::make_active() // 4. Set window's relevant settings object's execution ready flag. HTML::relevant_settings_object(window).execution_ready = true; + + if (m_needs_to_call_page_did_load) { + navigable()->traversable_navigable()->page().client().page_did_finish_loading(url()); + m_needs_to_call_page_did_load = false; + } } HTML::ListOfAvailableImages& Document::list_of_available_images() diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index fb93147bcb..a529150a77 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -767,6 +767,8 @@ private: // https://www.w3.org/TR/web-animations-1/#pending-animation-event-queue Vector m_pending_animation_event_queue; + + bool m_needs_to_call_page_did_load { false }; }; template<>