Truly independent web browser
LibWebView: Show the tab as loading when a traversal fetches its page
Andreas Klingc0eb6d52e7f4
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex 2fc67ca7faa..c27af5a7aab 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -748,6 +748,10 @@ void CanonicalTraversable::stop_loading()elseclear_active_document_load();+ // AD-HOC: A browser traversal still fetching its document is abandoned, so that the document does not replace the+ // page after the user stopped the load.+ abandon_browser_traversal_load();+// 3. Abort a document and its descendants given document.// NB: The page hosting document runs this step.if (auto page = display_page(); page && page->is_open())@@ -1049,6 +1053,8 @@ struct HistoryOperation {Vector<NonnullRefPtr<WebContentPage>> completion_endpoints;u64 sequence_number;Optional<Web::HTML::CrossProcessId> beforeunload_check_id;+ // The view is showing a load for the top-level document this traversal has yet to activate.+ bool has_unactivated_traversal_load { false };ChangingNavigable* pending_changing_job(Web::HTML::CrossProcessId navigable_id) const{@@ -1522,24 +1528,30 @@ bool CanonicalTraversable::run_changing_navigable_history_step_job(ApplyHistorySadd_history_operation_completion_endpoint(operation, *endpoint);- // A reload's top-level job repopulates the view's document; begin the recorded load where the job is- // dispatched instead of having the job echo it back.- if (navigable.is_top_level_traversable()- && operation.parameters.has<Web::ReloadHistoryOperationParameters>()) {- // 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);- }-if (auto const* parameters = operation.parameters.get_pointer<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>(); parameters && parameters->navigable_id == navigable_id) {if (auto const& populated_document = changing_navigable.target_entry->document_state->populated_document; populated_document.has_value())changing_navigable.populated_document = populated_document->document;}// 8. If targetEntry's document is null, or targetEntry's document state's reload pending is true:- if (!changing_navigable.target_document(*endpoint) || changing_navigable.target_entry_reload_pending)+ auto populates_target_entry_document = !changing_navigable.target_document(*endpoint) || changing_navigable.target_entry_reload_pending;+ if (populates_target_entry_document)changing_navigable.population = ChangingNavigable::AwaitingPopulation {};+ // NB: A reload, or a traversal whose top-level job populates the view's document, loads it. Begin the recorded load+ // where the job is dispatched instead of having the job echo it back. A navigation being finalized began its+ // load when it started.+ auto is_reload = operation.parameters.has<Web::ReloadHistoryOperationParameters>();+ auto is_traversal_load = !is_reload && populates_target_entry_document && !operation.parameters.has<Web::FinalizeCrossDocumentNavigationHistoryOperationParameters>();+ if (auto view = this->view(); view.has_value() && navigable.is_top_level_traversable() && (is_reload || is_traversal_load)) {+ if (is_traversal_load)+ operation.has_unactivated_traversal_load = true;++ // NB: 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);+ }+endpoint->owe_reply({ OwedReply::Kind::ChangingJob, operation.operation_id, navigable_id });endpoint->async_run_changing_navigable_history_job(operation.operation_id, navigable_id,@@ -1695,6 +1707,8 @@ void CanonicalTraversable::did_activate_history_entry(HistoryOperation& operationavigation_id = reload->value.id;reload->value.activated = true;}+ if (navigable.is_top_level_traversable())+ operation.has_unactivated_traversal_load = false;auto const* replaced_document = &navigable.active_document();// NB: The page that activated the document hosts it: the job's, which hosts the document the job populated, or else// the navigable's.@@ -2741,6 +2755,12 @@ void CanonicalTraversable::finish_history_operation(Web::HTML::CrossProcessId opbidi->reload_did_not_apply(*this, reload->id);}+ // A load the traversal began ends with it if the document it was for was never activated.+ if (operation->has_unactivated_traversal_load) {+ if (auto view = this->view(); view.has_value())+ view->did_not_activate_history_traversal_load();+ }+auto committed_step = operation->algorithm ? operation->algorithm->committed_step() : Optional<i32> {};if (committed_step.has_value()) {if (auto view = this->view(); view.has_value())@@ -2781,6 +2801,27 @@ void CanonicalTraversable::finish_history_operation(Web::HTML::CrossProcessId opCore::deferred_invoke([operation = move(operation)] { });}+void CanonicalTraversable::abandon_browser_traversal_load()+{+ auto* traversal = ongoing_browser_history_traversal();+ if (!traversal || !traversal->has_unactivated_traversal_load)+ return;++ // NB: Once the job has stopped populating, the displayed document may already be unloading.+ auto* changing_navigable = traversal->pending_changing_job(id());+ if (!changing_navigable || changing_navigable->population.has<Empty>())+ return;++ // NB: The job set the current entry to its target entry, which a later step to that entry would see as no change.+ set_current_session_history_entry(active_session_history_entry());+ finish_history_operation(traversal->operation_id);+}++bool CanonicalTraversable::has_unactivated_traversal_load() const+{+ return any_of(m_history_operations, [](auto const& entry) { return entry.value->has_unactivated_traversal_load; });+}+void CanonicalTraversable::abandon_history_operations(){while (!m_history_operations.is_empty())diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.hindex 2f67b3e29d2..9c136f472f3 100644--- a/Libraries/LibWebView/CanonicalTraversable.h+++ b/Libraries/LibWebView/CanonicalTraversable.h@@ -78,6 +78,7 @@ public: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();+ bool has_unactivated_traversal_load() const;RefPtr<WebContentPage> page_hosting(CanonicalNavigable const&) const;@@ -241,6 +242,7 @@ private:void run_browser_ui_traversal_at_queue_position(Function<Optional<i32>()> select_target_step, CheckForCancelation, Function<void()> on_ready, NonnullRefPtr<Core::Promise<Empty>>);void supersede_browser_history_traversal(HistoryOperation&, i32 target_step, Function<void()> on_ready);+ void abandon_browser_traversal_load();RefPtr<CanonicalSessionHistoryEntry> session_history_entry_named(CanonicalNavigable const&, Function<bool(CanonicalSessionHistoryEntry const&)> const& matches);RefPtr<CanonicalSessionHistoryEntry> session_history_entry_named(CanonicalNavigable const&, Web::HTML::SessionHistoryEntryIdentity const&);diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex 76824e55e18..e5eac90118f 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -708,6 +708,15 @@ void ViewImplementation::did_apply_top_level_history_traversal_step(Web::HTML::Ccomplete_webdriver_history_traversal(operation_id);}+// A traversal's load that activated no document leaves the tab loading only if something else is.+void ViewImplementation::did_not_activate_history_traversal_load()+{+ if (traversable().tracked_load_navigation_id().has_value())+ return;+ set_loading_state(false);+ notify_load_finish();+}+// A reload of the tab's document that did not apply leaves the tab loading only if something else is.void ViewImplementation::did_not_apply_reload(){@@ -3267,6 +3276,11 @@ void ViewImplementation::did_cancel_loading(Badge<CanonicalNavigable>, bool cancelse if (m_webdriver_navigation_observation.has_value())complete_webdriver_navigation();+ notify_load_finish();+}++void ViewImplementation::notify_load_finish()+{auto const& client_url = url();if (on_load_finish)on_load_finish(client_url);diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex 08933c3a008..57509aa6e74 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -794,6 +794,8 @@ protected:void complete_webdriver_history_traversal(Web::HTML::CrossProcessId operation_id);void update_navigation_action_state();void did_not_apply_reload();+ void did_not_activate_history_traversal_load();+ void notify_load_finish();void notify_session_history_changed();enum class SessionHistoryDumpMode {IfDebuggingEnabled,diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex f61fc6d4563..9173ab0e7d4 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -2945,6 +2945,10 @@ void WebContentPage::did_finish_loading(Web::HTML::CrossProcessId navigable_id,if (navigable->tracked_load_navigation_id() != navigable->active_document_load().navigation_id)return;+ // NB: The document a traversal is fetching a replacement for does not finish the traversal's load.+ if (navigable->is_top_level_traversable() && traversable().has_unactivated_traversal_load())+ return;+navigable->clear_active_document_load();if (!navigable->is_top_level_traversable())return;