Skip to content

Truly independent web browser

LibWebView: Let origin-keyed tabs share a process

Andreas Klingce59c52ec692
diff --git a/Libraries/LibWebView/CanonicalDocument.cpp b/Libraries/LibWebView/CanonicalDocument.cpp
index 2987a551691..c463cd5505f 100644
--- a/Libraries/LibWebView/CanonicalDocument.cpp
+++ b/Libraries/LibWebView/CanonicalDocument.cpp
@@ -83,8 +83,7 @@ bool CanonicalDocument::may_share_a_process_with_tabs_of_its_origin() const
return false;
auto const& agent = m_relevant_global_object->agent();
- return !agent.agent_cluster_is_origin_keyed()
- && agent.agent_cluster_cross_origin_isolation_mode() == Web::HTML::CrossOriginIsolationMode::None
+ return agent.agent_cluster_cross_origin_isolation_mode() == Web::HTML::CrossOriginIsolationMode::None
&& m_opener_policy.value != Web::HTML::OpenerPolicyValue::SameOriginPlusCOEP;
}
diff --git a/Libraries/LibWebView/CanonicalDocument.h b/Libraries/LibWebView/CanonicalDocument.h
index 977bd600d58..94a0c372776 100644
--- a/Libraries/LibWebView/CanonicalDocument.h
+++ b/Libraries/LibWebView/CanonicalDocument.h
@@ -95,8 +95,8 @@ public:
bool is_top_level() const;
- // Whether this top-level document may be hosted by one process with the tabs of its origin. A document that is
- // origin-keyed or cross-origin isolated may not. Other opener policies only keep cross-origin windows away.
+ // Whether this top-level document may be hosted by one process with the tabs of its origin. A cross-origin isolated
+ // document may not. Other opener policies only keep cross-origin windows away.
bool may_share_a_process_with_tabs_of_its_origin() const;
// Whether this is local file content, whose process may read local files: a document created from a file: URL, or
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 30401cb365f..b4afd9b552e 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -893,11 +893,11 @@ static Optional<String> origin_of_sandboxed_document(CanonicalNavigable const& n
return {};
}
-static RefPtr<WebContentClient> lowest_process_hosting_only_tabs_of(URL::Origin const& origin, BrowsingSession const& session)
+static RefPtr<WebContentClient> lowest_process_hosting_only_tabs_like(CanonicalDocument const& document, BrowsingSession const& session)
{
RefPtr<WebContentClient> process;
WebContentClient::for_each_client([&](WebContentClient& client) {
- if (&client.session() == &session && client.is_open() && !client.has_requested_close() && client.has_hosted_only_tabs_of(origin) && (!process || client.child_id() < process->child_id()))
+ if (&client.session() == &session && client.is_open() && !client.has_requested_close() && client.has_hosted_only_tabs_like(document) && (!process || client.child_id() < process->child_id()))
process = client;
return IterationDecision::Continue;
});
@@ -929,14 +929,15 @@ RefPtr<WebContentClient> CanonicalNavigable::process_to_host_for_site_isolation(
return nullptr;
}
- // A tab goes to a process that has hosted only tabs of its origin, to share what the process holds. Nothing else can
- // reach a browsing context group of one, whereas an opener could make a process it can connect to host the tab. A
- // tab recovering from a crash gets a process of its own, so that it can't take the tabs it joins down with it again.
+ // A tab goes to a process that has hosted only tabs of its origin that are origin-keyed just as it is, to share
+ // what the process holds. Nothing else can reach a browsing context group of one, whereas an opener could make a
+ // process it can connect to host the tab. A tab recovering from a crash gets a process of its own, so that it can't
+ // take the tabs it joins down with it again.
if (!parent() && process_holding_navigable && document.may_share_a_process_with_tabs_of_its_origin()
&& document.browsing_context().top_level_browsing_context().group()->browsing_context_set().size() == 1
&& !top_level_traversable().has_page_standing_in_for_lost_document()
&& Application::the().same_origin_tabs_may_share_a_process()) {
- if (auto process = lowest_process_hosting_only_tabs_of(document.origin(), process_holding_navigable->session()))
+ if (auto process = lowest_process_hosting_only_tabs_like(document, process_holding_navigable->session()))
return process;
}
@@ -957,9 +958,10 @@ RefPtr<WebContentClient> CanonicalNavigable::process_to_host_for_site_isolation(
// A traversable's first document takes the process its initial about:blank came with, unless that document
// inherited its creator's origin and shares the creator's process, or a browsing context group switch leaves the
// initial about:blank's group. A noopener popup's initial about:blank came with the process of the document that
- // opened it, which a document of another origin stays out of if that process hosts tabs of one origin.
+ // opened it, which a document unlike the tabs of that process stays out of if the process hosts tabs of one
+ // origin.
if (!parent() && active_document().is_initial_about_blank() && active_document().origin().is_opaque() && !active_browsing_context().is_auxiliary() && &document.browsing_context() == &active_browsing_context()) {
- if (process_holding_navigable && process_holding_navigable->has_hosted_only_tabs_of_an_origin_other_than(document.origin()))
+ if (process_holding_navigable && process_holding_navigable->has_hosted_only_tabs_unlike(document))
return nullptr;
return process_holding_navigable;
}
diff --git a/Libraries/LibWebView/WebContentClient.cpp b/Libraries/LibWebView/WebContentClient.cpp
index dd075585ffd..de6f22f5aa0 100644
--- a/Libraries/LibWebView/WebContentClient.cpp
+++ b/Libraries/LibWebView/WebContentClient.cpp
@@ -88,11 +88,14 @@ void WebContentClient::note_hosted_document(CanonicalDocument const& document)
auto const& origin = document.origin();
if (document.may_share_a_process_with_tabs_of_its_origin()) {
- if (!m_origin_of_hosted_tabs.has_value())
+ if (!m_origin_of_hosted_tabs.has_value()) {
m_origin_of_hosted_tabs = origin;
- if (m_origin_of_hosted_tabs == origin)
+ m_hosted_tabs_are_origin_keyed = document.relevant_global_object().agent().agent_cluster_is_origin_keyed();
+ }
+ if (has_hosted_only_tabs_like(document))
return;
- } else if (!document.is_top_level() && m_origin_of_hosted_tabs.has_value() && !origin.is_opaque() && origin.is_same_site(*m_origin_of_hosted_tabs)) {
+ } else if (!document.is_top_level() && m_origin_of_hosted_tabs.has_value() && !origin.is_opaque()
+ && (m_hosted_tabs_are_origin_keyed ? origin.is_same_origin(*m_origin_of_hosted_tabs) : origin.is_same_site(*m_origin_of_hosted_tabs))) {
return;
}
@@ -100,6 +103,17 @@ void WebContentClient::note_hosted_document(CanonicalDocument const& document)
m_origin_of_hosted_tabs.clear();
}
+bool WebContentClient::has_hosted_only_tabs_like(CanonicalDocument const& document) const
+{
+ return m_origin_of_hosted_tabs == document.origin()
+ && m_hosted_tabs_are_origin_keyed == document.relevant_global_object().agent().agent_cluster_is_origin_keyed();
+}
+
+bool WebContentClient::has_hosted_only_tabs_unlike(CanonicalDocument const& document) const
+{
+ return m_origin_of_hosted_tabs.has_value() && !has_hosted_only_tabs_like(document);
+}
+
bool WebContentClient::hosts_an_environment_with_storage_key(Web::StorageAPI::StorageKey const& storage_key)
{
bool hosts_one = false;
diff --git a/Libraries/LibWebView/WebContentClient.h b/Libraries/LibWebView/WebContentClient.h
index b3951e52e92..b3b33a74b6d 100644
--- a/Libraries/LibWebView/WebContentClient.h
+++ b/Libraries/LibWebView/WebContentClient.h
@@ -139,10 +139,11 @@ public:
Optional<String> const& hosted_web_ui() const { return m_hosted_web_ui; }
void set_hosted_web_ui(String host) { m_hosted_web_ui = move(host); }
// A process can take in a tab of an origin only if all it has ever hosted, and so may still hold, is tabs of that
- // origin with their same-site iframes.
+ // origin with their same-site iframes. An origin-keyed tab keeps apart from the other origins of its site, so it
+ // only joins origin-keyed tabs of its origin, in a process that has not hosted iframes of those other origins.
void note_hosted_document(CanonicalDocument const&);
- bool has_hosted_only_tabs_of(URL::Origin const& origin) const { return m_origin_of_hosted_tabs == origin; }
- bool has_hosted_only_tabs_of_an_origin_other_than(URL::Origin const& origin) const { return m_origin_of_hosted_tabs.has_value() && m_origin_of_hosted_tabs != origin; }
+ bool has_hosted_only_tabs_like(CanonicalDocument const&) const;
+ bool has_hosted_only_tabs_unlike(CanonicalDocument const&) const;
void register_embedded_page(Web::PageId page_id, CanonicalTraversable&);
void unregister_embedded_page(Web::PageId page_id);
Optional<Web::PageId> page_id_for_traversable(CanonicalTraversable const&) const;
@@ -268,6 +269,7 @@ private:
bool m_has_hosted_local_file_content { false };
Optional<String> m_hosted_web_ui;
Optional<URL::Origin> m_origin_of_hosted_tabs;
+ bool m_hosted_tabs_are_origin_keyed { false };
bool m_has_hosted_more_than_tabs_of_one_origin { false };
Vector<u64> m_crashed_view_ids;