Skip to content

Truly independent web browser

LibWeb+LibWebView+WebContent: Navigate from another agent in the UI

Shannon Booth841d6412822b
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 1a257e7f26b..3ea396880c6 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -3464,29 +3464,27 @@ void LocalNavigable::continue_navigation_after_population_dispatch(PreparedNavig
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate
-void LocalNavigable::continue_navigation_from_another_process(PreparedNavigationDescriptor descriptor)
-{
- // 8. If the surrounding agent is equal to navigable's active document's relevant agent, then continue these
- // steps. Otherwise, queue a global task on the navigation and traversal task source given navigable's active
- // window to continue these steps.
- // NB: The surrounding agent is the requesting process's, never navigable's active document's relevant agent.
- auto window = active_window();
- if (!window)
- return;
- queue_global_task(Task::Source::NavigationAndTraversal, relevant_global_object(*window), GC::create_function(heap(), [this, window, descriptor = move(descriptor)] mutable {
- MUST(continue_navigation_in_active_document_agent(create_prepared_navigation_from_descriptor(relevant_realm(*window), move(descriptor))));
- }));
-}
-
-// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate
-// NB: The UI process runs navigate for a navigation from the browser's UI, or of a document that was lost, but for the
-// steps that need navigable's container or active document. This process runs those, then the unload check and
-// the first steps of population it is asked for.
+// NB: The UI process runs navigate for a navigation from the browser's UI, from a sourceDocument in another process, or
+// of a document that was lost, but for the steps that need navigable's container or active document. This process
+// runs those, then the unload check and the first steps of population it is asked for.
void LocalNavigable::adopt_navigation_started_in_ui_process(Utf16String navigation_id)
{
if (has_been_destroyed() || !active_window())
return;
+ // 10. Let container be navigable's container.
+ auto container = this->container();
+
+ // 11. If container is an iframe element and will lazy load element steps given container returns true,
+ // then stop intersection-observing a lazy loading element container and set container's lazy load resumption steps to null.
+ if (container && container->is_html_iframe_element()) {
+ auto& iframe_element = static_cast<HTMLIFrameElement&>(*container);
+ if (iframe_element.will_lazy_load_element()) {
+ iframe_element.document().stop_intersection_observing_a_lazy_loading_element(iframe_element);
+ iframe_element.set_lazy_load_resumption_steps(nullptr);
+ }
+ }
+
// 15. If navigable's parent is non-null, then set navigable's is delaying load events to true.
if (parent())
set_delaying_load_events(true);
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index e53698c1123..dcbb012c639 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -190,7 +190,6 @@ public:
void clear_ongoing_history_traversal();
bool resume_navigation_params_creation(Utf16String const& navigation_id, Optional<NavigationPopulationRequest>);
- void continue_navigation_from_another_process(PreparedNavigationDescriptor);
void adopt_navigation_started_in_ui_process(Utf16String navigation_id);
void navigate_to_a_javascript_url_from_ui_process(URL::URL const&, HistoryHandlingBehavior, URL::Origin const& initiator_origin, NavigationSourceSnapshot const&, UserNavigationInvolvement, ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type, Utf16String navigation_id);
void navigate_to_a_fragment(URL::URL const&, HistoryHandlingBehavior, UserNavigationInvolvement, GC::Ptr<DOM::Element> source_element, Optional<StorageSerializationRecord> navigation_api_state, Utf16String navigation_id, GC::Ptr<NavigationAPIMethodTracker> api_method_tracker);
diff --git a/Libraries/LibWeb/HTML/PreparedNavigationDescriptor.cpp b/Libraries/LibWeb/HTML/PreparedNavigationDescriptor.cpp
index 392e141c922..ec95a623332 100644
--- a/Libraries/LibWeb/HTML/PreparedNavigationDescriptor.cpp
+++ b/Libraries/LibWeb/HTML/PreparedNavigationDescriptor.cpp
@@ -106,26 +106,4 @@ PreparedNavigationDescriptor prepare_navigation_from_document(DOM::Document& sou
};
}
-PreparedNavigation create_prepared_navigation_from_descriptor(JS::Realm& realm, PreparedNavigationDescriptor descriptor)
-{
- return {
- .url = move(descriptor.url),
- .document_resource = move(descriptor.document_resource),
- .response = nullptr,
- .history_handling = descriptor.history_handling,
- .navigation_api_state = move(descriptor.navigation_api_state),
- .form_data_entry_list = {},
- .referrer_policy = descriptor.referrer_policy,
- .user_involvement = descriptor.user_involvement,
- .navigation_id = move(descriptor.navigation_id),
- .source_element = nullptr,
- .initial_insertion = descriptor.initial_insertion,
- .api_method_tracker = nullptr,
- .csp_navigation_type = descriptor.csp_navigation_type,
- .source_snapshot_params = create_source_snapshot_params_from_navigation_source_snapshot(realm, descriptor.source_snapshot_params),
- .initiator_origin_snapshot = move(descriptor.initiator_origin_snapshot),
- .initiator_base_url_snapshot = move(descriptor.initiator_base_url_snapshot),
- };
-}
-
}
diff --git a/Libraries/LibWeb/HTML/PreparedNavigationDescriptor.h b/Libraries/LibWeb/HTML/PreparedNavigationDescriptor.h
index f9d288e3ad8..7f4309b44f4 100644
--- a/Libraries/LibWeb/HTML/PreparedNavigationDescriptor.h
+++ b/Libraries/LibWeb/HTML/PreparedNavigationDescriptor.h
@@ -28,6 +28,5 @@ struct NavigationSourceSnapshots {
WEB_API NavigationSourceSnapshots snapshot_navigation_source(GC::Ptr<DOM::Document> source_document);
WEB_API PreparedNavigationDescriptor prepare_navigation_from_document(DOM::Document& source_document, URL::URL, ReferrerPolicy::ReferrerPolicy);
-WEB_API PreparedNavigation create_prepared_navigation_from_descriptor(JS::Realm&, PreparedNavigationDescriptor);
}
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index ca0ff789ad1..1dcf601294f 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -189,9 +189,8 @@ void CanonicalNavigable::begin_navigation(Web::HTML::PreparedNavigationDescripto
if (traversable.is_unloading_document_of(id()))
return;
- // NB: A navigation from the browser's UI navigates a traversable, which has no container. A child's container ended
- // lazy loading, steps 10 and 11, when the document that was lost loaded, and the process populating its next
- // document runs step 15.
+ // NB: The page hosting navigable's active document, which has its container if any process does, runs steps 10,
+ // 11, and 15.
// 12. If historyHandling is "auto", then:
auto history_handling = navigation.history_handling;
@@ -283,8 +282,9 @@ void CanonicalNavigable::begin_navigation(Web::HTML::PreparedNavigationDescripto
return;
}
- // NB: Step 21 fires the navigate event at navigable's active window, which is gone with a lost document, and not
- // for a navigation from the browser's UI.
+ // NB: Step 21 fires the navigate event at navigable's active window, which is gone with a lost document. It is not
+ // fired for a navigation from the browser's UI, nor for a sourceDocument in another agent, which is never same
+ // origin-domain with navigable's active document.
// FIXME: 22. If sourceDocument is navigable's container document, then reserve deferred fetch quota for navigable's
// container given url's origin.
@@ -330,18 +330,6 @@ void CanonicalNavigable::begin_navigation(Web::HTML::PreparedNavigationDescripto
worker->begin_navigation_unload_check(*this, navigation_id);
}
-void CanonicalNavigable::set_routed_navigation(Utf16String navigation_id, URL::Origin initiator_origin)
-{
- m_routed_navigation = RoutedNavigation { move(navigation_id), move(initiator_origin) };
-}
-
-Optional<URL::Origin> CanonicalNavigable::take_routed_navigation_initiator_origin(Utf16String const& navigation_id)
-{
- if (!m_routed_navigation.has_value() || m_routed_navigation->navigation_id != navigation_id)
- return {};
- return m_routed_navigation.release_value().initiator_origin;
-}
-
// https://html.spec.whatwg.org/multipage/browsers.html#obtain-browsing-context-navigation
// NB: The browsing context is returned with its active document, which nothing else holds for a new one.
CanonicalBrowsingContext::BrowsingContextAndDocument CanonicalNavigable::obtain_a_browsing_context_to_use_for_a_navigation_response(NavigationLoader::ResponseDocument const& navigation_params)
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index 9a6bc814c7f..2aa7d2474d2 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -119,11 +119,6 @@ public:
Web::HTML::PreparedNavigationDescriptor prepare_navigation(URL::URL, Web::HTML::DocumentResource = {}, Web::Bindings::NavigationHistoryBehavior = Web::Bindings::NavigationHistoryBehavior::Auto);
void begin_navigation(Web::HTML::PreparedNavigationDescriptor);
- // A navigation another page started for the navigable continues in the page hosting its document, with the
- // initiator origin the UI process took from the page that started it.
- void set_routed_navigation(Utf16String navigation_id, URL::Origin initiator_origin);
- Optional<URL::Origin> take_routed_navigation_initiator_origin(Utf16String const& navigation_id);
-
CanonicalBrowsingContext::BrowsingContextAndDocument obtain_a_browsing_context_to_use_for_a_navigation_response(NavigationLoader::ResponseDocument const&);
NonnullRefPtr<CanonicalDocument> create_and_initialize_a_document(NavigationLoader::ResponseDocument const&);
@@ -262,11 +257,6 @@ private:
void end_navigation(CanonicalNavigation&);
OngoingNavigation m_ongoing_navigation;
Vector<NonnullOwnPtr<CanonicalNavigation>> m_navigations;
- struct RoutedNavigation {
- Utf16String navigation_id;
- URL::Origin initiator_origin;
- };
- Optional<RoutedNavigation> m_routed_navigation;
RefPtr<WebContentClient> process_to_host_for_site_isolation(CanonicalDocument const&, Optional<URL::Origin> const& initiator_origin) const;
ErrorOr<NonnullRefPtr<WebContentPage>> obtain_page_to_host_in(RefPtr<WebContentClient> process);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index a8f7ff3042d..1597494e32a 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -642,11 +642,11 @@ bool WebContentPage::take_owed_reply(OwedReply owed)
return m_owed_replies.remove(owed);
}
-static bool may_navigate_to_a_local_file(WebContentClient& requesting_client, Web::HTML::NavigationSourceSnapshot const& source_snapshot_params);
+static bool may_navigate_to_a_local_file(WebContentClient& requesting_client);
void WebContentPage::did_request_navigation_of_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id, Web::HTML::CrossProcessId source_document_id, Web::HTML::PreparedNavigationDescriptor navigation)
{
- if (navigation.url.scheme() == "file"sv && !may_navigate_to_a_local_file(client(), navigation.source_snapshot_params))
+ if (navigation.url.scheme() == "file"sv && !may_navigate_to_a_local_file(client()))
return;
auto target = traversable().find(navigable_id);
@@ -668,6 +668,11 @@ void WebContentPage::did_request_navigation_of_navigable(Web::HTML::CrossProcess
if (!source.has_value())
return;
auto& source_document = source->active_document();
+ auto const& fetch_client = navigation.source_snapshot_params.fetch_client;
+ if (!fetch_client.has_value() || fetch_client->id != source_document.relevant_global_object().relevant_settings_object().id()) {
+ client().did_misbehave("did_request_navigation_of_navigable"sv, "fetch client is not the source document's environment"sv);
+ return;
+ }
// 6. Otherwise:
// 2. If sourceDocument's node navigable is not allowed by sandboxing to navigate navigable given
@@ -683,18 +688,7 @@ void WebContentPage::did_request_navigation_of_navigable(Web::HTML::CrossProcess
// 3. Set initiatorOriginSnapshot to sourceDocument's origin.
navigation.initiator_origin_snapshot = source_document.origin();
- // A document that was lost with the process that hosted it is navigated from step 8 on here: no process hosts it.
- if (!target->active_document().host()) {
- target->begin_navigation(move(navigation));
- return;
- }
- target->set_routed_navigation(navigation.navigation_id, navigation.initiator_origin_snapshot);
-
- // The request continues navigate at step 8 in the process hosting the target's document.
- auto endpoint = endpoint_hosting_navigable_represented_by(navigable_id);
- if (!endpoint)
- return;
- endpoint->async_navigate_navigable(navigable_id, move(navigation));
+ target->begin_navigation(move(navigation));
}
void WebContentPage::did_post_message_to_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor message)
@@ -898,23 +892,9 @@ static Optional<URL::Origin> initiator_origin_snapshot(URL::Origin const& given_
// A page reaches local file content only by navigating there from local file content, or from the browser's UI: a
// process holding none could otherwise come to host a file: document, and with it read every file the user can.
-static bool may_navigate_to_a_local_file(WebContentClient& requesting_client, Web::HTML::NavigationSourceSnapshot const& source_snapshot_params)
+static bool may_navigate_to_a_local_file(WebContentClient& requesting_client)
{
- if (requesting_client.may_read_local_files())
- return true;
-
- // A navigation a page starts in another process's navigable continues in that process, so the process hosting the
- // fetch client vouches for it.
- if (!source_snapshot_params.fetch_client.has_value())
- return false;
- bool result = false;
- WebContentClient::for_each_client([&](WebContentClient& client) {
- if (!client.hosted_environment(source_snapshot_params.fetch_client->id).has_value())
- return IterationDecision::Continue;
- result = client.may_read_local_files();
- return IterationDecision::Break;
- });
- return result;
+ return requesting_client.may_read_local_files();
}
// A navigation a page asked the browser's UI to start for it, with the initiator origin the UI process takes from the
@@ -925,7 +905,7 @@ static Optional<Web::HTML::PreparedNavigationDescriptor> navigation_from_page(We
auto initiator_origin = initiator_origin_snapshot(navigation.initiator_origin_snapshot, navigation.source_snapshot_params, requesting_client);
if (!initiator_origin.has_value())
return {};
- if (navigation.url.scheme() == "file"sv && !may_navigate_to_a_local_file(requesting_client, navigation.source_snapshot_params))
+ if (navigation.url.scheme() == "file"sv && !may_navigate_to_a_local_file(requesting_client))
return {};
navigation.initiator_origin_snapshot = initiator_origin.release_value();
return navigation;
@@ -1924,14 +1904,9 @@ void WebContentPage::did_request_navigation_start(Web::HTML::CrossProcessId navi
// "traversal" since.
auto navigation_is_blocked_by_history_traversal = target_navigable
&& target_navigable->ongoing_navigation().has<CanonicalNavigable::Traversal>();
- // The page hosting the navigable's document continues navigate at step 8, for a sourceDocument it hosts or for
- // one another page hosts, which asked the UI process to route the navigation here.
Optional<URL::Origin> initiator_origin;
- if (start_request.has_value() && target_navigable) {
+ if (start_request.has_value())
initiator_origin = initiator_origin_snapshot(start_request->initiator_origin, start_request->source_snapshot_params, client());
- if (!initiator_origin.has_value())
- initiator_origin = target_navigable->take_routed_navigation_initiator_origin(navigation_id);
- }
if (!target_navigable
|| target_navigable->id() != navigable_id
|| !traversable().hosts(*target_navigable, *this)
@@ -1946,7 +1921,7 @@ void WebContentPage::did_request_navigation_start(Web::HTML::CrossProcessId navi
client().did_misbehave("did_request_navigation_start"sv, "start request names another URL"sv);
return;
}
- if (start_request.has_value() && url.scheme() == "file"sv && !may_navigate_to_a_local_file(client(), start_request->source_snapshot_params)) {
+ if (start_request.has_value() && url.scheme() == "file"sv && !may_navigate_to_a_local_file(client())) {
async_cancel_navigation_params_creation(navigable_id, navigation_id);
return;
}
diff --git a/Meta/Linters/check_libweb_realm_mentions.py b/Meta/Linters/check_libweb_realm_mentions.py
index 9bc01d81060..07ae9da5ce6 100755
--- a/Meta/Linters/check_libweb_realm_mentions.py
+++ b/Meta/Linters/check_libweb_realm_mentions.py
@@ -52,8 +52,8 @@ ALLOWED_REALM_MENTIONS = {
"FileAPI": (6, 11, "File/Blob/FileReader algorithms still create streams, buffers, and events in selected realms"),
"Geometry": (8, 8, "geometry constructors and structured clone still materialize JS-facing geometry objects"),
"HTML": (
- 73,
- 223,
+ 71,
+ 221,
"HTML algorithms still contain structured serialization, including posted-message preparation, canvas, navigation transfer/reconstruction, worker/worklet, and event realm use, and cross-origin Window/Location property functions are created in the current realm; RemoteWindow mirrors Window's postMessage",
),
"IndexedDB": (
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 7aba5e406be..9dfab3d32c3 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -282,12 +282,6 @@ void ConnectionFromClient::cancel_navigation_params_creation(Web::PageId page_id
page->cancel_navigation_params_creation(navigable_id, navigation_id);
}
-void ConnectionFromClient::navigate_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PreparedNavigationDescriptor navigation)
-{
- if (auto page = this->page(page_id); page.has_value())
- page->navigate_navigable(navigable_id, move(navigation));
-}
-
void ConnectionFromClient::deliver_posted_message(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor message)
{
if (auto page = this->page(page_id); page.has_value())
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index cdb9ff1058c..6990ecea99f 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -130,7 +130,6 @@ private:
virtual void run_navigation_unload_check(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, Web::HTML::UnloadPromptShown) override;
virtual void create_navigation_params(Web::PageId page_id, Web::HTML::NavigationPopulationRequest) override;
virtual void cancel_navigation_params_creation(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id) override;
- virtual void navigate_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PreparedNavigationDescriptor) override;
virtual void deliver_posted_message(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor) override;
virtual void close_traversable_from_script(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id) override;
virtual void run_focusing_steps_for_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index a7b53b856a4..a8351dbb9fb 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -280,13 +280,6 @@ void PageClient::request_set_opener_of_remote_navigable(Web::HTML::RemoteNavigab
client().async_did_request_set_opener_of_navigable(m_id, navigable.id(), opener.id());
}
-void PageClient::navigate_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::PreparedNavigationDescriptor navigation)
-{
- // A navigable the page represents without hosting its document is addressed by the page hosting it.
- if (auto* navigable = as_if<Web::HTML::LocalNavigable>(page().navigable_with_id(navigable_id).ptr()))
- navigable->continue_navigation_from_another_process(move(navigation));
-}
-
void PageClient::deliver_posted_message(Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor message)
{
if (auto* navigable = as_if<Web::HTML::LocalNavigable>(page().navigable_with_id(navigable_id).ptr()))
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 4bce9cb92e2..64fd6685ace 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -147,7 +147,6 @@ public:
void run_navigation_unload_check(Web::HTML::CrossProcessId navigable_id, Utf16String const& navigation_id, Web::HTML::UnloadPromptShown);
void did_receive_unload_check_result(Web::HTML::CrossProcessId check_id, Web::HTML::CheckIfUnloadingIsCanceledResult);
void create_navigation_params(Web::HTML::NavigationPopulationRequest);
- void navigate_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::PreparedNavigationDescriptor);
void deliver_posted_message(Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor);
void cancel_navigation_params_creation(Web::HTML::CrossProcessId navigable_id, Utf16String const& navigation_id);
void populate_navigation(Web::HTML::NavigationPopulationRequest, Web::HTML::NavigationPopulationResult);
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index eef0b572b53..b9fbbe8a932 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -102,7 +102,6 @@ endpoint WebContentServer routed by Web::PageId page_id
run_navigation_unload_check(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, Web::HTML::UnloadPromptShown unload_prompt_shown) =|
create_navigation_params(Web::PageId page_id, Web::HTML::NavigationPopulationRequest request) =|
cancel_navigation_params_creation(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id) =|
- navigate_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PreparedNavigationDescriptor navigation) =|
deliver_posted_message(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor message) =|
close_traversable_from_script(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id) =|
run_focusing_steps_for_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger focus_trigger) =|