Skip to content

Truly independent web browser

LibWeb+LibWebView: Finish history operations without callbacks

Shannon Booth1bee07744ceb
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 059a315ef09..c97cba0d665 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -4273,17 +4273,13 @@ void LocalNavigable::reload(Optional<StorageSerializationRecord> navigation_api_
.user_involvement = user_involvement,
},
{
- .on_apply_history_step_complete = GC::create_function(heap(), [this, reloading_entry](HistoryStepResult result) {
+ .on_apply_history_step_complete = GC::create_function(heap(), [reloading_entry](HistoryStepResult result) {
if (result == HistoryStepResult::Applied)
return;
// AD-HOC: The spec leaves reload pending set when the reload does not apply, so a later history step would
- // reload the document anyway.
- if (reloading_entry->document_state()->reload_pending()) {
- reloading_entry->document_state()->set_reload_pending(false);
- page().client().page_did_set_session_history_entry_document_state_reload_pending(
- id(), reloading_entry->navigation_api_key(), false);
- }
+ // reload the document anyway. The UI process clears its own.
+ reloading_entry->document_state()->set_reload_pending(false);
}),
});
}
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 1aaae6d5934..6123bd78d45 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -649,7 +649,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(OnHistoryStepApplied on_complete)
+void CanonicalTraversable::reload()
{
auto user_involvement = Web::HTML::UserNavigationInvolvement::BrowserUI;
@@ -660,8 +660,7 @@ void CanonicalTraversable::reload(OnHistoryStepApplied on_complete)
clear_active_document_load();
// 2. Set navigable's active session history entry's document state's reload pending to true.
- NonnullRefPtr reloading_entry = *active_session_history_entry();
- reloading_entry->document_state->reload_pending = true;
+ active_session_history_entry()->document_state->reload_pending = true;
session_history_changed();
// 3. Let traversable be navigable's traversable navigable.
@@ -671,16 +670,7 @@ void CanonicalTraversable::reload(OnHistoryStepApplied on_complete)
.navigable_id = id(),
.user_involvement = user_involvement,
};
- enqueue_history_operation(Application::the().allocate_ui_process_cross_process_id(), parameters, {}, next_sequence_number(), [this, reloading_entry, on_complete = move(on_complete)](Web::HTML::HistoryStepResult result, Optional<i32> committed_step) {
- // AD-HOC: The spec leaves reload pending set when the reload does not apply, so a later history step would
- // reload the document anyway.
- if (result != Web::HTML::HistoryStepResult::Applied && reloading_entry->document_state->reload_pending) {
- reloading_entry->document_state->reload_pending = false;
- session_history_changed();
- }
- if (on_complete)
- on_complete(result, committed_step);
- });
+ enqueue_history_operation(Application::the().allocate_ui_process_cross_process_id(), parameters, {}, next_sequence_number());
}
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#nav-stop
@@ -913,7 +903,7 @@ void CanonicalTraversable::reconstruct_the_history_to_step(i32 step)
return;
}
set_current_session_history_entry({});
- run_browser_history_traversal_at_queue_position(step, false, next_sequence_number(), nullptr, nullptr, move(promise));
+ run_browser_history_traversal_at_queue_position(step, false, next_sequence_number(), nullptr, move(promise));
});
}
@@ -974,11 +964,10 @@ struct CanonicalTraversable::HistoryOperation {
using Parameters = FlattenVariant<Web::HistoryOperationParameters, Variant<BrowserTraversal>>;
- HistoryOperation(Web::HTML::CrossProcessId operation_id, Parameters parameters, RefPtr<WebContentPage> requesting_page, u64 sequence_number, RefPtr<CanonicalSessionHistoryEntry> target_entry, OnHistoryStepApplied on_history_step_applied)
+ HistoryOperation(Web::HTML::CrossProcessId operation_id, Parameters parameters, RefPtr<WebContentPage> requesting_page, u64 sequence_number, RefPtr<CanonicalSessionHistoryEntry> target_entry)
: operation_id(operation_id)
, parameters(move(parameters))
, target_entry(move(target_entry))
- , on_history_step_applied(move(on_history_step_applied))
, requesting_page(move(requesting_page))
, sequence_number(sequence_number)
{
@@ -988,7 +977,6 @@ struct CanonicalTraversable::HistoryOperation {
Parameters parameters;
// The entry synchronous navigation steps finalize.
RefPtr<CanonicalSessionHistoryEntry> target_entry;
- OnHistoryStepApplied on_history_step_applied;
// Jobs resolve their endpoints at dispatch. The requesting page owns the process-local operation state.
RefPtr<WebContentPage> requesting_page;
Vector<NonnullRefPtr<WebContentPage>> completion_endpoints;
@@ -1161,7 +1149,7 @@ void CanonicalTraversable::run_browser_ui_traversal_at_queue_position(Function<O
return;
}
- run_browser_history_traversal_at_queue_position(*target_step, check_for_cancelation == CheckForCancelation::Yes, next_sequence_number(), move(on_ready), nullptr, move(promise));
+ run_browser_history_traversal_at_queue_position(*target_step, check_for_cancelation == CheckForCancelation::Yes, next_sequence_number(), move(on_ready), move(promise));
}
void CanonicalTraversable::supersede_browser_history_traversal(HistoryOperation& operation, i32 target_step, Function<void()> on_ready)
@@ -1173,7 +1161,7 @@ void CanonicalTraversable::supersede_browser_history_traversal(HistoryOperation&
if (has_uncommitted_navigation())
stop_loading();
end_history_operation(operation_id);
- run_browser_history_traversal_at_queue_position(target_step, true, next_sequence_number(), move(on_ready), nullptr, move(promise));
+ run_browser_history_traversal_at_queue_position(target_step, true, next_sequence_number(), move(on_ready), move(promise));
}
Optional<CanonicalTraversable::BrowserHistoryTraversalDiagnostic> CanonicalTraversable::browser_history_traversal_for_testing() const
@@ -1207,7 +1195,7 @@ RefPtr<CanonicalNavigation> CanonicalTraversable::finalized_navigation(HistoryOp
return navigation && navigation->is_finalizing() ? navigation : nullptr;
}
-void CanonicalTraversable::recover_from_web_content_process_crash(OnHistoryStepApplied on_complete)
+void CanonicalTraversable::recover_from_web_content_process_crash()
{
if (has_uncommitted_navigation())
clear_ongoing_navigation();
@@ -1224,7 +1212,7 @@ void CanonicalTraversable::recover_from_web_content_process_crash(OnHistoryStepA
VERIFY(reloading_entry);
reloading_entry->document_state->reload_pending = true;
session_history_changed();
- enqueue_browser_history_traversal(target_step, false, move(on_complete));
+ enqueue_browser_history_traversal(target_step, false);
}
RefPtr<WebContentPage> CanonicalTraversable::page_hosting(CanonicalNavigable const& navigable) const
@@ -2000,7 +1988,7 @@ 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, OnHistoryStepApplied 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, 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.
@@ -2020,17 +2008,17 @@ void CanonicalTraversable::run_history_operation_at_queue_position(Web::HTML::Cr
promise->resolve({});
return;
}
- m_history_operations.set(operation_id, make<HistoryOperation>(operation_id, move(request), move(requesting_page), sequence_number, move(target_entry), move(on_complete)));
+ m_history_operations.set(operation_id, make<HistoryOperation>(operation_id, move(request), move(requesting_page), sequence_number, move(target_entry)));
auto* operation = find_history_operation(operation_id);
VERIFY(operation);
operation->queue_promise = promise;
- start_history_operation(*operation, promise);
+ run_history_operation(*operation);
}
-void CanonicalTraversable::run_browser_history_traversal_at_queue_position(i32 target_step, bool check_for_cancelation, u64 sequence_number, Function<void()> on_ready, OnHistoryStepApplied on_complete, NonnullRefPtr<Core::Promise<Empty>> promise)
+void CanonicalTraversable::run_browser_history_traversal_at_queue_position(i32 target_step, bool check_for_cancelation, u64 sequence_number, Function<void()> on_ready, NonnullRefPtr<Core::Promise<Empty>> promise)
{
auto operation_id = Application::the().allocate_ui_process_cross_process_id();
- auto owned_operation = make<HistoryOperation>(operation_id, HistoryOperation::BrowserTraversal { target_step, check_for_cancelation, move(on_ready) }, RefPtr<WebContentPage> {}, sequence_number, RefPtr<CanonicalSessionHistoryEntry> {}, move(on_complete));
+ auto owned_operation = make<HistoryOperation>(operation_id, HistoryOperation::BrowserTraversal { target_step, check_for_cancelation, move(on_ready) }, RefPtr<WebContentPage> {}, sequence_number, RefPtr<CanonicalSessionHistoryEntry> {});
m_history_operations.set(operation_id, move(owned_operation));
auto* operation = find_history_operation(operation_id);
VERIFY(operation);
@@ -2040,7 +2028,7 @@ void CanonicalTraversable::run_browser_history_traversal_at_queue_position(i32 t
auto view = this->view();
VERIFY(view.has_value());
view->will_apply_history_traversal_step(operation_id);
- start_history_operation(*operation, promise);
+ run_history_operation(*operation);
}
void CanonicalTraversable::append_history_queue_steps(SessionHistoryTraversalSteps steps)
@@ -2149,7 +2137,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, OnHistoryStepApplied on_complete)
+void CanonicalTraversable::enqueue_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters request, RefPtr<WebContentPage> requesting_page, u64 sequence_number)
{
// 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
@@ -2198,8 +2186,8 @@ void CanonicalTraversable::enqueue_history_operation(Web::HTML::CrossProcessId o
if (request.has<Web::ResumeTraverseHistoryOperationParameters>() && requesting_page)
revocable_operation = SessionHistoryTraversalQueue::RevocableOperation { requesting_page->id(), operation_id };
- auto steps = [this, operation_id, request = move(request), requesting_page = move(requesting_page), sequence_number, target_entry, on_complete = move(on_complete)](NonnullRefPtr<Core::Promise<Empty>> promise) mutable {
- run_history_operation_at_queue_position(operation_id, move(request), move(requesting_page), sequence_number, move(target_entry), move(on_complete), move(promise));
+ auto steps = [this, operation_id, request = move(request), requesting_page = move(requesting_page), sequence_number, target_entry](NonnullRefPtr<Core::Promise<Empty>> promise) mutable {
+ run_history_operation_at_queue_position(operation_id, move(request), move(requesting_page), sequence_number, move(target_entry), move(promise));
};
if (synchronous_navigation_target.has_value())
@@ -2216,11 +2204,11 @@ void CanonicalTraversable::revoke_history_operation(WebContentPage& source_page,
source_page.async_complete_history_operation(operation_id, {}, m_session_history.size());
}
-void CanonicalTraversable::enqueue_browser_history_traversal(i32 target_step, bool check_for_cancelation, OnHistoryStepApplied on_complete)
+void CanonicalTraversable::enqueue_browser_history_traversal(i32 target_step, bool check_for_cancelation)
{
auto sequence_number = next_sequence_number();
- auto steps = [this, target_step, check_for_cancelation, sequence_number, on_complete = move(on_complete)](NonnullRefPtr<Core::Promise<Empty>> promise) mutable {
- run_browser_history_traversal_at_queue_position(target_step, check_for_cancelation, sequence_number, nullptr, move(on_complete), move(promise));
+ auto steps = [this, target_step, check_for_cancelation, sequence_number](NonnullRefPtr<Core::Promise<Empty>> promise) mutable {
+ run_browser_history_traversal_at_queue_position(target_step, check_for_cancelation, sequence_number, nullptr, move(promise));
};
m_history_traversal_queue.append_session_history_traversal_steps(move(steps));
}
@@ -2450,6 +2438,9 @@ void CanonicalTraversable::finalize_a_same_document_navigation(HistoryOperation&
void CanonicalTraversable::run_history_operation(HistoryOperation& operation)
{
+ if (operation.requesting_page)
+ add_history_operation_completion_endpoint(operation, *operation.requesting_page);
+
operation.parameters.visit(
[&](Web::ReloadHistoryOperationParameters const& parameters) {
apply_the_reload_history_step(operation, parameters.user_involvement);
@@ -2540,14 +2531,6 @@ void CanonicalTraversable::run_history_operation(HistoryOperation& operation)
});
}
-void CanonicalTraversable::start_history_operation(HistoryOperation& operation, NonnullRefPtr<Core::Promise<Empty>>)
-{
- if (operation.requesting_page)
- add_history_operation_completion_endpoint(operation, *operation.requesting_page);
-
- run_history_operation(operation);
-}
-
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#finalize-a-cross-document-navigation
void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation& operation)
{
@@ -2662,6 +2645,21 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
apply_the_push_or_replace_history_step(operation, *target_step, parameters.history_handling, parameters.user_involvement);
}
+void CanonicalTraversable::did_not_apply_reload(Web::HTML::CrossProcessId navigable_id)
+{
+ // AD-HOC: The spec leaves reload pending set when the reload does not apply, so a later history step would reload
+ // the document anyway.
+ if (auto navigable = find(navigable_id); navigable.has_value()) {
+ if (auto const& entry = navigable->active_session_history_entry())
+ entry->document_state->reload_pending = false;
+ }
+
+ if (navigable_id != id())
+ return;
+ if (auto view = this->view(); view.has_value())
+ view->did_not_apply_reload();
+}
+
// 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)
{
@@ -2672,9 +2670,9 @@ void CanonicalTraversable::finish_history_operation(Web::HTML::CrossProcessId op
// The requesting page learns the result before the operation completes.
if (operation->requesting_page)
operation->requesting_page->async_history_step_applied(operation_id, result);
+ if (auto const* reload = operation->parameters.get_pointer<Web::ReloadHistoryOperationParameters>(); reload && result != Web::HTML::HistoryStepResult::Applied)
+ did_not_apply_reload(reload->navigable_id);
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());
}
diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.h
index a8d8d657374..36ce3944860 100644
--- a/Libraries/LibWebView/CanonicalTraversable.h
+++ b/Libraries/LibWebView/CanonicalTraversable.h
@@ -51,10 +51,6 @@ public:
virtual bool is_top_level_traversable() const override { return true; }
- // 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 OnHistoryStepApplied = Function<void(Web::HTML::HistoryStepResult, Optional<i32> committed_step)>;
-
struct BrowserHistoryTraversalDiagnostic {
enum class Stage : u8 {
ApplyingInWebContent,
@@ -67,11 +63,13 @@ public:
Stage stage { Stage::ApplyingInWebContent };
};
- void enqueue_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters, RefPtr<WebContentPage> requesting_page, u64 sequence_number, OnHistoryStepApplied = nullptr);
+ // 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.
+ void enqueue_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters, RefPtr<WebContentPage> requesting_page, u64 sequence_number);
// 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, OnHistoryStepApplied, 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, NonnullRefPtr<Core::Promise<Empty>>);
u64 next_sequence_number() { return m_next_sequence_number++; }
void abandon_history_operations();
@@ -158,7 +156,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(OnHistoryStepApplied = nullptr);
+ void reload();
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 +173,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(OnHistoryStepApplied);
+ void recover_from_web_content_process_crash();
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,9 +214,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(i32 target_step, bool check_for_cancelation, OnHistoryStepApplied = nullptr);
- void run_browser_history_traversal_at_queue_position(i32 target_step, 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 enqueue_browser_history_traversal(i32 target_step, bool check_for_cancelation);
+ void run_browser_history_traversal_at_queue_position(i32 target_step, bool check_for_cancelation, u64 sequence_number, Function<void()> on_ready, 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&);
void apply_history_step(HistoryOperation&, i32 step, bool check_for_cancelation, Optional<Web::HTML::CrossProcessId> initiator_to_check, Web::HTML::UserNavigationInvolvement, Optional<Web::Bindings::NavigationType>, Optional<Web::HTML::NavigationSourceSnapshot> source_snapshot_params = {});
@@ -229,6 +226,7 @@ private:
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 end_history_operation(Web::HTML::CrossProcessId operation_id);
+ void did_not_apply_reload(Web::HTML::CrossProcessId navigable_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>);
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index e91c2af4704..b43690913c1 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -430,11 +430,7 @@ void ViewImplementation::reload()
return;
}
- traversable().reload([this](Web::HTML::HistoryStepResult result, Optional<i32>) {
- if (result != Web::HTML::HistoryStepResult::Applied)
- did_not_apply_reload();
- dump_session_history("reload-complete"sv);
- });
+ traversable().reload();
update_navigation_action_state();
dump_session_history("reload-mark-current-entry-reload-pending"sv);
}
@@ -2970,13 +2966,23 @@ void ViewImplementation::complete_webdriver_navigation(u64 navigation_id)
void ViewImplementation::complete_webdriver_history_traversal(Web::HTML::CrossProcessId operation_id)
{
- if (!m_webdriver_navigation_observation.has_value()
- || m_webdriver_navigation_observation->completion_source != WebDriverNavigationCompletionSource::HistoryTraversal
- || m_webdriver_navigation_observation->history_operation_id != operation_id) {
+ if (!m_webdriver_navigation_observation.has_value() || m_webdriver_navigation_observation->history_operation_id != operation_id)
return;
- }
- complete_webdriver_navigation(m_webdriver_navigation_observation->navigation_id);
+ auto& observation = *m_webdriver_navigation_observation;
+ switch (observation.completion_source) {
+ case WebDriverNavigationCompletionSource::HistoryTraversal:
+ complete_webdriver_navigation(observation.navigation_id);
+ break;
+ // A crash recovery is over once both its traversal and the load it starts are.
+ case WebDriverNavigationCompletionSource::CrashRecovery:
+ observation.history_operation_completed = true;
+ if (observation.load_completed)
+ complete_webdriver_navigation(observation.navigation_id);
+ break;
+ case WebDriverNavigationCompletionSource::Load:
+ break;
+ }
}
JsonValue ViewImplementation::webdriver_session_history() const
@@ -3023,17 +3029,8 @@ void ViewImplementation::recover_current_session_history_entry_with_history_oper
{
m_history_visit_transition_for_next_load = HistoryVisitTransition::Restore;
set_url(traversable().session_history().current_entry().url);
- auto navigation_id = begin_webdriver_navigation(WebDriverNavigationCompletionSource::CrashRecovery);
- traversable().recover_from_web_content_process_crash([this, navigation_id](Web::HTML::HistoryStepResult, Optional<i32>) {
- if (m_webdriver_navigation_observation.has_value()
- && m_webdriver_navigation_observation->navigation_id == navigation_id
- && m_webdriver_navigation_observation->completion_source == WebDriverNavigationCompletionSource::CrashRecovery) {
- m_webdriver_navigation_observation->history_operation_completed = true;
- if (m_webdriver_navigation_observation->load_completed)
- complete_webdriver_navigation(navigation_id);
- }
- dump_session_history("recovered-web-content-process-with-history-operation"sv);
- });
+ begin_webdriver_navigation(WebDriverNavigationCompletionSource::CrashRecovery);
+ traversable().recover_from_web_content_process_crash();
}
void ViewImplementation::reconstruct_current_session_history_entry_with_history_operation(StringView reason)
@@ -3154,24 +3151,6 @@ NonnullRefPtr<Core::Promise<Empty>> ViewImplementation::reset_session_history_fo
return *m_pending_session_history_reset_for_testing;
}
-void ViewImplementation::request_history_operation(Badge<WebContentPage>, WebContentPage& requesting_page, Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters parameters)
-{
- auto sequence_number = traversable().next_sequence_number();
-
- auto reloads_top_level = parameters.visit(
- [this](Web::ReloadHistoryOperationParameters const& parameters) {
- return parameters.navigable_id == traversable().id();
- },
- [](auto const&) { return false; });
- auto on_history_step_applied = [this, reloads_top_level](Web::HTML::HistoryStepResult result, Optional<i32>) {
- if (reloads_top_level && result != Web::HTML::HistoryStepResult::Applied)
- did_not_apply_reload();
- dump_session_history("requested-history-operation-complete"sv);
- };
-
- 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(
Badge<WebContentPage>, Web::HTML::SessionHistoryEntryDescriptor active_entry)
{
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index fca3af15f2d..1040b19bb47 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -368,7 +368,6 @@ public:
void did_change_screen_wake_lock_state(Badge<WebContentPage>, Web::ScreenWakeLockState);
Web::ScreenWakeLockState screen_wake_lock_state() const { return m_screen_wake_lock_state; }
- void request_history_operation(Badge<WebContentPage>, WebContentPage& requesting_page, Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters);
void did_reset_session_history_for_testing(Badge<WebContentPage>, Web::HTML::SessionHistoryEntryDescriptor);
bool capture_session_history_snapshot_for_testing(Badge<WebContentPage>);
bool restore_captured_session_history_snapshot_for_testing(Badge<WebContentPage>);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index d2f56eb67ed..0698d78b936 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1623,7 +1623,7 @@ void WebContentPage::request_history_operation(Web::HTML::CrossProcessId operati
client().did_misbehave("request_history_operation"sv, "resumed traversal to a step before every used step"sv);
return;
}
- view().request_history_operation({}, *this, operation_id, move(parameters));
+ traversable().enqueue_history_operation(operation_id, move(parameters), *this, traversable().next_sequence_number());
}
void WebContentPage::revoke_history_operation(Web::HTML::CrossProcessId operation_id)
diff --git a/Tests/LibWebView/TestSessionHistory.cpp b/Tests/LibWebView/TestSessionHistory.cpp
index 060bb422b7d..2697142d831 100644
--- a/Tests/LibWebView/TestSessionHistory.cpp
+++ b/Tests/LibWebView/TestSessionHistory.cpp
@@ -247,13 +247,7 @@ static Web::HTML::SameDocumentNavigationEntry same_document_entry(Web::HTML::Ses
};
}
-struct HistoryOperationResult {
- Web::HTML::HistoryStepResult result;
- Optional<i32> committed_step;
-};
-
-// 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)
+static void run_canonical_history_operation(WebView::CanonicalTraversable& traversable, Web::HistoryOperationParameters request)
{
auto operation_id = Web::HTML::CrossProcessId { 8, 1 };
RefPtr<WebView::CanonicalSessionHistoryEntry> target_entry;
@@ -264,16 +258,9 @@ static Optional<HistoryOperationResult> run_canonical_history_operation(WebView:
target_entry = traversable.session_history_entry_for(*navigable, parameters.target_entry);
}
- Optional<HistoryOperationResult> result;
auto queue_promise = Core::Promise<Empty>::construct();
- traversable.run_history_operation_at_queue_position(
- operation_id, move(request), {}, {}, move(target_entry),
- [&](auto operation_result, auto committed_step) {
- result = HistoryOperationResult { operation_result, committed_step };
- },
- queue_promise);
+ traversable.run_history_operation_at_queue_position(operation_id, move(request), {}, {}, move(target_entry), queue_promise);
VERIFY(queue_promise->is_resolved());
- return result;
}
static void expect_entry(WebView::TraversableSessionHistory const& history, size_t index, i32 expected_step, StringView expected_url)
@@ -1047,11 +1034,8 @@ TEST_CASE(same_document_push_clears_forward_history_at_queue_position)
.history_handling = Web::HTML::HistoryHandlingBehavior::Push,
.user_involvement = Web::HTML::UserNavigationInvolvement::None,
};
- auto operation_result = run_canonical_history_operation(traversable, move(request));
+ run_canonical_history_operation(traversable, move(request));
- 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);
@@ -1088,9 +1072,8 @@ TEST_CASE(failed_nested_same_document_push_preserves_forward_history)
.history_handling = Web::HTML::HistoryHandlingBehavior::Push,
.user_involvement = Web::HTML::UserNavigationInvolvement::None,
};
- auto operation_result = run_canonical_history_operation(traversable, move(request));
+ run_canonical_history_operation(traversable, move(request));
- EXPECT(!operation_result.has_value());
auto const& history = traversable.session_history();
EXPECT_EQ(history.current_step(), 0);
EXPECT_EQ(history.size(), 2uz);
@@ -1158,11 +1141,8 @@ TEST_CASE(same_document_replacement_replaces_the_active_entry)
.history_handling = Web::HTML::HistoryHandlingBehavior::Replace,
.user_involvement = Web::HTML::UserNavigationInvolvement::None,
};
- auto operation_result = run_canonical_history_operation(traversable, move(request));
+ run_canonical_history_operation(traversable, move(request));
- 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);