Skip to content

Truly independent web browser

LibWeb+LibWebView: Clear a navigable's traversal without a round trip

Shannon Booth6e4c46dd51e3
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.cpp b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
index dc641602838..38c7623962e 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.cpp
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
@@ -627,19 +627,15 @@ void HistoryExecutor::run_ui_changing_navigable_history_job(CrossProcessId opera
}));
}
-void HistoryExecutor::prepare_ui_changing_navigable_for_unload(CrossProcessId operation_id, CrossProcessId navigable_id, GC::Ref<GC::Function<void()>> on_complete)
+// Step 5.2 of deactivate a document for a cross-document navigation: set navigable's ongoing navigation to null.
+// NB: This mirrors it for the navigable whose job this operation's continuation is, and leaves a newer navigation's.
+void HistoryExecutor::clear_ui_changing_navigable_ongoing_traversal(CrossProcessId operation_id, CrossProcessId navigable_id)
{
auto* operation = find_history_operation(operation_id);
auto job = operation ? operation->changing_navigable_jobs.get(navigable_id) : OptionalNone {};
- if (!job.has_value() || !job->continuation) {
- on_complete->function()();
+ if (!job.has_value() || !job->continuation)
return;
- }
-
- // Step 5.2 of deactivate a document for a cross-document navigation: set navigable's ongoing navigation to null.
- if (auto navigable = local_navigable_with_id(navigable_id))
- navigable->clear_ongoing_history_traversal();
- on_complete->function()();
+ job->continuation->navigable->clear_ongoing_history_traversal();
}
// Steps 14.4 to 14.9 and step 14.12 of apply the history step, for the changing navigable continuation the UI process
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.h b/Libraries/LibWeb/HTML/HistoryExecutor.h
index 283baabfffe..741efad52ca 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.h
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.h
@@ -69,9 +69,9 @@ public:
void run_ui_beforeunload_check(Vector<CrossProcessId> navigable_ids, Optional<SessionHistoryEntryDescriptor> target_entry, Optional<UserNavigationInvolvement> user_involvement_for_navigate_event, UnloadPromptShown, GC::Ref<GC::Function<void(CheckIfUnloadingIsCanceledResult, UnloadPromptShown)>>);
void run_ui_changing_navigable_history_job(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryDescriptor target_entry_descriptor, UserNavigationInvolvement, Optional<Bindings::NavigationType>, TraversalYieldsTo, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id, Optional<NavigationSourceSnapshot>, GC::Ref<OnChangingNavigableHistoryStepJobComplete>, Optional<HistoryNavigationPopulation> = {});
bool resume_history_navigation_population(CrossProcessId operation_id, HistoryNavigationPopulation&&);
- void prepare_ui_changing_navigable_for_unload(CrossProcessId operation_id, CrossProcessId navigable_id, GC::Ref<GC::Function<void()>> on_complete);
void apply_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryIdentity target_entry_identity, HistoryObjectLengthAndIndex, Vector<SessionHistoryEntryDescriptor> entries_for_navigation_api, GC::Ref<OnChangingNavigableContinuationApplied>);
void unload_displayed_document_and_apply_ui_changing_navigable_continuation(CrossProcessId operation_id, CrossProcessId navigable_id, SessionHistoryEntryIdentity target_entry_identity, HistoryObjectLengthAndIndex, Vector<SessionHistoryEntryDescriptor> entries_for_navigation_api, GC::Ref<OnChangingNavigableContinuationApplied>);
+ void clear_ui_changing_navigable_ongoing_traversal(CrossProcessId operation_id, CrossProcessId navigable_id);
private:
explicit HistoryExecutor(Page&);
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 2caf20e6d0b..23313299866 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -1240,7 +1240,6 @@ void CanonicalTraversable::did_not_receive_reply(OwedReply const& owed)
return;
}
case OwedReply::Kind::ChangingJob:
- case OwedReply::Kind::UnloadPreparation:
case OwedReply::Kind::ContinuationApplied: {
auto* operation = find_history_operation(owed.id);
if (!operation || awaits_crash_recovery)
@@ -1511,7 +1510,6 @@ void CanonicalTraversable::send_displayed_document_unload_task(HistoryOperation&
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#deactivate-a-document-for-a-cross-document-navigation
void CanonicalTraversable::deactivate_a_document_for_cross_document_navigation(HistoryOperation& operation, ChangingNavigable& changing_navigable)
{
-
// 1. Let navigable be displayedDocument's node navigable.
// 2. Let potentiallyTriggerViewTransition be false.
// FIXME: 3. Let isBrowserUINavigation be true if userNavigationInvolvement is "browser UI"; otherwise false.
@@ -1524,13 +1522,21 @@ void CanonicalTraversable::deactivate_a_document_for_cross_document_navigation(H
// 1. Fire the pageswap event given displayedDocument, targetEntry, navigationType, and null.
// 2. Set navigable's ongoing navigation to null.
- // NB: The process running the job applies this step to its projection of the navigable, and reports back before
- // step 3 runs in unload_displayed_document_for_cross_document_navigation().
+ // NB: The process running the job also clears its projection of the navigable's ongoing navigation, before it runs
+ // any unload task step 3 sends it.
changing_navigable.navigable().clear_ongoing_navigation_traversal(operation.operation_id);
-
auto endpoint = changing_job_endpoint(changing_navigable);
- 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);
+ endpoint->async_clear_ongoing_history_traversal(operation.operation_id, changing_navigable.id);
+
+ // 3. Unload a document and its descendants given displayedDocument, targetEntry's document,
+ // afterPotentialUnloads, and firePageSwapBeforeUnload.
+ unload_a_document_and_its_descendants(changing_navigable.navigable(), endpoint, Web::HTML::ChildNavigableDestruction::No, [this, operation_id = operation.operation_id, navigable_id = changing_navigable.id](UnloadedInItsHost) {
+ // NB: The process running the job unloads the document it displays: displayedDocument, or the stand-in of a
+ // host chosen for the new document.
+ auto* operation = find_history_operation(operation_id);
+ if (auto* changing_navigable = operation ? operation->pending_changing_job(navigable_id) : nullptr)
+ send_displayed_document_unload_task(*operation, *changing_navigable);
+ });
// FIXME: 6. Otherwise, queue a global task on the navigation and traversal task source given navigable's active window to run the steps:
// 1. Let proceedWithNavigationAfterViewTransitionCapture be the following step:
@@ -1543,21 +1549,6 @@ void CanonicalTraversable::deactivate_a_document_for_cross_document_navigation(H
// 4. If viewTransition is null, then run proceedWithNavigationAfterViewTransitionCapture.
}
-// https://html.spec.whatwg.org/multipage/browsing-the-web.html#deactivate-a-document-for-a-cross-document-navigation
-void CanonicalTraversable::unload_displayed_document_for_cross_document_navigation(HistoryOperation& operation, ChangingNavigable& changing_navigable)
-{
- // 5. If potentiallyTriggerViewTransition is false, then:
- // 3. Unload a document and its descendants given displayedDocument, targetEntry's document,
- // afterPotentialUnloads, and firePageSwapBeforeUnload.
- unload_a_document_and_its_descendants(changing_navigable.navigable(), changing_job_endpoint(changing_navigable), Web::HTML::ChildNavigableDestruction::No, [this, operation_id = operation.operation_id, navigable_id = changing_navigable.id](UnloadedInItsHost) {
- // NB: The process running the job unloads the document it displays: displayedDocument, or the stand-in of a
- // host chosen for the new document.
- auto* operation = find_history_operation(operation_id);
- if (auto* changing_navigable = operation ? operation->pending_changing_job(navigable_id) : nullptr)
- send_displayed_document_unload_task(*operation, *changing_navigable);
- });
-}
-
// The process running a changing navigable's job activated targetEntry's document and applied the continuation's
// remaining steps.
void CanonicalTraversable::did_activate_history_entry(HistoryOperation& operation, ChangingNavigable& changing_navigable, NonnullRefPtr<WebContentPage> source_page, Web::HTML::HostedNavigableState activated_navigable_state)
@@ -1715,15 +1706,6 @@ void CanonicalTraversable::complete_document_unload_task(Web::HTML::CrossProcess
(*after_unload)();
}
-void CanonicalTraversable::did_receive_changing_navigable_unload_preparation_complete(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id)
-{
- if (!source_page.take_owed_reply({ OwedReply::Kind::UnloadPreparation, operation_id, navigable_id }))
- return;
- auto* operation = find_history_operation(operation_id);
- if (auto* changing_navigable = operation ? operation->pending_changing_job(navigable_id) : nullptr)
- unload_displayed_document_for_cross_document_navigation(*operation, *changing_navigable);
-}
-
// Whether the page hosting the navigable's active document is unloading it, or has, for a document another page hosts.
// That page stops hosting the navigable once the document is unloaded, and the other page takes it over only when the
// document replacing it is activated.
diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.h
index 14b5fe99204..8c4c66912e2 100644
--- a/Libraries/LibWebView/CanonicalTraversable.h
+++ b/Libraries/LibWebView/CanonicalTraversable.h
@@ -84,7 +84,6 @@ public:
bool is_handing_navigable_to_another_page(CanonicalNavigable const&) const;
void did_receive_changing_navigable_history_job_ready(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id);
void did_finish_history_navigation_params_creation(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::HistoryNavigationPopulation);
- void did_receive_changing_navigable_unload_preparation_complete(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id);
void did_receive_descendant_unload_task_complete(WebContentPage& source_page, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id);
void did_receive_child_navigable_unload_request(WebContentPage& source_page, Web::HTML::CrossProcessId navigable_id);
void did_receive_changing_navigable_continuation_applied(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Optional<Web::HTML::HostedNavigableState> activated_navigable_state, Optional<Web::HTML::SessionHistoryEntryPersistedState> previous_entry_persisted_state);
@@ -199,7 +198,6 @@ private:
void send_changing_navigable_continuation_task(HistoryOperation&, ChangingNavigable&);
void send_displayed_document_unload_task(HistoryOperation&, ChangingNavigable&);
void deactivate_a_document_for_cross_document_navigation(HistoryOperation&, ChangingNavigable&);
- void unload_displayed_document_for_cross_document_navigation(HistoryOperation&, ChangingNavigable&);
void did_activate_history_entry(HistoryOperation&, ChangingNavigable&, NonnullRefPtr<WebContentPage> source_page, Web::HTML::HostedNavigableState activated_navigable_state);
enum class UnloadedInItsHost : bool {
No,
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index cbdadf42b50..08ba9b99d98 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1657,11 +1657,6 @@ void WebContentPage::changing_navigable_history_job_ready(Web::HTML::CrossProces
traversable().did_receive_changing_navigable_history_job_ready(*this, operation_id, navigable_id, disposition, update_only, target_document_id);
}
-void WebContentPage::changing_navigable_unload_preparation_complete(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id)
-{
- traversable().did_receive_changing_navigable_unload_preparation_complete(*this, operation_id, navigable_id);
-}
-
void WebContentPage::descendant_unload_task_complete(Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id)
{
traversable().did_receive_descendant_unload_task_complete(*this, unload_id, navigable_id);
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 674446fb9a7..78b065c2ec6 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -35,7 +35,6 @@ struct OwedReply {
enum class Kind : u8 {
BeforeunloadCheck,
ChangingJob,
- UnloadPreparation,
ContinuationApplied,
NonchangingUpdate,
DescendantUnload,
@@ -270,7 +269,6 @@ private:
virtual void revoke_history_operation(Web::HTML::CrossProcessId operation_id) override;
virtual void beforeunload_check_result(Web::HTML::CrossProcessId operation_id, Web::HTML::CheckIfUnloadingIsCanceledResult result, Web::HTML::UnloadPromptShown unload_prompt_shown) override;
virtual void changing_navigable_history_job_ready(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id) override;
- virtual void changing_navigable_unload_preparation_complete(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void descendant_unload_task_complete(Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void request_navigable_document_abort(Web::HTML::CrossProcessId navigable_id) override;
virtual void request_navigable_document_unfullscreen(Web::HTML::CrossProcessId navigable_id) override;
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 3b6d3242173..52c3bfff883 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -622,17 +622,10 @@ void ConnectionFromClient::run_changing_navigable_history_job(Web::PageId page_i
}));
}
-void ConnectionFromClient::prepare_changing_navigable_for_unload(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id)
+void ConnectionFromClient::clear_ongoing_history_traversal(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id)
{
- auto page = this->page(page_id);
- if (!page.has_value()) {
- async_changing_navigable_unload_preparation_complete(page_id, operation_id, navigable_id);
- return;
- }
-
- page->page().history_executor().prepare_ui_changing_navigable_for_unload(operation_id, navigable_id, GC::create_function(Web::HTML::main_thread_event_loop().heap(), [this, page_id, operation_id, navigable_id] {
- async_changing_navigable_unload_preparation_complete(page_id, operation_id, navigable_id);
- }));
+ if (auto page = this->page(page_id); page.has_value())
+ page->page().history_executor().clear_ui_changing_navigable_ongoing_traversal(operation_id, navigable_id);
}
void ConnectionFromClient::apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api)
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index ecea77edd78..d8285594376 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -143,7 +143,7 @@ private:
virtual void discard_embedded_page(Web::PageId page_id) override;
virtual void queue_navigation_api_state_clear_task(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void run_changing_navigable_history_job(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Web::HTML::UserNavigationInvolvement user_involvement, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id, Optional<Web::HTML::NavigationSourceSnapshot> source_snapshot_params) override;
- virtual void prepare_changing_navigable_for_unload(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) override;
+ virtual void clear_ongoing_history_traversal(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api) override;
virtual void unload_displayed_document_and_apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api) override;
virtual void run_descendant_unload_task(Web::PageId page_id, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChildNavigableDestruction, Web::HTML::StopHostingAfterUnload) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index 56d38c03a07..b1e20a1ca00 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -256,7 +256,6 @@ endpoint WebContentClient routed by Web::PageId page_id
revoke_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id) =|
beforeunload_check_result(Web::PageId page_id, Web::HTML::CrossProcessId check_id, Web::HTML::CheckIfUnloadingIsCanceledResult result, Web::HTML::UnloadPromptShown unload_prompt_shown) =|
changing_navigable_history_job_ready(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChangingNavigableHistoryStepJobDisposition disposition, bool update_only, Optional<Web::HTML::CrossProcessId> target_document_id) =|
- changing_navigable_unload_preparation_complete(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) =|
descendant_unload_task_complete(Web::PageId page_id, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id) =|
request_child_navigable_unload(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
request_unload_check(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId check_id) =|
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index ff07c7a55e2..d7e4f2c156b 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -119,7 +119,7 @@ endpoint WebContentServer routed by Web::PageId page_id
queue_navigation_api_state_clear_task(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
continue_history_navigation_population(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::HistoryNavigationPopulation population) =|
run_changing_navigable_history_job(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryDescriptor target_entry, Web::HTML::UserNavigationInvolvement user_involvement, Optional<Web::Bindings::NavigationType> navigation_type, Web::HTML::TraversalYieldsTo traversal_yields_to, Optional<Utf16String> canceled_navigation_id, Optional<Utf16String> finalized_navigation_id, Optional<Web::HTML::NavigationSourceSnapshot> source_snapshot_params) =|
- prepare_changing_navigable_for_unload(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) =|
+ clear_ongoing_history_traversal(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) =|
apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api) =|
unload_displayed_document_and_apply_changing_navigable_continuation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity target_entry, u64 script_history_length, u64 script_history_index, Vector<Web::HTML::SessionHistoryEntryDescriptor> entries_for_navigation_api) =|
run_descendant_unload_task(Web::PageId page_id, Web::HTML::CrossProcessId unload_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ChildNavigableDestruction child_navigable_destruction, Web::HTML::StopHostingAfterUnload stop_hosting_after_unload) =|