Skip to content

Truly independent web browser

LibWebView: Make a navigable's ongoing navigation one value

Shannon Booth9e2988a74f08
diff --git a/Libraries/LibWebView/ApplyHistoryStep.cpp b/Libraries/LibWebView/ApplyHistoryStep.cpp
index e9500d28668..1bc744e08d8 100644
--- a/Libraries/LibWebView/ApplyHistoryStep.cpp
+++ b/Libraries/LibWebView/ApplyHistoryStep.cpp
@@ -501,7 +501,7 @@ void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& n
// AD-HOC: A navigation admitted after a same-document traversal takes precedence. The specification's traversal
// queue does not model Ladybird's independently admitted UI-process navigation transactions.
if (is_same_document_traversal
- && navigable.ongoing_navigation().has_value()
+ && navigable.ongoing_navigation()
&& navigable.ongoing_navigation()->sequence_number > m_operation_sequence_number) {
m_traversal_yields_to.set(navigable.id(), Web::HTML::TraversalYieldsTo::AdmittedNavigation);
return;
@@ -511,18 +511,18 @@ void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& n
if (m_navigation_type.has_value()
&& first_is_one_of(*m_navigation_type, Web::Bindings::NavigationType::Push, Web::Bindings::NavigationType::Replace)
&& target_document_is_active_document
- && navigable.ongoing_navigation().has_value()) {
+ && navigable.ongoing_navigation()) {
return;
}
// AD-HOC: A navigable creation/destruction update skips a navigable already claimed by its requested navigation.
// See https://github.com/whatwg/html/issues/12724.
- if (!m_navigation_type.has_value() && navigable.ongoing_navigation().has_value())
+ if (!m_navigation_type.has_value() && navigable.ongoing_navigation())
return;
if (m_navigation_type == Web::Bindings::NavigationType::Traverse) {
- auto const& ongoing_navigation = navigable.ongoing_navigation();
- if (is_same_document_traversal && ongoing_navigation.has_value() && ongoing_navigation->navigation_id.has_value())
+ auto const* ongoing_navigation = navigable.ongoing_navigation();
+ if (is_same_document_traversal && ongoing_navigation && ongoing_navigation->navigation_id.has_value())
m_canceled_navigation_ids.set(navigable.id(), *ongoing_navigation->navigation_id);
navigable.clear_ongoing_navigation();
}
@@ -533,6 +533,11 @@ void ApplyHistoryStep::set_ongoing_navigation_to_traversal(CanonicalNavigable& n
// started before this step ran in its own process. Its navigate() saw no traversal, and the admission
// recheck must not misattribute that ordering and drop the navigation the step has to yield to.
if (traversal_crosses_documents) {
+ // AD-HOC: A navigation admitted after the operation goes on, as the newest. See
+ // https://github.com/whatwg/html/issues/12581.
+ if (navigable.ongoing_navigation() && navigable.ongoing_navigation()->sequence_number > m_operation_sequence_number)
+ return;
+ navigable.clear_ongoing_navigation();
navigable.set_ongoing_navigation_to_traversal(m_operation_id);
m_navigables_with_ongoing_history_traversal.set(navigable.id());
}
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 35c5d5e73e8..d6b96616f2f 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -275,8 +275,8 @@ void CanonicalNavigable::begin_navigation(Web::HTML::PreparedNavigationDescripto
clear_ongoing_navigation();
return;
}
- auto& ongoing_navigation = *m_ongoing_navigation;
- ongoing_navigation.start_request = Web::HTML::NavigationStartRequest {
+ auto& ongoing = *ongoing_navigation();
+ ongoing.start_request = Web::HTML::NavigationStartRequest {
.navigable_id = id(),
.url = url,
.document_resource = move(navigation.document_resource),
@@ -296,8 +296,8 @@ void CanonicalNavigable::begin_navigation(Web::HTML::PreparedNavigationDescripto
.navigation_api_key = generate_a_random_uuid(),
.navigation_api_id = generate_a_random_uuid(),
};
- ongoing_navigation.retry = prepare_navigation_to_retry(*ongoing_navigation.start_request);
- ongoing_navigation.phase = CanonicalNavigation::Phase::AwaitingUnloadCheck;
+ ongoing.retry = prepare_navigation_to_retry(*ongoing.start_request);
+ ongoing.phase = CanonicalNavigation::Phase::AwaitingUnloadCheck;
set_navigation_population_worker(*worker);
worker->async_set_ongoing_navigation(id(), navigation_id);
worker->begin_navigation_unload_check(*this, navigation_id);
@@ -779,8 +779,8 @@ ErrorOr<NonnullRefPtr<WebContentPage>> CanonicalNavigable::obtain_page_to_host_i
Optional<PopulatedDocument> const& CanonicalNavigable::populated_document() const
{
- if (m_ongoing_navigation.has_value() && m_ongoing_navigation->populated_document.has_value())
- return m_ongoing_navigation->populated_document;
+ if (ongoing_navigation() && ongoing_navigation()->populated_document.has_value())
+ return ongoing_navigation()->populated_document;
return m_document_populated_by_history_job;
}
@@ -829,12 +829,12 @@ void CanonicalNavigable::populate_document(NonnullRefPtr<CanonicalDocumentState>
void CanonicalNavigable::populate_document_for_ongoing_navigation(NonnullRefPtr<CanonicalDocumentState> document_state, NonnullRefPtr<CanonicalDocument> document, Optional<URL::Origin> inline_content_origin)
{
- VERIFY(m_ongoing_navigation.has_value());
+ VERIFY(ongoing_navigation());
document->determine_whether_it_is_local_file_content(blob_url_store());
if (document->is_local_file_content())
document_state->held_local_file_content = true;
- abandon_populated_document(m_ongoing_navigation->populated_document);
- m_ongoing_navigation->populated_document = PopulatedDocument { move(document_state), move(document), move(inline_content_origin) };
+ abandon_populated_document(ongoing_navigation()->populated_document);
+ ongoing_navigation()->populated_document = PopulatedDocument { move(document_state), move(document), move(inline_content_origin) };
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate-to-a-javascript:-url
@@ -857,8 +857,8 @@ bool CanonicalNavigable::populate_document_for_javascript_url(NonnullRefPtr<Cano
void CanonicalNavigable::did_create_populated_document_with_an_origin_of_its_own(WebContentPage const& host, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin populated_document_origin, Web::HTML::EnvironmentId const& environment_id)
{
Optional<PopulatedDocument&> populated_document;
- if (m_ongoing_navigation.has_value() && m_ongoing_navigation->populated_document.has_value() && m_ongoing_navigation->populated_document->document->id() == document_id)
- populated_document = *m_ongoing_navigation->populated_document;
+ if (ongoing_navigation() && ongoing_navigation()->populated_document.has_value() && ongoing_navigation()->populated_document->document->id() == document_id)
+ populated_document = *ongoing_navigation()->populated_document;
else if (m_document_populated_by_history_job.has_value() && m_document_populated_by_history_job->document->id() == document_id)
populated_document = *m_document_populated_by_history_job;
if (!populated_document.has_value() || populated_document->document->host() != &host)
@@ -887,22 +887,28 @@ void CanonicalNavigable::did_create_populated_document_with_an_origin_of_its_own
populated_document->document = move(document);
}
-// The history job finalizing the ongoing navigation is going to activate the document populated for it, even if a
-// newer navigation starts before it does.
-void CanonicalNavigable::claim_document_populated_for_ongoing_navigation(CanonicalDocument const& 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)
{
- if (!m_ongoing_navigation.has_value() || !m_ongoing_navigation->populated_document.has_value())
- return;
- if (m_ongoing_navigation->populated_document->document != &document)
- return;
- abandon_populated_document(m_document_populated_by_history_job);
- m_document_populated_by_history_job = m_ongoing_navigation->populated_document.release_value();
+ if (!ongoing_navigation())
+ return {};
+ if (navigation_id.has_value() ? ongoing_navigation()->navigation_id != navigation_id : ongoing_navigation()->sequence_number > operation_sequence_number)
+ return {};
+ if (ongoing_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();
+ }
+ auto navigation = move(*ongoing_navigation());
+ m_ongoing_navigation = Empty {};
+ return navigation;
}
void CanonicalNavigable::abandon_populated_document(CanonicalDocument const& document)
{
- if (m_ongoing_navigation.has_value() && m_ongoing_navigation->populated_document.has_value() && m_ongoing_navigation->populated_document->document == &document)
- abandon_populated_document(m_ongoing_navigation->populated_document);
+ if (ongoing_navigation() && ongoing_navigation()->populated_document.has_value() && ongoing_navigation()->populated_document->document == &document)
+ abandon_populated_document(ongoing_navigation()->populated_document);
if (m_document_populated_by_history_job.has_value() && m_document_populated_by_history_job->document == &document)
abandon_populated_document(m_document_populated_by_history_job);
}
@@ -942,8 +948,8 @@ bool CanonicalNavigable::pending_host_matches(WebContentPage const& page) const
void CanonicalNavigable::discard_pending_host()
{
- if (m_ongoing_navigation.has_value())
- abandon_populated_document(m_ongoing_navigation->populated_document);
+ if (ongoing_navigation())
+ abandon_populated_document(ongoing_navigation()->populated_document);
abandon_populated_document(m_document_populated_by_history_job);
}
@@ -952,8 +958,8 @@ void CanonicalNavigable::discard_pending_host(WebContentPage const& page)
auto is_pending_in_page = [&](Optional<PopulatedDocument> const& populated_document) {
return populated_document.has_value() && populated_document->document->host() == &page && active_document().host() != &page;
};
- if (m_ongoing_navigation.has_value() && is_pending_in_page(m_ongoing_navigation->populated_document))
- abandon_populated_document(m_ongoing_navigation->populated_document);
+ if (ongoing_navigation() && is_pending_in_page(ongoing_navigation()->populated_document))
+ abandon_populated_document(ongoing_navigation()->populated_document);
if (is_pending_in_page(m_document_populated_by_history_job))
abandon_populated_document(m_document_populated_by_history_job);
}
@@ -1161,10 +1167,10 @@ bool CanonicalNavigable::active_document_is(CanonicalSessionHistoryEntry const&
void CanonicalNavigable::did_commit_navigation(CanonicalSessionHistoryEntry& entry, Web::HTML::HostedNavigableState hosted_state, u64 operation_sequence_number, Optional<Utf16String const&> navigation_id, DidPopulateDocument did_populate_document, RefPtr<WebContentPage> host)
{
// A navigation admitted after the operation, such as one a same-document traversal yields to, is newer than it.
- auto commits_ongoing_navigation = !m_ongoing_navigation.has_value()
+ auto commits_ongoing_navigation = !ongoing_navigation()
|| (navigation_id.has_value()
- ? navigation_id == m_ongoing_navigation->navigation_id
- : m_ongoing_navigation->sequence_number < operation_sequence_number);
+ ? navigation_id == ongoing_navigation()->navigation_id
+ : ongoing_navigation()->sequence_number < operation_sequence_number);
auto active_document_changed = !active_document_is(entry);
NonnullRefPtr previous_document = active_document();
@@ -1176,8 +1182,8 @@ void CanonicalNavigable::did_commit_navigation(CanonicalSessionHistoryEntry& ent
if (populated_document.document_state == entry.document_state && populated_document.inline_content_origin.has_value() && populated_document.document->origin().is_same_origin(*populated_document.inline_content_origin))
save_extra_document_state = false;
});
- if (m_ongoing_navigation.has_value() && m_ongoing_navigation->populated_document.has_value() && m_ongoing_navigation->populated_document->document_state == entry.document_state)
- m_ongoing_navigation->populated_document.clear();
+ if (ongoing_navigation() && ongoing_navigation()->populated_document.has_value() && ongoing_navigation()->populated_document->document_state == entry.document_state)
+ ongoing_navigation()->populated_document.clear();
if (m_document_populated_by_history_job.has_value() && m_document_populated_by_history_job->document_state == entry.document_state)
m_document_populated_by_history_job.clear();
VERIFY(document || !active_document_changed);
@@ -1246,9 +1252,12 @@ void CanonicalNavigable::did_commit_navigation(CanonicalSessionHistoryEntry& ent
// The activated document's load becomes the navigable's tracked load. Reloads can reuse the document state,
// while a same-document activation leaves the active document's load in place.
if (active_document_changed || did_populate_document == DidPopulateDocument::Yes) {
- m_active_document_load = ActiveDocumentLoad {
- .navigation_id = m_ongoing_navigation.has_value() ? m_ongoing_navigation->navigation_id : Optional<Utf16String> {},
- };
+ Optional<Utf16String> load_navigation_id;
+ if (navigation_id.has_value())
+ load_navigation_id = *navigation_id;
+ else if (ongoing_navigation())
+ load_navigation_id = ongoing_navigation()->navigation_id;
+ m_active_document_load = ActiveDocumentLoad { .navigation_id = move(load_navigation_id) };
}
clear_ongoing_navigation();
@@ -1267,19 +1276,19 @@ void CanonicalNavigable::set_ongoing_navigation(CanonicalNavigation ongoing_navi
void CanonicalNavigable::set_ongoing_navigation_to_traversal(Web::HTML::CrossProcessId operation_id)
{
- m_ongoing_navigation_traversal_operation_id = operation_id;
+ VERIFY(!ongoing_navigation());
+ m_ongoing_navigation = Traversal { operation_id };
}
void CanonicalNavigable::clear_ongoing_navigation_traversal(Web::HTML::CrossProcessId operation_id)
{
- if (m_ongoing_navigation_traversal_operation_id == operation_id)
- m_ongoing_navigation_traversal_operation_id.clear();
+ if (auto const* traversal = m_ongoing_navigation.get_pointer<Traversal>(); traversal && traversal->operation_id == operation_id)
+ m_ongoing_navigation = Empty {};
}
void CanonicalNavigable::clear_ongoing_navigation_state()
{
- m_ongoing_navigation.clear();
- m_ongoing_navigation_traversal_operation_id.clear();
+ m_ongoing_navigation = Empty {};
// NB: The navigation this covered has either been announced, and is held below, or is not coming.
m_pending_navigation_blob_url = {};
@@ -1289,8 +1298,8 @@ void CanonicalNavigable::clear_ongoing_navigation_state()
void CanonicalNavigable::clear_ongoing_navigation()
{
// The document populated for the navigation is not going to be activated.
- if (m_ongoing_navigation.has_value())
- abandon_populated_document(m_ongoing_navigation->populated_document);
+ if (ongoing_navigation())
+ abandon_populated_document(ongoing_navigation()->populated_document);
clear_ongoing_navigation_state();
}
@@ -1308,38 +1317,38 @@ void CanonicalNavigable::retain_blob_url_token(URL::BlobURLEntry::Token token)
void CanonicalNavigable::set_navigation_population_worker(WebContentPage& page)
{
- VERIFY(m_ongoing_navigation.has_value());
- auto& ongoing_navigation = *m_ongoing_navigation;
- VERIFY(!ongoing_navigation.population_worker);
- ongoing_navigation.population_worker = page;
+ VERIFY(ongoing_navigation());
+ auto& navigation = *ongoing_navigation();
+ VERIFY(!navigation.population_worker);
+ navigation.population_worker = page;
}
bool CanonicalNavigable::navigation_population_matches(WebContentPage const& page, Utf16String const& navigation_id) const
{
- return m_ongoing_navigation.has_value()
- && m_ongoing_navigation->navigation_id == navigation_id
- && m_ongoing_navigation->phase == CanonicalNavigation::Phase::Populating
+ return ongoing_navigation()
+ && ongoing_navigation()->navigation_id == navigation_id
+ && ongoing_navigation()->phase == CanonicalNavigation::Phase::Populating
&& navigation_population_worker_matches(page);
}
bool CanonicalNavigable::navigation_population_worker_matches(WebContentPage const& page) const
{
- return m_ongoing_navigation.has_value() && m_ongoing_navigation->population_worker.ptr() == &page;
+ return ongoing_navigation() && ongoing_navigation()->population_worker.ptr() == &page;
}
void CanonicalNavigable::set_navigation_host(WebContentPage& page)
{
- VERIFY(m_ongoing_navigation.has_value());
- auto& ongoing_navigation = *m_ongoing_navigation;
- ongoing_navigation.host = page;
+ VERIFY(ongoing_navigation());
+ auto& navigation = *ongoing_navigation();
+ navigation.host = page;
// The population worker conducts the navigation until the hosting process takes over.
- ongoing_navigation.population_worker = nullptr;
+ navigation.population_worker = nullptr;
}
bool CanonicalNavigable::navigation_host_matches(WebContentPage const& page) const
{
- return m_ongoing_navigation.has_value() && m_ongoing_navigation->host.ptr() == &page;
+ return ongoing_navigation() && ongoing_navigation()->host.ptr() == &page;
}
bool CanonicalNavigable::navigation_owner_matches(WebContentPage const& page) const
@@ -1349,21 +1358,21 @@ bool CanonicalNavigable::navigation_owner_matches(WebContentPage const& page) co
bool CanonicalNavigable::navigation_transaction_matches(Utf16String const& navigation_id, WebContentPage const& page) const
{
- return m_ongoing_navigation.has_value()
- && m_ongoing_navigation->navigation_id == navigation_id
- && m_ongoing_navigation->phase == CanonicalNavigation::Phase::Populating
+ 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 (!m_ongoing_navigation.has_value())
+ if (!ongoing_navigation())
return false;
auto is_page_of_client = [&](RefPtr<WebContentPage> const& page) {
return page && &page->client() == &client;
};
- if (!is_page_of_client(m_ongoing_navigation->population_worker) && !is_page_of_client(m_ongoing_navigation->host))
+ if (!is_page_of_client(ongoing_navigation()->population_worker) && !is_page_of_client(ongoing_navigation()->host))
return false;
clear_ongoing_navigation();
@@ -1376,7 +1385,7 @@ void CanonicalNavigable::did_finish_navigation_transaction(Optional<Utf16String>
return;
// A transaction still live at its operation's completion never activated its document.
- if (m_ongoing_navigation.has_value() && m_ongoing_navigation->navigation_id == navigation_id)
+ if (ongoing_navigation() && ongoing_navigation()->navigation_id == navigation_id)
clear_ongoing_navigation();
if (result != Web::HTML::HistoryStepResult::Applied
@@ -1388,8 +1397,8 @@ void CanonicalNavigable::did_finish_navigation_transaction(Optional<Utf16String>
bool CanonicalNavigable::matches_ongoing_navigation(Optional<Utf16String> const& navigation_id) const
{
// A live transaction owns the view's loading state, so completion signals must name it.
- if (m_ongoing_navigation.has_value())
- return navigation_id == m_ongoing_navigation->navigation_id;
+ 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;
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index 3dd656a5b9f..41492e5d911 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -103,15 +103,15 @@ 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);
- void claim_document_populated_for_ongoing_navigation(CanonicalDocument const&);
+ Optional<CanonicalNavigation> take_navigation_to_finalize(Optional<Utf16String> const& navigation_id, u64 operation_sequence_number);
void abandon_populated_document(CanonicalDocument const&);
void place_pending_document(WebContentPage&);
template<typename Callback>
void for_each_populated_document(Callback callback) const
{
- if (m_ongoing_navigation.has_value() && m_ongoing_navigation->populated_document.has_value())
- callback(*m_ongoing_navigation->populated_document);
+ if (auto const* navigation = ongoing_navigation(); navigation && navigation->populated_document.has_value())
+ callback(*navigation->populated_document);
if (m_document_populated_by_history_job.has_value())
callback(*m_document_populated_by_history_job);
}
@@ -215,9 +215,11 @@ public:
// navigation admitted before the operation's sequence number.
void did_commit_navigation(CanonicalSessionHistoryEntry&, Web::HTML::HostedNavigableState, u64 operation_sequence_number, Optional<Utf16String const&> navigation_id, DidPopulateDocument, RefPtr<WebContentPage> host);
- Optional<CanonicalNavigation>& ongoing_navigation() { return m_ongoing_navigation; }
- Optional<CanonicalNavigation> const& ongoing_navigation() const { return m_ongoing_navigation; }
- bool ongoing_navigation_is_traversal() const { return m_ongoing_navigation_traversal_operation_id.has_value(); }
+ // https://html.spec.whatwg.org/multipage/browsing-the-web.html#ongoing-navigation
+ // The navigation, if the navigable's ongoing navigation is a navigation ID rather than "traversal" or null.
+ CanonicalNavigation* ongoing_navigation() { return m_ongoing_navigation.get_pointer<CanonicalNavigation>(); }
+ CanonicalNavigation const* ongoing_navigation() const { return m_ongoing_navigation.get_pointer<CanonicalNavigation>(); }
+ bool ongoing_navigation_is_traversal() const { return m_ongoing_navigation.has<Traversal>(); }
// Held so that revoking a blob URL cannot take the entry away from a navigation on its way to this navigable, or
// from the document it loaded. Session history holds none, so a revoked blob URL cannot be traversed back to.
@@ -237,7 +239,7 @@ public:
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);
- bool has_uncommitted_navigation() const { return m_ongoing_navigation.has_value(); }
+ bool has_uncommitted_navigation() const { return ongoing_navigation(); }
bool matches_ongoing_navigation(Optional<Utf16String> const& navigation_id) const;
ActiveDocumentLoad const& active_document_load() const { return m_active_document_load; }
@@ -259,7 +261,10 @@ private:
Optional<PopulatedDocument> m_document_populated_by_history_job;
RefPtr<CanonicalSessionHistoryEntry> m_current_session_history_entry;
RefPtr<CanonicalSessionHistoryEntry> m_active_session_history_entry;
- Optional<CanonicalNavigation> m_ongoing_navigation;
+ struct Traversal {
+ Web::HTML::CrossProcessId operation_id;
+ };
+ Variant<Empty, Traversal, CanonicalNavigation> m_ongoing_navigation;
Optional<Web::HTML::PreparedNavigationDescriptor> m_navigation_waiting_for_traversal;
struct RoutedNavigation {
Utf16String navigation_id;
@@ -274,7 +279,6 @@ private:
BlobURLHandle m_pending_navigation_blob_url;
BlobURLHandle m_navigation_blob_url;
BlobURLHandle m_document_blob_url;
- Optional<Web::HTML::CrossProcessId> m_ongoing_navigation_traversal_operation_id;
ActiveDocumentLoad m_active_document_load;
Optional<Web::DevicePixelRect> m_viewport_rect;
Web::DevicePixelRect m_viewport_intersection;
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 20bb03803c1..baa89b7117e 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -974,6 +974,9 @@ struct CanonicalTraversable::HistoryOperation {
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.
+ Optional<CanonicalNavigation> finalized_navigation;
bool check_for_cancelation { false };
Function<void()> on_browser_traversal_ready;
Optional<Web::HTML::CrossProcessId> beforeunload_check_id;
@@ -1215,6 +1218,17 @@ CanonicalSessionHistoryEntry const* CanonicalTraversable::ongoing_browser_histor
return 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
+{
+ 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;
+}
+
void CanonicalTraversable::recover_from_web_content_process_crash(OnHistoryOperationComplete on_complete)
{
// The step a traversal the crash interrupted was applying is applied again, otherwise the current step is.
@@ -1336,6 +1350,8 @@ bool CanonicalTraversable::navigation_transaction_matches(HistoryOperation const
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);
}
@@ -1657,9 +1673,9 @@ void CanonicalTraversable::did_activate_history_entry(HistoryOperation& operatio
if (auto document = navigable->document_populated_for(*target_entry.document_state); document && document->host() == source_page)
host = source_page;
- auto navigation_id = operation.parameters.visit(
- [](Web::FinalizeCrossDocumentNavigationHistoryOperationParameters const& parameters) -> Optional<Utf16String const&> { return parameters.navigation_id; },
- [](auto const&) -> Optional<Utf16String const&> { return {}; });
+ Optional<Utf16String const&> navigation_id;
+ if (operation.finalized_navigation.has_value())
+ navigation_id = operation.finalized_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()) {
@@ -2695,6 +2711,10 @@ 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);
}
@@ -2918,8 +2938,6 @@ void CanonicalTraversable::did_receive_changing_navigable_history_job_ready(WebC
if (disposition == Web::HTML::ChangingNavigableHistoryStepJobDisposition::Ready) {
pending_job.value()->unload_displayed_document = unload_displayed_document;
- if (auto navigable = find(navigable_id); navigable.has_value() && pending_job.value()->document)
- navigable->claim_document_populated_for_ongoing_navigation(*pending_job.value()->document);
auto on_complete = move(pending_job.value()->on_complete);
on_complete(disposition);
return;
diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.h
index 55bb8524c0d..fca37d3a6f5 100644
--- a/Libraries/LibWebView/CanonicalTraversable.h
+++ b/Libraries/LibWebView/CanonicalTraversable.h
@@ -155,6 +155,7 @@ 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;
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 86bfa6cb43f..b06d1df515d 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -2488,8 +2488,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();
- auto stale = ongoing.has_value()
+ auto const* ongoing = traversable().ongoing_navigation();
+ auto stale = ongoing
? navigation_id != ongoing->navigation_id
: navigation_id != traversable().active_document_load().navigation_id;
if (stale)
@@ -3298,7 +3298,7 @@ void ViewImplementation::dump_session_history(StringView reason, SessionHistoryD
auto traversal = traversable().browser_history_traversal_for_testing();
Optional<URL::URL> loading_url;
- if (traversable().ongoing_navigation().has_value())
+ if (traversable().ongoing_navigation())
loading_url = traversable().ongoing_navigation()->url;
// The page displaying the tab can have lost its process, as when a crash recovery ends.
@@ -3425,10 +3425,12 @@ void ViewImplementation::respawn_web_content_process_after_crash()
Optional<ViewImplementation::NavigationToRetry> ViewImplementation::navigation_to_retry_for_ongoing_navigation() const
{
- auto const& ongoing_navigation = traversable().ongoing_navigation();
- if (!ongoing_navigation.has_value() || !ongoing_navigation->url.has_value())
+ auto const* navigation = traversable().ongoing_navigation();
+ if (!navigation)
+ navigation = traversable().navigation_being_finalized();
+ if (!navigation || !navigation->url.has_value())
return {};
- return NavigationToRetry { *ongoing_navigation->url, ongoing_navigation->retry };
+ return NavigationToRetry { *navigation->url, navigation->retry };
}
void ViewImplementation::retry_navigation(NavigationToRetry retry, Web::Bindings::NavigationHistoryBehavior history_handling)
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 532d7d0b7f4..fe41b2dbf06 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -301,8 +301,8 @@ bool WebContentPage::continue_navigation_population_in_selected_process(Web::HTM
return false;
auto navigation_awaits_population = [&](CanonicalNavigation::Phase phase) {
- auto const& ongoing_navigation = navigable->ongoing_navigation();
- return ongoing_navigation.has_value()
+ auto const* ongoing_navigation = navigable->ongoing_navigation();
+ return ongoing_navigation
&& ongoing_navigation->navigation_id == navigation_id
&& ongoing_navigation->phase == phase
&& ongoing_navigation->loader;
@@ -1451,8 +1451,8 @@ bool WebContentPage::populates_a_navigation_to_local_file(ByteString const& path
bool result = false;
traversable().for_each_in_inclusive_subtree([&](CanonicalNavigable const& navigable) {
- auto const& ongoing_navigation = navigable.ongoing_navigation();
- result = ongoing_navigation.has_value()
+ auto const* ongoing_navigation = navigable.ongoing_navigation();
+ result = ongoing_navigation
&& ongoing_navigation->population_worker.ptr() == this
&& ongoing_navigation->url.has_value()
&& ongoing_navigation->url->scheme() == "file"sv
@@ -2034,8 +2034,8 @@ void WebContentPage::did_complete_navigation_unload_check(Web::HTML::CrossProces
if (!navigable.has_value())
return;
- auto& ongoing_navigation = navigable->ongoing_navigation();
- if (!ongoing_navigation.has_value()
+ auto* ongoing_navigation = navigable->ongoing_navigation();
+ if (!ongoing_navigation
|| ongoing_navigation->navigation_id != navigation_id
|| ongoing_navigation->phase != CanonicalNavigation::Phase::AwaitingUnloadCheck
|| ongoing_navigation->population_worker != *this
@@ -2087,8 +2087,8 @@ void WebContentPage::did_finish_navigation_params_creation(Web::HTML::CrossProce
return;
}
- auto& ongoing_navigation = navigable->ongoing_navigation();
- if (!ongoing_navigation.has_value() || !ongoing_navigation->loader) {
+ auto* ongoing_navigation = navigable->ongoing_navigation();
+ if (!ongoing_navigation || !ongoing_navigation->loader) {
NavigationLoader::discard(client().is_private(), *result);
end_recorded_load_for_canceled_navigation();
navigable->clear_ongoing_navigation();
@@ -2119,8 +2119,8 @@ void WebContentPage::did_finish_navigation_params_creation(Web::HTML::CrossProce
if (open_page->continue_navigation_population_in_selected_process(navigable_id, navigation_id))
return;
if (auto navigable = open_page->population_worker_navigable(navigable_id); navigable.has_value()) {
- auto const& ongoing_navigation = navigable->ongoing_navigation();
- if (ongoing_navigation.has_value() && ongoing_navigation->navigation_id == navigation_id)
+ auto const* ongoing_navigation = navigable->ongoing_navigation();
+ if (ongoing_navigation && ongoing_navigation->navigation_id == navigation_id)
cancel_navigation(*navigable);
}
});
@@ -2140,8 +2140,8 @@ void WebContentPage::did_fail_navigation_population(Web::HTML::CrossProcessId na
// The failure must name the admitted transaction, and must come from a process that owns part of its
// outcome: the population worker (unload check, javascript: evaluation) or the population host.
- auto& ongoing_navigation = navigable->ongoing_navigation();
- if (!ongoing_navigation.has_value()
+ auto* ongoing_navigation = navigable->ongoing_navigation();
+ if (!ongoing_navigation
|| ongoing_navigation->navigation_id != navigation_id
|| !navigable->navigation_owner_matches(*this)) {
return;
@@ -2253,8 +2253,8 @@ Messages::WebContentClient::DidStartDownloadResponse WebContentPage::did_start_d
// received that response may claim it, and only while its population is in flight.
bool matches_in_flight_navigation = false;
if (auto navigable = population_worker_navigable(navigable_id); navigable.has_value()) {
- auto const& ongoing_navigation = navigable->ongoing_navigation();
- if (ongoing_navigation.has_value()
+ auto const* ongoing_navigation = navigable->ongoing_navigation();
+ if (ongoing_navigation
&& ongoing_navigation->navigation_id == navigation_id
&& ongoing_navigation->phase == CanonicalNavigation::Phase::Populating
&& ongoing_navigation->loader
diff --git a/Tests/LibWebView/TestApplyHistoryStep.cpp b/Tests/LibWebView/TestApplyHistoryStep.cpp
index 5a73e6df3e7..e20a516ec5a 100644
--- a/Tests/LibWebView/TestApplyHistoryStep.cpp
+++ b/Tests/LibWebView/TestApplyHistoryStep.cpp
@@ -329,7 +329,7 @@ TEST_CASE(same_document_traversal_names_the_older_navigation_it_cancels)
test.traversable.set_ongoing_navigation({ .navigation_id = "older"_utf16, .sequence_number = 1 });
test.traverse_to_step(0);
- EXPECT(!test.traversable.ongoing_navigation().has_value());
+ EXPECT(!test.traversable.ongoing_navigation());
EXPECT(!test.traversable.ongoing_navigation_is_traversal());
EXPECT_EQ(test.runner.changing_jobs.size(), 1uz);
auto const& job = test.runner.changing_jobs[0].job;
@@ -344,7 +344,7 @@ TEST_CASE(same_document_traversal_yields_to_a_newer_admitted_navigation)
test.traversable.set_ongoing_navigation({ .navigation_id = "newer"_utf16, .sequence_number = 3 });
test.traverse_to_step(0);
- EXPECT(test.traversable.ongoing_navigation().has_value());
+ EXPECT(test.traversable.ongoing_navigation());
EXPECT_EQ(test.runner.changing_jobs.size(), 1uz);
auto const& job = test.runner.changing_jobs[0].job;
EXPECT(job.traversal_yields_to == Web::HTML::TraversalYieldsTo::AdmittedNavigation);
@@ -358,7 +358,7 @@ TEST_CASE(cross_document_traversal_cancels_a_newer_navigation)
test.traversable.set_ongoing_navigation({ .navigation_id = "newer"_utf16, .sequence_number = 3 });
test.traverse_to_step(0);
- EXPECT(!test.traversable.ongoing_navigation().has_value());
+ EXPECT(!test.traversable.ongoing_navigation());
EXPECT(test.traversable.ongoing_navigation_is_traversal());
EXPECT_EQ(test.runner.changing_jobs.size(), 1uz);
auto const& job = test.runner.changing_jobs[0].job;
diff --git a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
index b2e811ee084..e466fbf9538 100644
--- a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
+++ b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
@@ -172,7 +172,7 @@ TEST_CASE(response_browsing_context_is_activated_only_at_commit)
traversable.did_commit_navigation(*committed_entry, move(committed_state), 1, navigation_id, WebView::CanonicalNavigable::DidPopulateDocument::Yes, {});
EXPECT_EQ(&traversable.active_browsing_context(), destination_context);
EXPECT(initial_group->browsing_context_set().is_empty());
- EXPECT(!traversable.ongoing_navigation().has_value());
+ EXPECT(!traversable.ongoing_navigation());
}
TEST_CASE(child_navigation_under_a_document_that_switched_groups_uses_its_group)
@@ -270,16 +270,16 @@ 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 job finalizing a navigation claims the document populated for it.
+ // The history operation finalizing a navigation takes it, with the document populated for it.
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);
- traversable.claim_document_populated_for_ongoing_navigation(*claimed_document);
+ EXPECT(traversable.take_navigation_to_finalize(claimed_navigation_id, 1).has_value());
+ EXPECT(!traversable.ongoing_navigation());
- // A newer navigation replaces the ongoing one before the claimed document is activated, and populates its own.
- traversable.clear_ongoing_navigation();
+ // 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) });
auto newer_document = make_document();
traversable.populate_document_for_ongoing_navigation(WebView::CanonicalDocumentState::create({}), newer_document);
@@ -297,7 +297,7 @@ TEST_CASE(document_claimed_by_a_history_job_outlives_a_newer_navigation)
traversable.did_commit_navigation(*WebView::CanonicalSessionHistoryEntry::create(claimed_document_state), move(committed_state), 1, claimed_navigation_id, WebView::CanonicalNavigable::DidPopulateDocument::Yes, {});
EXPECT_EQ(&traversable.active_document(), claimed_document.ptr());
EXPECT_EQ(traversable.pending_document().ptr(), newer_document.ptr());
- EXPECT(traversable.ongoing_navigation().has_value());
+ EXPECT(traversable.ongoing_navigation());
}
TEST_CASE(populated_document_replaces_tracked_load_when_document_state_is_reused)
@@ -344,11 +344,11 @@ TEST_CASE(same_document_traversal_commits_only_navigations_admitted_before_it)
// A navigation admitted after the traversal was requested goes on past the traversal's activation.
traversable.set_ongoing_navigation({ .navigation_id = Utf16String::from_utf8("newer"sv), .sequence_number = 2 });
traversable.did_commit_navigation(*entry, committed_state(), 1, {}, WebView::CanonicalNavigable::DidPopulateDocument::No, {});
- EXPECT(traversable.ongoing_navigation().has_value());
+ EXPECT(traversable.ongoing_navigation());
// One admitted before it does not.
traversable.did_commit_navigation(*entry, committed_state(), 3, {}, WebView::CanonicalNavigable::DidPopulateDocument::No, {});
- EXPECT(!traversable.ongoing_navigation().has_value());
+ EXPECT(!traversable.ongoing_navigation());
}
TEST_CASE(site_keyed_agent_clusters)
diff --git a/Tests/LibWebView/TestRendererOriginClaims.cpp b/Tests/LibWebView/TestRendererOriginClaims.cpp
index 93bbeda27eb..ce0d0918206 100644
--- a/Tests/LibWebView/TestRendererOriginClaims.cpp
+++ b/Tests/LibWebView/TestRendererOriginClaims.cpp
@@ -98,8 +98,8 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
.navigation_api_id = {},
};
stub.did_request_navigation_start(page_id, traversable.id(), Web::NavigationTarget::TopLevel, URL::about_blank(), navigation_id, move(request));
- auto const& ongoing_navigation = traversable.ongoing_navigation();
- return ongoing_navigation.has_value() && ongoing_navigation->navigation_id == navigation_id;
+ auto const* ongoing_navigation = traversable.ongoing_navigation();
+ return ongoing_navigation && ongoing_navigation->navigation_id == navigation_id;
};
// An about:blank document takes its initiator origin, so a victim's would give the renderer a document of its origin.