2021-04-03 06:43:08 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <andreas@ladybird.org>
|
2021-04-03 06:43:08 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-03 06:43:08 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2021-04-03 06:43:08 -03:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2025-10-16 10:07:09 -03:00
|
|
|
#include <LibWeb/HTML/InitialInsertion.h>
|
2021-04-03 06:43:08 -03:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API NavigableContainer : public HTMLElement {
|
2025-07-18 01:04:58 -03:00
|
|
|
WEB_NON_IDL_PLATFORM_OBJECT(NavigableContainer, HTMLElement);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2021-04-03 06:43:08 -03:00
|
|
|
public:
|
2026-01-29 08:50:29 -03:00
|
|
|
static constexpr bool OVERRIDES_FINALIZE = true;
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
static GC::Ptr<NavigableContainer> navigable_container_with_content_navigable(GC::Ref<Navigable> navigable);
|
2023-04-23 11:50:08 -03:00
|
|
|
|
2022-12-12 08:20:02 -03:00
|
|
|
virtual ~NavigableContainer() override;
|
2021-04-03 06:43:08 -03:00
|
|
|
|
2022-12-12 08:20:02 -03:00
|
|
|
static HashTable<NavigableContainer*>& all_instances();
|
2022-09-19 15:50:33 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Navigable> content_navigable() { return m_content_navigable; }
|
|
|
|
|
GC::Ptr<Navigable const> content_navigable() const { return m_content_navigable.ptr(); }
|
2021-04-03 06:43:08 -03:00
|
|
|
|
2025-08-29 09:02:52 -03:00
|
|
|
DOM::Document const* content_document() const;
|
2022-02-16 19:51:25 -03:00
|
|
|
DOM::Document const* content_document_without_origin_check() const;
|
2021-04-03 06:43:08 -03:00
|
|
|
|
2022-11-04 06:05:10 -03:00
|
|
|
HTML::WindowProxy* content_window();
|
2022-08-04 15:13:52 -03:00
|
|
|
|
2022-03-24 17:08:06 -03:00
|
|
|
DOM::Document const* get_svg_document() const;
|
|
|
|
|
|
2022-12-16 19:28:12 -03:00
|
|
|
void destroy_the_child_navigable();
|
|
|
|
|
|
2023-11-24 12:52:56 -03:00
|
|
|
// 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;
|
|
|
|
|
|
2025-10-16 10:07:09 -03:00
|
|
|
bool content_navigable_has_session_history_entry_and_ready_for_navigation() const;
|
2024-04-08 00:36:02 -03:00
|
|
|
|
2021-04-03 06:43:08 -03:00
|
|
|
protected:
|
2022-12-12 08:20:02 -03:00
|
|
|
NavigableContainer(DOM::Document&, DOM::QualifiedName);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2022-10-17 06:06:50 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2022-09-19 08:34:36 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#shared-attribute-processing-steps-for-iframe-and-frame-elements
|
2025-05-15 08:28:53 -03:00
|
|
|
Optional<URL::URL> shared_attribute_processing_steps_for_iframe_and_frame(InitialInsertion initial_insertion);
|
2022-09-19 08:34:36 -03:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#navigate-an-iframe-or-frame
|
2025-05-15 08:28:53 -03:00
|
|
|
void navigate_an_iframe_or_frame(URL::URL url, ReferrerPolicy::ReferrerPolicy referrer_policy, Optional<String> srcdoc_string = {}, InitialInsertion = InitialInsertion::No);
|
2022-03-23 21:13:34 -03:00
|
|
|
|
2026-03-30 11:39:50 -03:00
|
|
|
void create_new_child_navigable();
|
2023-07-10 16:08:57 -03:00
|
|
|
|
2023-06-21 09:45:41 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#content-navigable
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Navigable> m_content_navigable { nullptr };
|
2023-06-21 09:45:41 -03:00
|
|
|
|
LibWeb: Replace spin_until in HTMLParser::the_end() with state machine
HTMLParser::the_end() had three spin_until calls that blocked the event
loop: step 5 (deferred scripts), step 7 (ASAP scripts), and step 8
(load event delay). This replaces them with an HTMLParserEndState state
machine that progresses asynchronously via callbacks.
The state machine has three phases matching the three spin_until calls:
- WaitingForDeferredScripts: loops executing ready deferred scripts
- WaitingForASAPScripts: waits for ASAP script lists to empty
- WaitingForLoadEventDelay: waits for nothing to delay the load event
Notification triggers re-evaluate the state machine when conditions
change: HTMLScriptElement::mark_as_ready, stylesheet unblocking in
StyleElementBase/HTMLLinkElement, did_stop_being_active_document, and
DocumentLoadEventDelayer decrements. NavigableContainer state changes
(session history readiness, content navigable cleared, lazy load flag)
also trigger re-evaluation of the load event delay check.
Key design decisions and why:
1. Microtask checkpoint in schedule_progress_check(): The old spin_until
called perform_a_microtask_checkpoint() before checking conditions.
This is critical because HTMLImageElement::update_the_image_data step
8 queues a microtask that creates the DocumentLoadEventDelayer.
Without the checkpoint, check_progress() would see zero delayers and
complete before images start delaying the load event.
2. deferred_invoke in schedule_progress_check():
I tried Core::Timer (0ms), queue_global_task, and synchronous calls.
Timers caused non-deterministic ordering with the HTML event loop's
task processing timer, leading to image layout tests failing (wrong
subtest pass/fail patterns). Synchronous calls fired too early during
image load processing before dimensions were set, causing 0-height
images in layout tests. queue_global_task had task ordering issues
with the session history traversal queue. deferred_invoke runs after
the current callback returns but within the same event loop pump,
giving the right balance.
3. Navigation load event guard (m_navigation_load_event_guard): During
cross-document navigation, finalize_a_cross_document_navigation step
2 calls set_delaying_load_events(false) before the session history
traversal activates the new document. This creates a transient state
where the parent's load event delay check sees the about:blank (which
has ready_for_post_load_tasks=true) as the active document and
completes prematurely.
2026-03-28 05:39:51 -03:00
|
|
|
void set_potentially_delays_the_load_event(bool value);
|
2023-11-24 12:52:56 -03:00
|
|
|
|
2025-10-16 10:07:09 -03:00
|
|
|
void set_content_navigable_has_session_history_entry_and_ready_for_navigation();
|
2024-04-04 13:49:40 -03:00
|
|
|
|
2021-11-24 13:15:04 -03:00
|
|
|
private:
|
2022-12-12 08:20:02 -03:00
|
|
|
virtual bool is_navigable_container() const override { return true; }
|
2026-01-29 08:50:29 -03:00
|
|
|
|
|
|
|
|
virtual void finalize() override;
|
|
|
|
|
|
2023-11-24 12:52:56 -03:00
|
|
|
bool m_potentially_delays_the_load_event { true };
|
2021-04-03 06:43:08 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
2021-11-24 13:15:04 -03:00
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
2025-05-13 08:06:33 -03:00
|
|
|
|
2021-11-24 13:15:04 -03:00
|
|
|
template<>
|
2022-12-12 08:20:02 -03:00
|
|
|
inline bool Node::fast_is<HTML::NavigableContainer>() const { return is_navigable_container(); }
|
2025-05-13 08:06:33 -03:00
|
|
|
|
2021-11-24 13:15:04 -03:00
|
|
|
}
|