Skip to content

Truly independent web browser

LibWeb+LibWebView: Apply a continuation by the step the spec branches to

Shannon Boothcbb65f5e1e2c
diff --git a/Libraries/LibWeb/HTML/ApplyHistoryStep.h b/Libraries/LibWeb/HTML/ApplyHistoryStep.h
index a459a7f86f5..7688d232f10 100644
--- a/Libraries/LibWeb/HTML/ApplyHistoryStep.h
+++ b/Libraries/LibWeb/HTML/ApplyHistoryStep.h
@@ -6,13 +6,19 @@
#pragma once
+#include <AK/Optional.h>
#include <LibGC/Function.h>
#include <LibWebCommon/HTML/ApplyHistoryStep.h>
+#include <LibWebCommon/HTML/CrossProcessId.h>
+#include <LibWebCommon/HTML/ReplicatedNavigableState.h>
+#include <LibWebCommon/HTML/SessionHistoryEntryDescriptor.h>
namespace Web::HTML {
using OnApplyHistoryStepComplete = GC::Function<void(HistoryStepResult)>;
-using OnChangingNavigableHistoryStepJobComplete = GC::Function<void(ChangingNavigableHistoryStepJobDisposition, UnloadDisplayedDocument)>;
+using OnChangingNavigableHistoryStepJobComplete = GC::Function<void(ChangingNavigableHistoryStepJobDisposition, bool update_only, Optional<CrossProcessId> target_document_id)>;
+
+using OnChangingNavigableContinuationApplied = GC::Function<void(Optional<HostedNavigableState> activated_navigable_state, Optional<SessionHistoryEntryPersistedState> previous_entry_persisted_state)>;
}
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.cpp b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
index 2a4aacecfd3..445769b7aeb 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.cpp
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
@@ -40,7 +40,7 @@ struct ChangingNavigableContinuationState : public GC::Cell {
GC::Ptr<DOM::Document> pending_document;
GC::Ptr<PopulateSessionHistoryEntryDocumentOutput> population_output;
- GC::Ptr<DOM::Document> resolved_document;
+ GC::Ptr<DOM::Document> target_document;
Optional<URL::Origin> old_origin;
UserNavigationInvolvement user_involvement { UserNavigationInvolvement::None };
@@ -51,7 +51,7 @@ struct ChangingNavigableContinuationState : public GC::Cell {
visitor.visit(navigable);
visitor.visit(pending_document);
visitor.visit(population_output);
- visitor.visit(resolved_document);
+ visitor.visit(target_document);
}
};
@@ -267,11 +267,10 @@ void HistoryExecutor::enqueue_changing_navigable_continuation(CrossProcessId ope
if (auto* operation = find_history_operation(operation_id))
operation->changing_navigable_jobs.get(continuation->navigable->id())->continuation = continuation;
- auto unload_displayed_document = !continuation->update_only
- && continuation->resolved_document.ptr() != continuation->displayed_document.ptr()
- ? UnloadDisplayedDocument::Yes
- : UnloadDisplayedDocument::No;
- on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Ready, unload_displayed_document);
+ // NB: The UI process applies the continuation as step 14.10 or step 14.11 of apply the history step says, given
+ // its update-only and targetEntry's document.
+ auto target_document_id = continuation->target_document ? continuation->target_document->id() : Optional<CrossProcessId> {};
+ on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Ready, continuation->update_only, target_document_id);
}
void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryDescriptor target_entry_descriptor, UserNavigationInvolvement user_involvement, Optional<Bindings::NavigationType> navigation_type, TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id, Optional<NavigationSourceSnapshot> navigation_source_snapshot, GC::Ref<OnChangingNavigableHistoryStepJobComplete> on_complete, Optional<HistoryNavigationPopulation> population)
@@ -293,19 +292,19 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
if (pending_document && local_target_entry) {
GC::Ptr<DOM::Document> active_document = navigable ? navigable->active_document() : nullptr;
if (!navigable || navigable->has_been_destroyed() || pending_document->has_been_destroyed() || !pending_document->browsing_context() || !active_document || active_document->has_been_destroyed()) {
- on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Stale, UnloadDisplayedDocument::No);
+ on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Stale, false, {});
return;
}
}
if (!navigable) {
- on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Skipped, UnloadDisplayedDocument::No);
+ on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Skipped, false, {});
return;
}
if (local_target_entry) {
auto document_state = local_target_entry->document_state();
if (!document_state
|| document_state->cross_process_id() != target_entry_descriptor.document_state.id) {
- on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Stale, UnloadDisplayedDocument::No);
+ on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Stale, false, {});
return;
}
@@ -317,7 +316,7 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
// AD-HOC: This process can destroy a navigable before the UI process removes it, which leaves no active window to
// queue the task on.
if (navigable->has_been_destroyed() || !navigable->active_window()) {
- on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Skipped, UnloadDisplayedDocument::No);
+ on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Skipped, false, {});
return;
}
@@ -339,7 +338,7 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
if (applies_same_document_push_or_replace
&& active_entry != claimed_target_entry) {
navigable->set_current_session_history_entry(claimed_target_entry);
- on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Skipped, UnloadDisplayedDocument::No);
+ on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Skipped, false, {});
return;
}
@@ -361,7 +360,7 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
};
if (traversal_yields_to == TraversalYieldsTo::AdmittedNavigation
|| (traversal_yields_to == TraversalYieldsTo::UnadmittedNavigation && yields_to_unadmitted_navigation())) {
- on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Stale, UnloadDisplayedDocument::No);
+ on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Stale, false, {});
return;
}
@@ -399,7 +398,7 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
operation->changing_navigable_jobs.remove(navigable_id);
navigable->clear_ongoing_history_traversal();
}
- on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Stale, UnloadDisplayedDocument::No);
+ on_complete->function()(ChangingNavigableHistoryStepJobDisposition::Stale, false, {});
return;
}
target_entry = claimed_target_entry;
@@ -429,7 +428,7 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
if (is_update_only) {
// 1. Set changingNavigableContinuation's update-only to true.
changing_navigable_continuation->update_only = true;
- changing_navigable_continuation->resolved_document = navigable->active_document();
+ changing_navigable_continuation->target_document = navigable->active_document();
// 2. Enqueue changingNavigableContinuation on changingNavigableContinuations.
enqueue_changing_navigable_continuation(operation_id, *changing_navigable_continuation, on_complete);
@@ -493,20 +492,19 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
changing_navigable_continuation->population_output = output;
changing_navigable_continuation->old_origin = old_origin;
- // Compute the resolved document: pending document (from the finalize path),
- // population output (from traversal path), or active document (same-document).
- GC::Ptr<DOM::Document> resolved_document;
+ // NB: targetEntry's document is the finalized navigation's, the one population produced, or else the one
+ // its document state already had. Population that produces no document leaves that one in place.
+ GC::Ptr<DOM::Document> target_document;
if (changing_navigable_continuation->pending_document)
- resolved_document = changing_navigable_continuation->pending_document;
+ target_document = changing_navigable_continuation->pending_document;
else if (output && output->document)
- resolved_document = output->document;
- else
- resolved_document = navigable->active_document();
- changing_navigable_continuation->resolved_document = resolved_document;
+ target_document = output->document;
+ else if (target_entry->document_state()->document_id() == navigable->active_document_id())
+ target_document = navigable->active_document();
+ changing_navigable_continuation->target_document = target_document;
// 1. If targetEntry's document is null, then set changingNavigableContinuation's update-only to true.
- bool has_fresh_document = changing_navigable_continuation->pending_document || (output && output->document);
- if (!has_fresh_document && target_entry->document_state()->document_id() != navigable->active_document_id())
+ if (!target_document)
changing_navigable_continuation->update_only = true;
// 2. If targetEntry's document's origin is not oldOrigin, then set targetEntry's classic history API state to StructuredSerializeForStorage(null).
@@ -667,7 +665,9 @@ void HistoryExecutor::prepare_ui_changing_navigable_for_unload(CrossProcessId op
on_complete->function()();
}
-void HistoryExecutor::apply_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, HistoryObjectLengthAndIndex history_object_length_and_index, Vector<SessionHistoryEntryDescriptor> entry_descriptors_for_navigation_api, UnloadDisplayedDocument unload_displayed_document, GC::Ref<GC::Function<void(Optional<HostedNavigableState>, Optional<SessionHistoryEntryPersistedState>)>> on_complete)
+// Steps 14.4 to 14.9 and step 14.12 of apply the history step, for the changing navigable continuation the UI process
+// dequeued.
+Optional<HistoryExecutor::DequeuedChangingNavigableContinuation> HistoryExecutor::dequeue_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryIdentity target_entry_identity, HistoryObjectLengthAndIndex history_object_length_and_index, Vector<SessionHistoryEntryDescriptor> entry_descriptors_for_navigation_api, GC::Ref<OnChangingNavigableContinuationApplied> on_complete)
{
auto* operation = find_history_operation(operation_id);
VERIFY(operation);
@@ -675,99 +675,62 @@ void HistoryExecutor::apply_ui_changing_navigable_continuation(CrossProcessId op
VERIFY(job.has_value() && job->continuation);
GC::Ref continuation = *job->continuation;
- Vector<NonnullRefPtr<SessionHistoryEntry>> entries_for_navigation_api;
- if (auto navigable = local_navigable_with_id(navigable_id); navigable && !navigable->has_been_destroyed())
- entries_for_navigation_api = navigable->session_history_entries_for_navigation_api_from_ui_process(move(entry_descriptors_for_navigation_api), *continuation->target_entry);
-
- // AD-HOC: The spec has the continuation activate the target entry that the job's task retained. But a sync
- // navigation that jumped the queue while the job was paused can have replaced that entry (replaceState()
- // during a reload, e.g.). And then the session history — and so the entry list from the UI process — has
- // the replacement in its slot. A same-doc replacement keeps the navigation API key and the document state
- // of the entry it replaces. So those two name the slot. The replacement is the entry to activate: It's the
- // one that the session history has, it's the navigable's current entry already, and the document that the
- // job populated belongs to the document state they share. Activating the replaced entry instead would leave
- // the new document's navigation API entry list without the document's own entry in it.
- // See https://github.com/whatwg/html/issues/12961.
- //
- // Gecko/WebKit/Blink never leave it out either: Gecko Navigation::InitializeHistoryEntries finds it by
- // its navigation key, WebKit Navigation::initializeForNewWindow appends it if it isn't found, and Blink
- // NavigationApi::InitializeForNewWindow builds the list around it.
- // NB: The UI process has looked the target entry up again by then: It doesn't apply a traversal's continuation at
- // all if the slot itself is gone, and it has appended a navigation's new entry again.
- auto& target_entry = continuation->target_entry;
- auto is_target_entry = [&](auto const& entry) { return entry.ptr() == target_entry.ptr(); };
- if (entries_for_navigation_api.find_if(is_target_entry) == entries_for_navigation_api.end()) {
- auto replacement = entries_for_navigation_api.find_if([&](auto const& entry) {
- return entry->document_state()->cross_process_id() == target_entry->document_state()->cross_process_id()
- && entry->navigation_api_key() == target_entry->navigation_api_key();
- });
- if (replacement != entries_for_navigation_api.end())
- target_entry = *replacement;
- }
-
// 4. Let displayedDocument be changingNavigableContinuation's displayed document.
auto displayed_document = continuation->displayed_document;
// 5. Let targetEntry be changingNavigableContinuation's target entry.
- // NB: target_entry, as looked up again above.
-
- auto population_output = continuation->population_output;
- auto old_origin = continuation->old_origin;
+ auto& target_entry = continuation->target_entry;
// 6. Let navigable be changingNavigableContinuation's navigable.
auto navigable = continuation->navigable;
- if (unload_displayed_document == UnloadDisplayedDocument::Yes) {
- VERIFY(!continuation->update_only);
- VERIFY(continuation->resolved_document.ptr() != displayed_document.ptr());
- }
-
- // AD-HOC: We should not continue navigation if navigable has been destroyed.
- if (navigable->has_been_destroyed()) {
- on_complete->function()({}, {});
- return;
- }
- // AD-HOC: The displayed document may have been destroyed during the nested step execution above.
- if (!displayed_document->navigable()) {
- on_complete->function()({}, {});
- return;
- }
+ // AD-HOC: This process can destroy the navigable, or the displayed document, before the UI process removes it.
+ if (navigable->has_been_destroyed() || !displayed_document->navigable())
+ return {};
// 7. Let (scriptHistoryLength, scriptHistoryIndex) be the result of getting the history object length and index given traversable and targetStep.
auto script_history_length = history_object_length_and_index.script_history_length;
auto script_history_index = history_object_length_and_index.script_history_index;
// 9. Let entriesForNavigationAPI be the result of getting session history entries for the navigation API given navigable and targetStep.
- // NB: entries_for_navigation_api, from the UI process's descriptors above.
+ // NB: The UI process got these, and sent their descriptors.
+ auto entries_for_navigation_api = navigable->session_history_entries_for_navigation_api_from_ui_process(move(entry_descriptors_for_navigation_api), *target_entry);
+
+ // AD-HOC: The UI process looked targetEntry up again, and follows the entry a sync navigation that jumped the queue
+ // put in its slot. That entry is in entriesForNavigationAPI. See https://github.com/whatwg/html/issues/12961.
+ if (session_history_entry_identity(*target_entry) != target_entry_identity) {
+ auto updated_target_entry = entries_for_navigation_api.find_if([&](auto const& entry) {
+ return session_history_entry_identity(*entry) == target_entry_identity;
+ });
+ VERIFY(updated_target_entry != entries_for_navigation_api.end());
+ target_entry = *updated_target_entry;
+ }
- // NOTE: Steps 10 and 11 come after step 12.
+ auto population_output = continuation->population_output;
+ auto old_origin = continuation->old_origin;
// 12. In both cases, let afterPotentialUnloads be the following steps:
bool const update_only = continuation->update_only;
auto const displayed_document_id = continuation->displayed_document_id;
- auto after_potential_unload = GC::create_function(heap(), [this, navigable, update_only, unload_displayed_document, target_entry, continuation, population_output, old_origin, displayed_document_id, script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), navigation_type = continuation->navigation_type, on_complete] {
- if (unload_displayed_document == UnloadDisplayedDocument::No) {
- auto applies_same_document_push_or_replace = is_same_document_push_or_replace(
- navigation_type, *target_entry, displayed_document_id);
-
- if (applies_same_document_push_or_replace
- && navigable->active_session_history_entry() != target_entry) {
- navigable->clear_ongoing_history_traversal();
- on_complete->function()({}, {});
- return;
- }
+ auto after_potential_unload = GC::create_function(heap(), [this, navigable, update_only, target_entry, continuation, population_output, old_origin, displayed_document_id, script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), navigation_type = continuation->navigation_type, on_complete] {
+ // NB: Only step 14.10 applies a same-document push or replace: its targetEntry's document is displayedDocument.
+ if (is_same_document_push_or_replace(navigation_type, *target_entry, displayed_document_id)
+ && navigable->active_session_history_entry() != target_entry) {
+ navigable->clear_ongoing_history_traversal();
+ on_complete->function()({}, {});
+ return;
}
if (population_output)
population_output->apply_to(*target_entry);
// Post-population adjustments — only run when a fresh document was produced
- // (not for 204/205 no-document outcomes where resolved_document is the old active document).
+ // (not for 204/205 no-document outcomes where targetEntry's document is null).
bool has_fresh_document = continuation->pending_document || (population_output && population_output->document);
if (has_fresh_document) {
- auto resolved_document = continuation->resolved_document;
+ auto target_document = continuation->target_document;
// 2. If targetEntry's document's origin is not oldOrigin, then set targetEntry's classic history API state to StructuredSerializeForStorage(null).
- if (resolved_document->origin() != old_origin) {
+ if (target_document->origin() != old_origin) {
auto& vm = navigable->vm();
target_entry->set_classic_history_api_state(MUST(structured_serialize_for_storage(vm, JS::js_null())));
}
@@ -778,7 +741,7 @@ void HistoryExecutor::apply_ui_changing_navigable_continuation(CrossProcessId op
// - targetEntry's document's origin is not oldOrigin,
// then set targetEntry's document state's navigable target name to the empty string.
if (navigable->parent() == nullptr
- && !(resolved_document->browsing_context()->is_auxiliary() && resolved_document->browsing_context()->opener_browsing_context_window_proxy())
+ && !(target_document->browsing_context()->is_auxiliary() && target_document->browsing_context()->opener_browsing_context_window_proxy())
&& target_entry->document_state()->origin() != old_origin) {
target_entry->document_state()->set_navigable_target_name(Utf16String {});
}
@@ -793,8 +756,11 @@ void HistoryExecutor::apply_ui_changing_navigable_continuation(CrossProcessId op
auto previous_entry_document_is_initial_about_blank = continuation->displayed_document
&& (continuation->displayed_document->is_initial_about_blank() || navigable->is_provisional());
+ // AD-HOC: targetEntry's document is null when population produced no document, which made the continuation
+ // update-only. The spec then updates that null document. Update displayedDocument instead.
+ GC::Ref<DOM::Document> resolved_document = continuation->target_document ? *continuation->target_document : *continuation->displayed_document;
+
// 2. If changingNavigableContinuation's update-only is false, then activate history entry targetEntry for navigable.
- auto resolved_document = continuation->resolved_document;
Optional<HostedNavigableState> activated_navigable_state;
if (!update_only) {
navigable->activate_history_entry(*target_entry, *resolved_document);
@@ -843,28 +809,53 @@ void HistoryExecutor::apply_ui_changing_navigable_continuation(CrossProcessId op
on_complete->function()(move(activated_navigable_state), move(previous_entry_persisted_state));
});
- if (unload_displayed_document == UnloadDisplayedDocument::No) {
- // 10.2. Queue a global task on the navigation and traversal task source given navigable's active window to perform afterPotentialUnloads.
- // Mirror the traversal queue's ongoing-navigation transition in the local projection.
- navigable->clear_ongoing_history_traversal();
- queue_apply_history_step_task(*navigable, after_potential_unload);
- } else {
- // 11. Otherwise:
- // The UI process has already unloaded every descendant subtree of displayedDocument.
- // Queue the final task to unload displayedDocument and run afterPotentialUnloads.
- // 6. Queue a global task on the navigation and traversal task source given document's relevant global object to perform the following steps:
- // NB: Use a null document so this remains runnable after displayedDocument becomes non-fully-active.
- queue_a_task(Task::Source::NavigationAndTraversal, nullptr, nullptr,
- GC::create_function(heap(), [displayed_document = GC::Ref { *displayed_document }, new_document = continuation->resolved_document, after_potential_unload] {
- // FIXME: 1. If firePageSwapSteps is given, then run firePageSwapSteps.
-
- // 2. Unload document, passing along newDocument if it is not null.
- displayed_document->unload(new_document);
-
- // 3. If afterAllUnloads was given, then run it.
- after_potential_unload->function()();
- }));
+ return DequeuedChangingNavigableContinuation { continuation, after_potential_unload };
+}
+
+// 10. If changingNavigableContinuation's update-only is true, or targetEntry's document is displayedDocument:
+void HistoryExecutor::apply_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryIdentity target_entry_identity, HistoryObjectLengthAndIndex history_object_length_and_index, Vector<SessionHistoryEntryDescriptor> entries_for_navigation_api, GC::Ref<OnChangingNavigableContinuationApplied> on_complete)
+{
+ auto dequeued = dequeue_ui_changing_navigable_continuation(operation_id, navigable_id, target_entry_identity, history_object_length_and_index, move(entries_for_navigation_api), on_complete);
+ if (!dequeued.has_value()) {
+ on_complete->function()({}, {});
+ return;
}
+ auto navigable = dequeued->continuation->navigable;
+
+ // 1. Set navigable's ongoing navigation to null.
+ // NB: This mirrors the UI process's transition in the local projection.
+ navigable->clear_ongoing_history_traversal();
+
+ // 2. Queue a global task on the navigation and traversal task source given navigable's active window to perform
+ // afterPotentialUnloads.
+ queue_apply_history_step_task(*navigable, dequeued->after_potential_unloads);
+}
+
+// 11. Otherwise:
+// 2. Deactivate displayedDocument, given userInvolvement, targetEntry, navigationType, and afterPotentialUnloads.
+// NB: The UI process has unloaded every descendant subtree of displayedDocument. This is the task that unload a document
+// and its descendants queues last, for displayedDocument.
+void HistoryExecutor::unload_displayed_document_and_apply_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryIdentity target_entry_identity, HistoryObjectLengthAndIndex history_object_length_and_index, Vector<SessionHistoryEntryDescriptor> entries_for_navigation_api, GC::Ref<OnChangingNavigableContinuationApplied> on_complete)
+{
+ auto dequeued = dequeue_ui_changing_navigable_continuation(operation_id, navigable_id, target_entry_identity, history_object_length_and_index, move(entries_for_navigation_api), on_complete);
+ if (!dequeued.has_value()) {
+ on_complete->function()({}, {});
+ return;
+ }
+
+ // 6. Queue a global task on the navigation and traversal task source given document's relevant global object to
+ // perform the following steps:
+ // NB: Use a null document so this remains runnable after displayedDocument becomes non-fully-active.
+ queue_a_task(Task::Source::NavigationAndTraversal, nullptr, nullptr,
+ GC::create_function(heap(), [displayed_document = GC::Ref { *dequeued->continuation->displayed_document }, new_document = dequeued->continuation->target_document, after_potential_unloads = dequeued->after_potential_unloads] {
+ // FIXME: 1. If firePageSwapSteps is given, then run firePageSwapSteps.
+
+ // 2. Unload document, passing along newDocument if it is not null.
+ displayed_document->unload(new_document);
+
+ // 3. If afterAllUnloads was given, then run it.
+ after_potential_unloads->function()();
+ }));
}
}
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.h b/Libraries/LibWeb/HTML/HistoryExecutor.h
index 64f691532d5..283baabfffe 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.h
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.h
@@ -70,7 +70,8 @@ public:
void run_ui_changing_navigable_history_job(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryDescriptor target_entry_descriptor, UserNavigationInvolvement, Optional<Bindings::NavigationType>, TraversalYieldsTo, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id, Optional<NavigationSourceSnapshot>, 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>)>>);
+ void apply_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryIdentity target_entry_identity, HistoryObjectLengthAndIndex, Vector<SessionHistoryEntryDescriptor> entries_for_navigation_api, GC::Ref<OnChangingNavigableContinuationApplied>);
+ void unload_displayed_document_and_apply_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryIdentity target_entry_identity, HistoryObjectLengthAndIndex, Vector<SessionHistoryEntryDescriptor> entries_for_navigation_api, GC::Ref<OnChangingNavigableContinuationApplied>);
private:
explicit HistoryExecutor(Page&);
@@ -80,6 +81,12 @@ private:
HistoryOperationState* find_history_operation(CrossProcessId operation_id);
HistoryOperationState& ensure_history_operation(CrossProcessId operation_id);
+ struct DequeuedChangingNavigableContinuation {
+ GC::Ref<ChangingNavigableContinuationState> continuation;
+ GC::Ref<GC::Function<void()>> after_potential_unloads;
+ };
+ Optional<DequeuedChangingNavigableContinuation> dequeue_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryIdentity target_entry_identity, HistoryObjectLengthAndIndex, Vector<SessionHistoryEntryDescriptor> entries_for_navigation_api, GC::Ref<OnChangingNavigableContinuationApplied>);
+
void enqueue_changing_navigable_continuation(CrossProcessId operation_id, GC::Ref<ChangingNavigableContinuationState>, GC::Ref<OnChangingNavigableHistoryStepJobComplete>);
GC::Ref<Page> m_page;
diff --git a/Libraries/LibWebCommon/HTML/ApplyHistoryStep.h b/Libraries/LibWebCommon/HTML/ApplyHistoryStep.h
index 880f4052b43..0a5e1f784b2 100644
--- a/Libraries/LibWebCommon/HTML/ApplyHistoryStep.h
+++ b/Libraries/LibWebCommon/HTML/ApplyHistoryStep.h
@@ -51,11 +51,6 @@ enum class UnloadPromptShown : bool {
Yes,
};
-enum class UnloadDisplayedDocument : bool {
- No,
- Yes,
-};
-
enum class ChildNavigableDestruction : bool {
No,
Yes,
diff --git a/Libraries/LibWebView/ApplyHistoryStep.cpp b/Libraries/LibWebView/ApplyHistoryStep.cpp
index 34344b15188..df4c3b9d12f 100644
--- a/Libraries/LibWebView/ApplyHistoryStep.cpp
+++ b/Libraries/LibWebView/ApplyHistoryStep.cpp
@@ -172,6 +172,7 @@ void ApplyHistoryStep::run_changing_navigable_jobs()
// navigable's active window to run the steps:
for (auto& changing_navigable : m_changing_navigables) {
changing_navigable->target_entry_reload_pending = changing_navigable->target_entry->document_state->reload_pending;
+ changing_navigable->displayed_document = changing_navigable->navigable().active_document();
if (!m_traversable.run_changing_navigable_history_step_job(*this, *changing_navigable))
end_changing_navigable_job(*changing_navigable);
}
diff --git a/Libraries/LibWebView/ApplyHistoryStep.h b/Libraries/LibWebView/ApplyHistoryStep.h
index a2e56e18dff..88be5ae69ec 100644
--- a/Libraries/LibWebView/ApplyHistoryStep.h
+++ b/Libraries/LibWebView/ApplyHistoryStep.h
@@ -75,7 +75,13 @@ struct WEBVIEW_API ChangingNavigable {
};
Optional<Continuation> continuation;
- Web::HTML::UnloadDisplayedDocument unload_displayed_document { Web::HTML::UnloadDisplayedDocument::No };
+ // https://html.spec.whatwg.org/multipage/browsing-the-web.html#changing-navigable-continuation-state
+ // NB: Its target entry and navigable are the record's. The process running the job reports the rest.
+ RefPtr<CanonicalDocument> displayed_document;
+ bool update_only { false };
+ // targetEntry's document, as the job left it.
+ Optional<Web::HTML::CrossProcessId> target_document_id;
+
RefPtr<NavigationLoader> population_loader;
RefPtr<CanonicalDocument> populated_document;
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 23b5a879b7b..60a0a84ca1e 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -1439,7 +1439,7 @@ void CanonicalTraversable::apply_changing_navigable_history_step_continuation(Ap
VERIFY(changing_navigable.continuation.has_value());
// 10. If changingNavigableContinuation's update-only is true, or targetEntry's document is displayedDocument:
- if (changing_navigable.unload_displayed_document == Web::HTML::UnloadDisplayedDocument::No) {
+ if (changing_navigable.update_only || changing_navigable.target_document_id == changing_navigable.displayed_document->id()) {
// 1. Set navigable's ongoing navigation to null.
// NB: The canonical traversal claim is released when the continuation is applied. The queued task mirrors
// the null transition into the process-local projection.
@@ -1462,14 +1462,34 @@ void CanonicalTraversable::apply_changing_navigable_history_step_continuation(Ap
}
void CanonicalTraversable::send_changing_navigable_continuation_task(HistoryOperation& operation, ChangingNavigable& changing_navigable)
+{
+ VERIFY(changing_navigable.has_pending_job());
+ VERIFY(changing_navigable.continuation.has_value());
+ auto endpoint = changing_job_endpoint(changing_navigable);
+ auto continuation = *changing_navigable.continuation;
+ endpoint->owe_reply({ OwedReply::Kind::ContinuationApplied, operation.operation_id, changing_navigable.id });
+ endpoint->async_apply_changing_navigable_continuation(
+ operation.operation_id, changing_navigable.id, changing_navigable.target_entry->identity(),
+ continuation.history_object_length_and_index.script_history_length,
+ continuation.history_object_length_and_index.script_history_index,
+ move(continuation.entries_for_navigation_api));
+}
+
+// https://html.spec.whatwg.org/multipage/document-lifecycle.html#unload-a-document-and-its-descendants
+// 6. Queue a global task on the navigation and traversal task source given document's relevant global object to perform
+// the following steps:
+// 1. If firePageSwapSteps is given, then run firePageSwapSteps.
+// 2. Unload document, passing along newDocument if it is not null.
+// 3. If afterAllUnloads was given, then run it.
+// NB: For displayedDocument, in the process running the changing navigable's job, where afterPotentialUnloads runs.
+void CanonicalTraversable::send_displayed_document_unload_task(HistoryOperation& operation, ChangingNavigable& changing_navigable)
{
VERIFY(changing_navigable.has_pending_job());
VERIFY(changing_navigable.continuation.has_value());
auto endpoint = changing_job_endpoint(changing_navigable);
auto const& document_state = *changing_navigable.target_entry->document_state;
- if (changing_navigable.unload_displayed_document == Web::HTML::UnloadDisplayedDocument::Yes && changing_navigable.target_entry_reload_pending
- && operation.parameters.has<Web::ReloadHistoryOperationParameters>()) {
+ if (changing_navigable.target_entry_reload_pending && operation.parameters.has<Web::ReloadHistoryOperationParameters>()) {
// INTEROP: Reloading rebuilds the child history tree from the replacement document, as in WebKit.
// Keep the old entries until population succeeds so an abandoned reload preserves them.
Vector<Web::HTML::CrossProcessId> nested_history_ids;
@@ -1481,12 +1501,11 @@ void CanonicalTraversable::send_changing_navigable_continuation_task(HistoryOper
auto continuation = *changing_navigable.continuation;
endpoint->owe_reply({ OwedReply::Kind::ContinuationApplied, operation.operation_id, changing_navigable.id });
- endpoint->async_apply_changing_navigable_continuation(
- operation.operation_id, changing_navigable.id,
+ endpoint->async_unload_displayed_document_and_apply_changing_navigable_continuation(
+ operation.operation_id, changing_navigable.id, changing_navigable.target_entry->identity(),
continuation.history_object_length_and_index.script_history_length,
continuation.history_object_length_and_index.script_history_index,
- move(continuation.entries_for_navigation_api),
- changing_navigable.unload_displayed_document);
+ move(continuation.entries_for_navigation_api));
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#deactivate-a-document-for-a-cross-document-navigation
@@ -1531,11 +1550,11 @@ void CanonicalTraversable::unload_displayed_document_for_cross_document_navigati
// 3. Unload a document and its descendants given displayedDocument, targetEntry's document,
// afterPotentialUnloads, and firePageSwapBeforeUnload.
unload_a_document_and_its_descendants(changing_navigable.id, changing_job_endpoint(changing_navigable), Web::HTML::ChildNavigableDestruction::No, [this, operation_id = operation.operation_id, navigable_id = changing_navigable.id](UnloadedInItsHost) {
- // afterPotentialUnloads runs in the continuation task, in the process running the job. That process first
- // unloads the document it displays: displayedDocument, or the stand-in of a host chosen for the new document.
+ // NB: The process running the job unloads the document it displays: displayedDocument, or the stand-in of a
+ // host chosen for the new document.
auto* operation = find_history_operation(operation_id);
if (auto* changing_navigable = operation ? operation->pending_changing_job(navigable_id) : nullptr)
- send_changing_navigable_continuation_task(*operation, *changing_navigable);
+ send_displayed_document_unload_task(*operation, *changing_navigable);
});
}
@@ -1750,7 +1769,9 @@ bool CanonicalTraversable::is_handing_navigable_to_another_page(CanonicalNavigab
auto const* changing_navigable = operation.value->pending_changing_job(navigable.id());
if (changing_navigable
&& changing_navigable->continuation.has_value()
- && changing_navigable->unload_displayed_document == Web::HTML::UnloadDisplayedDocument::Yes
+ // NB: Step 14.11 of apply the history step applies the continuation, which deactivates displayedDocument.
+ && !changing_navigable->update_only
+ && changing_navigable->target_document_id != changing_navigable->displayed_document->id()
&& changing_job_endpoint(*changing_navigable) != navigable.active_document().host()) {
return true;
}
@@ -2776,7 +2797,7 @@ void CanonicalTraversable::did_receive_beforeunload_check_result(WebContentPage&
dispatch_next_beforeunload_group(check_id);
}
-void CanonicalTraversable::did_receive_changing_navigable_history_job_ready(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, Web::HTML::UnloadDisplayedDocument unload_displayed_document)
+void CanonicalTraversable::did_receive_changing_navigable_history_job_ready(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id)
{
if (!source_page.take_owed_reply({ OwedReply::Kind::ChangingJob, operation_id, navigable_id }))
return;
@@ -2789,7 +2810,8 @@ void CanonicalTraversable::did_receive_changing_navigable_history_job_ready(WebC
disposition = Web::HTML::ChangingNavigableHistoryStepJobDisposition::Stale;
if (disposition == Web::HTML::ChangingNavigableHistoryStepJobDisposition::Ready) {
- changing_navigable->unload_displayed_document = unload_displayed_document;
+ changing_navigable->update_only = update_only;
+ changing_navigable->target_document_id = target_document_id;
operation->algorithm->changing_navigable_job_completed(*changing_navigable, disposition);
return;
}
diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.h
index d4b9603a3a3..0948cc9044b 100644
--- a/Libraries/LibWebView/CanonicalTraversable.h
+++ b/Libraries/LibWebView/CanonicalTraversable.h
@@ -83,7 +83,7 @@ public:
Optional<Web::HTML::CrossProcessId> check_if_unloading_is_canceled(Vector<Web::HTML::CrossProcessId> navigables_that_need_before_unload, RefPtr<CanonicalSessionHistoryEntry> target_entry, Optional<Web::HTML::UserNavigationInvolvement> user_involvement_for_navigate_event, RefPtr<WebContentPage> skipped_endpoint, Web::HTML::UnloadPromptShown, Function<void(Web::HTML::CheckIfUnloadingIsCanceledResult, Web::HTML::UnloadPromptShown)> on_complete);
bool is_unloading_document_of(Web::HTML::CrossProcessId navigable_id) const;
bool is_handing_navigable_to_another_page(CanonicalNavigable const&) const;
- void did_receive_changing_navigable_history_job_ready(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition, Web::HTML::UnloadDisplayedDocument);
+ void did_receive_changing_navigable_history_job_ready(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id);
void did_finish_history_navigation_params_creation(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryNavigationPopulation);
void did_receive_changing_navigable_unload_preparation_complete(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id);
void did_receive_descendant_unload_task_complete(WebContentPage& source_page, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id);
@@ -198,6 +198,7 @@ private:
void did_fail_history_navigation_population(HistoryOperation&, ChangingNavigable&, WebContentPage&);
void continue_history_navigation_population(HistoryOperation&, ChangingNavigable&);
void send_changing_navigable_continuation_task(HistoryOperation&, ChangingNavigable&);
+ void send_displayed_document_unload_task(HistoryOperation&, ChangingNavigable&);
void deactivate_a_document_for_cross_document_navigation(HistoryOperation&, ChangingNavigable&);
void unload_displayed_document_for_cross_document_navigation(HistoryOperation&, ChangingNavigable&);
void did_activate_history_entry(HistoryOperation&, ChangingNavigable&, NonnullRefPtr<WebContentPage> source_page, Web::HTML::HostedNavigableState activated_navigable_state);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index ea52e2b9294..cbdadf42b50 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1652,9 +1652,9 @@ void WebContentPage::beforeunload_check_result(Web::HTML::CrossProcessId operati
traversable().did_receive_beforeunload_check_result(*this, operation_id, result, unload_prompt_shown);
}
-void WebContentPage::changing_navigable_history_job_ready(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, Web::HTML::UnloadDisplayedDocument unload_displayed_document)
+void WebContentPage::changing_navigable_history_job_ready(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id)
{
- traversable().did_receive_changing_navigable_history_job_ready(*this, operation_id, navigable_id, disposition, unload_displayed_document);
+ traversable().did_receive_changing_navigable_history_job_ready(*this, operation_id, navigable_id, disposition, update_only, target_document_id);
}
void WebContentPage::changing_navigable_unload_preparation_complete(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id)
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 868801717f5..674446fb9a7 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -269,7 +269,7 @@ private:
virtual void request_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters parameters) override;
virtual void revoke_history_operation(Web::HTML::CrossProcessId operation_id) override;
virtual void beforeunload_check_result(Web::HTML::CrossProcessId operation_id, Web::HTML::CheckIfUnloadingIsCanceledResult result, Web::HTML::UnloadPromptShown unload_prompt_shown) override;
- virtual void changing_navigable_history_job_ready(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, Web::HTML::UnloadDisplayedDocument unload_displayed_document) override;
+ virtual void changing_navigable_history_job_ready(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id) override;
virtual void changing_navigable_unload_preparation_complete(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void descendant_unload_task_complete(Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void request_navigable_document_abort(Web::HTML::CrossProcessId navigable_id) override;
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 202cde5433b..3b6d3242173 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -595,7 +595,7 @@ void ConnectionFromClient::continue_history_navigation_population(Web::PageId pa
auto page = this->page(page_id);
auto navigable_id = population.request.navigable_id;
if (!page.has_value()) {
- async_changing_navigable_history_job_ready(page_id, operation_id, navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition::Skipped, Web::HTML::UnloadDisplayedDocument::No);
+ async_changing_navigable_history_job_ready(page_id, operation_id, navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition::Skipped, false, {});
return;
}
auto& history_executor = page->page().history_executor();
@@ -603,8 +603,8 @@ void ConnectionFromClient::continue_history_navigation_population(Web::PageId pa
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, {}, {}, {},
- 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);
+ GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id](Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id) {
+ async_changing_navigable_history_job_ready(page_id, operation_id, navigable_id, disposition, update_only, target_document_id);
}),
move(population));
}
@@ -613,12 +613,12 @@ void ConnectionFromClient::run_changing_navigable_history_job(Web::PageId page_i
{
auto page = this->page(page_id);
if (!page.has_value()) {
- async_changing_navigable_history_job_ready(page_id, operation_id, navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition::Skipped, Web::HTML::UnloadDisplayedDocument::No);
+ async_changing_navigable_history_job_ready(page_id, operation_id, navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition::Skipped, false, {});
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), move(finalized_navigation_id), move(source_snapshot_params), 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);
+ 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), move(source_snapshot_params), GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id](Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id) {
+ async_changing_navigable_history_job_ready(page_id, operation_id, navigable_id, disposition, update_only, target_document_id);
}));
}
@@ -635,7 +635,7 @@ void ConnectionFromClient::prepare_changing_navigable_for_unload(Web::PageId pag
}));
}
-void ConnectionFromClient::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)
+void ConnectionFromClient::apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api)
{
auto page = this->page(page_id);
if (!page.has_value()) {
@@ -643,7 +643,20 @@ void ConnectionFromClient::apply_changing_navigable_continuation(Web::PageId pag
return;
}
- page->page().history_executor().apply_ui_changing_navigable_continuation(operation_id, navigable_id, { script_history_length, script_history_index }, move(entries_for_navigation_api), unload_displayed_document, GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id](Optional<Web::HTML::HostedNavigableState> activated_navigable_state, Optional<Web::HTML::SessionHistoryEntryPersistedState> previous_entry_persisted_state) {
+ page->page().history_executor().apply_ui_changing_navigable_continuation(operation_id, navigable_id, target_entry, { script_history_length, script_history_index }, move(entries_for_navigation_api), GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id](Optional<Web::HTML::HostedNavigableState> activated_navigable_state, Optional<Web::HTML::SessionHistoryEntryPersistedState> previous_entry_persisted_state) {
+ async_changing_navigable_continuation_applied(page_id, operation_id, navigable_id, move(activated_navigable_state), move(previous_entry_persisted_state));
+ }));
+}
+
+void ConnectionFromClient::unload_displayed_document_and_apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api)
+{
+ auto page = this->page(page_id);
+ if (!page.has_value()) {
+ async_changing_navigable_continuation_applied(page_id, operation_id, navigable_id, {}, {});
+ return;
+ }
+
+ page->page().history_executor().unload_displayed_document_and_apply_ui_changing_navigable_continuation(operation_id, navigable_id, target_entry, { script_history_length, script_history_index }, move(entries_for_navigation_api), GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id](Optional<Web::HTML::HostedNavigableState> activated_navigable_state, Optional<Web::HTML::SessionHistoryEntryPersistedState> previous_entry_persisted_state) {
async_changing_navigable_continuation_applied(page_id, operation_id, navigable_id, move(activated_navigable_state), move(previous_entry_persisted_state));
}));
}
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index 550d6d4a378..ecea77edd78 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -144,7 +144,8 @@ private:
virtual void queue_navigation_api_state_clear_task(Web::PageId page_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, Optional<Utf16String> finalized_navigation_id, Optional<Web::HTML::NavigationSourceSnapshot> source_snapshot_params) 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 apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api) override;
+ virtual void unload_displayed_document_and_apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api) 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;
virtual void continue_child_navigable_destruction(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void abort_navigable_document(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index deba78060d1..56d38c03a07 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -255,7 +255,7 @@ endpoint WebContentClient routed by Web::PageId page_id
request_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters parameters) =|
revoke_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id) =|
beforeunload_check_result(Web::PageId page_id, Web::HTML::CrossProcessId check_id, Web::HTML::CheckIfUnloadingIsCanceledResult result, Web::HTML::UnloadPromptShown unload_prompt_shown) =|
- changing_navigable_history_job_ready(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, Web::HTML::UnloadDisplayedDocument unload_displayed_document) =|
+ changing_navigable_history_job_ready(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id) =|
changing_navigable_unload_preparation_complete(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) =|
descendant_unload_task_complete(Web::PageId page_id, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id) =|
request_child_navigable_unload(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index 77ee6aa8ea7..ff07c7a55e2 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -120,7 +120,8 @@ endpoint WebContentServer routed by Web::PageId page_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, Optional<Utf16String> finalized_navigation_id, Optional<Web::HTML::NavigationSourceSnapshot> source_snapshot_params) =|
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) =|
+ apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api) =|
+ unload_displayed_document_and_apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api) =|
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) =|
continue_child_navigable_destruction(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
abort_navigable_document(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|