Skip to content

Truly independent web browser

LibWeb+LibWebView+WebContent: Report only applied history step results

Shannon Boothaf3e207de393
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.cpp b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
index 3ae08af324e..06b50e7b5d1 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.cpp
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
@@ -70,6 +70,8 @@ void HistoryExecutor::visit_edges(Cell::Visitor& visitor)
for (auto& operation : m_history_operations) {
visitor.visit(operation.value.pending_document);
visitor.visit(operation.value.on_complete);
+ visitor.visit(operation.value.on_apply_history_step_complete);
+ visitor.visit(operation.value.on_navigation_api_traversal_rejected);
for (auto& population : operation.value.pending_populations)
visitor.visit(population.value);
for (auto& continuation : operation.value.changing_navigable_continuations)
@@ -109,7 +111,7 @@ void HistoryExecutor::revoke_history_operation(CrossProcessId operation_id)
m_page->client().page_did_revoke_history_operation(operation_id);
}
-void HistoryExecutor::complete_ui_history_operation(CrossProcessId operation_id, HistoryStepResult result, Optional<i32> target_entry_step)
+void HistoryExecutor::complete_ui_history_operation(CrossProcessId operation_id, Optional<i32> target_entry_step)
{
auto operation = m_history_operations.take(operation_id);
if (!operation.has_value())
@@ -131,7 +133,21 @@ void HistoryExecutor::complete_ui_history_operation(CrossProcessId operation_id,
}
}
if (operation->on_complete)
- operation->on_complete->function()(result);
+ operation->on_complete->function()();
+}
+
+void HistoryExecutor::did_apply_ui_history_step(CrossProcessId operation_id, HistoryStepResult result)
+{
+ auto* operation = find_history_operation(operation_id);
+ if (operation && operation->on_apply_history_step_complete)
+ operation->on_apply_history_step_complete->function()(result);
+}
+
+void HistoryExecutor::reject_ui_navigation_api_traversal(CrossProcessId operation_id)
+{
+ auto* operation = find_history_operation(operation_id);
+ if (operation && operation->on_navigation_api_traversal_rejected)
+ operation->on_navigation_api_traversal_rejected->function()();
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#traverse-the-history-by-a-delta
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.h b/Libraries/LibWeb/HTML/HistoryExecutor.h
index 8fa0bc7eac4..0fdc672be63 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.h
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.h
@@ -44,7 +44,9 @@ public:
GC::Ptr<DOM::Document> pending_document {};
Optional<CrossProcessId> local_target_navigable_id {};
RefPtr<SessionHistoryEntry> local_target_entry {};
- GC::Ptr<OnApplyHistoryStepComplete> on_complete {};
+ GC::Ptr<GC::Function<void()>> on_complete {};
+ GC::Ptr<OnApplyHistoryStepComplete> on_apply_history_step_complete {};
+ GC::Ptr<GC::Function<void()>> on_navigation_api_traversal_rejected {};
// State retained between a changing job and its continuation, null until the claiming job is ready.
HashMap<CrossProcessId, GC::Ptr<ChangingNavigableContinuationState>> changing_navigable_continuations {};
@@ -55,7 +57,9 @@ public:
CrossProcessId request_history_operation(HistoryOperationParameters, HistoryOperationState);
// Takes back a requested operation the UI process has not started.
void revoke_history_operation(CrossProcessId operation_id);
- void complete_ui_history_operation(CrossProcessId operation_id, HistoryStepResult, Optional<i32> target_entry_step);
+ void complete_ui_history_operation(CrossProcessId operation_id, Optional<i32> target_entry_step);
+ void did_apply_ui_history_step(CrossProcessId operation_id, HistoryStepResult);
+ void reject_ui_navigation_api_traversal(CrossProcessId operation_id);
void traverse_the_history_by_delta(int delta, GC::Ptr<DOM::Document> source_document = {});
void finalize_same_document_navigation(GC::Ref<LocalNavigable>, NonnullRefPtr<SessionHistoryEntry>, RefPtr<SessionHistoryEntry> entry_to_replace, HistoryHandlingBehavior, UserNavigationInvolvement, Optional<SessionHistoryEntryPersistedState> previous_entry_persisted_state);
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index cf100b58ea1..946640e7451 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -4273,7 +4273,7 @@ void LocalNavigable::reload(Optional<StorageSerializationRecord> navigation_api_
.user_involvement = user_involvement,
},
{
- .on_complete = GC::create_function(heap(), [this, reloading_entry](HistoryStepResult result) {
+ .on_apply_history_step_complete = GC::create_function(heap(), [this, reloading_entry](HistoryStepResult result) {
if (result == HistoryStepResult::Applied)
return;
@@ -4566,7 +4566,7 @@ void finalize_a_cross_document_navigation(GC::Ref<LocalNavigable> navigable, His
.pending_document = pending_document,
.local_target_navigable_id = navigable->id(),
.local_target_entry = history_entry,
- .on_complete = GC::create_function(navigable->heap(), [navigable, navigation_id, has_document = !!pending_document](HistoryStepResult) {
+ .on_complete = GC::create_function(navigable->heap(), [navigable, navigation_id, has_document = !!pending_document] {
// AD-HOC: Step 2 runs as the navigation's document is activated. When the steps end without activating
// it, the navigation is dropped, and stops delaying load events.
if (has_document && !navigable->has_been_destroyed() && navigable->is_delaying_load_events())
diff --git a/Libraries/LibWeb/HTML/LocalTraversableNavigable.cpp b/Libraries/LibWeb/HTML/LocalTraversableNavigable.cpp
index ce0b77e1599..5ebf152631c 100644
--- a/Libraries/LibWeb/HTML/LocalTraversableNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalTraversableNavigable.cpp
@@ -261,22 +261,9 @@ void LocalTraversableNavigable::definitely_close_top_level_traversable(PromptToU
m_close_steps_have_been_appended = true;
// 3. Append the following session history traversal steps to traversable:
- page().history_executor().request_history_operation(
- CloseTopLevelTraversableHistoryOperationParameters {},
- {
- .on_complete = GC::create_function(heap(), [this](HistoryStepResult result) {
- // NB: An abandoned close never reached its queue position; do not destroy the traversable for it.
- if (result != HistoryStepResult::Applied) {
- m_close_steps_have_been_appended = false;
- set_closing(false);
- return;
- }
-
- // NB: The UI process runs the traversal steps' unload recursion and delivers the final
- // unload-and-destroy task through run_ui_traversable_close_unload_task before this
- // completion.
- }),
- });
+ // NB: The UI process runs the traversal steps' unload recursion and delivers the final unload-and-destroy task
+ // through run_ui_traversable_close_unload_task.
+ page().history_executor().request_history_operation(CloseTopLevelTraversableHistoryOperationParameters {});
};
if (prompt_to_unload == PromptToUnload::No) {
diff --git a/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Libraries/LibWeb/HTML/NavigableContainer.cpp
index 08aeb538787..f6c1232f63e 100644
--- a/Libraries/LibWeb/HTML/NavigableContainer.cpp
+++ b/Libraries/LibWeb/HTML/NavigableContainer.cpp
@@ -130,7 +130,7 @@ void NavigableContainer::create_new_child_navigable()
{
.local_target_navigable_id = navigable->id(),
.local_target_entry = history_entry,
- .on_complete = GC::create_function(heap(), [this, navigable](HistoryStepResult) {
+ .on_complete = GC::create_function(heap(), [this, navigable] {
if (navigable->has_been_destroyed() || content_navigable() != navigable)
return;
navigable->set_has_session_history_entry_and_ready_for_navigation();
diff --git a/Libraries/LibWeb/HTML/Navigation.cpp b/Libraries/LibWeb/HTML/Navigation.cpp
index 8d0daff690c..f5594ce6cec 100644
--- a/Libraries/LibWeb/HTML/Navigation.cpp
+++ b/Libraries/LibWeb/HTML/Navigation.cpp
@@ -695,12 +695,25 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
auto source_snapshot_params = snapshot_source_snapshot_params(document);
// 12. Append the following session history traversal steps to traversable:
- // NB: The UI process owns the session history traversal queue, resolves the key against the canonical session
- // history (steps 1-2 of the queued steps), and applies the step. The parts that need this process's state
- // stay with this process: the pre-steps run step 3 against the live navigable when the operation starts, and
- // the completion maps the result onto the API method tracker's promises.
+ // NB: The UI process runs these steps. This process rejects apiMethodTracker's finished promise when they say to.
+
+ // 2-3. If there is no targetSHE, or it is navigable's active session history entry:
+ // 1. Queue a global task on the navigation and traversal task source given navigation's relevant global object
+ // to reject the finished promise for apiMethodTracker with an "InvalidStateError" DOMException.
+ // 2. Abort these steps.
+ // NOTE: The target-missing path is taken if navigation's entry list was outdated compared to navigableSHEs,
+ // which can occur for brief periods while all the relevant threads and processes are being synchronized
+ // in reaction to a history change.
+ auto on_rejected = GC::create_function(heap(), [this, api_method_tracker] {
+ queue_global_task(Task::Source::NavigationAndTraversal, relevant_global_object(window()), GC::create_function(heap(), [this, api_method_tracker] {
+ auto& realm = relevant_realm(window());
+ TemporaryExecutionContext execution_context { realm };
+ reject_the_finished_promise(api_method_tracker,
+ WebIDL::InvalidStateError::create(realm, "Cannot traverse with stale session history entry"_utf16));
+ }));
+ });
- auto on_complete = GC::create_function(heap(), [this, api_method_tracker](HistoryStepResult result) {
+ auto on_apply_history_step_complete = GC::create_function(heap(), [this, api_method_tracker](HistoryStepResult result) {
// NOTE: When result is "canceled-by-beforeunload" or "initiator-disallowed", the navigate event was never fired,
// aborting the ongoing navigation would not be correct; it would result in a navigateerror event without a
// preceding navigate event. In the "canceled-by-navigate" case, navigate is fired, but the inner navigate event
@@ -708,22 +721,6 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
auto& realm = relevant_realm(window());
auto& global = relevant_global_object(window());
- // 1-2. (of the target-missing and already-active cases) Queue a global task on the navigation and traversal
- // task source given navigation's relevant global object to reject the finished promise for
- // apiMethodTracker with an "InvalidStateError" DOMException.
- // NOTE: The target-missing path is taken if navigation's entry list was outdated compared to navigableSHEs,
- // which can occur for brief periods while all the relevant threads and processes are being synchronized
- // in reaction to a history change.
- if (result == HistoryStepResult::NoMatchingEntry) {
- queue_global_task(HTML::Task::Source::NavigationAndTraversal, global, GC::create_function(heap(), [this, api_method_tracker] {
- auto& reject_realm = relevant_realm(window());
- TemporaryExecutionContext execution_context { reject_realm };
- reject_the_finished_promise(api_method_tracker,
- WebIDL::InvalidStateError::create(reject_realm, "Cannot traverse with stale session history entry"_utf16));
- }));
- return;
- }
-
// 5. If result is "canceled-by-beforeunload", then queue a global task on the navigation and traversal task source
// given navigation's relevant global object to reject the finished promise for apiMethodTracker with a
// new "AbortError" DOMException created in navigation's relevant realm.
@@ -755,7 +752,8 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
.user_involvement = UserNavigationInvolvement::None,
},
{
- .on_complete = on_complete,
+ .on_apply_history_step_complete = on_apply_history_step_complete,
+ .on_navigation_api_traversal_rejected = on_rejected,
});
// 13. Return a navigation API method tracker-derived result for apiMethodTracker.
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index e0fc0f7d041..d7670ad59d6 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -1578,7 +1578,7 @@ GC::Ref<WebIDL::Promise> Internals::flush_session_history_traversal_queue()
navigable->page().history_executor().request_history_operation(
FlushSessionHistoryTraversalQueueOperationParameters {},
{
- .on_complete = GC::create_function(heap(), [&realm, promise](Web::HTML::HistoryStepResult) {
+ .on_complete = GC::create_function(heap(), [&realm, promise] {
HTML::TemporaryExecutionContext execution_context { realm };
WebIDL::resolve_promise(promise);
}),
diff --git a/Libraries/LibWebCommon/HTML/ApplyHistoryStep.h b/Libraries/LibWebCommon/HTML/ApplyHistoryStep.h
index 310ac7a7371..880f4052b43 100644
--- a/Libraries/LibWebCommon/HTML/ApplyHistoryStep.h
+++ b/Libraries/LibWebCommon/HTML/ApplyHistoryStep.h
@@ -24,11 +24,6 @@ enum class HistoryStepResult {
InitiatorDisallowed,
CanceledByBeforeUnload,
CanceledByNavigate,
- // AD-HOC: This is an internal result used when WebContent no longer has the requested page.
- CanceledByMissingPage,
- // AD-HOC: An internal result for when the canonical session history has no entry matching the
- // requested operation (for example, a navigation API traversal to a pruned entry).
- NoMatchingEntry,
Applied,
};
diff --git a/Libraries/LibWebView/ApplyHistoryStep.cpp b/Libraries/LibWebView/ApplyHistoryStep.cpp
index f6661c78026..74e07b78ef4 100644
--- a/Libraries/LibWebView/ApplyHistoryStep.cpp
+++ b/Libraries/LibWebView/ApplyHistoryStep.cpp
@@ -56,13 +56,7 @@ void ApplyHistoryStep::apply_the_history_step()
// FIXME: 1. Assert: This is running within traversable's session history traversal queue.
// 2. Let targetStep be the result of getting the used step given traversable and step.
- auto target_step = m_session_history.get_the_used_step(m_step);
- if (!target_step.has_value()) {
- // AD-HOC: An empty canonical session history has no used steps to resolve against.
- return_result(Web::HTML::HistoryStepResult::CanceledByMissingPage);
- return;
- }
- m_target_step = *target_step;
+ m_target_step = m_session_history.get_the_used_step(m_step).value();
// 3. If initiatorToCheck is not null, then:
if (m_initiator_to_check.has_value()) {
@@ -114,10 +108,7 @@ void ApplyHistoryStep::apply_the_history_step()
}
auto* target_entry = m_session_history.get_the_target_history_entry(m_traversable_navigable, m_target_step);
- if (!target_entry) {
- return_result(Web::HTML::HistoryStepResult::CanceledByMissingPage);
- return;
- }
+ VERIFY(target_entry);
m_jobs.check_if_unloading_is_canceled(move(navigables_crossing_documents), *target_entry, m_user_involvement,
[this](Web::HTML::CheckIfUnloadingIsCanceledResult result) {
@@ -374,8 +365,11 @@ void ApplyHistoryStep::process_changing_navigable_continuations()
} else if (m_navigation_type == Web::Bindings::NavigationType::Push) {
target_entry = append_the_claimed_target_entry_again(*navigable, *claimed_target_entry);
if (!target_entry) {
- return_result(Web::HTML::HistoryStepResult::NoMatchingEntry);
- return;
+ // NB: The push left the navigable no entries to append to. As for a navigable that is gone, its
+ // continuation cannot be applied.
+ clear_ongoing_navigation_traversal(navigable_id);
+ m_completed_change_jobs++;
+ continue;
}
updated_target_entry = target_entry;
}
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index e4e27935382..9d32a7c025e 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -1384,16 +1384,13 @@ void CanonicalNavigable::cancel_navigation_for_client(WebContentClient& client)
end_navigation(*navigation);
}
-// The history operation finalizing a navigation is over. The document populated for it, if it was not activated, is not
-// going to be.
-void CanonicalNavigable::did_finish_finalizing_navigation(Utf16String const& navigation_id, Web::HTML::HistoryStepResult result)
+// The history operation finalizing a navigation is over.
+void CanonicalNavigable::did_finish_finalizing_navigation(Utf16String const& navigation_id)
{
auto navigation = navigation_with_id(navigation_id);
if (!navigation || !navigation->is_finalizing())
return;
end_navigation(*navigation);
- if (result != Web::HTML::HistoryStepResult::Applied && m_active_document_load.navigation_id == navigation_id)
- clear_active_document_load();
}
void CanonicalNavigable::did_cancel_navigation(Utf16String navigation_id)
@@ -1408,8 +1405,9 @@ void CanonicalNavigable::did_cancel_navigation(Utf16String navigation_id)
if (!is_tracked_load || !is_top_level_traversable())
return;
+ // A navigation being finalized that is canceled never activates its document, like an uncommitted one.
if (auto view = top_level_traversable().view(); view.has_value())
- view->did_cancel_loading({}, canceled_uncommitted_navigation);
+ view->did_cancel_loading({}, navigation != nullptr);
}
Optional<Utf16String> CanonicalNavigable::tracked_load_navigation_id() const
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index c665a3586bf..23359979d83 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -233,7 +233,7 @@ public:
void clear_ongoing_navigation_traversal(Web::HTML::CrossProcessId operation_id);
void clear_ongoing_navigation();
void cancel_navigation_for_client(WebContentClient&);
- void did_finish_finalizing_navigation(Utf16String const& navigation_id, Web::HTML::HistoryStepResult);
+ void did_finish_finalizing_navigation(Utf16String const& navigation_id);
void did_cancel_navigation(Utf16String navigation_id);
Optional<Utf16String> tracked_load_navigation_id() const;
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index e2280478660..b50fe7f0d5c 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -655,7 +655,7 @@ ByteString CanonicalTraversable::queued_same_document_session_history_entries_fo
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#reload
// NB: This is a reload from the browser's UI. One by script fires the navigate event in the process hosting the active
// document, which then asks for the reload history step.
-void CanonicalTraversable::reload(OnHistoryOperationComplete on_complete)
+void CanonicalTraversable::reload(OnHistoryStepApplied on_complete)
{
auto user_involvement = Web::HTML::UserNavigationInvolvement::BrowserUI;
@@ -979,11 +979,11 @@ StringView CanonicalTraversable::browser_history_traversal_stage_to_string(Brows
struct CanonicalTraversable::HistoryOperation {
AK_ALLOC_WITH_KMALLOC;
- HistoryOperation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters parameters, RefPtr<WebContentPage> initiating_page, u64 sequence_number, RefPtr<CanonicalSessionHistoryEntry> target_entry, OnHistoryOperationComplete on_complete)
+ HistoryOperation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters parameters, RefPtr<WebContentPage> initiating_page, u64 sequence_number, RefPtr<CanonicalSessionHistoryEntry> target_entry, OnHistoryStepApplied on_history_step_applied)
: operation_id(operation_id)
, parameters(move(parameters))
, target_entry(move(target_entry))
- , on_complete(move(on_complete))
+ , on_history_step_applied(move(on_history_step_applied))
, initiating_page(move(initiating_page))
, sequence_number(sequence_number)
{
@@ -993,7 +993,7 @@ struct CanonicalTraversable::HistoryOperation {
Web::HistoryOperationParameters parameters;
// The entry synchronous navigation steps finalize.
RefPtr<CanonicalSessionHistoryEntry> target_entry;
- OnHistoryOperationComplete on_complete;
+ OnHistoryStepApplied on_history_step_applied;
// Jobs resolve their endpoints at dispatch. This endpoint owns the process-local operation state.
RefPtr<WebContentPage> initiating_page;
Vector<NonnullRefPtr<WebContentPage>> completion_endpoints;
@@ -1231,32 +1231,25 @@ RefPtr<CanonicalNavigation> CanonicalTraversable::finalized_navigation(HistoryOp
return navigation && navigation->is_finalizing() ? navigation : nullptr;
}
-void CanonicalTraversable::recover_from_web_content_process_crash(OnHistoryOperationComplete on_complete)
+void CanonicalTraversable::recover_from_web_content_process_crash(OnHistoryStepApplied on_complete)
{
if (has_uncommitted_navigation())
clear_ongoing_navigation();
clear_active_document_load();
// The step a traversal the crash interrupted was applying is applied again, otherwise the current step is.
- Optional<i32> target_step;
+ auto target_step = m_session_history.current_step().value();
if (auto* traversal = ongoing_browser_history_traversal())
target_step = traversal->parameters.get<Web::TraverseToStepHistoryOperationParameters>().target_step;
abandon_history_operations();
- if (!target_step.has_value())
- target_step = m_session_history.current_step();
- if (!target_step.has_value()) {
- if (on_complete)
- on_complete(Web::HTML::HistoryStepResult::CanceledByMissingPage, {});
- return;
- }
// The tab's document is reloaded, the crashed process having destroyed the one its entry holds.
- NonnullRefPtr reloading_entry = *m_session_history.get_the_target_history_entry(*this, *target_step);
+ NonnullRefPtr reloading_entry = *m_session_history.get_the_target_history_entry(*this, target_step);
reloading_entry->document_state->reload_pending = true;
session_history_changed();
enqueue_browser_history_traversal(
Web::TraverseToStepHistoryOperationParameters {
- .target_step = *target_step,
+ .target_step = target_step,
.user_involvement = Web::HTML::UserNavigationInvolvement::BrowserUI,
},
false,
@@ -2043,14 +2036,14 @@ ApplyHistoryStepJobs CanonicalTraversable::create_apply_history_step_jobs(Histor
};
}
-void CanonicalTraversable::run_history_operation_at_queue_position(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters request, RefPtr<WebContentPage> requesting_page, u64 sequence_number, RefPtr<CanonicalSessionHistoryEntry> target_entry, OnHistoryOperationComplete on_complete, NonnullRefPtr<Core::Promise<Empty>> promise)
+void CanonicalTraversable::run_history_operation_at_queue_position(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters request, RefPtr<WebContentPage> requesting_page, u64 sequence_number, RefPtr<CanonicalSessionHistoryEntry> target_entry, OnHistoryStepApplied on_complete, NonnullRefPtr<Core::Promise<Empty>> promise)
{
// The traversal queue can outlive an embedded page which appended work to it. Such a page cannot receive
// completion, so discard its queued operation instead of waiting forever.
if (requesting_page && !requesting_page->is_open()) {
if (auto const* parameters = request.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>()) {
if (auto navigable = find(parameters->navigable_id); navigable.has_value())
- navigable->did_finish_finalizing_navigation(parameters->navigation_id, Web::HTML::HistoryStepResult::CanceledByMissingPage);
+ navigable->did_finish_finalizing_navigation(parameters->navigation_id);
}
promise->resolve({});
return;
@@ -2070,7 +2063,7 @@ void CanonicalTraversable::run_history_operation_at_queue_position(Web::HTML::Cr
start_history_operation(*operation, promise);
}
-void CanonicalTraversable::run_browser_history_traversal_at_queue_position(Web::TraverseToStepHistoryOperationParameters parameters, bool check_for_cancelation, u64 sequence_number, Function<void()> on_ready, OnHistoryOperationComplete on_complete, NonnullRefPtr<Core::Promise<Empty>> promise)
+void CanonicalTraversable::run_browser_history_traversal_at_queue_position(Web::TraverseToStepHistoryOperationParameters parameters, bool check_for_cancelation, u64 sequence_number, Function<void()> on_ready, OnHistoryStepApplied on_complete, NonnullRefPtr<Core::Promise<Empty>> promise)
{
auto operation_id = Application::the().allocate_ui_process_cross_process_id();
auto owned_operation = make<HistoryOperation>(operation_id, Web::HistoryOperationParameters { move(parameters) }, RefPtr<WebContentPage> {}, sequence_number, RefPtr<CanonicalSessionHistoryEntry> {}, move(on_complete));
@@ -2193,7 +2186,7 @@ void CanonicalTraversable::did_attempt_to_populate_the_history_entry_document(We
navigable->populate_document_for_javascript_url(*navigation, move(history_entry), navigable->create_and_initialize_a_document(response_document));
}
-void CanonicalTraversable::enqueue_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters request, RefPtr<WebContentPage> requesting_page, u64 sequence_number, OnHistoryOperationComplete on_complete)
+void CanonicalTraversable::enqueue_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters request, RefPtr<WebContentPage> requesting_page, u64 sequence_number, OnHistoryStepApplied on_complete)
{
// https://html.spec.whatwg.org/multipage/document-sequences.html#destroy-a-child-navigable
// Steps 6-7 remove the nested history before step 9 appends traversal steps. Apply the canonical counterpart while
@@ -2258,10 +2251,10 @@ void CanonicalTraversable::revoke_history_operation(WebContentPage& source_page,
// Steps that have started run to completion.
if (!m_history_traversal_queue.remove_steps_of_revoked_operation({ source_page.id(), operation_id }))
return;
- source_page.async_complete_history_operation(operation_id, Web::HTML::HistoryStepResult::Applied, {}, m_session_history.size());
+ source_page.async_complete_history_operation(operation_id, {}, m_session_history.size());
}
-void CanonicalTraversable::enqueue_browser_history_traversal(Web::TraverseToStepHistoryOperationParameters parameters, bool check_for_cancelation, OnHistoryOperationComplete on_complete)
+void CanonicalTraversable::enqueue_browser_history_traversal(Web::TraverseToStepHistoryOperationParameters parameters, bool check_for_cancelation, OnHistoryStepApplied on_complete)
{
auto sequence_number = next_sequence_number();
auto steps = [this, parameters = move(parameters), check_for_cancelation, sequence_number, on_complete = move(on_complete)](NonnullRefPtr<Core::Promise<Empty>> promise) mutable {
@@ -2274,6 +2267,13 @@ void CanonicalTraversable::apply_history_step(HistoryOperation& operation, i32 s
{
VERIFY(!operation.algorithm);
auto operation_id = operation.operation_id;
+
+ // NB: A step that a process asked to traverse to need not be one this session history can apply.
+ if (!m_session_history.get_the_used_step(step).has_value()) {
+ end_history_operation(operation_id);
+ return;
+ }
+
operation.algorithm = make<ApplyHistoryStep>(
m_session_history, *this, m_history_traversal_queue, m_apply_history_step_traversable_state, create_apply_history_step_jobs(operation),
operation_id, operation.sequence_number,
@@ -2301,14 +2301,10 @@ void CanonicalTraversable::apply_the_push_or_replace_history_step(HistoryOperati
void CanonicalTraversable::apply_the_reload_history_step(HistoryOperation& operation, Web::HTML::UserNavigationInvolvement user_involvement)
{
// 1. Let step be traversable's current session history step.
- auto step = m_session_history.current_step();
- if (!step.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
- return;
- }
+ auto step = m_session_history.current_step().value();
// 2. Return the result of applying the history step step to traversable given true, null, null, userInvolvement, and "reload".
- apply_history_step(operation, *step, true, {}, user_involvement, Web::Bindings::NavigationType::Reload);
+ apply_history_step(operation, step, true, {}, user_involvement, Web::Bindings::NavigationType::Reload);
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-traverse-history-step
@@ -2329,14 +2325,10 @@ void CanonicalTraversable::resume_applying_the_traverse_history_step(HistoryOper
void CanonicalTraversable::update_for_navigable_creation_or_destruction(HistoryOperation& operation)
{
// 1. Let step be traversable's current session history step.
- auto step = m_session_history.current_step();
- if (!step.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
- return;
- }
+ auto step = m_session_history.current_step().value();
// 2. Return the result of applying the history step step to traversable given false, null, null, "none", and null.
- apply_history_step(operation, *step, false, {}, Web::HTML::UserNavigationInvolvement::None, {});
+ apply_history_step(operation, step, false, {}, Web::HTML::UserNavigationInvolvement::None, {});
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#traverse-the-history-by-a-delta
@@ -2349,12 +2341,7 @@ void CanonicalTraversable::traverse_the_history_by_a_delta_at_queue_position(His
auto all_steps = m_session_history.used_steps();
// 2. Let currentStepIndex be the index of traversable's current session history step within allSteps.
- auto current_step = m_session_history.current_step();
- if (!current_step.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::Applied, {});
- return;
- }
- auto current_step_index = all_steps.find_first_index(*current_step);
+ auto current_step_index = all_steps.find_first_index(m_session_history.current_step().value());
VERIFY(current_step_index.has_value());
// 3. Let targetStepIndex be currentStepIndex plus delta.
@@ -2362,7 +2349,7 @@ void CanonicalTraversable::traverse_the_history_by_a_delta_at_queue_position(His
// 4. If allSteps[targetStepIndex] does not exist, then abort these steps.
if (target_step_index < 0 || static_cast<size_t>(target_step_index) >= all_steps.size()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::Applied, {});
+ end_history_operation(operation.operation_id);
return;
}
@@ -2374,41 +2361,47 @@ void CanonicalTraversable::traverse_the_history_by_a_delta_at_queue_position(His
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#performing-a-navigation-api-traversal
void CanonicalTraversable::perform_a_navigation_api_traversal_at_queue_position(HistoryOperation& operation, Web::NavigationAPITraverseHistoryOperationParameters const& request)
{
- auto navigable = find(request.navigable_id);
- if (!navigable.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
- return;
- }
+ // The substeps of steps 12.2 and 12.3:
+ // 1. Queue a global task on the navigation and traversal task source given navigation's relevant global object to
+ // reject the finished promise for apiMethodTracker with an "InvalidStateError" DOMException.
+ // 2. Abort these steps.
+ auto reject_and_abort = [&] {
+ if (operation.initiating_page)
+ operation.initiating_page->async_reject_navigation_api_traversal(operation.operation_id);
+ end_history_operation(operation.operation_id);
+ };
// 12.1. Let navigableSHEs be the result of getting session history entries given navigable.
- auto navigable_session_history_entries = m_session_history.get_session_history_entries(*navigable);
- if (!navigable_session_history_entries.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
- return;
+ // 12.2. Let targetSHE be the session history entry in navigableSHEs whose navigation API key is key. If no such
+ // entry exists, then:
+ // NB: The requesting process can still have a navigable this session history no longer has.
+ auto navigable = find(request.navigable_id);
+ RefPtr<CanonicalSessionHistoryEntry> target_entry;
+ if (navigable.has_value()) {
+ if (auto navigable_session_history_entries = m_session_history.get_session_history_entries(*navigable); navigable_session_history_entries.has_value()) {
+ auto entry = navigable_session_history_entries->find_if([&](auto const& entry) {
+ return entry->navigation_api_key == request.key;
+ });
+ if (entry != navigable_session_history_entries->end())
+ target_entry = *entry;
+ }
}
-
- // 12.2. Let targetSHE be the session history entry in navigableSHEs whose navigation API key is key. If no
- // such entry exists, queue rejection of the finished promise and abort these steps.
- auto target_entry = navigable_session_history_entries->find_if([&](auto const& entry) {
- return entry->navigation_api_key == request.key;
- });
- if (target_entry == navigable_session_history_entries->end()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ if (!target_entry) {
+ reject_and_abort();
return;
}
- // 12.3. If targetSHE is navigable's active session history entry, queue rejection of the finished promise and
- // abort these steps.
- if (auto const& active_entry = navigable->active_session_history_entry(); active_entry && active_entry->identity() == (*target_entry)->identity()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ // 12.3. If targetSHE is navigable's active session history entry, then:
+ if (auto const& active_entry = navigable->active_session_history_entry(); active_entry && active_entry->identity() == target_entry->identity()) {
+ reject_and_abort();
return;
}
// 12.4. Let result be the result of applying the traverse history step targetSHE's step to traversable, given
// sourceSnapshotParams, navigable, and "none".
- apply_the_traverse_history_step(operation, (*target_entry)->step, request.source_snapshot_params, request.navigable_id, Web::HTML::UserNavigationInvolvement::None);
+ apply_the_traverse_history_step(operation, target_entry->step, request.source_snapshot_params, request.navigable_id, Web::HTML::UserNavigationInvolvement::None);
- // Steps 12.5-12.6 are handled in Navigation's relevant realm when the operation completes.
+ // Steps 12.5-12.6 are handled in Navigation's relevant realm when the requesting process learns the result.
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#finalize-a-same-document-navigation
@@ -2417,7 +2410,7 @@ void CanonicalTraversable::finalize_a_same_document_navigation(HistoryOperation&
VERIFY(request.entry_to_replace.has_value() == (request.history_handling == Web::HTML::HistoryHandlingBehavior::Replace));
auto target_navigable = find(request.navigable_id);
if (!target_navigable.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
@@ -2440,7 +2433,7 @@ void CanonicalTraversable::finalize_a_same_document_navigation(HistoryOperation&
// document that is no longer active, so applying it would traverse across documents and populate the
// unloaded document again, replacing the one that just committed.
if (!target_entry || target_entry->document_state != target_navigable->active_session_history_entry()->document_state) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
@@ -2450,22 +2443,18 @@ void CanonicalTraversable::finalize_a_same_document_navigation(HistoryOperation&
// 4. Let targetEntries be the result of getting session history entries for targetNavigable.
auto target_entries = m_session_history.get_session_history_entries(*target_navigable);
if (!target_entries.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
// AD-HOC: The active entry of a navigable whose history is being reconstructed, which is that of its initial
// about:blank, is not among its session history entries.
if (!any_of(*target_entries, [&](auto const& entry) { return entry->document_state == target_entry->document_state; })) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
- auto current_step = m_session_history.current_step();
- if (!current_step.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
- return;
- }
+ auto current_step = m_session_history.current_step().value();
// 5. If entryToReplace is null:
if (!request.entry_to_replace.has_value()) {
@@ -2475,7 +2464,7 @@ void CanonicalTraversable::finalize_a_same_document_navigation(HistoryOperation&
// 5.4. Append targetEntry to targetEntries.
target_step = m_session_history.push_session_history_entry(*target_navigable, *target_entry);
if (!target_step.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
}
@@ -2485,19 +2474,19 @@ void CanonicalTraversable::finalize_a_same_document_navigation(HistoryOperation&
return entry->identity() == *request.entry_to_replace;
});
if (entry_to_replace == target_entries->end()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
// 5.1. Replace entryToReplace with targetEntry in targetEntries.
// 5.2. Set targetEntry's step to entryToReplace's step.
if (!m_session_history.replace_session_history_entry(*target_navigable, **entry_to_replace, *target_entry)) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
// 5.3. Set targetStep to traversable's current session history step.
- target_step = *current_step;
+ target_step = current_step;
}
target_navigable->set_active_session_history_entry(target_entry);
@@ -2510,17 +2499,13 @@ void CanonicalTraversable::run_history_operation(HistoryOperation& operation)
{
operation.parameters.visit(
[&](Web::ReloadHistoryOperationParameters const& parameters) {
- auto current_step = m_session_history.current_step();
- auto navigable = find(parameters.navigable_id);
- auto* target_entry = current_step.has_value() && navigable.has_value()
- ? m_session_history.get_the_target_history_entry(*navigable, *current_step)
- : nullptr;
- if (!target_entry) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
- return;
+ // NB: A navigable that is gone has no entry to reload. Applying the reload history step then changes nothing.
+ if (auto navigable = find(parameters.navigable_id); navigable.has_value()) {
+ if (auto* target_entry = m_session_history.get_the_target_history_entry(*navigable, m_session_history.current_step().value())) {
+ target_entry->document_state->reload_pending = true;
+ session_history_changed();
+ }
}
- target_entry->document_state->reload_pending = true;
- session_history_changed();
apply_the_reload_history_step(operation, parameters.user_involvement);
},
[&](Web::TraverseByDeltaHistoryOperationParameters const& request) {
@@ -2538,15 +2523,14 @@ void CanonicalTraversable::run_history_operation(HistoryOperation& operation)
[&](Web::NavigableCreationHistoryOperationParameters const& parameters) {
auto parent_navigable = find(parameters.parent_navigable_id);
auto child_navigable = find(parameters.navigable_id);
- auto current_step = m_session_history.current_step();
- if (!parent_navigable.has_value() || !child_navigable.has_value() || !current_step.has_value() || !operation.initiating_page) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ if (!parent_navigable.has_value() || !child_navigable.has_value() || !operation.initiating_page) {
+ end_history_operation(operation.operation_id);
return;
}
// A navigable created by a document repopulated for its entry already has the nested history that entry
// kept. Updating for its creation populates the entry the history holds for it at the current step.
- if (m_session_history.get_the_target_history_entry(*child_navigable, *current_step)) {
+ if (m_session_history.get_the_target_history_entry(*child_navigable, m_session_history.current_step().value())) {
update_for_navigable_creation_or_destruction(operation);
return;
}
@@ -2561,7 +2545,7 @@ void CanonicalTraversable::run_history_operation(HistoryOperation& operation)
// 5. Let nestedHistory be a new nested history whose id is navigable's id and entries list is « historyEntry ».
// 6. Append nestedHistory to parentDocState's nested histories.
if (!append_nested_history(*parent_navigable, parent_document_state, parameters.navigable_id).has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
@@ -2585,12 +2569,12 @@ void CanonicalTraversable::run_history_operation(HistoryOperation& operation)
return;
if (auto host = page_hosting(*this))
host->async_run_traversable_close_unload_task(operation_id);
- finish_history_operation(operation_id, Web::HTML::HistoryStepResult::Applied, {});
+ end_history_operation(operation_id);
});
},
[&](Web::FlushSessionHistoryTraversalQueueOperationParameters const&) {
// Flush is a queue barrier; completing at the queue position is the whole operation.
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::Applied, {});
+ end_history_operation(operation.operation_id);
},
[&](Web::ResumeTraverseHistoryOperationParameters const& parameters) {
resume_applying_the_traverse_history_step(operation, parameters.target_step, parameters.user_involvement);
@@ -2599,7 +2583,7 @@ void CanonicalTraversable::run_history_operation(HistoryOperation& operation)
// A navigation that ended before its completion steps appended this has nothing to finalize.
auto navigation = finalized_navigation(operation);
if (!navigation || navigation->host() != operation.initiating_page.ptr()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::Applied, {});
+ end_history_operation(operation.operation_id);
return;
}
finalize_a_cross_document_navigation(operation);
@@ -2613,7 +2597,7 @@ void CanonicalTraversable::start_history_operation(HistoryOperation& operation,
if (operation.is_browser_traversal()) {
if (!operation.initiating_page) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::CanceledByMissingPage, {});
+ end_history_operation(operation.operation_id);
return;
}
VERIFY(operation.parameters.has<Web::TraverseToStepHistoryOperationParameters>());
@@ -2634,14 +2618,14 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
auto const& parameters = operation.parameters.get<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>();
auto navigable = find(parameters.navigable_id);
if (!navigable.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
// NB: historyEntry is the navigation's. A javascript: URL navigation whose document was refused has none.
auto navigation = finalized_navigation(operation);
if (!navigation || !navigation->history_entry) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
NonnullRefPtr history_entry = *navigation->history_entry;
@@ -2662,7 +2646,7 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
document = populated_document->document;
if (!document) {
navigable->did_cancel_navigation(parameters.navigation_id);
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::Applied, {});
+ end_history_operation(operation.operation_id);
return;
}
@@ -2683,18 +2667,12 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
history_entry->document_state->navigable_target_name = {};
}
- auto current_step = m_session_history.current_step();
- if (!current_step.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
- return;
- }
-
// 5. Let entryToReplace be navigable's active session history entry if historyHandling is "replace", otherwise null.
RefPtr<CanonicalSessionHistoryEntry> entry_to_replace;
if (parameters.history_handling == Web::HTML::HistoryHandlingBehavior::Replace)
entry_to_replace = navigable->active_session_history_entry();
if (parameters.history_handling == Web::HTML::HistoryHandlingBehavior::Replace && !entry_to_replace) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
@@ -2707,7 +2685,7 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
// 8. Let targetEntries be the result of getting session history entries for navigable.
auto target_entries = m_session_history.get_session_history_entries(*navigable);
if (!target_entries.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
@@ -2719,7 +2697,7 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
// 4. Append historyEntry to targetEntries.
target_step = m_session_history.push_session_history_entry(*navigable, move(history_entry));
if (!target_step.has_value()) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
}
@@ -2728,7 +2706,7 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
// 1. Replace entryToReplace with historyEntry in targetEntries.
// 2. Set historyEntry's step to entryToReplace's step.
if (!m_session_history.replace_session_history_entry(*navigable, *entry_to_replace, history_entry)) {
- finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
+ end_history_operation(operation.operation_id);
return;
}
@@ -2741,59 +2719,68 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
}
// 4. Set targetStep to traversable's current session history step.
- target_step = *current_step;
+ target_step = m_session_history.current_step().value();
}
// 10. Apply the push/replace history step targetStep to traversable given historyHandling and userInvolvement.
apply_the_push_or_replace_history_step(operation, *target_step, parameters.history_handling, parameters.user_involvement);
}
+// The operation's apply the history step returned result.
void CanonicalTraversable::finish_history_operation(Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult result, Optional<i32> committed_step)
{
- auto operation = m_history_operations.take(operation_id);
- if (!operation.has_value())
+ auto operation = take_history_operation(operation_id);
+ if (!operation)
return;
- // The operation lets go of what it holds and reports its result before the traversal queue moves on, and what
- // waited for its traversal to be over runs after.
- release_history_operation(**operation, result);
- report_history_operation_result(**operation, result, committed_step);
-
- // NB: Resolving the queue promise can synchronously start the next queued operation.
- if ((*operation)->queue_promise)
- (*operation)->queue_promise->resolve({});
+ // The requesting page learns the result before the operation completes.
+ if (operation->initiating_page)
+ operation->initiating_page->async_history_step_applied(operation_id, result);
+ report_history_operation_completion(*operation, committed_step);
+ if (operation->on_history_step_applied)
+ operation->on_history_step_applied(result, committed_step);
+ settle_history_operation(operation.release_nonnull());
+}
- if (auto view = this->view(); view.has_value())
- view->run_webdriver_commands_waiting_for_a_document({});
+// The operation's steps ended without applying a history step.
+void CanonicalTraversable::end_history_operation(Web::HTML::CrossProcessId operation_id)
+{
+ auto operation = take_history_operation(operation_id);
+ if (!operation)
+ return;
- // The completion callback that brought us here can be running inside the algorithm object; destroy the
- // operation only once the stack has unwound.
- Core::deferred_invoke([operation = operation.release_value()] { });
+ report_history_operation_completion(*operation, {});
+ settle_history_operation(operation.release_nonnull());
}
-void CanonicalTraversable::release_history_operation(HistoryOperation& operation, Web::HTML::HistoryStepResult result)
+OwnPtr<CanonicalTraversable::HistoryOperation> CanonicalTraversable::take_history_operation(Web::HTML::CrossProcessId operation_id)
{
- operation.finished = true;
- if (m_browser_history_traversal == &operation)
+ auto operation = m_history_operations.take(operation_id);
+ if (!operation.has_value())
+ return nullptr;
+
+ (*operation)->finished = true;
+ if (m_browser_history_traversal == operation->ptr())
m_browser_history_traversal = nullptr;
- if (operation.beforeunload_check_id.has_value())
- m_pending_beforeunload_checks.remove(*operation.beforeunload_check_id);
+ if ((*operation)->beforeunload_check_id.has_value())
+ m_pending_beforeunload_checks.remove(*(*operation)->beforeunload_check_id);
// A changing job still pending when its operation finishes never activates the document it populated. The job
// stays with the operation: its completion can be what finished it.
- for (auto const& [navigable_id, pending_job] : operation.pending_changing_jobs)
+ for (auto const& [navigable_id, pending_job] : (*operation)->pending_changing_jobs)
pending_job->abandon(find(navigable_id));
- if (auto const* parameters = operation.parameters.get_pointer<Web::NavigableCreationHistoryOperationParameters>()) {
+ if (auto const* parameters = (*operation)->parameters.get_pointer<Web::NavigableCreationHistoryOperationParameters>()) {
if (auto navigable = find(parameters->navigable_id); navigable.has_value())
- navigable->clear_ongoing_navigation_traversal(operation.operation_id);
+ navigable->clear_ongoing_navigation_traversal(operation_id);
}
- if (auto const* parameters = operation.parameters.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>()) {
+ if (auto const* parameters = (*operation)->parameters.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>()) {
if (auto navigable = find(parameters->navigable_id); navigable.has_value())
- navigable->did_finish_finalizing_navigation(parameters->navigation_id, result);
+ navigable->did_finish_finalizing_navigation(parameters->navigation_id);
}
+ return operation.release_value();
}
-void CanonicalTraversable::report_history_operation_result(HistoryOperation& operation, Web::HTML::HistoryStepResult result, Optional<i32> committed_step)
+void CanonicalTraversable::report_history_operation_completion(HistoryOperation& operation, Optional<i32> committed_step)
{
if (committed_step.has_value()) {
if (auto view = this->view(); view.has_value()) {
@@ -2811,28 +2798,39 @@ void CanonicalTraversable::report_history_operation_result(HistoryOperation& ope
}
for (auto& endpoint : operation.completion_endpoints)
- endpoint->async_complete_history_operation(operation.operation_id, result, target_entry_step, m_session_history.size());
+ endpoint->async_complete_history_operation(operation.operation_id, target_entry_step, m_session_history.size());
// All apply-driven mutations have settled at operation completion.
session_history_changed();
+}
- if (operation.on_complete)
- operation.on_complete(result, committed_step);
-
- if (operation.is_browser_traversal()) {
- if (auto callback = move(operation.browser_traversal->on_ready))
+// The operation has let go of what it holds and reported its completion. What waited for its traversal to be over runs
+// now.
+void CanonicalTraversable::settle_history_operation(NonnullOwnPtr<HistoryOperation> operation)
+{
+ if (operation->is_browser_traversal()) {
+ if (auto callback = move(operation->browser_traversal->on_ready))
callback();
if (auto view = this->view(); view.has_value())
- view->did_finish_history_traversal(operation.operation_id, result);
+ view->did_finish_history_traversal(operation->operation_id);
}
+
+ // NB: Resolving the queue promise can synchronously start the next queued operation.
+ if (operation->queue_promise)
+ operation->queue_promise->resolve({});
+
+ 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.
+ Core::deferred_invoke([operation = move(operation)] { });
}
void CanonicalTraversable::abandon_history_operations()
{
- while (!m_history_operations.is_empty()) {
- auto operation_id = m_history_operations.begin()->key;
- finish_history_operation(operation_id, Web::HTML::HistoryStepResult::CanceledByMissingPage, {});
- }
+ while (!m_history_operations.is_empty())
+ end_history_operation(m_history_operations.begin()->key);
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#checking-if-unloading-is-canceled
diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.h
index 0602cbce03b..fa0982ce774 100644
--- a/Libraries/LibWebView/CanonicalTraversable.h
+++ b/Libraries/LibWebView/CanonicalTraversable.h
@@ -53,7 +53,7 @@ public:
// Apply-the-history-step coordination. Operations serialize on the traversable's session history traversal
// queue; the algorithm runs here and dispatches its per-navigable jobs to the processes hosting the documents.
- using OnHistoryOperationComplete = Function<void(Web::HTML::HistoryStepResult, Optional<i32> committed_step)>;
+ using OnHistoryStepApplied = Function<void(Web::HTML::HistoryStepResult, Optional<i32> committed_step)>;
struct BrowserHistoryTraversalDiagnostic {
enum class Stage : u8 {
@@ -67,11 +67,11 @@ public:
Stage stage { Stage::ApplyingInWebContent };
};
- void enqueue_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters, RefPtr<WebContentPage> requesting_page, u64 sequence_number, OnHistoryOperationComplete = nullptr);
+ void enqueue_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters, RefPtr<WebContentPage> requesting_page, u64 sequence_number, OnHistoryStepApplied = nullptr);
// Appends plain algorithm steps; a requested traversal defers its target resolution to its queued position, the
// way the specification's queued steps do, and then starts its operation at that position.
void append_history_queue_steps(SessionHistoryTraversalSteps);
- void run_history_operation_at_queue_position(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters, RefPtr<WebContentPage> requesting_page, u64 sequence_number, RefPtr<CanonicalSessionHistoryEntry> target_entry, OnHistoryOperationComplete, NonnullRefPtr<Core::Promise<Empty>>);
+ void run_history_operation_at_queue_position(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters, RefPtr<WebContentPage> requesting_page, u64 sequence_number, RefPtr<CanonicalSessionHistoryEntry> target_entry, OnHistoryStepApplied, NonnullRefPtr<Core::Promise<Empty>>);
u64 next_sequence_number() { return m_next_sequence_number++; }
void abandon_history_operations();
@@ -158,7 +158,7 @@ public:
Vector<NonnullRefPtr<CanonicalSessionHistoryEntry>> queued_same_document_session_history_entries(CanonicalNavigable const&) const;
ByteString queued_same_document_session_history_entries_for_debug() const;
- void reload(OnHistoryOperationComplete = nullptr);
+ void reload(OnHistoryStepApplied = nullptr);
void stop_loading();
static CanonicalTraversable& create_a_new_top_level_traversable(Web::HTML::CrossProcessId id, Optional<CanonicalNavigable&> opener, Web::HTML::SessionHistoryEntryDescriptor initial_history_entry, Web::HTML::CrossProcessId document_id);
static bool is_origin_held_by_a_document(URL::Origin const&);
@@ -175,7 +175,7 @@ public:
void traverse_the_history_to_step(i32 step, CheckForCancelation, Function<void()> on_ready = nullptr);
void reconstruct_the_history_to_step(i32 step);
ErrorOr<URL::URL> restore_session_history_from_ui_snapshot(SessionHistorySnapshot);
- void recover_from_web_content_process_crash(OnHistoryOperationComplete);
+ void recover_from_web_content_process_crash(OnHistoryStepApplied);
void reset_session_history_for_testing(Web::HTML::SessionHistoryEntryDescriptor);
bool initialize_session_history_for_testing(Vector<Web::HTML::SessionHistoryEntryDescriptor>, Vector<i32> used_steps, size_t current_used_step_index);
@@ -216,8 +216,8 @@ private:
void traverse_the_history_by_a_delta_at_queue_position(HistoryOperation&, Web::TraverseByDeltaHistoryOperationParameters const&);
void perform_a_navigation_api_traversal_at_queue_position(HistoryOperation&, Web::NavigationAPITraverseHistoryOperationParameters const&);
void finalize_a_same_document_navigation(HistoryOperation&, Web::FinalizeSameDocumentNavigationHistoryOperationParameters const&);
- void enqueue_browser_history_traversal(Web::TraverseToStepHistoryOperationParameters, bool check_for_cancelation, OnHistoryOperationComplete = nullptr);
- void run_browser_history_traversal_at_queue_position(Web::TraverseToStepHistoryOperationParameters, bool check_for_cancelation, u64 sequence_number, Function<void()> on_ready, OnHistoryOperationComplete, NonnullRefPtr<Core::Promise<Empty>>);
+ void enqueue_browser_history_traversal(Web::TraverseToStepHistoryOperationParameters, bool check_for_cancelation, OnHistoryStepApplied = nullptr);
+ void run_browser_history_traversal_at_queue_position(Web::TraverseToStepHistoryOperationParameters, bool check_for_cancelation, u64 sequence_number, Function<void()> on_ready, OnHistoryStepApplied, NonnullRefPtr<Core::Promise<Empty>>);
void start_history_operation(HistoryOperation&, NonnullRefPtr<Core::Promise<Empty>>);
void did_attempt_to_populate_the_history_entry_document(WebContentPage& source_page, Web::FinalizeCrossDocumentNavigationHistoryOperationParameters const&);
void finalize_a_cross_document_navigation(HistoryOperation&);
@@ -228,8 +228,10 @@ private:
void resume_applying_the_traverse_history_step(HistoryOperation&, i32 step, Web::HTML::UserNavigationInvolvement);
void update_for_navigable_creation_or_destruction(HistoryOperation&);
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 end_history_operation(Web::HTML::CrossProcessId operation_id);
+ OwnPtr<HistoryOperation> take_history_operation(Web::HTML::CrossProcessId operation_id);
+ void report_history_operation_completion(HistoryOperation&, Optional<i32> committed_step);
+ void settle_history_operation(NonnullOwnPtr<HistoryOperation>);
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/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 36e887a093e..a4ef6086da9 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -517,20 +517,13 @@ void ViewImplementation::did_apply_top_level_history_traversal_step(Web::HTML::C
complete_webdriver_history_traversal(operation_id);
}
-void ViewImplementation::did_finish_history_traversal(Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult result)
+void ViewImplementation::did_finish_history_traversal(Web::HTML::CrossProcessId operation_id)
{
- if (result == Web::HTML::HistoryStepResult::Applied) {
- if (auto const* current_entry = traversable().session_history().current_entry())
- set_url(current_entry->url);
- }
-
complete_webdriver_history_traversal(operation_id);
update_navigation_action_state();
if (on_browser_history_traversal_complete)
on_browser_history_traversal_complete();
- dump_session_history(result == Web::HTML::HistoryStepResult::Applied
- ? "webcontent-history-step-applied"sv
- : "webcontent-history-step-canceled"sv);
+ dump_session_history("webcontent-history-traversal-complete"sv);
}
Vector<ViewImplementation::SessionHistoryTraversalMenuItem> ViewImplementation::session_history_traversal_menu_items(int direction) const
@@ -2488,10 +2481,10 @@ void ViewImplementation::did_start_navigation()
dump_session_history("did-start-navigation"sv);
}
-void ViewImplementation::did_cancel_loading(Badge<CanonicalNavigable>, bool canceled_ongoing_navigation)
+void ViewImplementation::did_cancel_loading(Badge<CanonicalNavigable>, bool canceled_navigation)
{
set_loading_state(false);
- if (canceled_ongoing_navigation)
+ if (canceled_navigation)
did_end_uncommitted_navigation("did-cancel-navigation"sv);
else if (m_webdriver_navigation_observation.has_value())
complete_webdriver_navigation(m_webdriver_navigation_observation->navigation_id);
@@ -3206,7 +3199,7 @@ void ViewImplementation::request_history_operation(Badge<WebContentPage>, WebCon
return parameters.navigable_id == traversable().id();
},
[](auto const&) { return false; });
- auto requested_operation_completion = [this, reloads_top_level, finalizes_top_level_cross_document_navigation](Web::HTML::HistoryStepResult result, Optional<i32> committed_step) {
+ auto on_history_step_applied = [this, reloads_top_level, finalizes_top_level_cross_document_navigation](Web::HTML::HistoryStepResult result, Optional<i32> committed_step) {
if (reloads_top_level && result != Web::HTML::HistoryStepResult::Applied && !traversable().tracked_load_navigation_id().has_value()) {
set_loading_state(false);
if (m_webdriver_navigation_observation.has_value())
@@ -3221,7 +3214,7 @@ void ViewImplementation::request_history_operation(Badge<WebContentPage>, WebCon
dump_session_history("requested-history-operation-complete"sv);
};
- traversable().enqueue_history_operation(operation_id, move(parameters), requesting_page, sequence_number, move(requested_operation_completion));
+ traversable().enqueue_history_operation(operation_id, move(parameters), requesting_page, sequence_number, move(on_history_step_applied));
}
void ViewImplementation::did_reset_session_history_for_testing(
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index dae7c567582..ed09045faeb 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -111,7 +111,7 @@ public:
CanonicalTraversable& traversable() const;
virtual void prepare_page_for_tab(WebContentPage&);
void did_change_display_page(Badge<CanonicalNavigable>, RefPtr<WebContentPage> previous_page);
- void did_cancel_loading(Badge<CanonicalNavigable>, bool canceled_ongoing_navigation);
+ void did_cancel_loading(Badge<CanonicalNavigable>, bool canceled_navigation);
void did_stop_loading(Badge<CanonicalTraversable>, bool stopped_navigation);
void set_url(Badge<WebContentPage>, URL::URL url) { set_url(move(url)); }
@@ -553,7 +553,7 @@ public:
protected:
void will_apply_history_traversal_step(Web::HTML::CrossProcessId operation_id);
void did_apply_top_level_history_traversal_step(Web::HTML::CrossProcessId operation_id);
- void did_finish_history_traversal(Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult);
+ void did_finish_history_traversal(Web::HTML::CrossProcessId operation_id);
virtual Web::Clipboard::SystemClipboardItem clipboard_item() const;
virtual void insert_clipboard_item(Web::Clipboard::SystemClipboardItem);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index bd301a3a230..0ee44fb8506 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1616,7 +1616,7 @@ void WebContentPage::request_history_operation(Web::HTML::CrossProcessId operati
{
// Only the process hosting a navigable's active document appends its synchronous navigation steps.
if (auto const* same_document = parameters.get_pointer<Web::FinalizeSameDocumentNavigationHistoryOperationParameters>(); same_document && !hosted_navigable(same_document->navigable_id).has_value()) {
- async_complete_history_operation(operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {}, traversable().session_history().size());
+ async_complete_history_operation(operation_id, {}, traversable().session_history().size());
return;
}
view().request_history_operation({}, *this, operation_id, move(parameters));
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index e66f5fc5234..7a69cc91273 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -801,7 +801,19 @@ void ConnectionFromClient::update_nonchanging_navigable_history_state(Web::PageI
}));
}
-void ConnectionFromClient::complete_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult result, Optional<i32> target_entry_step, u64 session_history_entry_count)
+void ConnectionFromClient::history_step_applied(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult result)
+{
+ if (auto page = this->page(page_id); page.has_value())
+ page->page().history_executor().did_apply_ui_history_step(operation_id, result);
+}
+
+void ConnectionFromClient::reject_navigation_api_traversal(Web::PageId page_id, Web::HTML::CrossProcessId operation_id)
+{
+ if (auto page = this->page(page_id); page.has_value())
+ page->page().history_executor().reject_ui_navigation_api_traversal(operation_id);
+}
+
+void ConnectionFromClient::complete_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Optional<i32> target_entry_step, u64 session_history_entry_count)
{
auto page = this->page(page_id);
if (!page.has_value())
@@ -809,7 +821,7 @@ void ConnectionFromClient::complete_history_operation(Web::PageId page_id, Web::
if (auto* traversable = as_if<Web::HTML::LocalTraversableNavigable>(*page->page().top_level_traversable()))
traversable->set_session_history_entry_count(session_history_entry_count);
- page->page().history_executor().complete_ui_history_operation(operation_id, result, target_entry_step);
+ page->page().history_executor().complete_ui_history_operation(operation_id, target_entry_step);
}
void ConnectionFromClient::set_viewport(Web::PageId page_id, Web::DevicePixelSize size, double device_pixel_ratio, Web::ViewportIsFullscreen is_fullscreen)
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index dc00df42aa0..e44a8737237 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -156,7 +156,9 @@ private:
virtual void container_unfullscreen_complete(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void run_traversable_close_unload_task(Web::PageId page_id, Web::HTML::CrossProcessId operation_id) override;
virtual void update_nonchanging_navigable_history_state(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, u64 script_history_length, u64 script_history_index) override;
- virtual void complete_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult result, Optional<i32> target_entry_step, u64 session_history_entry_count) override;
+ virtual void history_step_applied(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult result) override;
+ virtual void reject_navigation_api_traversal(Web::PageId page_id, Web::HTML::CrossProcessId operation_id) override;
+ virtual void complete_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Optional<i32> target_entry_step, u64 session_history_entry_count) override;
virtual void set_viewport(Web::PageId page_id, Web::DevicePixelSize, double device_pixel_ratio, Web::ViewportIsFullscreen is_fullscreen) override;
virtual void set_viewport_is_fullscreen(Web::PageId page_id, Web::ViewportIsFullscreen is_fullscreen) override;
virtual void deny_fullscreen_window(Web::PageId page_id) override;
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index 1faea60cee5..ac355d0be84 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -129,7 +129,9 @@ endpoint WebContentServer routed by Web::PageId page_id
container_unfullscreen_complete(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
run_traversable_close_unload_task(Web::PageId page_id, Web::HTML::CrossProcessId operation_id) =|
update_nonchanging_navigable_history_state(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, u64 script_history_length, u64 script_history_index) =|
- complete_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult result, Optional<i32> target_entry_step, u64 session_history_entry_count) =|
+ history_step_applied(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryStepResult result) =|
+ reject_navigation_api_traversal(Web::PageId page_id, Web::HTML::CrossProcessId operation_id) =|
+ complete_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Optional<i32> target_entry_step, u64 session_history_entry_count) =|
set_viewport(Web::PageId page_id, Web::DevicePixelSize size, double device_pixel_ratio, Web::ViewportIsFullscreen is_fullscreen) =|
set_viewport_is_fullscreen(Web::PageId page_id, Web::ViewportIsFullscreen is_fullscreen) =|
diff --git a/Tests/LibWebView/TestSessionHistory.cpp b/Tests/LibWebView/TestSessionHistory.cpp
index 1c1e354be7f..5b9254b319d 100644
--- a/Tests/LibWebView/TestSessionHistory.cpp
+++ b/Tests/LibWebView/TestSessionHistory.cpp
@@ -247,7 +247,8 @@ struct HistoryOperationResult {
Optional<i32> committed_step;
};
-static HistoryOperationResult run_canonical_history_operation(WebView::CanonicalTraversable& traversable, Web::HistoryOperationParameters request)
+// The result of the operation's apply the history step, if its steps applied one.
+static Optional<HistoryOperationResult> run_canonical_history_operation(WebView::CanonicalTraversable& traversable, Web::HistoryOperationParameters request)
{
auto operation_id = Web::HTML::CrossProcessId { 8, 1 };
RefPtr<WebView::CanonicalSessionHistoryEntry> target_entry;
@@ -266,9 +267,8 @@ static HistoryOperationResult run_canonical_history_operation(WebView::Canonical
result = HistoryOperationResult { operation_result, committed_step };
},
queue_promise);
- VERIFY(result.has_value());
VERIFY(queue_promise->is_resolved());
- return result.release_value();
+ return result;
}
static void expect_entry(WebView::TraversableSessionHistory const& history, size_t index, i32 expected_step, StringView expected_url)
@@ -1051,8 +1051,9 @@ TEST_CASE(same_document_push_clears_forward_history_at_queue_position)
};
auto operation_result = run_canonical_history_operation(traversable, move(request));
- EXPECT_EQ(operation_result.result, Web::HTML::HistoryStepResult::Applied);
- EXPECT_EQ(operation_result.committed_step, 1);
+ VERIFY(operation_result.has_value());
+ EXPECT_EQ(operation_result->result, Web::HTML::HistoryStepResult::Applied);
+ EXPECT_EQ(operation_result->committed_step, 1);
auto const& history = traversable.session_history();
EXPECT_EQ(history.current_step(), 1);
EXPECT_EQ(history.size(), 2uz);
@@ -1091,8 +1092,7 @@ TEST_CASE(failed_nested_same_document_push_preserves_forward_history)
};
auto operation_result = run_canonical_history_operation(traversable, move(request));
- EXPECT_EQ(operation_result.result, Web::HTML::HistoryStepResult::NoMatchingEntry);
- EXPECT(!operation_result.committed_step.has_value());
+ EXPECT(!operation_result.has_value());
auto const& history = traversable.session_history();
EXPECT_EQ(history.current_step(), 0);
EXPECT_EQ(history.size(), 2uz);
@@ -1162,8 +1162,9 @@ TEST_CASE(same_document_replacement_replaces_the_active_entry)
};
auto operation_result = run_canonical_history_operation(traversable, move(request));
- EXPECT_EQ(operation_result.result, Web::HTML::HistoryStepResult::Applied);
- EXPECT_EQ(operation_result.committed_step, 0);
+ VERIFY(operation_result.has_value());
+ EXPECT_EQ(operation_result->result, Web::HTML::HistoryStepResult::Applied);
+ EXPECT_EQ(operation_result->committed_step, 0);
auto const& history = traversable.session_history();
EXPECT_EQ(history.current_step(), 0);
EXPECT_EQ(history.size(), 2uz);