Skip to content

Truly independent web browser

LibWebView: Assert that a pending history step job has a page

Shannon Booth27d6ea0bc827
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 82c7c12100f..db2ecc32d2c 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -1335,9 +1335,7 @@ void CanonicalTraversable::continue_history_navigation_population(HistoryOperati
{
if (!changing_navigable.population_loader)
return;
- auto endpoint = changing_job_endpoint(changing_navigable);
- if (!endpoint)
- return;
+ RefPtr<WebContentPage> endpoint = changing_job_endpoint(changing_navigable);
auto loader = move(changing_navigable.population_loader);
NonnullRefPtr target_entry = *changing_navigable.target_entry;
@@ -1392,7 +1390,7 @@ bool CanonicalTraversable::run_changing_navigable_history_step_job(ApplyHistoryS
auto navigable_id = changing_navigable.id;
auto& navigable = changing_navigable.navigable();
auto endpoint = changing_job_endpoint(changing_navigable);
- if (!endpoint || !endpoint->is_open())
+ if (!endpoint->is_open())
return false;
if (navigable.is_top_level_traversable()) {
@@ -1413,11 +1411,9 @@ bool CanonicalTraversable::run_changing_navigable_history_step_job(ApplyHistoryS
// dispatched instead of having the job echo it back.
if (navigable.is_top_level_traversable()
&& operation.parameters.has<Web::ReloadHistoryOperationParameters>()) {
- if (endpoint->is_open()) {
- // A load a history operation starts, rather than a navigation, is tracked as the active document's.
- clear_active_document_load();
- endpoint->begin_top_level_load(changing_navigable.target_entry->url);
- }
+ // A load a history operation starts, rather than a navigation, is tracked as the active document's.
+ clear_active_document_load();
+ endpoint->begin_top_level_load(changing_navigable.target_entry->url);
}
Optional<Utf16String> finalized_navigation_id;
@@ -1470,8 +1466,6 @@ void CanonicalTraversable::send_changing_navigable_continuation_task(HistoryOper
VERIFY(changing_navigable.has_pending_job());
VERIFY(changing_navigable.continuation.has_value());
auto endpoint = changing_job_endpoint(changing_navigable);
- if (!endpoint)
- return;
auto const& document_state = *changing_navigable.target_entry->document_state;
if (changing_navigable.unload_displayed_document == Web::HTML::UnloadDisplayedDocument::Yes && changing_navigable.target_entry_reload_pending
@@ -1516,8 +1510,6 @@ void CanonicalTraversable::deactivate_a_document_for_cross_document_navigation(H
changing_navigable.navigable().clear_ongoing_navigation_traversal(operation.operation_id);
auto endpoint = changing_job_endpoint(changing_navigable);
- if (!endpoint)
- return;
endpoint->owe_reply({ OwedReply::Kind::UnloadPreparation, operation.operation_id, changing_navigable.id });
endpoint->async_prepare_changing_navigable_for_unload(operation.operation_id, changing_navigable.id);
@@ -1538,10 +1530,7 @@ void CanonicalTraversable::unload_displayed_document_for_cross_document_navigati
// 5. If potentiallyTriggerViewTransition is false, then:
// 3. Unload a document and its descendants given displayedDocument, targetEntry's document,
// afterPotentialUnloads, and firePageSwapBeforeUnload.
- auto endpoint = changing_job_endpoint(changing_navigable);
- if (!endpoint)
- return;
- unload_a_document_and_its_descendants(changing_navigable.id, *endpoint, Web::HTML::ChildNavigableDestruction::No, [this, operation_id = operation.operation_id, navigable_id = changing_navigable.id](UnloadedInItsHost) {
+ unload_a_document_and_its_descendants(changing_navigable.id, changing_job_endpoint(changing_navigable), Web::HTML::ChildNavigableDestruction::No, [this, operation_id = operation.operation_id, navigable_id = changing_navigable.id](UnloadedInItsHost) {
// afterPotentialUnloads runs in the continuation task, in the process running the job. That process first
// unloads the document it displays: displayedDocument, or the stand-in of a host chosen for the new document.
auto* operation = find_history_operation(operation_id);
@@ -1792,9 +1781,13 @@ RefPtr<WebContentPage> CanonicalTraversable::changing_job_endpoint(CanonicalNavi
return page_hosting(navigable);
}
-RefPtr<WebContentPage> CanonicalTraversable::changing_job_endpoint(ChangingNavigable const& changing_navigable) const
+// NB: A pending job's navigable is in the tree, so its document's page, or the page holding its container, is there: a
+// navigable whose container's page is lost is removed with it, ending its job.
+NonnullRefPtr<WebContentPage> CanonicalTraversable::changing_job_endpoint(ChangingNavigable const& changing_navigable) const
{
- return changing_job_endpoint(changing_navigable.navigable(), *changing_navigable.target_entry->document_state);
+ auto endpoint = changing_job_endpoint(changing_navigable.navigable(), *changing_navigable.target_entry->document_state);
+ VERIFY(endpoint);
+ return endpoint.release_nonnull();
}
void CanonicalTraversable::did_receive_descendant_unload_task_complete(WebContentPage& source_page, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id)
@@ -1875,8 +1868,7 @@ void CanonicalTraversable::check_if_unloading_is_canceled(ApplyHistoryStep& run,
void CanonicalTraversable::queue_navigation_api_state_clear_task(ApplyHistoryStep& run, ChangingNavigable& changing_navigable)
{
auto endpoint = page_hosting(changing_navigable.navigable());
- if (!endpoint)
- return;
+ VERIFY(endpoint);
add_history_operation_completion_endpoint(run.operation(), *endpoint);
endpoint->async_queue_navigation_api_state_clear_task(changing_navigable.id);
}
diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.h
index 8b429d1705e..d4b9603a3a3 100644
--- a/Libraries/LibWebView/CanonicalTraversable.h
+++ b/Libraries/LibWebView/CanonicalTraversable.h
@@ -209,7 +209,7 @@ private:
void unload_document_in_its_host(NonnullRefPtr<WebContentPage>, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChildNavigableDestruction, Function<void()> after_unload);
void stand_in_for_lost_document(CanonicalNavigable&);
RefPtr<WebContentPage> changing_job_endpoint(CanonicalNavigable const&, CanonicalDocumentState const& target_document_state) const;
- RefPtr<WebContentPage> changing_job_endpoint(ChangingNavigable const&) const;
+ NonnullRefPtr<WebContentPage> changing_job_endpoint(ChangingNavigable const&) const;
void dispatch_descendant_unload_task(Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id);
void complete_descendant_unload_task(Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id);
void run_history_operation(HistoryOperation&);
diff --git a/Tests/LibWebView/TestSessionHistory.cpp b/Tests/LibWebView/TestSessionHistory.cpp
index 31da5e2c490..8326aa84f7b 100644
--- a/Tests/LibWebView/TestSessionHistory.cpp
+++ b/Tests/LibWebView/TestSessionHistory.cpp
@@ -258,22 +258,6 @@ static Web::HTML::SameDocumentNavigationEntry same_document_entry(Web::HTML::Ses
};
}
-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;
- if (request.has<Web::FinalizeSameDocumentNavigationHistoryOperationParameters>()) {
- auto const& parameters = request.get<Web::FinalizeSameDocumentNavigationHistoryOperationParameters>();
- auto navigable = traversable.find(parameters.navigable_id);
- if (navigable.has_value())
- target_entry = traversable.session_history_entry_for(*navigable, parameters.target_entry);
- }
-
- auto queue_promise = Core::Promise<Empty>::construct();
- traversable.run_history_operation_at_queue_position(operation_id, move(request), {}, {}, move(target_entry), queue_promise);
- VERIFY(queue_promise->is_resolved());
-}
-
TEST_CASE(fragment_directive_state_is_separate_from_entry_url)
{
auto entry = create_test_entry(0, parse_url("https://example.test/#feature-detectability"sv));
@@ -297,44 +281,6 @@ TEST_CASE(fragment_directive_state_is_separate_from_entry_url)
EXPECT_EQ(descriptor.directive_state_value, "text=For-,feature%20detectability"sv);
}
-TEST_CASE(replace_navigation_updates_every_shared_directive_state_descriptor)
-{
- Core::EventLoop event_loop;
- WebView::CanonicalTraversable traversable({ 9, 1 }, canonical_entry(entry(0, "https://example.test/initial"sv)));
- give_active_document(traversable);
- auto shared_directive_state_id = test_document_state_id(3000);
-
- auto first_entry = entry(0, "https://example.test/first"sv);
- first_entry.navigation_api_key = "first-key"_utf16;
- first_entry.directive_state_id = shared_directive_state_id;
- first_entry.directive_state_value = "text=old"_string;
-
- auto second_entry = entry(1, "https://example.test/second"sv);
- second_entry.navigation_api_key = "second-key"_utf16;
- second_entry.directive_state_id = shared_directive_state_id;
- second_entry.directive_state_value = "text=old"_string;
-
- EXPECT(traversable.initialize_session_history_for_testing({ first_entry, second_entry }, { 0, 1 }, 1));
-
- auto target_entry = second_entry;
- target_entry.directive_state_value = "text=new"_string;
- auto request = Web::FinalizeSameDocumentNavigationHistoryOperationParameters {
- .navigable_id = traversable.id(),
- .target_entry = same_document_entry(move(target_entry)),
- .entry_to_replace = Web::HTML::SessionHistoryEntryIdentity {
- .document_state_id = second_entry.document_state.id,
- .navigation_api_id = second_entry.navigation_api_id,
- },
- .previous_entry_persisted_state = {},
- .history_handling = Web::HTML::HistoryHandlingBehavior::Replace,
- .user_involvement = Web::HTML::UserNavigationInvolvement::None,
- };
- run_canonical_history_operation(traversable, move(request));
-
- EXPECT_EQ(traversable.session_history().entry_at(0)->directive_state_value, "text=new"sv);
- EXPECT_EQ(traversable.session_history().entry_at(1)->directive_state_value, "text=new"sv);
-}
-
static void expect_entry(WebView::TraversableSessionHistory const& history, size_t index, i32 expected_step, StringView expected_url)
{
auto* entry = history.entry_at(index);
@@ -1085,81 +1031,6 @@ TEST_CASE(nested_cross_document_replacement_updates_copied_session_histories)
}
}
-TEST_CASE(same_document_push_clears_forward_history_at_queue_position)
-{
- Core::EventLoop event_loop;
- WebView::CanonicalTraversable traversable { {}, initial_history_entry() };
- traversable.set_id({ 9, 1 });
- give_active_document(traversable);
-
- auto current_entry = entry(0, "https://example.com/current"sv, 10, "main"sv);
- current_entry.navigation_api_key = Utf16String::from_utf8("current"sv);
- current_entry.navigation_api_id = Utf16String::from_utf8("current-id"sv);
- auto update_result = traversable.initialize_session_history_for_testing(
- { move(current_entry), entry(2, "https://example.com/forward"sv) }, { 0, 2 }, 0);
- EXPECT_EQ(update_result, true);
-
- auto target_entry = entry(0, "https://example.com/pushed"sv, 10, "main"sv);
- target_entry.navigation_api_key = Utf16String::from_utf8("pushed"sv);
- target_entry.navigation_api_id = Utf16String::from_utf8("pushed-id"sv);
- auto request = Web::FinalizeSameDocumentNavigationHistoryOperationParameters {
- .navigable_id = traversable.id(),
- .target_entry = same_document_entry(move(target_entry)),
- .entry_to_replace = {},
- .previous_entry_persisted_state = {},
- .history_handling = Web::HTML::HistoryHandlingBehavior::Push,
- .user_involvement = Web::HTML::UserNavigationInvolvement::None,
- };
- run_canonical_history_operation(traversable, move(request));
-
- auto const& history = traversable.session_history();
- EXPECT_EQ(history.current_step(), 1);
- EXPECT_EQ(history.size(), 2uz);
- expect_entry(history, 0, 0, "https://example.com/current"sv);
- expect_entry(history, 1, 1, "https://example.com/pushed"sv);
- expect_current_entry(history, 1, "https://example.com/pushed"sv);
-}
-
-TEST_CASE(failed_nested_same_document_push_preserves_forward_history)
-{
- Core::EventLoop event_loop;
- WebView::CanonicalTraversable traversable { {}, initial_history_entry() };
- traversable.set_id({ 9, 1 });
- give_active_document(traversable);
- auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame"sv)));
-
- auto nested_entry = entry(1, "https://frame.example/current"sv, 20, ""sv);
- auto update_result = traversable.initialize_session_history_for_testing(
- {
- entry(0, "https://top.example/current"sv),
- entry(2, "https://top.example/forward"sv, { nested_history("frame"sv, { move(nested_entry) }) }),
- },
- { 0, 1, 2 }, 0);
- EXPECT_EQ(update_result, true);
-
- auto target_entry = entry(0, "https://frame.example/pushed"sv, 20, ""sv);
- target_entry.navigation_api_key = Utf16String::from_utf8("pushed"sv);
- target_entry.navigation_api_id = Utf16String::from_utf8("pushed-id"sv);
- auto request = Web::FinalizeSameDocumentNavigationHistoryOperationParameters {
- .navigable_id = child.id(),
- .target_entry = same_document_entry(move(target_entry)),
- .entry_to_replace = {},
- .previous_entry_persisted_state = {},
- .history_handling = Web::HTML::HistoryHandlingBehavior::Push,
- .user_involvement = Web::HTML::UserNavigationInvolvement::None,
- };
- run_canonical_history_operation(traversable, move(request));
-
- auto const& history = traversable.session_history();
- EXPECT_EQ(history.current_step(), 0);
- EXPECT_EQ(history.size(), 2uz);
- EXPECT_EQ(history.used_step_count(), 3uz);
- EXPECT(can_go_forward(history));
- expect_entry(history, 0, 0, "https://top.example/current"sv);
- expect_entry(history, 1, 2, "https://top.example/forward"sv);
- expect_nested_history(*history.entry_at(1), 0, "frame"sv, 1);
-}
-
TEST_CASE(failed_nested_cross_document_push_preserves_forward_history)
{
WebView::CanonicalTraversable traversable { {}, initial_history_entry() };
@@ -1189,43 +1060,6 @@ TEST_CASE(failed_nested_cross_document_push_preserves_forward_history)
expect_nested_history(*history.entry_at(1), 0, "frame"sv, 1);
}
-TEST_CASE(same_document_replacement_replaces_the_active_entry)
-{
- Core::EventLoop event_loop;
- WebView::CanonicalTraversable traversable { {}, initial_history_entry() };
- traversable.set_id({ 9, 1 });
- give_active_document(traversable);
-
- auto current_entry = entry(0, "https://example.com/current"sv, 10, "main"sv);
- current_entry.navigation_api_key = Utf16String::from_utf8("current"sv);
- current_entry.navigation_api_id = Utf16String::from_utf8("current-id"sv);
- auto update_result = traversable.initialize_session_history_for_testing(
- { move(current_entry), entry(2, "https://example.com/forward"sv) }, { 0, 2 }, 0);
- EXPECT_EQ(update_result, true);
-
- auto target_entry = entry(0, "https://example.com/replaced"sv, 10, "main"sv);
- target_entry.navigation_api_key = Utf16String::from_utf8("replacement"sv);
- target_entry.navigation_api_id = Utf16String::from_utf8("replacement-id"sv);
- auto request = Web::FinalizeSameDocumentNavigationHistoryOperationParameters {
- .navigable_id = traversable.id(),
- .target_entry = same_document_entry(move(target_entry)),
- .entry_to_replace = Web::HTML::SessionHistoryEntryIdentity {
- .document_state_id = test_document_state_id(10),
- .navigation_api_id = Utf16String::from_utf8("current-id"sv),
- },
- .previous_entry_persisted_state = {},
- .history_handling = Web::HTML::HistoryHandlingBehavior::Replace,
- .user_involvement = Web::HTML::UserNavigationInvolvement::None,
- };
- run_canonical_history_operation(traversable, move(request));
-
- auto const& history = traversable.session_history();
- EXPECT_EQ(history.current_step(), 0);
- EXPECT_EQ(history.size(), 2uz);
- expect_current_entry(history, 0, "https://example.com/replaced"sv);
- expect_entry(history, 1, 2, "https://example.com/forward"sv);
-}
-
TEST_CASE(nested_finalization_rejects_a_changed_initial_entry_identity)
{
WebView::CanonicalTraversable traversable { {}, initial_history_entry() };