LibWeb: Set the document "completely loaded time" when appropriate

This commit is contained in:
Andreas Kling 2022-09-19 13:29:56 +02:00
parent 954da8fde5
commit 0810e77d77
Notes: sideshowbarker 2024-07-17 06:50:11 +09:00
2 changed files with 16 additions and 3 deletions

View File

@ -1454,24 +1454,31 @@ EventTarget* Document::get_parent(Event const& event)
return &window();
}
// https://html.spec.whatwg.org/#completely-loaded
bool Document::is_completely_loaded() const
{
return m_completely_loaded_time.has_value();
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#completely-finish-loading
void Document::completely_finish_loading()
{
// 1. Assert: document's browsing context is non-null.
VERIFY(browsing_context());
// FIXME: 2. Set document's completely loaded time to the current time.
// 2. Set document's completely loaded time to the current time.
m_completely_loaded_time = AK::Time::now_realtime();
// 3. Let container be document's browsing context's container.
auto container = JS::make_handle(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.
// 4. 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<HTML::HTMLIFrameElement>(*container)) {
container->queue_an_element_task(HTML::Task::Source::DOMManipulation, [container]() mutable {
run_iframe_load_event_steps(static_cast<HTML::HTMLIFrameElement&>(*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.
// 5. 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(container->window(), HTML::EventNames::load));

View File

@ -365,6 +365,9 @@ public:
auto& pending_scroll_event_targets() { return m_pending_scroll_event_targets; }
auto& pending_scrollend_event_targets() { return m_pending_scrollend_event_targets; }
// https://html.spec.whatwg.org/#completely-loaded
bool is_completely_loaded() const;
protected:
virtual void visit_edges(Cell::Visitor&) override;
@ -496,6 +499,9 @@ private:
JS::GCPtr<HTMLCollection> m_forms;
JS::GCPtr<HTMLCollection> m_scripts;
JS::GCPtr<HTMLCollection> m_all;
// https://html.spec.whatwg.org/#completely-loaded-time
Optional<AK::Time> m_completely_loaded_time;
};
}