2022-12-12 07:46:54 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2025-06-26 17:33:58 -03:00
|
|
|
* Copyright (c) 2023-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2022-12-12 07:46:54 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-08-22 11:00:42 -03:00
|
|
|
#include <AK/HashTable.h>
|
2023-08-24 19:18:40 -03:00
|
|
|
#include <AK/String.h>
|
2025-03-23 08:38:21 -03:00
|
|
|
#include <AK/Tuple.h>
|
2022-12-12 07:46:54 -03:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/Navigation.h>
|
2023-09-13 20:22:00 -03:00
|
|
|
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2022-12-12 07:46:54 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2023-04-11 04:20:11 -03:00
|
|
|
#include <LibWeb/HTML/ActivateTab.h>
|
2026-03-26 18:48:49 -03:00
|
|
|
#include <LibWeb/HTML/DocumentState.h>
|
2023-01-01 13:46:00 -03:00
|
|
|
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
|
2025-10-16 10:07:09 -03:00
|
|
|
#include <LibWeb/HTML/InitialInsertion.h>
|
2025-11-06 23:24:50 -03:00
|
|
|
#include <LibWeb/HTML/NavigationObserver.h>
|
2023-09-21 16:47:19 -03:00
|
|
|
#include <LibWeb/HTML/NavigationParams.h>
|
2023-01-01 13:46:00 -03:00
|
|
|
#include <LibWeb/HTML/POSTResource.h>
|
2025-06-26 17:33:58 -03:00
|
|
|
#include <LibWeb/HTML/RenderingThread.h>
|
2023-08-28 13:06:10 -03:00
|
|
|
#include <LibWeb/HTML/SandboxingFlagSet.h>
|
2023-04-06 12:10:12 -03:00
|
|
|
#include <LibWeb/HTML/SourceSnapshotParams.h>
|
2025-07-17 14:40:50 -03:00
|
|
|
#include <LibWeb/HTML/StructuredSerializeTypes.h>
|
2023-04-11 04:20:11 -03:00
|
|
|
#include <LibWeb/HTML/TokenizedFeatures.h>
|
2025-10-16 10:07:09 -03:00
|
|
|
#include <LibWeb/HTML/WindowType.h>
|
2024-09-02 12:47:32 -03:00
|
|
|
#include <LibWeb/InvalidateDisplayList.h>
|
2024-04-26 11:59:04 -03:00
|
|
|
#include <LibWeb/Page/EventHandler.h>
|
2025-06-26 17:33:58 -03:00
|
|
|
#include <LibWeb/Painting/BackingStoreManager.h>
|
2023-08-22 11:00:42 -03:00
|
|
|
#include <LibWeb/PixelUnits.h>
|
2023-08-28 13:06:10 -03:00
|
|
|
#include <LibWeb/XHR/FormDataEntry.h>
|
2022-12-12 07:46:54 -03:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
LibWeb: Separate input/output in populate_session_history_entry_document
Previously, populate_session_history_entry_document() took a
SessionHistoryEntry as both input and output — reading URL and
document_state fields while also mutating the entry across a chain of
async functions. This made it very hard to reason about data flow.
Refactor the internal helpers
(create_navigation_params_from_a_srcdoc_resource,
create_navigation_params_by_fetching, NavigationParamsFetchStateHolder,
perform_navigation_params_fetch) to take individual field values instead
of reading from the entry, and accumulate redirect mutations on the
state holder rather than writing them to the entry immediately.
Introduce PopulateSessionHistoryEntryDocumentOutput, a GC cell that
collects all mutations (document, redirect URL, classic history API
state, replacement document state, resource cleared flag, and
finalization data). The completion_steps callback now receives this
output object (or nullptr on cancellation), and callers apply it to the
entry via apply_to().
The replacement DocumentState for the redirect path is built eagerly at
redirect time from values captured on the state holder, making
apply_to() fully self-contained — it never reads from the target entry's
live document_state. This is important for the traversal path where the
entry may be mutated during unload (e.g. window.name writes
navigable_target_name through the active session history entry).
2026-03-26 18:30:54 -03:00
|
|
|
struct PopulateSessionHistoryEntryDocumentOutput;
|
|
|
|
|
|
2026-03-29 07:06:39 -03:00
|
|
|
enum class HistoryStepResult {
|
|
|
|
|
InitiatorDisallowed,
|
|
|
|
|
CanceledByBeforeUnload,
|
|
|
|
|
CanceledByNavigate,
|
|
|
|
|
Applied,
|
|
|
|
|
};
|
|
|
|
|
using OnApplyHistoryStepComplete = GC::Function<void(HistoryStepResult)>;
|
|
|
|
|
|
2023-08-28 13:06:10 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#target-snapshot-params
|
|
|
|
|
struct TargetSnapshotParams {
|
|
|
|
|
SandboxingFlagSet sandboxing_flags {};
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#navigable
|
2025-10-16 06:13:54 -03:00
|
|
|
class WEB_API Navigable : public JS::Cell {
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_CELL(Navigable, JS::Cell);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(Navigable);
|
2022-12-12 07:46:54 -03:00
|
|
|
|
|
|
|
|
public:
|
2025-12-28 21:33:12 -03:00
|
|
|
static constexpr bool OVERRIDES_FINALIZE = true;
|
|
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
virtual ~Navigable() override;
|
|
|
|
|
|
2025-04-02 04:51:45 -03:00
|
|
|
using NullOrError = Optional<String>;
|
2024-11-13 21:08:01 -03:00
|
|
|
using NavigationParamsVariant = Variant<NullOrError, GC::Ref<NavigationParams>, GC::Ref<NonFetchSchemeNavigationParams>>;
|
2024-06-18 10:26:12 -03:00
|
|
|
|
2026-04-03 07:53:39 -03:00
|
|
|
void initialize_navigable(NonnullRefPtr<DocumentState> document_state, GC::Ptr<Navigable> parent, GC::Ref<DOM::Document> document);
|
2023-04-25 14:46:32 -03:00
|
|
|
|
2024-10-25 11:26:01 -03:00
|
|
|
void register_navigation_observer(Badge<NavigationObserver>, NavigationObserver&);
|
|
|
|
|
void unregister_navigation_observer(Badge<NavigationObserver>, NavigationObserver&);
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
Vector<GC::Root<Navigable>> child_navigables() const;
|
2023-04-06 17:16:38 -03:00
|
|
|
|
2025-04-18 05:25:56 -03:00
|
|
|
virtual bool is_traversable() const { return false; }
|
2023-08-27 12:06:39 -03:00
|
|
|
|
2023-07-07 23:48:11 -03:00
|
|
|
String const& id() const { return m_id; }
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Navigable> parent() const { return m_parent; }
|
|
|
|
|
bool is_ancestor_of(GC::Ref<Navigable>) const;
|
2022-12-12 07:46:54 -03:00
|
|
|
|
2023-07-07 23:48:11 -03:00
|
|
|
bool is_closing() const { return m_closing; }
|
|
|
|
|
void set_closing(bool value) { m_closing = value; }
|
2024-10-05 16:56:35 -03:00
|
|
|
bool is_script_closable();
|
2022-12-12 07:46:54 -03:00
|
|
|
|
2024-12-05 06:56:47 -03:00
|
|
|
void stop_loading();
|
|
|
|
|
|
2023-09-13 20:22:00 -03:00
|
|
|
void set_delaying_load_events(bool value);
|
2023-11-24 12:18:57 -03:00
|
|
|
bool is_delaying_load_events() const { return m_delaying_the_load_event.has_value(); }
|
2022-12-12 07:46:54 -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_navigation_load_event_guard(DOM::Document& parent_doc);
|
|
|
|
|
void clear_navigation_load_event_guard();
|
|
|
|
|
|
2026-04-03 07:53:39 -03:00
|
|
|
RefPtr<SessionHistoryEntry> active_session_history_entry() const;
|
|
|
|
|
void set_active_session_history_entry(RefPtr<SessionHistoryEntry>);
|
|
|
|
|
RefPtr<SessionHistoryEntry> current_session_history_entry() const;
|
|
|
|
|
void set_current_session_history_entry(RefPtr<SessionHistoryEntry>);
|
2022-12-12 07:46:54 -03:00
|
|
|
|
2026-04-03 07:53:39 -03:00
|
|
|
Vector<NonnullRefPtr<SessionHistoryEntry>>& get_session_history_entries() const;
|
2023-04-06 12:08:44 -03:00
|
|
|
|
2026-04-03 07:53:39 -03:00
|
|
|
void activate_history_entry(RefPtr<SessionHistoryEntry>, GC::Ref<DOM::Document>);
|
2023-04-06 17:33:21 -03:00
|
|
|
|
2025-09-04 10:10:57 -03:00
|
|
|
GC::Ptr<DOM::Document> active_document() const;
|
2026-03-31 11:56:18 -03:00
|
|
|
Optional<UniqueNodeID> active_document_id() const;
|
|
|
|
|
void set_active_document(GC::Ptr<DOM::Document>);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<BrowsingContext> active_browsing_context();
|
|
|
|
|
GC::Ptr<WindowProxy> active_window_proxy();
|
|
|
|
|
GC::Ptr<Window> active_window();
|
2022-12-12 07:46:54 -03:00
|
|
|
|
2026-04-03 07:53:39 -03:00
|
|
|
RefPtr<SessionHistoryEntry> get_the_target_history_entry(int target_step) const;
|
2023-04-06 17:30:02 -03:00
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
String target_name() const;
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<NavigableContainer> container() const;
|
|
|
|
|
GC::Ptr<DOM::Document> container_document() const;
|
2022-12-12 07:46:54 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<TraversableNavigable> traversable_navigable() const;
|
|
|
|
|
GC::Ptr<TraversableNavigable> top_level_traversable();
|
2022-12-12 08:07:41 -03:00
|
|
|
|
2023-08-28 13:00:52 -03:00
|
|
|
virtual bool is_top_level_traversable() const { return false; }
|
|
|
|
|
|
2024-04-26 11:59:04 -03:00
|
|
|
[[nodiscard]] bool is_focused() const;
|
|
|
|
|
|
2023-04-11 04:20:11 -03:00
|
|
|
struct ChosenNavigable {
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Navigable> navigable;
|
2023-04-11 04:20:11 -03:00
|
|
|
WindowType window_type;
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-28 12:12:18 -03:00
|
|
|
ChosenNavigable choose_a_navigable(StringView name, TokenizedFeature::NoOpener no_opener, ActivateTab = ActivateTab::Yes, Optional<TokenizedFeature::Map const&> window_features = {});
|
2023-04-11 04:20:11 -03:00
|
|
|
|
2025-01-05 14:21:31 -03:00
|
|
|
GC::Ptr<Navigable> find_a_navigable_by_target_name(StringView name);
|
|
|
|
|
|
2023-04-24 15:37:35 -03:00
|
|
|
enum class Traversal {
|
|
|
|
|
Tag
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Variant<Empty, Traversal, String> ongoing_navigation() const { return m_ongoing_navigation; }
|
2023-08-22 10:22:50 -03:00
|
|
|
void set_ongoing_navigation(Variant<Empty, Traversal, String> ongoing_navigation);
|
2023-04-24 15:37:35 -03:00
|
|
|
|
2025-09-30 13:15:55 -03:00
|
|
|
void populate_session_history_entry_document(
|
2026-03-26 18:48:49 -03:00
|
|
|
URL::URL url,
|
|
|
|
|
Variant<Empty, String, POSTResource> document_resource,
|
|
|
|
|
Fetch::Infrastructure::Request::ReferrerType request_referrer,
|
|
|
|
|
ReferrerPolicy::ReferrerPolicy request_referrer_policy,
|
|
|
|
|
Optional<URL::Origin> initiator_origin,
|
|
|
|
|
Optional<URL::Origin> origin,
|
2026-04-03 07:53:39 -03:00
|
|
|
Variant<SerializedPolicyContainer, DocumentState::Client> history_policy_container,
|
2026-03-26 18:48:49 -03:00
|
|
|
Optional<URL::URL> about_base_url,
|
|
|
|
|
String navigable_target_name,
|
|
|
|
|
bool reload_pending,
|
|
|
|
|
bool ever_populated,
|
LibWeb: Separate input/output in populate_session_history_entry_document
Previously, populate_session_history_entry_document() took a
SessionHistoryEntry as both input and output — reading URL and
document_state fields while also mutating the entry across a chain of
async functions. This made it very hard to reason about data flow.
Refactor the internal helpers
(create_navigation_params_from_a_srcdoc_resource,
create_navigation_params_by_fetching, NavigationParamsFetchStateHolder,
perform_navigation_params_fetch) to take individual field values instead
of reading from the entry, and accumulate redirect mutations on the
state holder rather than writing them to the entry immediately.
Introduce PopulateSessionHistoryEntryDocumentOutput, a GC cell that
collects all mutations (document, redirect URL, classic history API
state, replacement document state, resource cleared flag, and
finalization data). The completion_steps callback now receives this
output object (or nullptr on cancellation), and callers apply it to the
entry via apply_to().
The replacement DocumentState for the redirect path is built eagerly at
redirect time from values captured on the state holder, making
apply_to() fully self-contained — it never reads from the target entry's
live document_state. This is important for the traversal path where the
entry may be mutated during unload (e.g. window.name writes
navigable_target_name through the active session history entry).
2026-03-26 18:30:54 -03:00
|
|
|
GC::Ref<SourceSnapshotParams> source_snapshot_params,
|
2023-09-21 16:47:19 -03:00
|
|
|
TargetSnapshotParams const& target_snapshot_params,
|
2025-01-07 11:58:48 -03:00
|
|
|
UserNavigationInvolvement user_involvement,
|
2026-03-26 18:48:49 -03:00
|
|
|
Optional<String> navigation_id,
|
|
|
|
|
NavigationParamsVariant navigation_params,
|
|
|
|
|
ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type,
|
|
|
|
|
bool allow_POST,
|
|
|
|
|
GC::Ptr<GC::Function<void(GC::Ptr<PopulateSessionHistoryEntryDocumentOutput>)>> completion_steps);
|
2023-04-06 12:10:12 -03:00
|
|
|
|
2023-10-10 11:05:38 -03:00
|
|
|
struct NavigateParams {
|
2025-02-26 20:22:12 -03:00
|
|
|
URL::URL url;
|
2025-08-07 10:32:20 -03:00
|
|
|
// FIXME: source_document should now be nullable, and default to nullptr.
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<DOM::Document> source_document;
|
2023-10-10 11:05:38 -03:00
|
|
|
Variant<Empty, String, POSTResource> document_resource = Empty {};
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Fetch::Infrastructure::Response> response = nullptr;
|
2023-10-10 11:05:38 -03:00
|
|
|
bool exceptions_enabled = false;
|
|
|
|
|
Bindings::NavigationHistoryBehavior history_handling = Bindings::NavigationHistoryBehavior::Auto;
|
|
|
|
|
Optional<SerializationRecord> navigation_api_state = {};
|
2025-02-26 20:22:12 -03:00
|
|
|
Optional<Vector<XHR::FormDataEntry>> form_data_entry_list = {};
|
2023-10-10 11:05:38 -03:00
|
|
|
ReferrerPolicy::ReferrerPolicy referrer_policy = ReferrerPolicy::ReferrerPolicy::EmptyString;
|
|
|
|
|
UserNavigationInvolvement user_involvement = UserNavigationInvolvement::None;
|
2025-01-30 11:14:13 -03:00
|
|
|
GC::Ptr<DOM::Element> source_element = nullptr;
|
2025-05-15 08:28:53 -03:00
|
|
|
InitialInsertion initial_insertion = InitialInsertion::No;
|
2025-02-26 20:22:12 -03:00
|
|
|
|
|
|
|
|
void visit_edges(Cell::Visitor& visitor);
|
2023-10-10 11:05:38 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> navigate(NavigateParams);
|
2023-01-01 13:46:00 -03:00
|
|
|
|
2025-01-07 11:58:48 -03:00
|
|
|
GC::Ptr<DOM::Document> evaluate_javascript_url(URL::URL const&, URL::Origin const& new_document_origin, UserNavigationInvolvement, String navigation_id);
|
2023-01-01 13:46:00 -03:00
|
|
|
|
2023-09-28 01:59:57 -03:00
|
|
|
bool allowed_by_sandboxing_to_navigate(Navigable const& target, SourceSnapshotParams const&);
|
|
|
|
|
|
2026-02-10 18:30:55 -03:00
|
|
|
void reload(Optional<SerializationRecord> navigation_api_state = {}, UserNavigationInvolvement = UserNavigationInvolvement::None);
|
2023-04-06 18:08:39 -03:00
|
|
|
|
2023-09-05 18:36:20 -03:00
|
|
|
// https://github.com/whatwg/html/issues/9690
|
|
|
|
|
[[nodiscard]] bool has_been_destroyed() const { return m_has_been_destroyed; }
|
2026-04-01 05:18:55 -03:00
|
|
|
void set_has_been_destroyed();
|
|
|
|
|
void remove_from_all_navigables();
|
2023-09-05 18:36:20 -03:00
|
|
|
|
2023-08-22 11:00:42 -03:00
|
|
|
CSSPixelPoint to_top_level_position(CSSPixelPoint);
|
|
|
|
|
CSSPixelRect to_top_level_rect(CSSPixelRect const&);
|
|
|
|
|
|
|
|
|
|
CSSPixelPoint viewport_scroll_offset() const { return m_viewport_scroll_offset; }
|
2025-06-17 11:29:06 -03:00
|
|
|
CSSPixelRect viewport_rect() const { return { m_viewport_scroll_offset, m_viewport_size }; }
|
|
|
|
|
CSSPixelSize viewport_size() const { return m_viewport_size; }
|
2026-02-20 18:09:39 -03:00
|
|
|
void set_viewport_size(CSSPixelSize, InvalidateDisplayList = InvalidateDisplayList::No);
|
2026-01-05 14:27:37 -03:00
|
|
|
void perform_scroll_of_viewport_scrolling_box(CSSPixelPoint position);
|
2026-02-26 07:36:17 -03:00
|
|
|
void clamp_viewport_scroll_offset();
|
2023-08-22 11:00:42 -03:00
|
|
|
|
2026-02-05 14:02:28 -03:00
|
|
|
Painting::BackingStoreManager& backing_store_manager() { return *m_backing_store_manager; }
|
|
|
|
|
|
2025-02-04 09:01:46 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#rendering-opportunity
|
2023-09-20 03:09:59 -03:00
|
|
|
[[nodiscard]] bool has_a_rendering_opportunity() const;
|
|
|
|
|
|
2023-09-21 16:47:19 -03:00
|
|
|
[[nodiscard]] TargetSnapshotParams snapshot_target_snapshot_params();
|
|
|
|
|
|
2024-04-26 09:55:54 -03:00
|
|
|
Page& page() { return m_page; }
|
|
|
|
|
Page const& page() const { return m_page; }
|
|
|
|
|
|
2024-04-26 11:59:04 -03:00
|
|
|
String selected_text() const;
|
|
|
|
|
void select_all();
|
2025-09-18 10:18:54 -03:00
|
|
|
void paste(Utf16String const&);
|
2024-04-26 11:59:04 -03:00
|
|
|
|
|
|
|
|
Web::EventHandler& event_handler() { return m_event_handler; }
|
|
|
|
|
Web::EventHandler const& event_handler() const { return m_event_handler; }
|
|
|
|
|
|
2025-03-23 08:38:21 -03:00
|
|
|
// https://drafts.csswg.org/css-view-transitions-1/#snapshot-containing-block
|
|
|
|
|
CSSPixelRect snapshot_containing_block();
|
|
|
|
|
// https://drafts.csswg.org/css-view-transitions-1/#snapshot-containing-block-size
|
|
|
|
|
CSSPixelSize snapshot_containing_block_size();
|
|
|
|
|
|
2025-02-26 20:22:12 -03:00
|
|
|
bool has_session_history_entry_and_ready_for_navigation() const { return m_has_session_history_entry_and_ready_for_navigation; }
|
|
|
|
|
void set_has_session_history_entry_and_ready_for_navigation();
|
|
|
|
|
|
2025-04-26 00:39:13 -03:00
|
|
|
void inform_the_navigation_api_about_child_navigable_destruction();
|
|
|
|
|
|
2025-02-26 20:22:12 -03:00
|
|
|
bool has_pending_navigations() const { return !m_pending_navigations.is_empty(); }
|
2026-03-29 07:06:39 -03:00
|
|
|
void clear_pending_navigations() { m_pending_navigations.clear(); }
|
2025-02-26 20:22:12 -03:00
|
|
|
|
2025-06-26 17:33:58 -03:00
|
|
|
void ready_to_paint();
|
2026-01-26 08:59:43 -03:00
|
|
|
void record_display_list_and_scroll_state(PaintConfig);
|
2025-06-26 17:33:58 -03:00
|
|
|
void paint_next_frame();
|
2026-01-26 08:59:43 -03:00
|
|
|
void render_screenshot(Gfx::PaintingSurface&, PaintConfig, Function<void()>&& callback);
|
2025-06-26 17:33:58 -03:00
|
|
|
|
|
|
|
|
bool needs_repaint() const { return m_needs_repaint; }
|
|
|
|
|
void set_needs_repaint() { m_needs_repaint = true; }
|
|
|
|
|
|
2025-10-23 06:19:10 -03:00
|
|
|
[[nodiscard]] bool has_inclusive_ancestor_with_visibility_hidden() const;
|
|
|
|
|
|
2026-01-26 08:59:43 -03:00
|
|
|
RenderingThread& rendering_thread() { return m_rendering_thread; }
|
|
|
|
|
|
2026-04-05 12:00:40 -03:00
|
|
|
NonnullRefPtr<Painting::ExternalContentSource> external_content_source() const;
|
|
|
|
|
|
2025-06-26 17:33:58 -03:00
|
|
|
void set_pending_set_browser_zoom_request(bool value) { m_pending_set_browser_zoom_request = value; }
|
|
|
|
|
bool pending_set_browser_zoom_request() const { return m_pending_set_browser_zoom_request; }
|
|
|
|
|
|
|
|
|
|
void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
|
|
|
|
|
|
2025-07-12 18:38:18 -03:00
|
|
|
bool is_svg_page() const { return m_is_svg_page; }
|
|
|
|
|
|
2025-04-18 05:25:56 -03:00
|
|
|
template<typename T>
|
|
|
|
|
bool fast_is() const = delete;
|
|
|
|
|
|
2026-01-05 16:14:20 -03:00
|
|
|
GC::Ref<WebIDL::Promise> scroll_viewport_by_delta(CSSPixelPoint delta);
|
|
|
|
|
GC::Ref<WebIDL::Promise> perform_a_scroll_of_the_viewport(CSSPixelPoint position);
|
2025-10-09 15:29:12 -03:00
|
|
|
void reset_zoom();
|
2025-10-09 11:56:58 -03:00
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
protected:
|
2025-06-26 17:33:58 -03:00
|
|
|
explicit Navigable(GC::Ref<Page>, bool is_svg_page);
|
2022-12-12 07:46:54 -03:00
|
|
|
|
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2025-01-16 22:18:36 -03:00
|
|
|
virtual void finalize() override;
|
2022-12-12 07:46:54 -03:00
|
|
|
|
2023-04-24 15:37:35 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#ongoing-navigation
|
|
|
|
|
Variant<Empty, Traversal, String> m_ongoing_navigation;
|
|
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
private:
|
2025-02-26 20:22:12 -03:00
|
|
|
void begin_navigation(NavigateParams);
|
|
|
|
|
void navigate_to_a_fragment(URL::URL const&, HistoryHandlingBehavior, UserNavigationInvolvement, GC::Ptr<DOM::Element> source_element, Optional<SerializationRecord> navigation_api_state, String navigation_id);
|
2025-05-15 08:28:53 -03:00
|
|
|
void navigate_to_a_javascript_url(URL::URL const&, HistoryHandlingBehavior, GC::Ref<SourceSnapshotParams>, URL::Origin const& initiator_origin, UserNavigationInvolvement, ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type, InitialInsertion, String navigation_id);
|
2025-02-26 20:22:12 -03:00
|
|
|
|
2024-04-26 11:59:04 -03:00
|
|
|
void reset_cursor_blink_cycle();
|
|
|
|
|
|
2023-08-22 11:00:42 -03:00
|
|
|
void scroll_offset_did_change();
|
|
|
|
|
|
2023-09-21 02:21:16 -03:00
|
|
|
void inform_the_navigation_api_about_aborting_navigation();
|
|
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-id
|
|
|
|
|
String m_id;
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-parent
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Navigable> m_parent;
|
2022-12-12 07:46:54 -03:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-current-history-entry
|
2026-04-03 07:53:39 -03:00
|
|
|
RefPtr<SessionHistoryEntry> m_current_session_history_entry;
|
2022-12-12 07:46:54 -03:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-active-history-entry
|
2026-04-03 07:53:39 -03:00
|
|
|
RefPtr<SessionHistoryEntry> m_active_session_history_entry;
|
2022-12-12 07:46:54 -03:00
|
|
|
|
2026-03-31 11:56:18 -03:00
|
|
|
// AD-HOC: Direct reference to the active document, decoupled from session history.
|
|
|
|
|
// This is the authoritative source for active_document().
|
|
|
|
|
GC::Ptr<DOM::Document> m_active_document;
|
|
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#is-closing
|
|
|
|
|
bool m_closing { false };
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#delaying-load-events-mode
|
2023-09-13 20:22:00 -03:00
|
|
|
Optional<DOM::DocumentLoadEventDelayer> m_delaying_the_load_event;
|
2022-12-12 07:46:54 -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
|
|
|
// AD-HOC: Guards the parent document's load event delay count during cross-document navigation.
|
|
|
|
|
Optional<DOM::DocumentLoadEventDelayer> m_navigation_load_event_guard;
|
|
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
// Implied link between navigable and its container.
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<NavigableContainer> m_container;
|
2023-09-05 18:36:20 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<Page> m_page;
|
2024-04-26 09:55:54 -03:00
|
|
|
|
2025-11-06 23:24:50 -03:00
|
|
|
NavigationObserver::NavigationObserversList m_navigation_observers;
|
2024-10-25 11:26:01 -03:00
|
|
|
|
2023-09-05 18:36:20 -03:00
|
|
|
bool m_has_been_destroyed { false };
|
2023-08-22 11:00:42 -03:00
|
|
|
|
2025-06-17 11:29:06 -03:00
|
|
|
CSSPixelSize m_viewport_size;
|
2023-08-22 11:00:42 -03:00
|
|
|
CSSPixelPoint m_viewport_scroll_offset;
|
2024-02-23 18:10:35 -03:00
|
|
|
|
2024-04-26 11:59:04 -03:00
|
|
|
Web::EventHandler m_event_handler;
|
2025-02-26 20:22:12 -03:00
|
|
|
|
|
|
|
|
bool m_has_session_history_entry_and_ready_for_navigation { false };
|
|
|
|
|
|
|
|
|
|
Vector<NavigateParams> m_pending_navigations;
|
2025-06-26 17:33:58 -03:00
|
|
|
|
|
|
|
|
bool m_is_svg_page { false };
|
|
|
|
|
bool m_needs_repaint { true };
|
|
|
|
|
bool m_pending_set_browser_zoom_request { false };
|
|
|
|
|
bool m_should_show_line_box_borders { false };
|
|
|
|
|
GC::Ref<Painting::BackingStoreManager> m_backing_store_manager;
|
|
|
|
|
RenderingThread m_rendering_thread;
|
2026-04-05 12:00:40 -03:00
|
|
|
RefPtr<Painting::ExternalContentSource> m_external_content_source;
|
2022-12-12 07:46:54 -03:00
|
|
|
};
|
|
|
|
|
|
LibWeb: Separate input/output in populate_session_history_entry_document
Previously, populate_session_history_entry_document() took a
SessionHistoryEntry as both input and output — reading URL and
document_state fields while also mutating the entry across a chain of
async functions. This made it very hard to reason about data flow.
Refactor the internal helpers
(create_navigation_params_from_a_srcdoc_resource,
create_navigation_params_by_fetching, NavigationParamsFetchStateHolder,
perform_navigation_params_fetch) to take individual field values instead
of reading from the entry, and accumulate redirect mutations on the
state holder rather than writing them to the entry immediately.
Introduce PopulateSessionHistoryEntryDocumentOutput, a GC cell that
collects all mutations (document, redirect URL, classic history API
state, replacement document state, resource cleared flag, and
finalization data). The completion_steps callback now receives this
output object (or nullptr on cancellation), and callers apply it to the
entry via apply_to().
The replacement DocumentState for the redirect path is built eagerly at
redirect time from values captured on the state holder, making
apply_to() fully self-contained — it never reads from the target entry's
live document_state. This is important for the traversal path where the
entry may be mutated during unload (e.g. window.name writes
navigable_target_name through the active session history entry).
2026-03-26 18:30:54 -03:00
|
|
|
struct PopulateSessionHistoryEntryDocumentOutput final : public JS::Cell {
|
|
|
|
|
GC_CELL(PopulateSessionHistoryEntryDocumentOutput, JS::Cell);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(PopulateSessionHistoryEntryDocumentOutput);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
GC::Ptr<DOM::Document> document;
|
|
|
|
|
|
|
|
|
|
Navigable::NavigationParamsVariant navigation_params { Navigable::NullOrError {} };
|
|
|
|
|
bool save_extra_document_state = true;
|
|
|
|
|
|
|
|
|
|
Optional<URL::URL> redirected_url;
|
|
|
|
|
Optional<SerializationRecord> classic_history_api_state;
|
2026-04-03 07:53:39 -03:00
|
|
|
RefPtr<DocumentState> replacement_document_state;
|
LibWeb: Separate input/output in populate_session_history_entry_document
Previously, populate_session_history_entry_document() took a
SessionHistoryEntry as both input and output — reading URL and
document_state fields while also mutating the entry across a chain of
async functions. This made it very hard to reason about data flow.
Refactor the internal helpers
(create_navigation_params_from_a_srcdoc_resource,
create_navigation_params_by_fetching, NavigationParamsFetchStateHolder,
perform_navigation_params_fetch) to take individual field values instead
of reading from the entry, and accumulate redirect mutations on the
state holder rather than writing them to the entry immediately.
Introduce PopulateSessionHistoryEntryDocumentOutput, a GC cell that
collects all mutations (document, redirect URL, classic history API
state, replacement document state, resource cleared flag, and
finalization data). The completion_steps callback now receives this
output object (or nullptr on cancellation), and callers apply it to the
entry via apply_to().
The replacement DocumentState for the redirect path is built eagerly at
redirect time from values captured on the state holder, making
apply_to() fully self-contained — it never reads from the target entry's
live document_state. This is important for the traversal path where the
entry may be mutated during unload (e.g. window.name writes
navigable_target_name through the active session history entry).
2026-03-26 18:30:54 -03:00
|
|
|
bool resource_cleared = false;
|
|
|
|
|
|
2026-04-03 07:53:39 -03:00
|
|
|
void apply_to(NonnullRefPtr<SessionHistoryEntry> entry);
|
LibWeb: Separate input/output in populate_session_history_entry_document
Previously, populate_session_history_entry_document() took a
SessionHistoryEntry as both input and output — reading URL and
document_state fields while also mutating the entry across a chain of
async functions. This made it very hard to reason about data flow.
Refactor the internal helpers
(create_navigation_params_from_a_srcdoc_resource,
create_navigation_params_by_fetching, NavigationParamsFetchStateHolder,
perform_navigation_params_fetch) to take individual field values instead
of reading from the entry, and accumulate redirect mutations on the
state holder rather than writing them to the entry immediately.
Introduce PopulateSessionHistoryEntryDocumentOutput, a GC cell that
collects all mutations (document, redirect URL, classic history API
state, replacement document state, resource cleared flag, and
finalization data). The completion_steps callback now receives this
output object (or nullptr on cancellation), and callers apply it to the
entry via apply_to().
The replacement DocumentState for the redirect path is built eagerly at
redirect time from values captured on the state holder, making
apply_to() fully self-contained — it never reads from the target entry's
live document_state. This is important for the traversal path where the
entry may be mutated during unload (e.g. window.name writes
navigable_target_name through the active session history entry).
2026-03-26 18:30:54 -03:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
WEB_API HashTable<GC::RawRef<Navigable>>& all_navigables();
|
2023-09-05 18:36:20 -03:00
|
|
|
|
2024-03-18 00:22:27 -03:00
|
|
|
bool navigation_must_be_a_replace(URL::URL const& url, DOM::Document const& document);
|
2026-04-03 07:53:39 -03:00
|
|
|
void finalize_a_cross_document_navigation(GC::Ref<Navigable>, HistoryHandlingBehavior, UserNavigationInvolvement, NonnullRefPtr<SessionHistoryEntry>, GC::Ptr<DOM::Document> pending_document, GC::Ref<OnApplyHistoryStepComplete> on_complete);
|
2024-03-28 08:58:43 -03:00
|
|
|
void perform_url_and_history_update_steps(DOM::Document& document, URL::URL new_url, Optional<SerializationRecord> = {}, HistoryHandlingBehavior history_handling = HistoryHandlingBehavior::Replace);
|
2023-08-24 19:18:40 -03:00
|
|
|
|
2022-12-12 07:46:54 -03:00
|
|
|
}
|