LibWeb: Pass SynchronousNavigation flag into "apply the history step"

Workaround spec bug by explicitly carrying information whether
navigation is sync (History api, fragment change) or not.

See for more details https://github.com/whatwg/html/issues/10232
This commit is contained in:
Aliaksandr Kalenik 2024-04-05 16:02:52 +02:00 committed by Alexander Kalenik
parent 93ba99f14a
commit adcc3905e5
Notes: sideshowbarker 2024-07-17 06:38:11 +09:00
3 changed files with 17 additions and 11 deletions

View file

@ -1866,7 +1866,7 @@ void finalize_a_cross_document_navigation(JS::NonnullGCPtr<Navigable> navigable,
} }
// 10. Apply the push/replace history step targetStep to traversable. // 10. Apply the push/replace history step targetStep to traversable.
traversable->apply_the_push_or_replace_history_step(target_step, history_handling); traversable->apply_the_push_or_replace_history_step(target_step, history_handling, TraversableNavigable::SynchronousNavigation::No);
} }
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#url-and-history-update-steps // https://html.spec.whatwg.org/multipage/browsing-the-web.html#url-and-history-update-steps

View file

@ -384,7 +384,8 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
Optional<SourceSnapshotParams> source_snapshot_params, Optional<SourceSnapshotParams> source_snapshot_params,
JS::GCPtr<Navigable> initiator_to_check, JS::GCPtr<Navigable> initiator_to_check,
Optional<UserNavigationInvolvement> user_involvement_for_navigate_events, Optional<UserNavigationInvolvement> user_involvement_for_navigate_events,
Optional<Bindings::NavigationType> navigation_type) Optional<Bindings::NavigationType> navigation_type,
SynchronousNavigation synchronous_navigation)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
// FIXME: 1. Assert: This is running within traversable's session history traversal queue. // FIXME: 1. Assert: This is running within traversable's session history traversal queue.
@ -474,7 +475,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
}; };
// 4. If displayedEntry is targetEntry and targetEntry's document state's reload pending is false, then: // 4. If displayedEntry is targetEntry and targetEntry's document state's reload pending is false, then:
if (displayed_entry == target_entry && !target_entry->document_state()->reload_pending()) { if (synchronous_navigation == SynchronousNavigation::Yes && !target_entry->document_state()->reload_pending()) {
// 1. Set changingNavigableContinuation's update-only to true. // 1. Set changingNavigableContinuation's update-only to true.
changing_navigable_continuation.update_only = true; changing_navigable_continuation.update_only = true;
@ -907,7 +908,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::update_for_navigab
auto step = current_session_history_step(); auto step = current_session_history_step();
// 2. Return the result of applying the history step to traversable given false, null, null, null, and null. // 2. Return the result of applying the history step to traversable given false, null, null, null, and null.
return apply_the_history_step(step, false, {}, {}, {}, {}); return apply_the_history_step(step, false, {}, {}, {}, {}, SynchronousNavigation::No);
} }
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-reload-history-step // https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-reload-history-step
@ -917,20 +918,20 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_reload_h
auto step = current_session_history_step(); auto step = current_session_history_step();
// 2. Return the result of applying the history step step to traversable given true, null, null, null, and "reload". // 2. Return the result of applying the history step step to traversable given true, null, null, null, and "reload".
return apply_the_history_step(step, true, {}, {}, {}, Bindings::NavigationType::Reload); return apply_the_history_step(step, true, {}, {}, {}, Bindings::NavigationType::Reload, SynchronousNavigation::No);
} }
TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_push_or_replace_history_step(int step, HistoryHandlingBehavior history_handling) TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_push_or_replace_history_step(int step, HistoryHandlingBehavior history_handling, SynchronousNavigation synchronous_navigation)
{ {
// 1. Return the result of applying the history step step to traversable given false, null, null, null, and historyHandling. // 1. Return the result of applying the history step step to traversable given false, null, null, null, and historyHandling.
auto navigation_type = history_handling == HistoryHandlingBehavior::Replace ? Bindings::NavigationType::Replace : Bindings::NavigationType::Push; auto navigation_type = history_handling == HistoryHandlingBehavior::Replace ? Bindings::NavigationType::Replace : Bindings::NavigationType::Push;
return apply_the_history_step(step, false, {}, {}, {}, navigation_type); return apply_the_history_step(step, false, {}, {}, {}, navigation_type, synchronous_navigation);
} }
TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_traverse_history_step(int step, Optional<SourceSnapshotParams> source_snapshot_params, JS::GCPtr<Navigable> initiator_to_check, UserNavigationInvolvement user_involvement) TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_traverse_history_step(int step, Optional<SourceSnapshotParams> source_snapshot_params, JS::GCPtr<Navigable> initiator_to_check, UserNavigationInvolvement user_involvement)
{ {
// 1. Return the result of applying the history step step to traversable given true, sourceSnapshotParams, initiatorToCheck, userInvolvement, and "traverse". // 1. Return the result of applying the history step step to traversable given true, sourceSnapshotParams, initiatorToCheck, userInvolvement, and "traverse".
return apply_the_history_step(step, true, move(source_snapshot_params), initiator_to_check, user_involvement, Bindings::NavigationType::Traverse); return apply_the_history_step(step, true, move(source_snapshot_params), initiator_to_check, user_involvement, Bindings::NavigationType::Traverse, SynchronousNavigation::No);
} }
// https://html.spec.whatwg.org/multipage/document-sequences.html#close-a-top-level-traversable // https://html.spec.whatwg.org/multipage/document-sequences.html#close-a-top-level-traversable
@ -1034,7 +1035,7 @@ void finalize_a_same_document_navigation(JS::NonnullGCPtr<TraversableNavigable>
} }
// 6. Apply the push/replace history step targetStep to traversable given historyHandling. // 6. Apply the push/replace history step targetStep to traversable given historyHandling.
traversable->apply_the_push_or_replace_history_step(*target_step, history_handling); traversable->apply_the_push_or_replace_history_step(*target_step, history_handling, TraversableNavigable::SynchronousNavigation::Yes);
} }
// https://html.spec.whatwg.org/multipage/interaction.html#system-visibility-state // https://html.spec.whatwg.org/multipage/interaction.html#system-visibility-state

