Skip to content

Truly independent web browser

LibWeb+LibWebView: Return at navigate step 18 instead of deferring

Shannon Boothb332db15f519
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index ba0e46f9c15..ec1fc1e1cec 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -1245,7 +1245,7 @@ WebIDL::ExceptionOr<Document*> Document::open(Optional<Utf16String> const&, Opti
return this;
// 8. If document's node navigable is non-null and document's node navigable's ongoing navigation is a navigation ID, then stop loading document's node navigable.
- // AD-HOC: A navigation can also wait for a traversal or for its population, so we need to cancel those too.
+ // AD-HOC: A navigation can also wait for the UI process to continue it, so we need to cancel that too.
if (auto navigable = this->navigable()) {
navigable->clear_pending_navigations();
if (navigable->ongoing_navigation().has<Utf16String>())
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.cpp b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
index ab314ea10ba..c0fe0d95fd6 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.cpp
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
@@ -337,14 +337,16 @@ bool HistoryExecutor::run_changing_navigable_history_step_job_impl(ChangingNavig
// 2. Set navigable's current session history entry to targetEntry.
navigable->set_current_session_history_entry(claimed_target_entry);
- // AD-HOC: The UI operation owns the authoritative traversal tracker. LocalNavigable still uses this process-local
- // value to serialize pending navigations, so mirror it when the already-required changing job begins. A
- // same-document push or replace can arrive after a newer navigation installed its local ID, in which case
- // that navigation wins.
- auto preserve_ongoing_navigation = applies_same_document_push_or_replace
- && navigable->ongoing_navigation().has<Utf16String>();
- if (!preserve_ongoing_navigation)
+ // AD-HOC: The UI operation owns the authoritative traversal tracker, mirrored here when the changing job begins.
+ // As in browsers, only a traversal or reload sets it to "traversal". A push or replace leaves a newer
+ // navigation's ID in place, as that navigation goes on and commits after this one, and nulls the ID of the
+ // navigation it finalizes. See https://github.com/whatwg/html/issues/12581.
+ if (job.navigation_type.has_value() && first_is_one_of(*job.navigation_type, Bindings::NavigationType::Push, Bindings::NavigationType::Replace)) {
+ if (job.finalized_navigation_id.has_value() && navigable->ongoing_navigation() == *job.finalized_navigation_id)
+ navigable->set_ongoing_navigation_without_informing_navigation_api(Empty {});
+ } else {
navigable->set_ongoing_navigation_without_informing_navigation_api(HTML::LocalNavigable::Traversal::Tag);
+ }
queue_apply_history_step_task(*navigable, navigable->active_document(), GC::create_function(heap(), [this, job = move(job), source_snapshot_params, pending_document, claimed_target_entry = move(claimed_target_entry), navigable, on_complete]() mutable {
// NOTE: This check is not in the spec but we should not continue navigation if navigable has been destroyed.
@@ -357,22 +359,14 @@ bool HistoryExecutor::run_changing_navigable_history_step_job_impl(ChangingNavig
auto displayed_entry = navigable->active_session_history_entry();
// 2. Let targetEntry be navigable's current session history entry.
+ // AD-HOC: A synchronous navigation that jumps the queue during this run's apply-history-step re-claims the
+ // navigable before this task runs. It supersedes a same-document push or replace, as the newest claim
+ // wins, but no other run: that run still applies its claimed target entry once the jumped navigation's
+ // nested run completes. A navigation proven newer completes the job as stale before this task is
+ // queued.
auto target_entry = navigable->current_session_history_entry();
- if (!target_entry || target_entry != claimed_target_entry) {
- // AD-HOC: The HTML Standard expects the session history traversal queue to serialize this task with
- // later navigations. Our web-compatible deferral of navigations that arrive during traversal
- // can let a newer navigation replace the current entry before this task runs. Treat this state
- // as stale instead of applying its old target step after the newer navigation.
- //
- // A synchronous navigation that jumps the queue during this run's apply-history-step re-claims
- // the navigable the same way, but does not supersede a traversal, reload, or cross-document
- // navigation: those runs still apply their claimed target entry once the jumped navigation's
- // nested run completes. A navigation proven newer completes the job as stale before this task
- // is queued.
- auto reclaimed_by_cooperating_synchronous_navigation = target_entry
- && job.navigation_type.has_value()
- && !is_same_document_push_or_replace(job.navigation_type, *claimed_target_entry, navigable->active_document_id());
- if (!reclaimed_by_cooperating_synchronous_navigation) {
+ if (target_entry != claimed_target_entry) {
+ if (!target_entry || is_same_document_push_or_replace(job.navigation_type, *claimed_target_entry, navigable->active_document_id())) {
on_complete->function()({ ChangingNavigableHistoryStepJobDisposition::Stale, nullptr });
return;
}
@@ -829,7 +823,7 @@ bool HistoryExecutor::resume_history_navigation_population(CrossProcessId operat
return true;
}
-void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryDescriptor target_entry, UserNavigationInvolvement user_involvement, Optional<Bindings::NavigationType> navigation_type, TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id, GC::Ref<OnChangingNavigableHistoryStepJobComplete> on_complete, Optional<HistoryNavigationPopulation> population)
+void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryDescriptor target_entry, UserNavigationInvolvement user_involvement, Optional<Bindings::NavigationType> navigation_type, TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id, GC::Ref<OnChangingNavigableHistoryStepJobComplete> on_complete, Optional<HistoryNavigationPopulation> population)
{
auto& operation = ensure_history_operation(operation_id);
auto source_snapshot_params = operation.source_snapshot_params;
@@ -880,6 +874,7 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
.navigation_type = navigation_type,
.traversal_yields_to = traversal_yields_to,
.canceled_navigation_id = move(canceled_navigation_id),
+ .finalized_navigation_id = move(finalized_navigation_id),
.source_snapshot = operation.serialized_source_snapshot_params,
.population = move(population),
},
@@ -895,7 +890,7 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
}
}
// AD-HOC: A job can claim its navigable before becoming stale, or finish after its operation was
- // abandoned. Release the document-local projection so pending navigations can resume.
+ // abandoned. Release the document-local projection.
if (result.disposition != ChangingNavigableHistoryStepJobDisposition::Ready || !operation) {
if (auto navigable = local_navigable_with_id(navigable_id))
navigable->clear_ongoing_history_traversal();
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.h b/Libraries/LibWeb/HTML/HistoryExecutor.h
index c564de04113..5eede8871a1 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.h
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.h
@@ -68,7 +68,7 @@ public:
void finalize_same_document_navigation(GC::Ref<LocalNavigable>, NonnullRefPtr<SessionHistoryEntry>, RefPtr<SessionHistoryEntry> entry_to_replace, HistoryHandlingBehavior, UserNavigationInvolvement, Optional<SessionHistoryEntryPersistedState> previous_entry_persisted_state);
void run_ui_beforeunload_check(Vector<CrossProcessId> navigable_ids, Optional<SessionHistoryEntryDescriptor> target_entry, Optional<UserNavigationInvolvement> user_involvement_for_navigate_event, UnloadPromptShown, GC::Ref<GC::Function<void(CheckIfUnloadingIsCanceledResult, UnloadPromptShown)>>);
- void run_ui_changing_navigable_history_job(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryDescriptor target_entry, UserNavigationInvolvement, Optional<Bindings::NavigationType>, TraversalYieldsTo, Optional<Utf16String> canceled_navigation_id, GC::Ref<OnChangingNavigableHistoryStepJobComplete>, Optional<HistoryNavigationPopulation> = {});
+ void run_ui_changing_navigable_history_job(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryDescriptor target_entry, UserNavigationInvolvement, Optional<Bindings::NavigationType>, TraversalYieldsTo, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id, GC::Ref<OnChangingNavigableHistoryStepJobComplete>, Optional<HistoryNavigationPopulation> = {});
bool resume_history_navigation_population(CrossProcessId operation_id, HistoryNavigationPopulation&&);
void prepare_ui_changing_navigable_for_unload(CrossProcessId operation_id, CrossProcessId navigable_id, GC::Ref<GC::Function<void()>> on_complete);
void apply_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, HistoryObjectLengthAndIndex, Vector<SessionHistoryEntryDescriptor> entries_for_navigation_api, UnloadDisplayedDocument, GC::Ref<GC::Function<void(Optional<HostedNavigableState>, Optional<SessionHistoryEntryPersistedState>)>>);
@@ -90,6 +90,7 @@ private:
Optional<Bindings::NavigationType> navigation_type;
TraversalYieldsTo traversal_yields_to { TraversalYieldsTo::Nothing };
Optional<Utf16String> canceled_navigation_id;
+ Optional<Utf16String> finalized_navigation_id;
Optional<NavigationSourceSnapshot> source_snapshot;
Optional<HistoryNavigationPopulation> population;
};
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 72ff67d2b5c..f96fffe3b9c 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -783,8 +783,6 @@ void LocalNavigable::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_input_method_composition_node);
m_event_handler.visit_edges(visitor);
- if (m_navigation_waiting_for_traversal.has_value())
- m_navigation_waiting_for_traversal->visit_edges(visitor);
for (auto& parked : m_navigations_parked_for_population) {
if (parked.navigation.has_value())
parked.navigation->visit_edges(visitor);
@@ -1652,18 +1650,12 @@ void LocalNavigable::set_ongoing_navigation_without_informing_navigation_api(Var
set_delaying_load_events(false);
}
- auto was_traversal = m_ongoing_navigation.has<Traversal>();
m_ongoing_navigation = ongoing_navigation;
for (auto& navigation_observer : m_navigation_observers) {
if (navigation_observer.ongoing_navigation_changed())
navigation_observer.ongoing_navigation_changed()->function()();
}
-
- // AD-HOC: If we just finished a traversal and a navigation was deferred because the traversal was ongoing, begin
- // it now.
- if (was_traversal && !ongoing_navigation.has<Traversal>())
- begin_navigation_waiting_for_traversal();
}
void LocalNavigable::clear_ongoing_history_traversal()
@@ -1678,7 +1670,6 @@ void LocalNavigable::clear_ongoing_history_traversal()
void LocalNavigable::clear_pending_navigations()
{
- m_navigation_waiting_for_traversal.clear();
if (m_navigations_parked_for_population.is_empty())
return;
m_navigations_parked_for_population.clear();
@@ -1713,13 +1704,6 @@ Optional<LocalNavigable::NavigationParkedForPopulation> LocalNavigable::take_nav
return m_navigations_parked_for_population.take(*index);
}
-void LocalNavigable::begin_navigation_waiting_for_traversal()
-{
- if (!m_navigation_waiting_for_traversal.has_value() || ongoing_navigation().has<Traversal>())
- return;
- begin_navigation(m_navigation_waiting_for_traversal.release_value());
-}
-
// https://html.spec.whatwg.org/multipage/document-sequences.html#the-rules-for-choosing-a-navigable
LocalNavigable::ChosenNavigable LocalNavigable::choose_a_navigable(Utf16View name, TokenizedFeature::NoOpener no_opener, ActivateTab activate_tab, Optional<TokenizedFeature::Map const&> window_features)
{
@@ -3705,12 +3689,6 @@ void LocalNavigable::begin_navigation(PreparedNavigation navigation)
// FIXME: 1. Invoke WebDriver BiDi navigation failed with navigable and a new WebDriver BiDi navigation status whose id
// is navigationId, status is "canceled", and url is url.
- // AD-HOC: The HTML Standard cancels a navigation that starts while a traversal is ongoing. We defer it
- // instead so UI-initiated navigations that race the tail end of a previous load are not dropped.
- // Match Chromium, WebKit, and Gecko's observable behavior by letting the newest navigation win.
- // See https://github.com/whatwg/html/issues/12581.
- m_navigation_waiting_for_traversal = move(navigation);
-
// 2. Return.
return;
}
@@ -4611,16 +4589,7 @@ void finalize_a_cross_document_navigation(GC::Ref<LocalNavigable> navigable, His
return;
}
- HashTable<CrossProcessId> claimed_navigables;
- if (pending_document) {
- // AD-HOC: The navigation is committed from here on, and the steps finalizing it set navigable's ongoing
- // navigation to "traversal" only once the UI process reaches them. Set it now, so that a navigation
- // this process starts meanwhile waits for them instead of crossing them on its way to the UI process.
- if (!navigable->ongoing_navigation().has<Utf16String>() || navigable->ongoing_navigation() == navigation_id) {
- navigable->set_ongoing_navigation_without_informing_navigation_api(LocalNavigable::Traversal::Tag);
- claimed_navigables.set(navigable->id());
- }
- } else {
+ if (!pending_document) {
// 2. Set navigable's is delaying load events to false.
// 3. If historyEntry's document is null, then return.
navigable->set_delaying_load_events(false);
@@ -4636,7 +4605,7 @@ void finalize_a_cross_document_navigation(GC::Ref<LocalNavigable> navigable, His
FinalizeCrossDocumentNavigationHistoryOperationParameters {
.navigable_id = navigable->id(),
.history_entry = create_pending_session_history_entry_descriptor(*history_entry),
- .navigation_id = move(navigation_id),
+ .navigation_id = navigation_id,
.history_handling = history_handling,
.user_involvement = user_involvement,
.environment_id = pending_document ? Optional<Web::HTML::EnvironmentId> { pending_document->relevant_settings_object().id } : Optional<Web::HTML::EnvironmentId> {},
@@ -4652,7 +4621,6 @@ void finalize_a_cross_document_navigation(GC::Ref<LocalNavigable> navigable, His
container->set_needs_layout_update(DOM::SetNeedsLayoutReason::FinalizeACrossDocumentNavigation);
on_complete->function()(result);
}),
- .claimed_navigables_awaiting_continuation = move(claimed_navigables),
});
}
@@ -6679,9 +6647,7 @@ void LocalNavigable::stop_loading()
// 1. Let document be navigable's active document.
auto document = active_document();
- // AD-HOC: The HTML Standard does not cancel planned navigations here, but Chromium, WebKit, and Gecko do so when
- // handling window.stop(). Prevent navigations deferred behind an ongoing traversal from starting once it
- // completes. See https://github.com/whatwg/html/issues/12609.
+ // NB: A navigation waiting for the UI process to continue it is not continued.
clear_pending_navigations();
// NB: This is what makes step 2 of navigate to a javascript: URL return for a navigation this stops.
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index 99fc2bd14ea..09f52ca8af3 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -298,7 +298,6 @@ public:
void inform_the_navigation_api_about_child_navigable_destruction();
- bool has_pending_navigations() const { return m_navigation_waiting_for_traversal.has_value() || !m_navigations_parked_for_population.is_empty(); }
bool has_navigation_parked_for_population(Utf16String const& navigation_id) const;
void clear_pending_navigations();
@@ -472,7 +471,6 @@ private:
void continue_navigation_after_population_dispatch(PreparedNavigation, NavigationPopulationRequest);
void park_navigation_for_population(Utf16String navigation_id, Optional<PreparedNavigation>, GC::Ref<GC::Function<void(Optional<PreparedNavigation>, Optional<NavigationPopulationRequest>)>> continue_steps);
Optional<NavigationParkedForPopulation> take_navigation_parked_for_population(Utf16String const& navigation_id);
- void begin_navigation_waiting_for_traversal();
void navigate_to_a_javascript_url(GC::Ref<Fetch::Infrastructure::Request>, HistoryHandlingBehavior, URL::Origin const& initiator_origin, UserNavigationInvolvement, ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type, InitialInsertion, Utf16String navigation_id);
void reset_cursor_blink_cycle();
@@ -603,7 +601,6 @@ private:
bool m_has_session_history_entry_and_ready_for_navigation { false };
- Optional<PreparedNavigation> m_navigation_waiting_for_traversal;
Vector<NavigationParkedForPopulation> m_navigations_parked_for_population;
// The navigation IDs of javascript: URL navigations whose navigate to a javascript: URL task is queued.
diff --git a/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Libraries/LibWeb/HTML/NavigableContainer.cpp
index 76352d31487..8521dc1dad9 100644
--- a/Libraries/LibWeb/HTML/NavigableContainer.cpp
+++ b/Libraries/LibWeb/HTML/NavigableContainer.cpp
@@ -234,16 +234,7 @@ Optional<URL::URL> NavigableContainer::shared_attribute_processing_steps_for_ifr
// 4. If url matches about:blank and initialInsertion is true, then perform the URL and history update steps given element's content navigable's active document and url.
if (url_matches_about_blank(url) && initial_insertion == InitialInsertion::Yes) {
// NB: A newly inserted element's content navigable was created in this process.
- auto& local_navigable = as<LocalNavigable>(*m_content_navigable);
-
- // AD-HOC: If the content navigable already has a navigation in progress or pending, skip the initial
- // about:blank URL update. Without this, the URL update creates a state machine that clobbers the
- // navigable's ongoing_navigation, causing the real navigation to be dropped when its populate completion
- // callback checks ongoing_navigation != navigation_id.
- if (local_navigable.has_pending_navigations() || !local_navigable.ongoing_navigation().has<Empty>())
- return {};
-
- perform_url_and_history_update_steps(*local_navigable.active_document(), url);
+ perform_url_and_history_update_steps(*as<LocalNavigable>(*m_content_navigable).active_document(), url);
}
// 5. Return url.
diff --git a/Libraries/LibWebView/ApplyHistoryStep.cpp b/Libraries/LibWebView/ApplyHistoryStep.cpp
index e01c640ef7b..815a25f9b2a 100644
--- a/Libraries/LibWebView/ApplyHistoryStep.cpp
+++ b/Libraries/LibWebView/ApplyHistoryStep.cpp
@@ -500,6 +500,13 @@ Web::HTML::SessionHistoryEntryDescriptor ApplyHistoryStepJobs::ChangingNavigable
void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& navigable, CanonicalSessionHistoryEntry const& target_entry)
{
+ // AD-HOC: As in browsers, a push or replace leaves the ongoing navigation alone: a newer navigation goes on, and
+ // commits after it. See https://github.com/whatwg/html/issues/12581.
+ if (m_navigation_type.has_value()
+ && first_is_one_of(*m_navigation_type, Web::Bindings::NavigationType::Push, Web::Bindings::NavigationType::Replace)) {
+ return;
+ }
+
auto target_document_is_active_document = navigable.active_document_is(target_entry);
auto traversal_crosses_documents = !target_document_is_active_document
|| target_entry.document_state->reload_pending;
@@ -521,14 +528,6 @@ void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& n
return;
}
- // AD-HOC: Same-document push/replace finalization can run while its NavigateEvent handlers are settling.
- if (m_navigation_type.has_value()
- && first_is_one_of(*m_navigation_type, Web::Bindings::NavigationType::Push, Web::Bindings::NavigationType::Replace)
- && target_document_is_active_document
- && ongoing_navigation_id.has_value()) {
- return;
- }
-
// AD-HOC: A navigable creation/destruction update skips a navigable already claimed by its requested navigation.
// See https://github.com/whatwg/html/issues/12724.
if (!m_navigation_type.has_value() && ongoing_navigation_id.has_value())
@@ -543,7 +542,7 @@ void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& n
// AD-HOC: The installed marker cancels navigation-start requests that arrive while this operation is on the
// traversal queue, matching navigate()'s "if navigable's ongoing navigation is 'traversal', then return".
- // A same-document traversal, push, or replace must not install it. A navigation racing one genuinely
+ // A same-document traversal must not install it. A navigation racing one genuinely
// started before this step ran in its own process. Its navigate() saw no traversal, and the admission
// recheck must not misattribute that ordering and drop the navigation the step has to yield to.
if (traversal_crosses_documents) {
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 611e909cc18..ca0ff789ad1 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -242,16 +242,11 @@ void CanonicalNavigable::begin_navigation(Web::HTML::PreparedNavigationDescripto
// id is navigationId, status is "pending", and url is url.
// 18. If navigable's ongoing navigation is "traversal", then:
- if (m_ongoing_navigation.has<Traversal>()) {
+ // AD-HOC: A navigation from the browser's UI goes on, and takes the navigable over from the traversal.
+ if (m_ongoing_navigation.has<Traversal>() && user_involvement != Web::HTML::UserNavigationInvolvement::BrowserUI) {
// FIXME: 1. Invoke WebDriver BiDi navigation failed with navigable and a new WebDriver BiDi navigation status
// whose id is navigationId, status is "canceled", and url is url.
- // AD-HOC: The HTML Standard cancels a navigation that starts while a traversal is ongoing. We defer it instead
- // so UI-initiated navigations that race the tail end of a previous load are not dropped. Match
- // Chromium, WebKit, and Gecko's observable behavior by letting the newest navigation win.
- // See https://github.com/whatwg/html/issues/12581.
- m_navigation_waiting_for_traversal = move(navigation);
-
// 2. Return.
return;
}
@@ -347,13 +342,6 @@ Optional<URL::Origin> CanonicalNavigable::take_routed_navigation_initiator_origi
return m_routed_navigation.release_value().initiator_origin;
}
-void CanonicalNavigable::begin_navigation_waiting_for_traversal()
-{
- if (!m_navigation_waiting_for_traversal.has_value() || m_ongoing_navigation.has<Traversal>())
- return;
- begin_navigation(m_navigation_waiting_for_traversal.release_value());
-}
-
// https://html.spec.whatwg.org/multipage/browsers.html#obtain-browsing-context-navigation
// NB: The browsing context is returned with its active document, which nothing else holds for a new one.
CanonicalBrowsingContext::BrowsingContextAndDocument CanonicalNavigable::obtain_a_browsing_context_to_use_for_a_navigation_response(NavigationLoader::ResponseDocument const& navigation_params)
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index c534b2e9193..9a6bc814c7f 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -118,13 +118,11 @@ public:
void navigate(URL::URL, Web::HTML::DocumentResource = {}, Web::Bindings::NavigationHistoryBehavior = Web::Bindings::NavigationHistoryBehavior::Auto);
Web::HTML::PreparedNavigationDescriptor prepare_navigation(URL::URL, Web::HTML::DocumentResource = {}, Web::Bindings::NavigationHistoryBehavior = Web::Bindings::NavigationHistoryBehavior::Auto);
void begin_navigation(Web::HTML::PreparedNavigationDescriptor);
- bool has_navigation_waiting_for_traversal() const { return m_navigation_waiting_for_traversal.has_value(); }
// A navigation another page started for the navigable continues in the page hosting its document, with the
// initiator origin the UI process took from the page that started it.
void set_routed_navigation(Utf16String navigation_id, URL::Origin initiator_origin);
Optional<URL::Origin> take_routed_navigation_initiator_origin(Utf16String const& navigation_id);
- void begin_navigation_waiting_for_traversal();
CanonicalBrowsingContext::BrowsingContextAndDocument obtain_a_browsing_context_to_use_for_a_navigation_response(NavigationLoader::ResponseDocument const&);
NonnullRefPtr<CanonicalDocument> create_and_initialize_a_document(NavigationLoader::ResponseDocument const&);
@@ -264,7 +262,6 @@ private:
void end_navigation(CanonicalNavigation&);
OngoingNavigation m_ongoing_navigation;
Vector<NonnullOwnPtr<CanonicalNavigation>> m_navigations;
- Optional<Web::HTML::PreparedNavigationDescriptor> m_navigation_waiting_for_traversal;
struct RoutedNavigation {
Utf16String navigation_id;
URL::Origin initiator_origin;
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 22abf425ef6..32cedda99ae 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -1516,13 +1516,17 @@ void CanonicalTraversable::dispatch_changing_navigable_history_step_job(HistoryO
pending_job.value()->population_loader->reclaim_response_body_after_failed_handoff();
pending_job.value()->population_loader = nullptr;
auto target_entry = pending_job.value()->job.target_entry_descriptor();
+ Optional<Utf16String> finalized_navigation_id;
+ if (auto const* parameters = operation.parameters.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>(); parameters && parameters->navigable_id == navigable_id)
+ finalized_navigation_id = parameters->navigation_id;
endpoint->owe_reply({ OwedReply::Kind::ChangingJob, operation.operation_id, navigable_id });
endpoint->async_run_changing_navigable_history_job(
operation.operation_id, navigable_id,
move(target_entry), pending_job.value()->job.user_involvement,
pending_job.value()->job.navigation_type,
pending_job.value()->job.traversal_yields_to,
- pending_job.value()->job.canceled_navigation_id);
+ pending_job.value()->job.canceled_navigation_id,
+ finalized_navigation_id);
}
void CanonicalTraversable::dispatch_changing_navigable_history_step_continuation(HistoryOperation& operation, Web::HTML::CrossProcessId navigable_id)
@@ -2776,7 +2780,8 @@ void CanonicalTraversable::finish_history_operation(Web::HTML::CrossProcessId op
if ((*operation)->queue_promise)
(*operation)->queue_promise->resolve({});
- run_steps_waiting_for_traversal();
+ if (auto view = this->view(); view.has_value())
+ view->run_webdriver_commands_waiting_for_a_document({});
// The completion callback that brought us here can be running inside the algorithm object; destroy the
// operation only once the stack has unwound.
@@ -2831,25 +2836,6 @@ void CanonicalTraversable::report_history_operation_result(HistoryOperation& ope
}
}
-// The navigations that waited for a traversal to be over begin, unless another traversal began, and so do the WebDriver
-// commands that waited for a document.
-void CanonicalTraversable::run_steps_waiting_for_traversal()
-{
- Vector<Web::HTML::CrossProcessId> navigables_with_waiting_navigation;
- for_each_in_inclusive_subtree([&](CanonicalNavigable const& navigable) {
- if (navigable.has_navigation_waiting_for_traversal())
- navigables_with_waiting_navigation.append(navigable.id());
- return IterationDecision::Continue;
- });
- for (auto navigable_id : navigables_with_waiting_navigation) {
- if (auto navigable = find(navigable_id); navigable.has_value())
- navigable->begin_navigation_waiting_for_traversal();
- }
-
- if (auto view = this->view(); view.has_value())
- view->run_webdriver_commands_waiting_for_a_document({});
-}
-
void CanonicalTraversable::abandon_history_operations()
{
while (!m_history_operations.is_empty()) {
diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.h
index 053ee27d81c..929bde5c2bc 100644
--- a/Libraries/LibWebView/CanonicalTraversable.h
+++ b/Libraries/LibWebView/CanonicalTraversable.h
@@ -230,7 +230,6 @@ private:
void finish_history_operation(Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult, Optional<i32> committed_step);
void release_history_operation(HistoryOperation&, Web::HTML::HistoryStepResult);
void report_history_operation_result(HistoryOperation&, Web::HTML::HistoryStepResult, Optional<i32> committed_step);
- void run_steps_waiting_for_traversal();
HistoryOperation* ongoing_browser_history_traversal();
void run_browser_ui_traversal_at_queue_position(Function<Optional<i32>()> select_target_step, CheckForCancelation, Function<void()> on_ready, NonnullRefPtr<Core::Promise<Empty>>);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index f795695b75b..a8f7ff3042d 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1917,8 +1917,11 @@ void WebContentPage::did_request_navigation_start(Web::HTML::CrossProcessId navi
target_navigable = child_frame.has_value() ? &*child_frame : nullptr;
}
- // AD-HOC: The local ongoing-navigation check can run before the UI traversal queue sets its canonical value.
- // Recheck it here so navigation admission and history traversal remain ordered by the UI process.
+ // https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate
+ // 18. If navigable's ongoing navigation is "traversal", then:
+ // 2. Return.
+ // NB: The page ran this step against the ongoing navigation it knew of, which the traversal queue can have set to
+ // "traversal" since.
auto navigation_is_blocked_by_history_traversal = target_navigable
&& target_navigable->ongoing_navigation().has<CanonicalNavigable::Traversal>();
// The page hosting the navigable's document continues navigate at step 8, for a sourceDocument it hosts or for
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 50cb27ec7d1..7aba5e406be 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -621,14 +621,14 @@ void ConnectionFromClient::continue_history_navigation_population(Web::PageId pa
if (history_executor.resume_history_navigation_population(operation_id, move(population)))
return;
auto user_involvement = population.request.user_involvement;
- history_executor.run_ui_changing_navigable_history_job(operation_id, navigable_id, move(target_entry), user_involvement, navigation_type, Web::HTML::TraversalYieldsTo::Nothing, {},
+ history_executor.run_ui_changing_navigable_history_job(operation_id, navigable_id, move(target_entry), user_involvement, navigation_type, Web::HTML::TraversalYieldsTo::Nothing, {}, {},
GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id](Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, Web::HTML::UnloadDisplayedDocument unload_displayed_document) {
async_changing_navigable_history_job_ready(page_id, operation_id, navigable_id, disposition, unload_displayed_document);
}),
move(population));
}
-void ConnectionFromClient::run_changing_navigable_history_job(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Web::HTML::UserNavigationInvolvement user_involvement, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id)
+void ConnectionFromClient::run_changing_navigable_history_job(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Web::HTML::UserNavigationInvolvement user_involvement, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id)
{
auto page = this->page(page_id);
if (!page.has_value()) {
@@ -636,7 +636,7 @@ void ConnectionFromClient::run_changing_navigable_history_job(Web::PageId page_i
return;
}
- page->page().history_executor().run_ui_changing_navigable_history_job(operation_id, navigable_id, move(target_entry), user_involvement, navigation_type, traversal_yields_to, move(canceled_navigation_id), GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id](Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, Web::HTML::UnloadDisplayedDocument unload_displayed_document) {
+ page->page().history_executor().run_ui_changing_navigable_history_job(operation_id, navigable_id, move(target_entry), user_involvement, navigation_type, traversal_yields_to, move(canceled_navigation_id), move(finalized_navigation_id), GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id](Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, Web::HTML::UnloadDisplayedDocument unload_displayed_document) {
async_changing_navigable_history_job_ready(page_id, operation_id, navigable_id, disposition, unload_displayed_document);
}));
}
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index 43bf103fbe9..cdb9ff1058c 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -144,7 +144,7 @@ private:
virtual void run_beforeunload_check(Web::PageId page_id, Web::HTML::CrossProcessId check_id, Vector<Web::HTML::CrossProcessId> navigable_ids, Optional<Web::HTML::SessionHistoryEntryDescriptor> target_entry, Optional<Web::HTML::UserNavigationInvolvement> user_involvement_for_navigate_event, Web::HTML::UnloadPromptShown unload_prompt_shown) override;
virtual void discard_embedded_page(Web::PageId page_id) override;
virtual void queue_navigation_api_state_clear_task(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) override;
- virtual void run_changing_navigable_history_job(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Web::HTML::UserNavigationInvolvement user_involvement, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id) override;
+ virtual void run_changing_navigable_history_job(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Web::HTML::UserNavigationInvolvement user_involvement, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id) override;
virtual void prepare_changing_navigable_for_unload(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api, Web::HTML::UnloadDisplayedDocument unload_displayed_document) override;
virtual void run_descendant_unload_task(Web::PageId page_id, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChildNavigableDestruction, Web::HTML::StopHostingAfterUnload) override;
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index 5dd360ea96e..eef0b572b53 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -118,7 +118,7 @@ endpoint WebContentServer routed by Web::PageId page_id
discard_embedded_page(Web::PageId page_id) =|
queue_navigation_api_state_clear_task(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) =|
continue_history_navigation_population(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::HistoryNavigationPopulation population) =|
- run_changing_navigable_history_job(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Web::HTML::UserNavigationInvolvement user_involvement, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id) =|
+ run_changing_navigable_history_job(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Web::HTML::UserNavigationInvolvement user_involvement, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id) =|
prepare_changing_navigable_for_unload(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) =|
apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api, Web::HTML::UnloadDisplayedDocument unload_displayed_document) =|
run_descendant_unload_task(Web::PageId page_id, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChildNavigableDestruction child_navigable_destruction, Web::HTML::StopHostingAfterUnload stop_hosting_after_unload) =|