Truly independent web browser
LibWebView: Name the load a navigable's signals concern in one place
Shannon Boothd2cbaa62f865
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex 4f5fba19035..18c39bb3d9f 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -918,21 +918,19 @@ void CanonicalNavigable::did_create_populated_document_with_an_origin_of_its_ownpopulated_document->document = move(document);}-// 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)+// A newer navigation can start before the history operation finalizing this one applies the history step.+bool CanonicalNavigable::take_navigation_to_finalize(Utf16String const& navigation_id, WebContentPage const& page){auto* navigation = ongoing_navigation();if (!navigation || navigation->navigation_id != navigation_id || navigation->host() != &page)- return {};+ return false;if (navigation->populated_document.has_value()) {abandon_populated_document(m_document_populated_by_history_job);m_document_populated_by_history_job = navigation->populated_document.release_value();}- auto taken_navigation = move(*navigation);+ m_navigation_being_finalized = move(*navigation);m_ongoing_navigation = Empty {};- return taken_navigation;+ return true;}void CanonicalNavigable::abandon_populated_document(CanonicalDocument const& document)@@ -1371,6 +1369,9 @@ bool CanonicalNavigable::cancel_navigation_for_client(WebContentClient& client)// going to be.void CanonicalNavigable::did_finish_finalizing_navigation(Utf16String const& navigation_id, Web::HTML::CrossProcessId document_state_id, Web::HTML::HistoryStepResult result){+ if (!m_navigation_being_finalized.has_value() || m_navigation_being_finalized->navigation_id != navigation_id)+ return;+ m_navigation_being_finalized.clear();if (auto const* populated_document = populated_document_with_state_id(document_state_id)) {NonnullRefPtr document = populated_document->document;abandon_populated_document(*document);@@ -1379,14 +1380,13 @@ void CanonicalNavigable::did_finish_finalizing_navigation(Utf16String const& navclear_active_document_load();}-bool CanonicalNavigable::matches_ongoing_navigation(Optional<Utf16String> const& navigation_id) const+Optional<Utf16String> CanonicalNavigable::tracked_load_navigation_id() const{- // A live transaction owns the view's loading state, so completion signals must name it.- if (ongoing_navigation())- return navigation_id == ongoing_navigation()->navigation_id;-- // Otherwise completion signals concern the active document's tracked load.- return navigation_id == m_active_document_load.navigation_id;+ if (auto const* navigation = ongoing_navigation())+ return navigation->navigation_id;+ if (m_navigation_being_finalized.has_value())+ return m_navigation_being_finalized->navigation_id;+ return m_active_document_load.navigation_id;}}diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.hindex 769fa5a72b9..cf1f3b15830 100644--- a/Libraries/LibWebView/CanonicalNavigable.h+++ b/Libraries/LibWebView/CanonicalNavigable.h@@ -103,7 +103,7 @@ public:// 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(Utf16String const& navigation_id, WebContentPage const&);+ bool take_navigation_to_finalize(Utf16String const& navigation_id, WebContentPage const&);void abandon_populated_document(CanonicalDocument const&);void place_pending_document(WebContentPage&);@@ -232,9 +232,10 @@ public:void clear_ongoing_navigation_state();void set_navigation_host(WebContentPage&);bool cancel_navigation_for_client(WebContentClient&);+ CanonicalNavigation const* navigation_being_finalized() const { return m_navigation_being_finalized.has_value() ? &*m_navigation_being_finalized : nullptr; }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;+ Optional<Utf16String> tracked_load_navigation_id() const;ActiveDocumentLoad const& active_document_load() const { return m_active_document_load; }void clear_active_document_load() { m_active_document_load = {}; }@@ -259,6 +260,7 @@ private:Web::HTML::CrossProcessId operation_id;};Variant<Empty, Traversal, CanonicalNavigation> m_ongoing_navigation;+ Optional<CanonicalNavigation> m_navigation_being_finalized;Optional<Web::HTML::PreparedNavigationDescriptor> m_navigation_waiting_for_traversal;struct RoutedNavigation {Utf16String navigation_id;diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex f8dafc375ba..fcb0fd9661a 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -973,9 +973,6 @@ struct CanonicalTraversable::HistoryOperation {Vector<NonnullRefPtr<WebContentPage>> completion_endpoints;u64 sequence_number;bool was_initiated_by_browser { false };- // 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;Optional<Web::HTML::CrossProcessId> beforeunload_check_id;@@ -1217,15 +1214,17 @@ CanonicalSessionHistoryEntry const* CanonicalTraversable::ongoing_browser_historreturn nullptr;}-// The traversable's navigation that a history operation is finalizing, which is no longer its ongoing navigation.-CanonicalNavigation const* CanonicalTraversable::navigation_being_finalized() const+// The navigation a cross-document navigation's finalization took from its navigable at its queue position.+CanonicalNavigation const* CanonicalTraversable::finalized_navigation(HistoryOperation const& operation) const{- for (auto const& operation : m_history_operations) {- auto const* parameters = operation.value->parameters.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>();- if (parameters && parameters->navigable_id == id() && operation.value->finalized_navigation.has_value())- return &*operation.value->finalized_navigation;- }- return nullptr;+ auto const* parameters = operation.parameters.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>();+ if (!parameters)+ return nullptr;+ auto navigable = find(parameters->navigable_id);+ if (!navigable.has_value())+ return nullptr;+ auto const* navigation = navigable->navigation_being_finalized();+ return navigation && navigation->navigation_id == parameters->navigation_id ? navigation : nullptr;}void CanonicalTraversable::recover_from_web_content_process_crash(OnHistoryOperationComplete on_complete)@@ -1340,7 +1339,8 @@ bool CanonicalTraversable::navigation_transaction_matches(HistoryOperation constauto const& parameters = operation.parameters.get<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>();if (reply_navigable_id.has_value() && *reply_navigable_id != parameters.navigable_id)return true;- return operation.finalized_navigation.has_value() && operation.finalized_navigation->host() == &page;+ auto const* navigation = finalized_navigation(operation);+ return navigation && navigation->host() == &page;}void CanonicalTraversable::add_history_operation_completion_endpoint(HistoryOperation& operation, NonnullRefPtr<WebContentPage> endpoint)@@ -1662,8 +1662,8 @@ void CanonicalTraversable::did_activate_history_entry(HistoryOperation& operatiohost = source_page;Optional<Utf16String const&> navigation_id;- if (operation.finalized_navigation.has_value())- navigation_id = operation.finalized_navigation->navigation_id;+ if (auto const* navigation = finalized_navigation(operation))+ navigation_id = navigation->navigation_id;navigable->did_commit_navigation(target_entry, move(activated_navigable_state), operation.sequence_number, navigation_id, did_populate_document, move(host));if (navigable_id == id()) {@@ -2524,9 +2524,8 @@ void CanonicalTraversable::start_history_operation(HistoryOperation& operation,}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()) {+ auto navigable = find(parameters->navigable_id);+ if (!navigable.has_value() || !navigable->take_navigation_to_finalize(parameters->navigation_id, *operation.initiating_page)) {finish_history_operation(operation.operation_id, Web::HTML::HistoryStepResult::Applied, {});return;}@@ -2560,7 +2559,7 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation// NB: The process running a javascript: URL navigation evaluates it, creates newDocument in navigable's active// 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 (operation.finalized_navigation->state.has<CanonicalNavigation::EvaluatingJavaScriptURL>()) {+ if (navigable->navigation_being_finalized()->state.has<CanonicalNavigation::EvaluatingJavaScriptURL>()) {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.@@ -2743,10 +2742,9 @@ 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.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_finalizing_navigation(parameters.navigation_id, parameters.history_entry.document_state.id, result);+ if (auto const* parameters = taken_operation.parameters.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>()) {+ if (auto navigable = find(parameters->navigable_id); navigable.has_value())+ 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/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.hindex fca37d3a6f5..66fc12e97e8 100644--- a/Libraries/LibWebView/CanonicalTraversable.h+++ b/Libraries/LibWebView/CanonicalTraversable.h@@ -155,7 +155,6 @@ public:Optional<BrowserHistoryTraversalDiagnostic> browser_history_traversal_for_testing() const;CanonicalSessionHistoryEntry const* ongoing_browser_history_traversal_target_entry() const;- CanonicalNavigation const* navigation_being_finalized() const;// The entries of the synchronous navigations of a navigable whose finalization is queued.Vector<NonnullRefPtr<CanonicalSessionHistoryEntry>> queued_same_document_session_history_entries(CanonicalNavigable const&) const;ByteString queued_same_document_session_history_entries_for_debug() const;@@ -188,6 +187,7 @@ private:void session_history_changed();HistoryOperation* find_history_operation(Web::HTML::CrossProcessId operation_id);bool navigation_transaction_matches(HistoryOperation const&, WebContentPage&, Optional<Web::HTML::CrossProcessId> reply_navigable_id = {}) const;+ CanonicalNavigation const* finalized_navigation(HistoryOperation const&) const;bool update_session_history_entry_persisted_state(CanonicalNavigable&, Web::HTML::SessionHistoryEntryPersistedState const&);void add_history_operation_completion_endpoint(HistoryOperation&, NonnullRefPtr<WebContentPage>);bool select_changing_navigable_history_step_job_endpoint(HistoryOperation&, ApplyHistoryStepJobs::ChangingNavigableHistoryStepJob&);diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex e4bee7695f9..c814ea33363 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -453,8 +453,9 @@ void ViewImplementation::stop_loading()if (!m_is_loading)return;// Only a stopped navigation that never activated its document needs reissuing on reload; a stopped- // active-document load reloads through the session history.- m_last_stopped_navigation = navigation_to_retry_for_ongoing_navigation();+ // active-document load reloads through the session history. A navigation a history operation is finalizing is+ // not stopped, and activates its document.+ m_last_stopped_navigation = traversable().has_uncommitted_navigation() ? navigation_to_retry_for_ongoing_navigation() : Optional<NavigationToRetry> {};if (cancel_uncommitted_top_level_navigation("stop-loading"sv, true))return;set_loading_state(false);@@ -2488,13 +2489,7 @@ void ViewImplementation::did_start_navigation(Optional<Utf16String> const& navigbool 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;- if (stale)+ if (navigation_id != traversable().tracked_load_navigation_id())return false;set_loading_state(false);@@ -2528,11 +2523,6 @@ void ViewImplementation::did_cancel_loading(Optional<Utf16String> const& navigat}}-bool ViewImplementation::matches_ongoing_navigation(Optional<Utf16String> const& navigation_id) const-{- return traversable().matches_ongoing_navigation(navigation_id);-}-void ViewImplementation::did_finish_navigation(){set_loading_state(false);diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex a5a7b0e2372..3390135220d 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -570,7 +570,6 @@ protected:void did_cancel_loading(Optional<Utf16String> const& navigation_id);bool did_cancel_navigation(Optional<Utf16String> const& navigation_id);void did_finish_navigation();- bool matches_ongoing_navigation(Optional<Utf16String> const& navigation_id) const;void set_loading_state(bool);void complete_webdriver_navigation_completion(u64 request_id, Web::WebDriver::Response);void set_webdriver_current_browsing_context(CanonicalNavigable const&);diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex 6ef2a75ce0d..bd0993c600f 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -2308,7 +2308,7 @@ void WebContentPage::did_finish_loading(Web::HTML::CrossProcessId navigable_id,if (!navigable.has_value())return;- if (!navigable->matches_ongoing_navigation(navigation_id))+ if (navigation_id != navigable->tracked_load_navigation_id())return;// A page standing in for a document the navigable lost, as the page displaying the tab after its process crashed