Truly independent web browser
LibWebView: Take a navigable's active document URL from its active entry
Shannon Boothbde0258e73e1
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 4f2d7d4ef46..0ca85c4d663 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -1527,7 +1527,6 @@ HostedNavigableState LocalNavigable::hosted_state() const{VERIFY(m_active_document);return {- .active_document_url = m_active_document->url(),.active_document_is_fully_active = m_active_document->is_fully_active(),.is_closing = m_closing,.container = container_state(),diff --git a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cppindex 88c0ea1e2ae..241fbf38dc9 100644--- a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp+++ b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp@@ -37,7 +37,6 @@ ErrorOr<Web::HTML::ReplicatedContainerState> decode(Decoder& decoder)template<>ErrorOr<void> encode(Encoder& encoder, Web::HTML::HostedNavigableState const& state){- TRY(encoder.encode(state.active_document_url));TRY(encoder.encode(state.active_document_is_fully_active));TRY(encoder.encode(state.is_closing));TRY(encoder.encode(state.container));@@ -50,7 +49,6 @@ template<>ErrorOr<Web::HTML::HostedNavigableState> decode(Decoder& decoder){return Web::HTML::HostedNavigableState {- .active_document_url = TRY(decoder.decode<URL::URL>()),.active_document_is_fully_active = TRY(decoder.decode<bool>()),.is_closing = TRY(decoder.decode<bool>()),.container = TRY(decoder.decode<Web::HTML::ReplicatedContainerState>()),diff --git a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.hindex 0bc638dbece..75a9bec81af 100644--- a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h+++ b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h@@ -42,7 +42,6 @@ struct ReplicatedContainerState {// What the process hosting a navigable's active document reports of it to the UI process, which composes the// navigable's replicated state from this and the session history, browsing contexts and documents it holds.struct HostedNavigableState {- URL::URL active_document_url;bool active_document_is_fully_active { false };bool is_closing { false };ReplicatedContainerState container;diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex 7653a42d8d7..82801b7bf3f 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -46,6 +46,12 @@ CanonicalDocument& CanonicalNavigable::active_document() constreturn *m_active_session_history_entry->document_state->document;}+URL::URL const& CanonicalNavigable::active_document_url() const+{+ VERIFY(m_active_session_history_entry);+ return m_active_session_history_entry->url;+}+CanonicalBrowsingContext& CanonicalNavigable::active_browsing_context() const{// A navigable's active browsing context is its active document's browsing context.@@ -196,7 +202,7 @@ void CanonicalNavigable::begin_navigation(Web::HTML::PreparedNavigationDescripto// 1. If url equals navigable's active document's URL, and either userInvolvement is "browser UI" or// initiatorOriginSnapshot is same origin with navigable's active document's origin, then set historyHandling// to "replace".- if (m_hosted_state.has_value() && url == m_hosted_state->active_document_url+ if (url == active_document_url()&& (user_involvement == Web::HTML::UserNavigationInvolvement::BrowserUI || navigation.initiator_origin_snapshot.is_same_origin(active_document().origin()))) {history_handling = Web::Bindings::NavigationHistoryBehavior::Replace;}@@ -1012,7 +1018,7 @@ void CanonicalNavigable::send_viewport_to(WebContentPage& host) constvoid CanonicalNavigable::set_hosted_state(Web::HTML::HostedNavigableState state){- m_document_blob_url = BlobURLHandle::for_url(blob_url_store(), state.active_document_url);+ m_document_blob_url = BlobURLHandle::for_url(blob_url_store(), active_document_url());m_hosted_state = move(state);}@@ -1072,7 +1078,7 @@ Optional<Web::HTML::ReplicatedNavigableState> CanonicalNavigable::replicated_stareturn Web::HTML::ReplicatedNavigableState {.target_name = target_name(),- .active_document_url = hosted_state.active_document_url,+ .active_document_url = active_document_url(),.active_document_origin = active_document().origin(),.active_document_is_fully_active = hosted_state.active_document_is_fully_active,.top_level_creation_url = traversable.active_document().creation_url(),diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.hindex bf1271a14b9..a0cd70e51bd 100644--- a/Libraries/LibWebView/CanonicalNavigable.h+++ b/Libraries/LibWebView/CanonicalNavigable.h@@ -85,6 +85,7 @@ public:// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-documentCanonicalDocument& active_document() const;+ URL::URL const& active_document_url() const;// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-target-nameUtf16String const& target_name() const;diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex 5c4b527c92b..dc519676825 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -751,7 +751,6 @@ CanonicalTraversable& CanonicalTraversable::create_a_new_top_level_traversable(Wtraversable->set_active_session_history_entry(history_entry);// NB: The initial document is active from the traversable's creation, before a process hosts it.traversable->set_hosted_state({- .active_document_url = initial_history_entry.url,.active_document_is_fully_active = true,.is_closing = false,.container = {},@@ -2272,6 +2271,7 @@ void CanonicalTraversable::finalize_a_same_document_navigation(HistoryOperation&m_session_history.update_directive_state_value(target_entry->directive_state_id, target_entry->directive_state_value);target_navigable->set_active_session_history_entry(target_entry);+ target_navigable->send_replicated_state();// 6. Apply the push/replace history step targetStep to traversable given historyHandling and userInvolvement.apply_the_push_or_replace_history_step(operation, *target_step, request.history_handling, request.user_involvement);diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex cc2575c4f1d..6259eaac8b9 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -152,7 +152,7 @@ URL::URL ViewImplementation::url() const{if (!m_top_level_traversable)return URL::about_blank();- return m_top_level_traversable->active_session_history_entry()->url;+ return m_top_level_traversable->active_document_url();}void ViewImplementation::did_update_url()diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex 12e38a3aa81..b9680471832 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -127,7 +127,7 @@ public:void did_change_active_document(Badge<CanonicalTraversable>);void set_text_fragment_indication_visibility(Badge<WebContentPage>, bool);- // The URL of the tab's active session history entry.+ // The URL of the tab's active document.URL::URL url() const;URL::URL const& displayed_url() const { return m_displayed_url; }diff --git a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cppindex 95916f73bd7..9ac09beaeec 100644--- a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp+++ b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp@@ -146,7 +146,6 @@ TEST_CASE(target_snapshot_params_take_the_popup_or_container_sandboxing_flags)auto& frame = traversable.append_child(make<WebView::CanonicalNavigable>(Web::HTML::CrossProcessId { 2, 1 }));frame.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, frame_document)));frame.set_hosted_state({- .active_document_url = URL::about_blank(),.active_document_is_fully_active = true,.is_closing = false,.container = embedder,@@ -200,7 +199,6 @@ TEST_CASE(response_browsing_context_is_activated_only_at_commit)traversable.set_ongoing_navigation(navigation_for_testing(navigation_id, 0, committed_entry));traversable.populate_document(traversable.uncommitted_navigation()->history_entry->document_state, destination_document);Web::HTML::HostedNavigableState committed_state {- .active_document_url = destination_url,.active_document_is_fully_active = true,.is_closing = false,.container = {},@@ -244,7 +242,6 @@ TEST_CASE(child_navigation_under_a_document_that_switched_groups_uses_its_group)traversable.set_ongoing_navigation(navigation_for_testing(navigation_id, 0, WebView::CanonicalSessionHistoryEntry::create(destination_document_state)));traversable.populate_document(traversable.uncommitted_navigation()->history_entry->document_state, destination_document);Web::HTML::HostedNavigableState committed_state {- .active_document_url = destination_url,.active_document_is_fully_active = true,.is_closing = false,.container = {},@@ -324,7 +321,6 @@ TEST_CASE(document_claimed_by_a_history_job_outlives_a_newer_navigation)EXPECT_EQ(claimed_document_state->populated_document->document.ptr(), claimed_document.ptr());Web::HTML::HostedNavigableState committed_state {- .active_document_url = URL::about_blank(),.active_document_is_fully_active = true,.is_closing = false,.container = {},@@ -350,7 +346,6 @@ TEST_CASE(populated_document_replaces_tracked_load_when_document_state_is_reusedauto destination_url = URL::Parser::basic_parse("https://ladybird.org/redirected"sv).release_value();Web::HTML::HostedNavigableState committed_state {- .active_document_url = destination_url,.active_document_is_fully_active = true,.is_closing = false,.container = {},@@ -369,7 +364,6 @@ TEST_CASE(same_document_traversal_commits_only_navigations_admitted_before_it)traversable.set_active_session_history_entry(entry);auto committed_state = [] {return Web::HTML::HostedNavigableState {- .active_document_url = URL::about_blank(),.active_document_is_fully_active = true,.is_closing = false,.container = {},