Skip to content

Truly independent web browser

LibWeb+LibWebView+WebContent: Replicate completely loaded from document

Shannon Bootha7f09a3bd1aa
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index c449cdf65c7..350a901304c 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -4700,7 +4700,7 @@ void Document::completely_finish_loading()
// document, reached through the UI process, which mirrors that the document is completely loaded.
if (container)
container->content_navigable_completely_finished_loading();
- navigable->page().client().page_did_completely_finish_loading(navigable->id());
+ navigable->page().client().page_did_completely_finish_loading(navigable->id(), *this);
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-cookie
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index b01bbe924fe..6d87fb0cd75 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -1540,7 +1540,6 @@ HostedNavigableState LocalNavigable::hosted_state() const
.active_document_url = m_active_document->url(),
.active_document_is_fully_active = m_active_document->is_fully_active(),
.opener_policy = m_active_document->opener_policy(),
- .active_document_is_completely_loaded = m_active_document->is_completely_loaded(),
.is_closing = m_closing,
.container = container_state(),
.delays_the_load_event_of_its_container = delays_the_load_event_of_its_container(),
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 0bcf2a58b5e..b8b7028a8e7 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -611,7 +611,7 @@ public:
virtual void page_did_create_child_frame(HTML::CrossProcessId, DOM::Document const&, HTML::CrossProcessId, HTML::HostedNavigableState const&, HTML::PendingSessionHistoryEntryDescriptor const&, URL::Origin const&, HTML::EnvironmentId const&, HTML::CrossProcessId) { }
virtual void page_did_change_hosted_navigable_state([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] HTML::HostedNavigableState const& state) { }
virtual void page_did_set_opener_browsing_context([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] Optional<HTML::CrossProcessId> opener_navigable_id) { }
- virtual void page_did_completely_finish_loading([[maybe_unused]] HTML::CrossProcessId navigable_id) { }
+ virtual void page_did_completely_finish_loading([[maybe_unused]] HTML::CrossProcessId navigable_id, DOM::Document const&) { }
virtual void page_did_change_navigable_container_state([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] HTML::ReplicatedContainerState const& state) { }
virtual void page_did_update_child_frame_viewport(HTML::CrossProcessId, [[maybe_unused]] DevicePixelRect viewport_rect, [[maybe_unused]] DevicePixelRect viewport_intersection) { }
virtual void page_did_destroy_child_frame(HTML::CrossProcessId) { }
diff --git a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp
index a75cd4a218e..b9317baa670 100644
--- a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp
+++ b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp
@@ -40,7 +40,6 @@ ErrorOr<void> encode(Encoder& encoder, Web::HTML::HostedNavigableState const& st
TRY(encoder.encode(state.active_document_url));
TRY(encoder.encode(state.active_document_is_fully_active));
TRY(encoder.encode(state.opener_policy));
- TRY(encoder.encode(state.active_document_is_completely_loaded));
TRY(encoder.encode(state.is_closing));
TRY(encoder.encode(state.container));
TRY(encoder.encode(state.delays_the_load_event_of_its_container));
@@ -55,7 +54,6 @@ ErrorOr<Web::HTML::HostedNavigableState> decode(Decoder& decoder)
.active_document_url = TRY(decoder.decode<URL::URL>()),
.active_document_is_fully_active = TRY(decoder.decode<bool>()),
.opener_policy = TRY(decoder.decode<Web::HTML::OpenerPolicy>()),
- .active_document_is_completely_loaded = TRY(decoder.decode<bool>()),
.is_closing = TRY(decoder.decode<bool>()),
.container = TRY(decoder.decode<Web::HTML::ReplicatedContainerState>()),
.delays_the_load_event_of_its_container = TRY(decoder.decode<bool>()),
diff --git a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h
index fe27ebf73f1..f34ae6f7e1d 100644
--- a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h
+++ b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h
@@ -45,7 +45,6 @@ struct HostedNavigableState {
URL::URL active_document_url;
bool active_document_is_fully_active { false };
OpenerPolicy opener_policy;
- bool active_document_is_completely_loaded { false };
bool is_closing { false };
ReplicatedContainerState container;
bool delays_the_load_event_of_its_container { false };
diff --git a/Libraries/LibWebView/CanonicalBrowsingContext.cpp b/Libraries/LibWebView/CanonicalBrowsingContext.cpp
index da8893240fa..2cb05994bb3 100644
--- a/Libraries/LibWebView/CanonicalBrowsingContext.cpp
+++ b/Libraries/LibWebView/CanonicalBrowsingContext.cpp
@@ -102,6 +102,9 @@ CanonicalBrowsingContext::BrowsingContextAndDocument CanonicalBrowsingContext::c
// 23. Make active document.
document->make_active();
+ // 24. Completely finish loading document.
+ document->set_completely_loaded();
+
// 25. Return browsingContext and document.
return { browsing_context, document };
}
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 3e4bdab2967..5101692c683 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -1034,7 +1034,7 @@ Optional<Web::HTML::ReplicatedNavigableState> CanonicalNavigable::replicated_sta
.opener_policy = hosted_state.opener_policy,
.active_browsing_context_is_auxiliary = browsing_context.is_auxiliary(),
.opener_navigable_id = opener_navigable_id,
- .active_document_is_completely_loaded = hosted_state.active_document_is_completely_loaded,
+ .active_document_is_completely_loaded = active_document().is_completely_loaded(),
.is_closing = hosted_state.is_closing,
.container = hosted_state.container,
.delays_the_load_event_of_its_container = hosted_state.delays_the_load_event_of_its_container,
@@ -1114,12 +1114,17 @@ bool CanonicalNavigable::has_session_history_entry_and_ready_for_navigation() co
return is_top_level_traversable() || top_level_traversable().session_history().get_session_history_entries(*this).has_value();
}
-void CanonicalNavigable::active_document_completely_finished_loading()
+void CanonicalNavigable::document_completely_finished_loading(CanonicalDocument& document)
{
- active_document().set_completely_loaded();
+ document.set_completely_loaded();
+ if (&document != &active_document())
+ return;
+ send_replicated_state();
+ send_completely_finished_loading_to_container();
+}
- // The navigable's container runs the load event steps in the page hosting its parent's document, which is among
- // the pages representing the navigable.
+void CanonicalNavigable::send_completely_finished_loading_to_container() const
+{
top_level_traversable().for_each_page_representing(*this, [&](WebContentPage& page) {
page.async_content_navigable_completely_finished_loading(id());
});
@@ -1203,6 +1208,8 @@ void CanonicalNavigable::did_commit_navigation(CanonicalSessionHistoryEntry& ent
view->did_change_display_page({}, previous_display_page);
}
update_hosted_state(move(hosted_state));
+ if (document != previous_document && document->is_completely_loaded())
+ send_completely_finished_loading_to_container();
// The displaced document is gone, and its child navigables with it. When another page hosts the activated
// document, the page that hosted the displaced one holds the navigable remotely from now on.
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index d7885eedc5e..0759f4b02de 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -188,7 +188,7 @@ public:
bool active_document_has_cross_site_ancestor() const;
// Whether the navigable's active session history entry is among its session history entries.
bool has_session_history_entry_and_ready_for_navigation() const;
- void active_document_completely_finished_loading();
+ void document_completely_finished_loading(CanonicalDocument&);
void update_container_state(Web::HTML::ReplicatedContainerState);
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-current-history-entry
@@ -240,6 +240,8 @@ public:
void clear_active_document_load() { m_active_document_load = {}; }
private:
+ void send_completely_finished_loading_to_container() const;
+
Web::HTML::CrossProcessId m_id;
CanonicalNavigable* m_parent { nullptr };
RefPtr<CanonicalDocument> m_container_document;
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 033c5c7f092..49e8540a398 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -760,7 +760,6 @@ CanonicalTraversable& CanonicalTraversable::create_a_new_top_level_traversable(W
.active_document_url = initial_history_entry.url,
.active_document_is_fully_active = true,
.opener_policy = {},
- .active_document_is_completely_loaded = false,
.is_closing = false,
.container = {},
.delays_the_load_event_of_its_container = false,
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 31ad69b270b..b0515e34e2a 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -720,13 +720,16 @@ void WebContentPage::did_request_set_opener_of_navigable(Web::HTML::CrossProcess
endpoint->async_set_opener_of_navigable(navigable_id, opener_navigable_id);
}
-void WebContentPage::did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id)
+void WebContentPage::did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id)
{
- // Only the process hosting a navigable's active document speaks for it.
- auto navigable = hosted_navigable(navigable_id);
+ // Only the process hosting a document speaks for it.
+ auto navigable = traversable().find(navigable_id);
if (!navigable.has_value())
return;
- navigable->active_document_completely_finished_loading();
+ auto document = navigable->document_with_id(document_id);
+ if (!document || document->host() != this)
+ return;
+ navigable->document_completely_finished_loading(*document);
}
void WebContentPage::did_create_populated_document_with_an_origin_of_its_own(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin origin, Web::HTML::EnvironmentId environment_id)
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 0413d3aeb04..488584e91ef 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -172,7 +172,7 @@ private:
virtual void did_request_focusing_steps_for_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger focus_trigger) override;
virtual void did_request_window_focus_of_navigable(Web::HTML::CrossProcessId navigable_id) override;
virtual void did_request_set_opener_of_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId opener_navigable_id) override;
- virtual void did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id) override;
+ virtual void did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id) override;
virtual void did_create_populated_document_with_an_origin_of_its_own(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin origin, Web::HTML::EnvironmentId environment_id) override;
virtual void did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId container_document_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState replicated_state, Web::HTML::PendingSessionHistoryEntryDescriptor initial_history_entry, URL::Origin origin, Web::HTML::EnvironmentId environment_id, Web::HTML::CrossProcessId document_id) override;
virtual void did_set_browser_zoom(double factor) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 7d9cdb886bc..03eccbeb3bf 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -391,9 +391,9 @@ void PageClient::page_did_set_opener_browsing_context(Web::HTML::CrossProcessId
client().async_did_set_opener_browsing_context(m_id, navigable_id, opener_navigable_id);
}
-void PageClient::page_did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id)
+void PageClient::page_did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id, Web::DOM::Document const& document)
{
- client().async_did_completely_finish_loading(m_id, navigable_id);
+ client().async_did_completely_finish_loading(m_id, navigable_id, document.id());
}
void PageClient::page_did_change_navigable_container_state(Web::HTML::CrossProcessId navigable_id, Web::HTML::ReplicatedContainerState const& state)
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 2fdcde863f7..8e03f360669 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -199,7 +199,7 @@ private:
virtual void navigation_population_failed(Web::HTML::CrossProcessId, Utf16String const&) override;
virtual void page_did_change_hosted_navigable_state(Web::HTML::CrossProcessId navigable_id, Web::HTML::HostedNavigableState const&) override;
virtual void page_did_set_opener_browsing_context(Web::HTML::CrossProcessId navigable_id, Optional<Web::HTML::CrossProcessId> opener_navigable_id) override;
- virtual void page_did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id) override;
+ virtual void page_did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id, Web::DOM::Document const&) override;
virtual void page_did_change_navigable_container_state(Web::HTML::CrossProcessId navigable_id, Web::HTML::ReplicatedContainerState const&) override;
virtual void page_did_create_populated_document_with_an_origin_of_its_own(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin, Web::HTML::EnvironmentId const& environment_id) override;
virtual void page_did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::DOM::Document const& container_document, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState const&, Web::HTML::PendingSessionHistoryEntryDescriptor const& initial_history_entry, URL::Origin const& origin, Web::HTML::EnvironmentId const& environment_id, Web::HTML::CrossProcessId document_id) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index fd2d0dfc3d1..89169057cd9 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -99,7 +99,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_create_child_frame(Web::PageId page_id, Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId container_document_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState hosted_state, Web::HTML::PendingSessionHistoryEntryDescriptor initial_history_entry, URL::Origin origin, Web::HTML::EnvironmentId environment_id, Web::HTML::CrossProcessId document_id) =|
did_change_hosted_navigable_state(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::HostedNavigableState state) =|
did_set_opener_browsing_context(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Optional<Web::HTML::CrossProcessId> opener_navigable_id) =|
- did_completely_finish_loading(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
+ did_completely_finish_loading(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id) =|
did_change_navigable_container_state(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ReplicatedContainerState state) =|
did_update_child_frame_viewport(Web::PageId page_id, Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio) =|
did_forward_mouse_event_to_child_frame(Web::PageId page_id, Web::HTML::CrossProcessId frame_id, Web::MouseEvent event) =|
diff --git a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
index 1bdd5f69836..0b8996080b5 100644
--- a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
+++ b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
@@ -110,7 +110,6 @@ TEST_CASE(target_snapshot_params_take_the_popup_or_container_sandboxing_flags)
.active_document_url = URL::about_blank(),
.active_document_is_fully_active = true,
.opener_policy = {},
- .active_document_is_completely_loaded = false,
.is_closing = false,
.container = embedder,
.delays_the_load_event_of_its_container = false,
@@ -165,7 +164,6 @@ TEST_CASE(response_browsing_context_is_activated_only_at_commit)
.active_document_url = destination_url,
.active_document_is_fully_active = true,
.opener_policy = {},
- .active_document_is_completely_loaded = false,
.is_closing = false,
.container = {},
.delays_the_load_event_of_its_container = false,
@@ -211,7 +209,6 @@ TEST_CASE(child_navigation_under_a_document_that_switched_groups_uses_its_group)
.active_document_url = destination_url,
.active_document_is_fully_active = true,
.opener_policy = {},
- .active_document_is_completely_loaded = false,
.is_closing = false,
.container = {},
.delays_the_load_event_of_its_container = false,
@@ -292,7 +289,6 @@ TEST_CASE(document_claimed_by_a_history_job_outlives_a_newer_navigation)
.active_document_url = URL::about_blank(),
.active_document_is_fully_active = true,
.opener_policy = {},
- .active_document_is_completely_loaded = false,
.is_closing = false,
.container = {},
.delays_the_load_event_of_its_container = false,
@@ -318,7 +314,6 @@ TEST_CASE(populated_document_replaces_tracked_load_when_document_state_is_reused
.active_document_url = destination_url,
.active_document_is_fully_active = true,
.opener_policy = {},
- .active_document_is_completely_loaded = false,
.is_closing = false,
.container = {},
.delays_the_load_event_of_its_container = false,
@@ -339,7 +334,6 @@ TEST_CASE(same_document_traversal_commits_only_navigations_admitted_before_it)
.active_document_url = URL::about_blank(),
.active_document_is_fully_active = true,
.opener_policy = {},
- .active_document_is_completely_loaded = true,
.is_closing = false,
.container = {},
.delays_the_load_event_of_its_container = false,