View file

@ -50,7 +50,11 @@ public:
HistoryStepResult apply_the_traverse_history_step(int, Optional<SourceSnapshotParams>, JS::GCPtr<Navigable>, UserNavigationInvolvement); HistoryStepResult apply_the_traverse_history_step(int, Optional<SourceSnapshotParams>, JS::GCPtr<Navigable>, UserNavigationInvolvement);
HistoryStepResult apply_the_reload_history_step(); HistoryStepResult apply_the_reload_history_step();
HistoryStepResult apply_the_push_or_replace_history_step(int step, HistoryHandlingBehavior history_handling); enum class SynchronousNavigation : bool {
Yes,
No,
};
HistoryStepResult apply_the_push_or_replace_history_step(int step, HistoryHandlingBehavior history_handling, SynchronousNavigation);
HistoryStepResult update_for_navigable_creation_or_destruction(); HistoryStepResult update_for_navigable_creation_or_destruction();
int get_the_used_step(int step) const; int get_the_used_step(int step) const;
@ -98,7 +102,8 @@ private:
Optional<SourceSnapshotParams>, Optional<SourceSnapshotParams>,
JS::GCPtr<Navigable> initiator_to_check, JS::GCPtr<Navigable> initiator_to_check,
Optional<UserNavigationInvolvement> user_involvement_for_navigate_events, Optional<UserNavigationInvolvement> user_involvement_for_navigate_events,
Optional<Bindings::NavigationType> navigation_type); Optional<Bindings::NavigationType> navigation_type,
SynchronousNavigation);
Vector<JS::NonnullGCPtr<SessionHistoryEntry>> get_session_history_entries_for_the_navigation_api(JS::NonnullGCPtr<Navigable>, int); Vector<JS::NonnullGCPtr<SessionHistoryEntry>> get_session_history_entries_for_the_navigation_api(JS::NonnullGCPtr<Navigable>, int);