Skip to content

Truly independent web browser

LibWeb+LibWebView: Cancel a navigation the UI process ends

Shannon Booth2c3d2bb30c06
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index bb5084c634d..3aa43c0efff 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -1643,13 +1643,6 @@ void LocalNavigable::set_ongoing_navigation_without_informing_navigation_api(Var
if (m_ongoing_navigation == ongoing_navigation)
return;
- // AD-HOC: A UI-approved traversal supersedes any older navigation parked while the UI process coordinates
- // population. Do not let that navigation resume after the traversal finishes.
- if (ongoing_navigation.has<Traversal>() && m_ongoing_navigation.has<Utf16String>()) {
- if (take_navigation_parked_for_population(m_ongoing_navigation.get<Utf16String>()).has_value())
- set_delaying_load_events(false);
- }
-
m_ongoing_navigation = ongoing_navigation;
for (auto& navigation_observer : m_navigation_observers) {
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index e7098de3a95..e4e27935382 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -1289,26 +1289,13 @@ void CanonicalNavigable::set_the_ongoing_navigation(OngoingNavigation value)
// 2. Inform the navigation API about aborting navigation given navigable.
// NB: The page holding navigable does this as it sets its own ongoing navigation.
+ auto superseded_navigation = uncommitted_navigation();
+
// 3. Set navigable's ongoing navigation to newValue.
m_ongoing_navigation = move(value);
- auto ongoing_navigation_id = this->ongoing_navigation_id();
- Vector<NonnullRefPtr<CanonicalNavigation>> ended_navigations;
- for (size_t i = 0; i < m_navigations.size();) {
- auto const& navigation = *m_navigations[i];
- auto ends = navigation.ends_when_superseded()
- && (!ongoing_navigation_id.has_value() || navigation.navigation_id != *ongoing_navigation_id);
- if (ends)
- ended_navigations.append(m_navigations.take(i));
- else
- ++i;
- }
-
- // The document populated for an ended navigation is not going to be activated.
- for (auto const& navigation : ended_navigations) {
- if (navigation->history_entry)
- abandon_populated_document(navigation->history_entry->document_state);
- }
+ if (superseded_navigation && superseded_navigation->ends_when_superseded())
+ end_navigation(*superseded_navigation);
}
void CanonicalNavigable::set_ongoing_navigation(CanonicalNavigation::Start navigation)
@@ -1361,8 +1348,14 @@ void CanonicalNavigable::end_navigation(CanonicalNavigation& navigation)
auto index = m_navigations.find_first_index_if([&](auto const& candidate) { return candidate.ptr() == &navigation; });
VERIFY(index.has_value());
auto ended_navigation = m_navigations.take(*index);
- if (ended_navigation->history_entry)
- abandon_populated_document(ended_navigation->history_entry->document_state);
+
+ // The page checking if unloading is canceled holds the navigation until it is told to continue it.
+ if (auto worker = navigation.worker(); worker && worker->is_open() && navigation.state.has<CanonicalNavigation::CheckingIfUnloadingIsCanceled>())
+ worker->async_cancel_navigation_params_creation(id(), navigation.navigation_id);
+
+ // The document populated for an ended navigation is not going to be activated.
+ if (navigation.history_entry)
+ abandon_populated_document(navigation.history_entry->document_state);
}
BlobURLStore* CanonicalNavigable::blob_url_store() const