Truly independent web browser
LibWebView: Gather a history step run's queue-jump state in one place
Shannon Booth30e461af496c
diff --git a/Libraries/LibWebView/ApplyHistoryStep.cpp b/Libraries/LibWebView/ApplyHistoryStep.cppindex 3fdfc775614..6239f1a2f85 100644--- a/Libraries/LibWebView/ApplyHistoryStep.cpp+++ b/Libraries/LibWebView/ApplyHistoryStep.cpp@@ -181,9 +181,11 @@ void ApplyHistoryStep::run_changing_navigable_jobs().target_entry_reload_pending = target_entry->document_state->reload_pending,.user_involvement = m_user_involvement,.navigation_type = m_navigation_type,- .traversal_yields_to = m_traversal_yields_to.get(navigable_id).value_or(Web::HTML::TraversalYieldsTo::Nothing),- .canceled_navigation_id = m_canceled_navigation_ids.get(navigable_id).copy(),};+ if (auto yield = m_same_document_traversal_yields.get(navigable_id); yield.has_value()) {+ job.traversal_yields_to = yield->yields_to;+ job.canceled_navigation_id = yield->canceled_navigation_id;+ }if (!m_jobs.select_changing_navigable_history_step_job_endpoint(job)) {changing_navigable_job_completed(navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition::Skipped);continue;@@ -507,7 +509,7 @@ void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& n&& navigable.ongoing_navigation()&& navigable.ongoing_navigation()->sequence_number > m_operation_sequence_number) {if (is_same_document_traversal)- m_traversal_yields_to.set(navigable.id(), Web::HTML::TraversalYieldsTo::AdmittedNavigation);+ m_same_document_traversal_yields.set(navigable.id(), { Web::HTML::TraversalYieldsTo::AdmittedNavigation, {} });return;}@@ -524,10 +526,10 @@ void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& nif (!m_navigation_type.has_value() && navigable.ongoing_navigation())return;+ Optional<Utf16String> canceled_navigation_id;if (m_navigation_type == Web::Bindings::NavigationType::Traverse) {- auto const* ongoing_navigation = navigable.ongoing_navigation();- if (is_same_document_traversal && ongoing_navigation && ongoing_navigation->navigation_id.has_value())- m_canceled_navigation_ids.set(navigable.id(), *ongoing_navigation->navigation_id);+ if (auto const* ongoing_navigation = navigable.ongoing_navigation(); is_same_document_traversal && ongoing_navigation)+ canceled_navigation_id = ongoing_navigation->navigation_id;navigable.clear_ongoing_navigation();}@@ -543,7 +545,7 @@ void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& n}if (is_same_document_traversal)- m_traversal_yields_to.set(navigable.id(), Web::HTML::TraversalYieldsTo::UnadmittedNavigation);+ m_same_document_traversal_yields.set(navigable.id(), { Web::HTML::TraversalYieldsTo::UnadmittedNavigation, move(canceled_navigation_id) });}void ApplyHistoryStep::clear_ongoing_navigation_traversal(Web::HTML::CrossProcessId navigable_id)diff --git a/Libraries/LibWebView/ApplyHistoryStep.h b/Libraries/LibWebView/ApplyHistoryStep.hindex f26adbc1b91..2253ce7c154 100644--- a/Libraries/LibWebView/ApplyHistoryStep.h+++ b/Libraries/LibWebView/ApplyHistoryStep.h@@ -167,24 +167,34 @@ private:Function<void(Web::HTML::HistoryStepResult)> m_on_complete;// The algorithm's variables.- u64 m_generation;i32 m_target_step { 0 };Vector<Web::HTML::CrossProcessId> m_changing_navigables;Vector<Web::HTML::CrossProcessId> m_nonchanging_navigables_that_still_need_updates;- // The target entry that each changing navigable's job claimed. Its document state and navigation API key name its- // slot in the session history — a same-document replacement of the entry keeps both.- HashMap<Web::HTML::CrossProcessId, NonnullRefPtr<CanonicalSessionHistoryEntry>> m_claimed_target_entries;- HashMap<Web::HTML::CrossProcessId, Web::HTML::TraversalYieldsTo> m_traversal_yields_to;- HashMap<Web::HTML::CrossProcessId, Utf16String> m_canceled_navigation_ids;HashTable<Web::HTML::CrossProcessId> m_navigables_with_ongoing_history_traversal;size_t m_completed_change_jobs { 0 };// NB: The continuation states live in the processes that ran the jobs; this queue holds the navigables whose// continuations are ready to be applied.Vector<Web::HTML::CrossProcessId> m_changing_navigable_continuations;HashTable<Web::HTML::CrossProcessId> m_navigables_that_must_wait_before_handling_sync_navigation;- Optional<u64> m_synchronous_navigation_steps_to_jump_through;size_t m_completed_nonchanging_jobs { 0 };+ // AD-HOC: Synchronous navigations jump the traversal queue while a run is paused, and navigations are admitted+ // independently of the queue. What keeps a paused run consistent with them:+ // - The generation that orders the runs' commits of the current step (whatwg/html#12576).+ // - The target entry each changing navigable's job claimed, which the run looks up again before+ // activating it (whatwg/html#12961). Its document state and navigation API key name its slot in the+ // session history: a same-document replacement of the entry keeps both.+ // - How far the run lets synchronous navigation steps jump.+ // - What a same-document traversal yields to, with the admitted navigation it canceled.+ u64 m_generation;+ HashMap<Web::HTML::CrossProcessId, NonnullRefPtr<CanonicalSessionHistoryEntry>> m_claimed_target_entries;+ Optional<u64> m_synchronous_navigation_steps_to_jump_through;+ struct SameDocumentTraversalYield {+ Web::HTML::TraversalYieldsTo yields_to;+ Optional<Utf16String> canceled_navigation_id;+ };+ HashMap<Web::HTML::CrossProcessId, SameDocumentTraversalYield> m_same_document_traversal_yields;+// The synchronous navigation steps this run is paused on ("running nested apply history step" is true).RefPtr<Core::Promise<Empty>> m_running_synchronous_navigation_steps;