Skip to content

Truly independent web browser

LibWeb+LibWebView: Finalize a javascript: URL navigation by its ID

Shannon Boothdcf506a1dd81
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 0559c959ca7..4ae398cb45c 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -972,7 +972,7 @@ void LocalNavigable::continue_navigation_at_population(NavigationPopulationReque
if (output)
output->apply_to(*history_entry);
auto pending_document = output ? output->document : GC::Ptr<DOM::Document> {};
- finalize_a_cross_document_navigation(navigable, to_history_handling_behavior(history_handling), user_involvement, history_entry, pending_document, navigation_id, GC::create_function(navigable->heap(), [](HistoryStepResult) { }));
+ finalize_a_cross_document_navigation(navigable, to_history_handling_behavior(history_handling), user_involvement, history_entry, pending_document, navigation_id, navigation_id, GC::create_function(navigable->heap(), [](HistoryStepResult) { }));
}));
}
@@ -3763,8 +3763,8 @@ void LocalNavigable::begin_navigation(PreparedNavigation navigation)
// 20. If url's scheme is "javascript", then:
if (url.scheme() == "javascript"sv) {
- if (is_top_level_traversable())
- active_browsing_context()->page().client().request_navigation_start(*this, NavigationTarget::TopLevel, url, navigation_id, {});
+ auto target = is_top_level_traversable() ? NavigationTarget::TopLevel : NavigationTarget::IFrame;
+ active_browsing_context()->page().client().request_navigation_start(*this, target, url, navigation_id, {});
// 1. Let request be a new request, with
// URL: url
@@ -4192,8 +4192,7 @@ void LocalNavigable::navigate_to_a_javascript_url(GC::Ref<Fetch::Infrastructure:
// load-event delay and tell the UI that the admitted navigation produced no document.
auto finish_loading_without_navigation = [&] {
stop_delaying_load_events_for_navigation(navigation_id);
- if (is_top_level_traversable())
- active_browsing_context()->page().client().navigation_population_failed(id(), navigation_id);
+ active_browsing_context()->page().client().navigation_population_failed(id(), navigation_id);
};
// 1. Assert: historyHandling is "replace".
@@ -4295,7 +4294,9 @@ void LocalNavigable::navigate_to_a_javascript_url(GC::Ref<Fetch::Infrastructure:
history_entry->set_document_state(document_state);
// 13. Append session history traversal steps to targetNavigable's traversable to finalize a cross-document navigation with targetNavigable, historyHandling, userInvolvement, and historyEntry.
- finalize_a_cross_document_navigation(*this, history_handling, user_involvement, history_entry, new_document, {}, GC::create_function(heap(), [](HistoryStepResult) { }));
+ // NB: The UI process finalizes the navigation it admitted by its ID, though targetNavigable's ongoing navigation is
+ // null from step 3.
+ finalize_a_cross_document_navigation(*this, history_handling, user_involvement, history_entry, new_document, navigation_id, {}, GC::create_function(heap(), [](HistoryStepResult) { }));
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#reload
@@ -4659,13 +4660,13 @@ void check_if_unloading_is_canceled(Vector<GC::Root<LocalNavigable>> navigables_
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#finalize-a-cross-document-navigation
-void finalize_a_cross_document_navigation(GC::Ref<LocalNavigable> navigable, HistoryHandlingBehavior history_handling, UserNavigationInvolvement user_involvement, NonnullRefPtr<SessionHistoryEntry> history_entry, GC::Ptr<DOM::Document> pending_document, Optional<Utf16String> expected_ongoing_navigation_id, GC::Ref<OnApplyHistoryStepComplete> on_complete)
+void finalize_a_cross_document_navigation(GC::Ref<LocalNavigable> navigable, HistoryHandlingBehavior history_handling, UserNavigationInvolvement user_involvement, NonnullRefPtr<SessionHistoryEntry> history_entry, GC::Ptr<DOM::Document> pending_document, Utf16String navigation_id, Optional<Utf16String> expected_ongoing_navigation_id, GC::Ref<OnApplyHistoryStepComplete> on_complete)
{
navigable->page().history_executor().request_history_operation(
FinalizeCrossDocumentNavigationHistoryOperationParameters {
.navigable_id = navigable->id(),
.history_entry = create_pending_session_history_entry_descriptor(*history_entry),
- .navigation_id = expected_ongoing_navigation_id,
+ .navigation_id = move(navigation_id),
.history_handling = history_handling,
.user_involvement = user_involvement,
.environment_id = pending_document ? Optional<Web::HTML::EnvironmentId> { pending_document->relevant_settings_object().id } : Optional<Web::HTML::EnvironmentId> {},
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index 91cd7672fdd..86ad739f75a 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -733,7 +733,7 @@ WEB_API HashTable<GC::RawRef<LocalNavigable>>& all_local_navigables();
WEB_API GC::Ptr<LocalNavigable> local_navigable_with_id(CrossProcessId);
bool navigation_must_be_a_replace(URL::URL const& url, DOM::Document const& document);
-void finalize_a_cross_document_navigation(GC::Ref<LocalNavigable>, HistoryHandlingBehavior, UserNavigationInvolvement, NonnullRefPtr<SessionHistoryEntry>, GC::Ptr<DOM::Document> pending_document, Optional<Utf16String> expected_ongoing_navigation_id, GC::Ref<OnApplyHistoryStepComplete> on_complete);
+void finalize_a_cross_document_navigation(GC::Ref<LocalNavigable>, HistoryHandlingBehavior, UserNavigationInvolvement, NonnullRefPtr<SessionHistoryEntry>, GC::Ptr<DOM::Document> pending_document, Utf16String navigation_id, Optional<Utf16String> expected_ongoing_navigation_id, GC::Ref<OnApplyHistoryStepComplete> on_complete);
enum class CheckIfUnloadingIsCanceledResult {
CanceledByBeforeUnload,
diff --git a/Libraries/LibWebCommon/HTML/HistoryOperation.cpp b/Libraries/LibWebCommon/HTML/HistoryOperation.cpp
index 6f8ad6b9c4e..7b64b73c2e7 100644
--- a/Libraries/LibWebCommon/HTML/HistoryOperation.cpp
+++ b/Libraries/LibWebCommon/HTML/HistoryOperation.cpp
@@ -27,7 +27,7 @@ ErrorOr<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters> IPC::dec
return Web::FinalizeCrossDocumentNavigationHistoryOperationParameters {
.navigable_id = TRY(decoder.decode<Web::HTML::CrossProcessId>()),
.history_entry = TRY(decoder.decode<Web::HTML::PendingSessionHistoryEntryDescriptor>()),
- .navigation_id = TRY(decoder.decode<Optional<Utf16String>>()),
+ .navigation_id = TRY(decoder.decode<Utf16String>()),
.history_handling = TRY(decoder.decode<Web::HTML::HistoryHandlingBehavior>()),
.user_involvement = TRY(decoder.decode<Web::HTML::UserNavigationInvolvement>()),
.environment_id = TRY(decoder.decode<Optional<Web::HTML::EnvironmentId>>()),
diff --git a/Libraries/LibWebCommon/HTML/HistoryOperation.h b/Libraries/LibWebCommon/HTML/HistoryOperation.h
index fac2ae22623..aeb00058068 100644
--- a/Libraries/LibWebCommon/HTML/HistoryOperation.h
+++ b/Libraries/LibWebCommon/HTML/HistoryOperation.h
@@ -25,7 +25,7 @@ namespace Web {
struct FinalizeCrossDocumentNavigationHistoryOperationParameters {
HTML::CrossProcessId navigable_id;
HTML::PendingSessionHistoryEntryDescriptor history_entry;
- Optional<Utf16String> navigation_id;
+ Utf16String navigation_id;
HTML::HistoryHandlingBehavior history_handling;
HTML::UserNavigationInvolvement user_involvement;
Optional<Web::HTML::EnvironmentId> environment_id;
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index d6b96616f2f..6e0bc58304a 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -57,6 +57,15 @@ static Utf16String generate_a_random_uuid()
// A navigation made again from the same source — one the user stopped, or a crash cut short — as a GET: A retry
// shouldn't resubmit a form behind the user's back, so the document resource isn't sent again.
+// The page conducting the navigation: the one evaluating a javascript: URL, otherwise the one hosting the document it
+// populated.
+bool CanonicalNavigation::is_conducted_by(WebContentPage const& page) const
+{
+ if (url.has_value() && url->scheme() == "javascript"sv)
+ return population_worker == &page;
+ return phase == Phase::Populating && host == &page;
+}
+
Web::HTML::PreparedNavigationDescriptor prepare_navigation_to_retry(Web::HTML::PreparedNavigationDescriptor navigation)
{
navigation.document_resource = {};
@@ -784,12 +793,6 @@ Optional<PopulatedDocument> const& CanonicalNavigable::populated_document() cons
return m_document_populated_by_history_job;
}
-RefPtr<CanonicalDocumentState> CanonicalNavigable::populating_document_state() const
-{
- auto const& populated_document = this->populated_document();
- return populated_document.has_value() ? populated_document->document_state.ptr() : nullptr;
-}
-
RefPtr<CanonicalDocument> CanonicalNavigable::pending_document() const
{
auto const& populated_document = this->populated_document();
@@ -806,6 +809,16 @@ RefPtr<CanonicalDocument> CanonicalNavigable::document_populated_for(CanonicalDo
return document;
}
+PopulatedDocument const* CanonicalNavigable::populated_document_with_state_id(Web::HTML::CrossProcessId document_state_id) const
+{
+ PopulatedDocument const* result = nullptr;
+ for_each_populated_document([&](PopulatedDocument const& populated_document) {
+ if (populated_document.document_state->id == document_state_id)
+ result = &populated_document;
+ });
+ return result;
+}
+
RefPtr<CanonicalDocument> CanonicalNavigable::document_with_id(Web::HTML::CrossProcessId id) const
{
if (active_document().id() == id)
@@ -887,22 +900,21 @@ void CanonicalNavigable::did_create_populated_document_with_an_origin_of_its_own
populated_document->document = move(document);
}
-// The history operation finalizing the ongoing navigation takes it: the one it names, or for a javascript: URL, which
-// names none, the one admitted before it. The document populated for the navigation waits on the navigable as a
-// history job's until the operation activates it.
-Optional<CanonicalNavigation> CanonicalNavigable::take_navigation_to_finalize(Optional<Utf16String> const& navigation_id, u64 operation_sequence_number)
+// The history operation finalizing the navigation takes it from the navigable at its queue position. A newer navigation
+// can still start before the operation applies the history step, which sets the ongoing navigation to "traversal". The
+// document populated for the navigation waits on the navigable as a history job's until the operation activates it.
+Optional<CanonicalNavigation> CanonicalNavigable::take_navigation_to_finalize(Utf16String const& navigation_id, WebContentPage const& page)
{
- if (!ongoing_navigation())
- return {};
- if (navigation_id.has_value() ? ongoing_navigation()->navigation_id != navigation_id : ongoing_navigation()->sequence_number > operation_sequence_number)
+ auto* navigation = ongoing_navigation();
+ if (!navigation || navigation->navigation_id != navigation_id || !navigation->is_conducted_by(page))
return {};
- if (ongoing_navigation()->populated_document.has_value()) {
+ if (navigation->populated_document.has_value()) {
abandon_populated_document(m_document_populated_by_history_job);
- m_document_populated_by_history_job = ongoing_navigation()->populated_document.release_value();
+ m_document_populated_by_history_job = navigation->populated_document.release_value();
}
- auto navigation = move(*ongoing_navigation());
+ auto taken_navigation = move(*navigation);
m_ongoing_navigation = Empty {};
- return navigation;
+ return taken_navigation;
}
void CanonicalNavigable::abandon_populated_document(CanonicalDocument const& document)
@@ -1356,14 +1368,6 @@ bool CanonicalNavigable::navigation_owner_matches(WebContentPage const& page) co
return navigation_population_worker_matches(page) || navigation_host_matches(page);
}
-bool CanonicalNavigable::navigation_transaction_matches(Utf16String const& navigation_id, WebContentPage const& page) const
-{
- return ongoing_navigation()
- && ongoing_navigation()->navigation_id == navigation_id
- && ongoing_navigation()->phase == CanonicalNavigation::Phase::Populating
- && navigation_host_matches(page);
-}
-
bool CanonicalNavigable::cancel_navigation_transaction_for_client(WebContentClient& client)
{
if (!ongoing_navigation())
@@ -1379,19 +1383,16 @@ bool CanonicalNavigable::cancel_navigation_transaction_for_client(WebContentClie
return true;
}
-void CanonicalNavigable::did_finish_navigation_transaction(Optional<Utf16String> const& navigation_id, Web::HTML::HistoryStepResult result)
+// 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::CrossProcessId document_state_id, Web::HTML::HistoryStepResult result)
{
- if (!navigation_id.has_value())
- return;
-
- // A transaction still live at its operation's completion never activated its document.
- if (ongoing_navigation() && ongoing_navigation()->navigation_id == navigation_id)
- clear_ongoing_navigation();
-
- if (result != Web::HTML::HistoryStepResult::Applied
- && m_active_document_load.navigation_id == navigation_id) {
- clear_active_document_load();
+ if (auto const* populated_document = populated_document_with_state_id(document_state_id)) {
+ NonnullRefPtr document = populated_document->document;
+ abandon_populated_document(*document);
}
+ if (result != Web::HTML::HistoryStepResult::Applied && m_active_document_load.navigation_id == navigation_id)
+ clear_active_document_load();
}
bool CanonicalNavigable::matches_ongoing_navigation(Optional<Utf16String> const& navigation_id) const
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index 41492e5d911..d1d2c70d85f 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -94,16 +94,16 @@ public:
// for a navigation goes with the navigation until a history job claims it to activate it; one a history job
// populated or claimed goes when the job's operation finishes. A newer navigation can populate its own document
// while a claimed one waits to be activated.
- RefPtr<CanonicalDocumentState> populating_document_state() const;
RefPtr<CanonicalDocument> pending_document() const;
RefPtr<CanonicalDocument> document_populated_for(CanonicalDocumentState const&) const;
+ PopulatedDocument const* populated_document_with_state_id(Web::HTML::CrossProcessId) const;
RefPtr<CanonicalDocument> document_with_id(Web::HTML::CrossProcessId) const;
void populate_document(NonnullRefPtr<CanonicalDocumentState>, NonnullRefPtr<CanonicalDocument>, Optional<URL::Origin> inline_content_origin = {});
void populate_document_for_ongoing_navigation(NonnullRefPtr<CanonicalDocumentState>, NonnullRefPtr<CanonicalDocument>, Optional<URL::Origin> inline_content_origin = {});
// Returns false, populating nothing, for a document that would hold access the active document lacks.
bool populate_document_for_javascript_url(NonnullRefPtr<CanonicalDocumentState>, NonnullRefPtr<CanonicalDocument>);
void did_create_populated_document_with_an_origin_of_its_own(WebContentPage const& host, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin, Web::HTML::EnvironmentId const& environment_id);
- Optional<CanonicalNavigation> take_navigation_to_finalize(Optional<Utf16String> const& navigation_id, u64 operation_sequence_number);
+ Optional<CanonicalNavigation> take_navigation_to_finalize(Utf16String const& navigation_id, WebContentPage const&);
void abandon_populated_document(CanonicalDocument const&);
void place_pending_document(WebContentPage&);
@@ -236,9 +236,8 @@ public:
void set_navigation_host(WebContentPage&);
bool navigation_host_matches(WebContentPage const&) const;
bool navigation_owner_matches(WebContentPage const&) const;
- bool navigation_transaction_matches(Utf16String const&, WebContentPage const&) const;
bool cancel_navigation_transaction_for_client(WebContentClient&);
- void did_finish_navigation_transaction(Optional<Utf16String> const&, Web::HTML::HistoryStepResult);
+ void did_finish_finalizing_navigation(Utf16String const& navigation_id, Web::HTML::CrossProcessId document_state_id, Web::HTML::HistoryStepResult);
bool has_uncommitted_navigation() const { return ongoing_navigation(); }
bool matches_ongoing_navigation(Optional<Utf16String> const& navigation_id) const;
diff --git a/Libraries/LibWebView/CanonicalNavigation.h b/Libraries/LibWebView/CanonicalNavigation.h
index 6a6f8a19fec..0453a7c5a0b 100644
--- a/Libraries/LibWebView/CanonicalNavigation.h
+++ b/Libraries/LibWebView/CanonicalNavigation.h
@@ -52,6 +52,8 @@ public:
RefPtr<WebContentPage> population_worker {};
RefPtr<WebContentPage> host {};
Optional<PopulatedDocument> populated_document {};
+
+ bool is_conducted_by(WebContentPage const&) const;
};
WEBVIEW_API Web::HTML::PreparedNavigationDescriptor prepare_navigation_to_retry(Web::HTML::PreparedNavigationDescriptor);
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index baa89b7117e..44a7b908fbf 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -973,9 +973,8 @@ struct CanonicalTraversable::HistoryOperation {
Vector<NonnullRefPtr<WebContentPage>> completion_endpoints;
u64 sequence_number;
bool was_initiated_by_browser { false };
- bool owns_navigation_transaction { false };
- // The navigation a cross-document navigation's finalization finalizes, which it takes from the navigable when it
- // applies the history step: the navigable's ongoing navigation is "traversal" from then on.
+ // The navigation a cross-document navigation's finalization finalizes, which it takes from the navigable at its
+ // queue position.
Optional<CanonicalNavigation> finalized_navigation;
bool check_for_cancelation { false };
Function<void()> on_browser_traversal_ready;
@@ -1345,14 +1344,7 @@ bool CanonicalTraversable::navigation_transaction_matches(HistoryOperation const
if (!navigable.has_value())
return false;
- // A javascript: navigation clears the spec's ongoing-navigation value before finalization and therefore has no
- // UI-owned population transaction. It must still come from the process hosting the active document.
- if (!parameters.navigation_id.has_value())
- return page_hosting(*navigable) == page;
-
- if (operation.finalized_navigation.has_value())
- return operation.finalized_navigation->host == &page;
- return navigable->navigation_transaction_matches(*parameters.navigation_id, page);
+ return operation.finalized_navigation.has_value() && operation.finalized_navigation->is_conducted_by(page);
}
void CanonicalTraversable::add_history_operation_completion_endpoint(HistoryOperation& operation, NonnullRefPtr<WebContentPage> endpoint)
@@ -2535,9 +2527,10 @@ void CanonicalTraversable::start_history_operation(HistoryOperation& operation,
return;
}
- if (operation.parameters.has<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>()) {
- operation.owns_navigation_transaction = navigation_transaction_matches(operation, *operation.initiating_page);
- if (!operation.owns_navigation_transaction) {
+ if (auto const* parameters = operation.parameters.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>()) {
+ if (auto navigable = find(parameters->navigable_id); navigable.has_value())
+ operation.finalized_navigation = navigable->take_navigation_to_finalize(parameters->navigation_id, *operation.initiating_page);
+ if (!operation.finalized_navigation.has_value()) {
finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::Applied, {});
return;
}
@@ -2558,8 +2551,8 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
// NB: historyEntry's document state is the navigation's documentState, which holds the document it populated.
CanonicalSessionHistoryEntry::DocumentStates document_states;
- if (auto document_state = navigable->populating_document_state(); document_state && document_state->id == parameters.history_entry.document_state.id)
- document_states.set(document_state->id, *document_state);
+ if (auto const* populated_document = navigable->populated_document_with_state_id(parameters.history_entry.document_state.id))
+ document_states.set(populated_document->document_state->id, populated_document->document_state);
auto history_entry_or_error = CanonicalSessionHistoryEntry::create_from_descriptor(Web::HTML::create_session_history_entry_descriptor(parameters.history_entry, 0), document_states, CanonicalSessionHistoryEntry::UpdateDocumentState::Yes);
if (history_entry_or_error.is_error()) {
finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::NoMatchingEntry, {});
@@ -2569,9 +2562,9 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate-to-a-javascript:-url
// NB: The process running a javascript: URL navigation evaluates it, creates newDocument in navigable's active
- // browsing context, and reports historyEntry with these steps, without a navigation ID. The UI process runs the
- // steps that decide newDocument's origin, and populates the document it holds for historyEntry's document state.
- if (!parameters.navigation_id.has_value()) {
+ // browsing context, and reports historyEntry with these steps. The UI process runs the steps that decide
+ // newDocument's origin, and populates the document it holds for historyEntry's document state.
+ if (auto const& url = operation.finalized_navigation->url; url.has_value() && url->scheme() == "javascript"sv) {
auto const& initiator_origin = history_entry->document_state->initiator_origin;
// 4. If initiatorOrigin is not same origin-domain with targetNavigable's active document's origin, then return.
@@ -2623,7 +2616,7 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
// 3. If historyEntry's document is null, then return.
// NB: The document populated for historyEntry's document state waits on navigable until historyEntry is activated.
- RefPtr<CanonicalDocument> document = navigable->populating_document_state().ptr() == history_entry->document_state.ptr() ? navigable->pending_document() : nullptr;
+ RefPtr<CanonicalDocument> document = navigable->document_populated_for(*history_entry->document_state);
if (!document) {
if (navigable->is_top_level_traversable()) {
if (auto view = this->view(); view.has_value())
@@ -2711,10 +2704,6 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation
target_step = *current_step;
}
- // NB: Applying the history step sets navigable's ongoing navigation to "traversal". This operation holds the
- // navigation it finalizes until it is over.
- operation.finalized_navigation = navigable->take_navigation_to_finalize(parameters.navigation_id, operation.sequence_number);
-
// 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);
}
@@ -2758,10 +2747,10 @@ void CanonicalTraversable::finish_history_operation(Web::HTML::CrossProcessId op
// stays with the operation: its completion can be what finished it.
for (auto const& [navigable_id, pending_job] : taken_operation.pending_changing_jobs)
pending_job->abandon(find(navigable_id));
- if (taken_operation.owns_navigation_transaction) {
+ if (taken_operation.finalized_navigation.has_value()) {
auto const& parameters = taken_operation.parameters.get<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>();
if (auto navigable = find(parameters.navigable_id); navigable.has_value())
- navigable->did_finish_navigation_transaction(parameters.navigation_id, result);
+ navigable->did_finish_finalizing_navigation(parameters.navigation_id, parameters.history_entry.document_state.id, result);
}
if (committed_step.has_value()) {
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index b06d1df515d..e4bee7695f9 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -2489,6 +2489,8 @@ void ViewImplementation::did_start_navigation(Optional<Utf16String> const& navig
bool ViewImplementation::did_cancel_navigation(Optional<Utf16String> const& navigation_id)
{
auto const* ongoing = traversable().ongoing_navigation();
+ if (!ongoing)
+ ongoing = traversable().navigation_being_finalized();
auto stale = ongoing
? navigation_id != ongoing->navigation_id
: navigation_id != traversable().active_document_load().navigation_id;
diff --git a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
index e466fbf9538..65bddc6fd3d 100644
--- a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
+++ b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
@@ -270,14 +270,11 @@ TEST_CASE(document_claimed_by_a_history_job_outlives_a_newer_navigation)
auto make_document = [] { return WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document; };
traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, make_document())));
- // The history operation finalizing a navigation takes it, with the document populated for it.
+ // The history operation finalizing a navigation took it, and holds the document populated for it as a history job's.
auto claimed_navigation_id = Utf16String::from_utf8("claimed"sv);
auto claimed_document_state = WebView::CanonicalDocumentState::create({});
auto claimed_document = make_document();
- traversable.set_ongoing_navigation(WebView::CanonicalNavigation { .navigation_id = claimed_navigation_id });
- traversable.populate_document_for_ongoing_navigation(claimed_document_state, claimed_document);
- EXPECT(traversable.take_navigation_to_finalize(claimed_navigation_id, 1).has_value());
- EXPECT(!traversable.ongoing_navigation());
+ traversable.populate_document(claimed_document_state, claimed_document);
// A newer navigation starts before the claimed document is activated, and populates its own.
traversable.set_ongoing_navigation(WebView::CanonicalNavigation { .navigation_id = Utf16String::from_utf8("newer"sv) });