LibWeb: Allow NavigableContainers to report whether to delay load event

Four elements match the "potentially delay the load event" check in the
spec: `<embed>`, `<frame>`, `<iframe>`, and `<object>`. These four are
the same set of elements that are NavigableContainers (or will be once
we implement them) so let's put this logic there.

Note that other things can delay the load event, this is just the name
the spec gives to this particular behaviour.
This commit is contained in:
Sam Atkins 2023-11-24 15:52:56 +00:00 committed by Andreas Kling
parent 6c5450f9ce
commit 7f509317fd
Notes: sideshowbarker 2024-07-17 05:01:20 +09:00
2 changed files with 36 additions and 0 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -287,4 +288,31 @@ void NavigableContainer::destroy_the_child_navigable()
});
}
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#potentially-delays-the-load-event
bool NavigableContainer::currently_delays_the_load_event() const
{
if (!m_potentially_delays_the_load_event)
return false;
// If an element type potentially delays the load event, then for each element element of that type,
// the user agent must delay the load event of element's node document if element's content navigable is non-null
// and any of the following are true:
if (!m_content_navigable)
return false;
// - element's content navigable's active document is not ready for post-load tasks;
if (!m_content_navigable->active_document()->ready_for_post_load_tasks())
return true;
// - element's content navigable's is delaying load events is true; or
if (m_content_navigable->is_delaying_load_events())
return true;
// - anything is delaying the load event of element's content navigable's active document.
if (m_content_navigable->active_document()->anything_is_delaying_the_load_event())
return true;
return false;
}
}

View file

@ -46,6 +46,11 @@ public:
void destroy_the_child_navigable();
// All elements that extend NavigableContainer "potentially delay the load event".
// (embed, frame, iframe, and object)
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#potentially-delays-the-load-event
bool currently_delays_the_load_event() const;
protected:
NavigableContainer(DOM::Document&, DOM::QualifiedName);
@ -62,8 +67,11 @@ protected:
// https://html.spec.whatwg.org/multipage/document-sequences.html#content-navigable
JS::GCPtr<Navigable> m_content_navigable { nullptr };
void set_potentially_delays_the_load_event(bool value) { m_potentially_delays_the_load_event = value; }
private:
virtual bool is_navigable_container() const override { return true; }
bool m_potentially_delays_the_load_event { true };
};
}