Skip to content

Commit

Permalink
LibWeb: Match spec changes to "apply the history step"
Browse files Browse the repository at this point in the history
Corresponds to whatwg/html#10704

Also a tiny formatting change because the commit hook demands it.
  • Loading branch information
AtkinsSJ committed Nov 8, 2024
1 parent 8709926 commit 4be2965
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4386,7 +4386,7 @@ void Document::restore_the_history_object_state(JS::NonnullGCPtr<HTML::SessionHi
}

// https://html.spec.whatwg.org/multipage/browsing-the-web.html#update-document-for-history-step-application
void Document::update_for_history_step_application(JS::NonnullGCPtr<HTML::SessionHistoryEntry> entry, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional<Bindings::NavigationType> navigation_type, Optional<Vector<JS::NonnullGCPtr<HTML::SessionHistoryEntry>>> entries_for_navigation_api, Optional<JS::NonnullGCPtr<HTML::SessionHistoryEntry>> previous_entry_for_activation, bool update_navigation_api)
void Document::update_for_history_step_application(JS::NonnullGCPtr<HTML::SessionHistoryEntry> entry, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional<Bindings::NavigationType> navigation_type, Optional<Vector<JS::NonnullGCPtr<HTML::SessionHistoryEntry>>> entries_for_navigation_api, JS::GCPtr<HTML::SessionHistoryEntry> previous_entry_for_activation, bool update_navigation_api)
{
(void)previous_entry_for_activation;

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/DOM/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class Document

HTML::SourceSnapshotParams snapshot_source_snapshot_params() const;

void update_for_history_step_application(JS::NonnullGCPtr<HTML::SessionHistoryEntry>, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional<Bindings::NavigationType> navigation_type, Optional<Vector<JS::NonnullGCPtr<HTML::SessionHistoryEntry>>> entries_for_navigation_api = {}, Optional<JS::NonnullGCPtr<HTML::SessionHistoryEntry>> previous_entry_for_activation = {}, bool update_navigation_api = true);
void update_for_history_step_application(JS::NonnullGCPtr<HTML::SessionHistoryEntry>, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional<Bindings::NavigationType> navigation_type, Optional<Vector<JS::NonnullGCPtr<HTML::SessionHistoryEntry>>> entries_for_navigation_api = {}, JS::GCPtr<HTML::SessionHistoryEntry> previous_entry_for_activation = {}, bool update_navigation_api = true);

HashMap<URL::URL, JS::GCPtr<HTML::SharedResourceRequest>>& shared_resource_requests();

Expand Down
19 changes: 12 additions & 7 deletions Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,8 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
// that is synchronous navigation steps with a target navigable not contained in navigablesThatMustWaitBeforeHandlingSyncNavigation.
// 2. Remove steps from traversable's session history traversal queue's algorithm set.
for (auto entry = m_session_history_traversal_queue->first_synchronous_navigation_steps_with_target_navigable_not_contained_in(navigables_that_must_wait_before_handling_sync_navigation);
entry;
entry = m_session_history_traversal_queue->first_synchronous_navigation_steps_with_target_navigable_not_contained_in(navigables_that_must_wait_before_handling_sync_navigation)) {
entry;
entry = m_session_history_traversal_queue->first_synchronous_navigation_steps_with_target_navigable_not_contained_in(navigables_that_must_wait_before_handling_sync_navigation)) {

// 3. Set traversable's running nested apply history step to true.
m_running_nested_apply_history_step = true;
Expand Down Expand Up @@ -735,6 +735,8 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
// 9. Let entriesForNavigationAPI be the result of getting session history entries for the navigation API given navigable and targetStep.
auto entries_for_navigation_api = get_session_history_entries_for_the_navigation_api(*navigable, target_step);

// NOTE: Steps 10 and 11 come after step 12.

// 12. In both cases, let afterPotentialUnloads be the following steps:
bool const update_only = changing_navigable_continuation->update_only;
JS::GCPtr<SessionHistoryEntry> const target_entry = changing_navigable_continuation->target_entry;
Expand All @@ -746,15 +748,18 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
target_entry->set_classic_history_api_state(populated_target_entry->classic_history_api_state());
}

// 1. If changingNavigableContinuation's update-only is false, then activate history entry targetEntry for navigable.
// 1. Let previousEntry be navigable's active session history entry.
JS::GCPtr<SessionHistoryEntry> const previous_entry = navigable->active_session_history_entry();

// 2. If changingNavigableContinuation's update-only is false, then activate history entry targetEntry for navigable.
if (!update_only)
navigable->activate_history_entry(*target_entry);

// 2. Let updateDocument be an algorithm step which performs update document for history step application given
// 3. Let updateDocument be an algorithm step which performs update document for history step application given
// targetEntry's document, targetEntry, changingNavigableContinuation's update-only, scriptHistoryLength,
// scriptHistoryIndex, navigationType, entriesForNavigationAPI, and displayedEntry.
auto update_document = [script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), target_entry, update_only, navigation_type] {
target_entry->document()->update_for_history_step_application(*target_entry, update_only, script_history_length, script_history_index, navigation_type, entries_for_navigation_api);
// scriptHistoryIndex, navigationType, entriesForNavigationAPI, and previousEntry.
auto update_document = [script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), target_entry, update_only, navigation_type, previous_entry] {
target_entry->document()->update_for_history_step_application(*target_entry, update_only, script_history_length, script_history_index, navigation_type, entries_for_navigation_api, previous_entry);
};

// 3. If targetEntry's document is equal to displayedDocument, then perform updateDocument.
Expand Down

0 comments on commit 4be2965

Please sign in to comment.