blob: 24f2067bd6d1a8bf019905576ba8a610f1441d23 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2021 The Chromium Authors
Sharon Yangd70a5392021-10-26 23:06:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_SITE_INFO_H_
6#define CONTENT_BROWSER_SITE_INFO_H_
7
Camille Lamyd1f015d2024-07-06 14:14:108#include "content/browser/agent_cluster_key.h"
Sharon Yangd70a5392021-10-26 23:06:329#include "content/browser/url_info.h"
10#include "content/browser/web_exposed_isolation_info.h"
11#include "content/common/content_export.h"
12#include "content/public/browser/storage_partition_config.h"
Robbie McElratheae661e2023-08-10 19:05:2813#include "content/public/browser/web_exposed_isolation_level.h"
Sharon Yangd70a5392021-10-26 23:06:3214#include "url/gurl.h"
15#include "url/origin.h"
16
17namespace content {
18
19class BrowserContext;
20class IsolationContext;
21class StoragePartitionConfig;
22struct UrlInfo;
23
24// SiteInfo represents the principal of a SiteInstance. All documents and
25// workers within a SiteInstance are considered part of this principal and will
26// share a renderer process. Any two documents within the same browsing context
27// group (i.e., BrowsingInstance) that are allowed to script each other *must*
28// have the same SiteInfo principal, so that they end up in the same renderer
29// process.
30//
31// As a result, SiteInfo is primarily defined in terms of "site URL," which is
32// often the scheme plus the eTLD+1 of a URL. This allows same-site URLs to
33// always share a process even when document.domain is modified. However, some
34// site URLs can be finer grained (e.g., origins) or coarser grained (e.g.,
35// file://). See |site_url()| for more considerations.
36//
37// In the future, we may add more information to SiteInfo for cases where the
38// site URL is not sufficient to identify which process a document belongs in.
39// For example, origin isolation (https://crbug.com/1067389) will introduce a
40// 'keying' bit ('site' or 'origin') to avoid an ambiguity between sites and
41// origins, and it will be possible for two SiteInstances with different keying
42// values to have the same site URL. It is important that any extra members of
43// SiteInfo do not cause two documents that can script each other to end up in
44// different SiteInfos and thus different processes.
45class CONTENT_EXPORT SiteInfo {
46 public:
Alex Moshchuk1b945fc2022-02-08 23:38:4547 // Helper to create a SiteInfo that will be used for an error page. This is
48 // used only when error page isolation is enabled. Note that when site
49 // isolation for guests is enabled, an error page SiteInfo may also be
Adithya Srinivasaneae091b2022-09-02 18:31:3350 // associated with a guest. Similarly, when process isolation for fenced
51 // frames is enabled, error pages inside fenced frames will be isolated from
52 // embedders.
Arthur Hemerya06697f2023-03-14 09:20:5753 //
Camille Lamy52a51202025-07-29 14:16:1254 // `web_exposed_isolation_info` and `cross_origin_isolation_key` describe the
55 // isolation state of the error page. Top-level error pages use a non-isolated
56 // WebExposedIsolationInfo and CrossOriginIsolationKey, while subframes and
57 // embedded content (including fenced frames, protals, etc.) will inherit the
58 // WebExposedIsolationInfo value from their embedder and may inherit the
59 // CrossOriginIsolationKey (depending on whether cross-origin isolation was
60 // enabled by COOP+COEP or DIP).
Sharon Yangd70a5392021-10-26 23:06:3261 static SiteInfo CreateForErrorPage(
Alex Moshchuk1b945fc2022-02-08 23:38:4562 const StoragePartitionConfig storage_partition_config,
Adithya Srinivasaneae091b2022-09-02 18:31:3363 bool is_guest,
Arthur Hemerya06697f2023-03-14 09:20:5764 bool is_fenced,
Robbie McElratheae661e2023-08-10 19:05:2865 const WebExposedIsolationInfo& web_exposed_isolation_info,
Camille Lamy52a51202025-07-29 14:16:1266 WebExposedIsolationLevel web_exposed_isolation_level,
67 const std::optional<AgentClusterKey::CrossOriginIsolationKey>&
68 cross_origin_isolation_key);
Alex Moshchuk1b945fc2022-02-08 23:38:4569
70 // Helper to create a SiteInfo for default SiteInstances. Default
71 // SiteInstances are used for non-isolated sites on platforms without strict
Alex Moshchuk39948d22022-06-23 21:54:1172 // site isolation, such as on Android. They may also be used on desktop
73 // platforms when strict site isolation is explicitly turned off (e.g., via
74 // switches::kDisableSiteIsolation).
Sharon Yangd70a5392021-10-26 23:06:3275 static SiteInfo CreateForDefaultSiteInstance(
Alex Moshchuk39948d22022-06-23 21:54:1176 const IsolationContext& isolation_context,
Sharon Yangd70a5392021-10-26 23:06:3277 const StoragePartitionConfig storage_partition_config,
Camille Lamy52a51202025-07-29 14:16:1278 const WebExposedIsolationInfo& web_exposed_isolation_info,
79 const std::optional<AgentClusterKey::CrossOriginIsolationKey>&
80 cross_origin_isolation_key);
Alex Moshchukdf15d8e2022-02-01 04:43:4981
82 // Helper to create a SiteInfo for a <webview> guest. This helper can be
83 // used for a new guest associated with a specific StoragePartitionConfig
84 // (prior to navigations).
Alex Moshchuk49b1d1912021-11-19 20:04:1885 static SiteInfo CreateForGuest(
86 BrowserContext* browser_context,
87 const StoragePartitionConfig& partition_config);
Sharon Yangd70a5392021-10-26 23:06:3288
89 // This function returns a SiteInfo with the appropriate site_url and
90 // process_lock_url computed. This function can only be called on the UI
91 // thread because it must be able to compute an effective URL.
92 static SiteInfo Create(const IsolationContext& isolation_context,
93 const UrlInfo& url_info);
94
95 // Similar to the function above, but this method can only be called on the
96 // IO thread. All fields except for the site_url should be the same as
97 // the other method. The site_url field will match the process_lock_url
98 // in the object returned by this function. This is because we cannot compute
99 // the effective URL from the IO thread.
100 //
101 // `url_info` MUST contain a StoragePartitionConfig because we can't ask the
102 // embedder which StoragePartitionConfig to use from the IO thread.
103 //
104 // NOTE: Do not use this method unless there is a very clear and good reason
105 // to do so. It primarily exists to facilitate the creation of ProcessLocks
106 // from any thread. ProcessLocks do not rely on the site_url field so the
107 // difference between this method and Create() does not cause problems for
108 // that usecase.
109 static SiteInfo CreateOnIOThread(const IsolationContext& isolation_context,
110 const UrlInfo& url_info);
111
112 // Method to make creating SiteInfo objects for tests easier. It is a thin
113 // wrapper around Create() that uses UrlInfo::CreateForTesting(),
114 // and WebExposedIsolationInfo::CreateNonIsolated() to generate the
115 // information that is not provided.
116 static SiteInfo CreateForTesting(const IsolationContext& isolation_context,
117 const GURL& url);
118
119 // Returns the site of a given |origin|. Unlike Create(), this does
120 // not utilize effective URLs, isolated origins, or other special logic. It
121 // only translates an origin into a site (i.e., scheme and eTLD+1) and is
122 // used internally by GetSiteForURLInternal(). For making process model
123 // decisions, Create() should be used instead.
124 static GURL GetSiteForOrigin(const url::Origin& origin);
125
Sharon Yangb670da6b2023-11-21 02:01:20126 // Returns the site URL derived from an opaque data: origin. This has the form
127 // data:<serialized nonce>. This is only to be called for data: URLs with
128 // opaque origins, and will crash otherwise, e.g. in LoadDataWithBaseURL,
129 // where the base URL is not an opaque origin.
130 static GURL GetOriginBasedSiteURLForDataURL(const url::Origin& origin);
131
Alex Moshchuke1f71d3a2023-03-28 19:36:39132 // Returns a StoragePartitionConfig for the specified URL. Note that the URL
133 // can be both a site URL that was generated by a SiteInfo or a regular
134 // user-provided URL.
Sharon Yangd70a5392021-10-26 23:06:32135 //
136 // Note: New callers of this method should be discouraged. New code should
137 // have access to a SiteInfo object and call GetStoragePartitionConfig() on
138 // that. For cases where code just needs the StoragePartition for a user
139 // provided URL or origin, it should use
140 // BrowserContext::GetStoragePartitionForUrl() instead of directly calling
141 // this method.
142 static StoragePartitionConfig GetStoragePartitionConfigForUrl(
143 BrowserContext* browser_context,
Alex Moshchuke1f71d3a2023-03-28 19:36:39144 const GURL& site_or_regular_url);
Sharon Yangd70a5392021-10-26 23:06:32145
Robbie McElratheae661e2023-08-10 19:05:28146 // Computes the web-exposed cross-origin isolation capability that should be
147 // used for a SiteInfo with the given WebExposedIsolationInfo and UrlInfo.
148 // This will be the same as the BrowsingInstance's WebExposedIsolationInfo
149 // except for agents that are cross-origin to an "isolated application"
150 // BrowsingInstance.
151 //
152 // See ProcessLock::GetWebExposedIsolationLevel() for more information.
153 static WebExposedIsolationLevel ComputeWebExposedIsolationLevel(
154 const WebExposedIsolationInfo& web_exposed_isolation_info,
155 const UrlInfo& url_info);
156
157 // Computes the web-exposed cross-origin isolation capability that should be
158 // used for a SiteInfo with the given WebExposedIsolationInfo that isn't
159 // locked to a site.
160 static WebExposedIsolationLevel ComputeWebExposedIsolationLevelForEmptySite(
161 const WebExposedIsolationInfo& web_exposed_isolation_info);
162
Sharon Yang01fdd492025-05-22 19:45:33163 // A helper to determine whether a site requires a dedicated process, based on
164 // fields from SiteInfo. This takes the relevant bits individually so it's not
165 // necessary to create a SiteInfo first.
166 static bool RequiresDedicatedProcessInternal(
167 const GURL& site_url,
168 const IsolationContext& isolation_context,
169 BrowserContext* browser_context,
170 bool does_site_request_dedicated_process_for_coop,
171 bool requires_origin_keyed_process,
172 bool is_error_page,
173 bool is_sandboxed,
174 bool is_pdf);
175
176 // Exposes functionality of `GetSiteForURLInternal so tests can do effective
177 // URL translation.
178 static GURL GetSiteForURLForTest(const IsolationContext& isolation_context,
179 const UrlInfo& url_info,
180 bool should_use_effective_urls);
181
Sharon Yangd70a5392021-10-26 23:06:32182 // Initializes |storage_partition_config_| with a value appropriate for
183 // |browser_context|.
184 explicit SiteInfo(BrowserContext* browser_context);
185 // The SiteInfo constructor should take in all values needed for comparing two
186 // SiteInfos, to help ensure all creation sites are updated accordingly when
Ellyc737a6302024-08-19 15:30:51187 // new values are added. The private function MakeSecurityPrincipalKey()
188 // should be updated accordingly.
Camille Lamy52a51202025-07-29 14:16:12189 SiteInfo(const AgentClusterKey& agent_cluster_key,
190 const GURL& site_url,
Arthur Hemery9a5d1bd2022-01-13 11:17:45191 const GURL& process_lock_url,
192 bool requires_origin_keyed_process,
Camille Lamy5ce9b962025-08-08 12:10:45193 AgentClusterKey::OACStatus oac_status,
W. James MacLeanc79153d2022-02-10 19:17:34194 bool is_sandboxed,
W. James MacLean37dd4aade2022-07-28 15:40:51195 int unique_sandbox_id,
Arthur Hemery9a5d1bd2022-01-13 11:17:45196 const StoragePartitionConfig storage_partition_config,
197 const WebExposedIsolationInfo& web_exposed_isolation_info,
Robbie McElratheae661e2023-08-10 19:05:28198 WebExposedIsolationLevel web_exposed_isolation_level,
Arthur Hemery9a5d1bd2022-01-13 11:17:45199 bool is_guest,
200 bool does_site_request_dedicated_process_for_coop,
201 bool is_jit_disabled,
Ellyc737a6302024-08-19 15:30:51202 bool are_v8_optimizations_disabled,
Adithya Srinivasanf6377b12022-08-31 21:58:44203 bool is_pdf,
Camille Lamy52a51202025-07-29 14:16:12204 bool is_fenced);
Sharon Yangd70a5392021-10-26 23:06:32205 SiteInfo() = delete;
206 SiteInfo(const SiteInfo& rhs);
207 ~SiteInfo();
208
W. James MacLean38f86382021-11-16 22:06:50209 // This function returns a new SiteInfo which is equivalent to the original,
210 // except that (1) is_origin_keyed is false, and (2) the remaining SiteInfo
211 // state is used to compute a new SiteInfo from a UrlInfo reconstructed from
212 // the original SiteInfo, minus any OAC opt-in request.
213 SiteInfo GetNonOriginKeyedEquivalentForMetrics(
214 const IsolationContext& isolation_context) const;
215
Sharon Yangd70a5392021-10-26 23:06:32216 // Returns the site URL associated with all of the documents and workers in
217 // this principal, as described above.
218 //
219 // NOTE: In most cases, code should be performing checks against the origin
220 // returned by |RenderFrameHost::GetLastCommittedOrigin()|. In contrast, the
221 // GURL returned by |site_url()| should not be considered authoritative
222 // because:
223 // - A SiteInstance can host pages from multiple sites if "site per process"
224 // is not enabled and the SiteInstance isn't hosting pages that require
225 // process isolation (e.g. WebUI or extensions).
226 // - Even with site per process, the site URL is not an origin: while often
227 // derived from the origin, it only contains the scheme and the eTLD + 1,
228 // i.e. an origin with the host "deeply.nested.subdomain.example.com"
229 // corresponds to a site URL with the host "example.com".
230 // - When origin isolation is in use, there may be multiple SiteInstance with
231 // the same site_url() but that differ in other properties.
232 const GURL& site_url() const { return site_url_; }
233
Camille Lamyd1f015d2024-07-06 14:14:10234 // Returns the AgentClusterKey of the execution contexts within this SiteInfo.
Camille Lamy52a51202025-07-29 14:16:12235 const AgentClusterKey& agent_cluster_key() const {
Camille Lamyd1f015d2024-07-06 14:14:10236 return agent_cluster_key_;
237 }
238
Sharon Yangd70a5392021-10-26 23:06:32239 // Returns the URL which should be used in a SetProcessLock call for this
240 // SiteInfo's process. This is the same as |site_url_| except for cases
241 // involving effective URLs, such as hosted apps. In those cases, this URL is
242 // a site URL that is computed without the use of effective URLs.
243 //
244 // NOTE: This URL is currently set even in cases where this SiteInstance's
245 // process is *not* going to be locked to it. Callers should be careful
246 // to consider this case when comparing lock URLs;
247 // ShouldLockProcessToSite() may be used to determine whether the
248 // process lock will actually be used.
249 //
250 // TODO(alexmos): See if we can clean this up and not set |process_lock_url_|
251 // if the SiteInstance's process isn't going to be locked.
252 const GURL& process_lock_url() const { return process_lock_url_; }
253
W. James MacLean7f76c2202021-11-15 16:27:49254 // Returns whether this SiteInfo requires an origin-keyed process, such as for
255 // an OriginAgentCluster response header. This resolves an ambiguity of
Sharon Yangd70a5392021-10-26 23:06:32256 // whether a process with a lock_url() like "https://foo.example" is allowed
257 // to include "https://sub.foo.example" or not. In opt-in isolation, it is
258 // possible for example.com to be isolated, and sub.example.com not be
259 // isolated. In contrast, if command-line isolation is used to isolate
260 // example.com, then sub.example.com is also (automatically) isolated.
261 // Also note that opt-in isolated origins will include ports (if non-default)
262 // in their site urls.
W. James MacLean7f76c2202021-11-15 16:27:49263 bool requires_origin_keyed_process() const {
264 return requires_origin_keyed_process_;
265 }
Sharon Yangd70a5392021-10-26 23:06:32266
Camille Lamy5ce9b962025-08-08 12:10:45267 // The status of the Origin-Agent-Cluster header request for this SiteInfo.
268 // This is mainly used to distinguish between SiteInfos that received process
269 // isolation for their origin due to an explicit OAC opt-in via header
270 // (kOriginKeyedByHeader) from the SiteInfos that received process isolation
271 // due to features::kOriginKeyedProcessesByDefault (kOriginKeyedByDefault).
272 // The former must be tracked per BrowsingInstance to maintain a consistent
273 // OAC state, while the later do not need to do so.
274 // Note that this only applies to OAC that is backed by process isolation. OAC
275 // can also be logical, in which case it will only apply in the renderer
276 // process and is not tracked in the SiteInfo.
277 // Also note that having an |oac_status_| of kOriginKeyedByHeader or
278 // kOriginKeyedByDefault will make the |agent_cluster_key_| origin-keyed, the
279 // reverse is not true. It is possible for the |agent_cluster_key_| to be
280 // origin-keyed and |oac_status_| to be kSiteKeyedByDefault, for example in
281 // the case of a cross-origin isolated document with DocumentIsolationPolicy.
282 AgentClusterKey::OACStatus oac_status() const { return oac_status_; }
W. James MacLean2a84fbf2023-05-12 18:13:43283
W. James MacLeanc79153d2022-02-10 19:17:34284 // The following accessor is for the `is_sandboxed` flag, which is true when
285 // this SiteInfo is for an origin-restricted-sandboxed iframe.
286 bool is_sandboxed() const { return is_sandboxed_; }
287
W. James MacLean37dd4aade2022-07-28 15:40:51288 // Returns either kInvalidUniqueSandboxId or the unique sandbox id provided
289 // when this SiteInfo was created. The latter case only occurs when
290 // `is_sandboxed` is true, and kIsolateSandboxedIframes was specified with
291 // the per-document grouping parameter.
292 int unique_sandbox_id() const { return unique_sandbox_id_; }
293
Robbie McElratheae661e2023-08-10 19:05:28294 // Returns the web-exposed isolation mode of the BrowsingInstance hosting
295 // SiteInstances with this SiteInfo. The level of isolation which a page
296 // opts-into has implications for the set of other pages which can live in
297 // this SiteInstance, process allocation decisions, and API exposure in the
298 // page's JavaScript context.
Sharon Yangd70a5392021-10-26 23:06:32299 const WebExposedIsolationInfo& web_exposed_isolation_info() const {
300 return web_exposed_isolation_info_;
301 }
302
Robbie McElratheae661e2023-08-10 19:05:28303 // Returns the web-exposed isolation capability of agents with this SiteInfo,
304 // ignoring the 'cross-origin-isolated' permissions policy. This should be
305 // used in conjunction with permissions policy to determine whether a frame
306 // can access APIs gated behind cross-origin isolation.
307 //
308 // This may return a lower isolation level than
309 // `web_exposed_isolation_info_` because "Isolated Application" cannot be
310 // delegated cross-origin.
311 WebExposedIsolationLevel web_exposed_isolation_level() const {
312 return web_exposed_isolation_level_;
313 }
314
Sharon Yangd70a5392021-10-26 23:06:32315 bool is_guest() const { return is_guest_; }
316 bool is_error_page() const;
317 bool is_jit_disabled() const { return is_jit_disabled_; }
Ellyc737a6302024-08-19 15:30:51318 bool are_v8_optimizations_disabled() const {
319 return are_v8_optimizations_disabled_;
320 }
Sharon Yangd70a5392021-10-26 23:06:32321 bool is_pdf() const { return is_pdf_; }
Adithya Srinivasanf6377b12022-08-31 21:58:44322 bool is_fenced() const { return is_fenced_; }
Sharon Yangd70a5392021-10-26 23:06:32323
324 // See comments on `does_site_request_dedicated_process_for_coop_` for more
325 // details.
326 bool does_site_request_dedicated_process_for_coop() const {
327 return does_site_request_dedicated_process_for_coop_;
328 }
329
330 // Returns true if the site_url() is empty.
331 bool is_empty() const { return site_url().possibly_invalid_spec().empty(); }
332
333 SiteInfo& operator=(const SiteInfo& rhs);
334
335 // Determine whether one SiteInfo represents the same security principal as
336 // another SiteInfo. Note that this does not necessarily translate to an
337 // equality comparison of all the fields in SiteInfo (see comments in the
338 // implementation).
339 bool IsSamePrincipalWith(const SiteInfo& other) const;
340
341 // Returns true if all fields in `other` match the corresponding fields in
342 // this object.
343 bool IsExactMatch(const SiteInfo& other) const;
344
W. James MacLeanf336dd42021-12-09 21:30:49345 // Determines how a ProcessLock based on this SiteInfo compares to a
346 // ProcessLock based on the `other` SiteInfo. Note that this doesn't just
347 // compare all SiteInfo fields, e.g. it doesn't use site_url_ since that
348 // may include effective URLs.
349 // Returns -1 if `this` < `other`, 1 if `this` > `other`, 0 otherwise.
350 int ProcessLockCompareTo(const SiteInfo& other) const;
351
Sharon Yangd70a5392021-10-26 23:06:32352 // Note: equality operators are defined in terms of IsSamePrincipalWith().
353 bool operator==(const SiteInfo& other) const;
Sharon Yangd70a5392021-10-26 23:06:32354
355 // Defined to allow this object to act as a key for std::map and std::set.
356 // Note that the key is determined based on what distinguishes one security
357 // principal from another (see IsSamePrincipalWith) and does not necessarily
358 // include all the fields in SiteInfo.
Jan Keitel35be68c2025-05-16 15:47:52359 std::weak_ordering operator<=>(const SiteInfo& other) const;
Sharon Yangd70a5392021-10-26 23:06:32360
361 // Returns a string representation of this SiteInfo principal.
362 std::string GetDebugString() const;
363
364 // Returns true if pages loaded with this SiteInfo ought to be handled only
365 // by a renderer process isolated from other sites. If --site-per-process is
366 // used, like it is on desktop platforms, then this is true for all sites. In
367 // other site isolation modes, only a subset of sites will require dedicated
368 // processes.
369 bool RequiresDedicatedProcess(
370 const IsolationContext& isolation_context) const;
371
372 // Returns true if a process for this SiteInfo should be locked to a
373 // ProcessLock whose is_locked_to_site() method returns true. Returning true
374 // here also implies that this SiteInfo requires a dedicated process. However,
375 // the converse does not hold: this might still return false for certain
376 // special cases where a site specific process lock can't be applied even when
377 // this SiteInfo requires a dedicated process (e.g., with
378 // --site-per-process). Examples of those cases include <webview> guests,
379 // single-process mode, or extensions where a process is currently allowed to
380 // be reused for different extensions. Most of these special cases should
381 // eventually be removed, and this function should become equivalent to
382 // RequiresDedicatedProcess().
383 bool ShouldLockProcessToSite(const IsolationContext& isolation_context) const;
384
385 // Returns whether the process-per-site model is in use (globally or just for
386 // the current site), in which case we should ensure there is only one
387 // RenderProcessHost per site for the entire browser context.
388 bool ShouldUseProcessPerSite(BrowserContext* browser_context) const;
389
Alex Moshchuk8015afcf2022-01-31 22:59:25390 // Get the StoragePartitionConfig, which describes the StoragePartition this
391 // SiteInfo is associated with. For example, this will correspond to a
392 // non-default StoragePartition for <webview> guests.
Sharon Yangd70a5392021-10-26 23:06:32393 const StoragePartitionConfig& storage_partition_config() const {
394 return storage_partition_config_;
395 }
396
397 // Write a representation of this object into a trace.
398 void WriteIntoTrace(perfetto::TracedValue context) const;
399
400 private:
401 // Helper that returns a tuple of all the fields that are relevant for
402 // comparing one SiteInfo to another, to tell whether they represent the same
403 // underlying security principal. This determines the SiteInfo's key for
404 // containers; two SiteInfos that return the same value here will map to the
405 // same entry in std::map, etc.
406 static auto MakeSecurityPrincipalKey(const SiteInfo& site_info);
407
408 // Helper method containing common logic used by the public
409 // Create() and CreateOnIOThread() methods. Most of the parameters simply
410 // match the values passed into the caller. `compute_site_url` controls
411 // whether the site_url field is computed from an effective URL or simply
412 // copied from the `process_lock_url_`. `compute_site_url` is set to false in
413 // contexts where it may not be possible to get the effective URL (e.g. on the
414 // IO thread).
415 static SiteInfo CreateInternal(const IsolationContext& isolation_context,
416 const UrlInfo& url_info,
417 bool compute_site_url);
418
419 // Returns the URL to which a process should be locked for the given UrlInfo.
420 // This is computed similarly to the site URL but without resolving effective
421 // URLs.
422 static GURL DetermineProcessLockURL(const IsolationContext& isolation_context,
423 const UrlInfo& url_info);
424
425 // Returns the site for the given UrlInfo, which includes only the scheme and
426 // registered domain. Returns an empty GURL if the UrlInfo has no host.
427 // |should_use_effective_urls| specifies whether to resolve |url| to an
428 // effective URL (via ContentBrowserClient::GetEffectiveURL()) before
429 // determining the site.
430 static GURL GetSiteForURLInternal(const IsolationContext& isolation_context,
431 const UrlInfo& url,
432 bool should_use_effective_urls);
433
W. James MacLeanf336dd42021-12-09 21:30:49434 // Helper function for ProcessLockCompareTo(). Returns a std::tie of the
435 // SiteInfo elements required for doing a ProcessLock comparison.
436 auto MakeProcessLockComparisonKey() const;
437
Sharon Yangd70a5392021-10-26 23:06:32438 GURL site_url_;
439
Camille Lamyd1f015d2024-07-06 14:14:10440 // The AgentClusterKey for the execution context. This represents the
Camille Lamy52a51202025-07-29 14:16:12441 // set of contexts that has synchronous access to each other and must be
442 // placed in the same process. Currently, it duplicates part of the
443 // information stored in the SiteInfo (such as requires_origin_keyed_process_
444 // and process_lock_url_). We plan to refactor SiteInfo so that the
445 // AgentClusterKey eventually replaces the duplicated members.
446 // TODO(crbug.com/342365078): Refactor the Origin-Agent-Cluster code to take
447 // advantage of AgentClusterKeys.
Camille Lamyd1f015d2024-07-06 14:14:10448 // TODO(crbug.com/342365083): Documents crossOriginIsolated through the use of
449 // COOP and COEP should also use the AgentClusterKey instead of
450 // WebExposedIsolationInfo.
Camille Lamy52a51202025-07-29 14:16:12451 AgentClusterKey agent_cluster_key_;
Camille Lamyd1f015d2024-07-06 14:14:10452
Sharon Yangd70a5392021-10-26 23:06:32453 // The URL to use when locking a process to this SiteInstance's site via
454 // SetProcessLock(). This is the same as |site_url_| except for cases
455 // involving effective URLs, such as hosted apps. In those cases, this URL is
456 // a site URL that is computed without the use of effective URLs.
Camille Lamy52a51202025-07-29 14:16:12457 // TODO(crbug.com/342572253): Now that we have AgentClusterKeys for all
458 // navigation, this is redundant with the AgentClusterKey. Remove it.
Sharon Yangd70a5392021-10-26 23:06:32459 GURL process_lock_url_;
460
W. James MacLean7f76c2202021-11-15 16:27:49461 // Indicates whether this SiteInfo is specific to a single origin and requires
462 // an origin-keyed process, rather than including all subdomains of that
463 // origin. Only used for OriginAgentCluster header opt-ins. In contrast, the
464 // site-level URLs that are typically used in SiteInfo include subdomains, as
465 // do command-line isolated origins.
Camille Lamy52a51202025-07-29 14:16:12466 // TODO(crbug.com/342365078): Now that we have AgentClusterKeys for all
467 // navigation, this is redundant with the AgentClusterKey. Remove it.
W. James MacLean7f76c2202021-11-15 16:27:49468 bool requires_origin_keyed_process_ = false;
Sharon Yangd70a5392021-10-26 23:06:32469
Camille Lamy5ce9b962025-08-08 12:10:45470 // Tracks the status of the OAC header opt-in request for this SiteInfo.
471 // Note: this is not taken into account in
472 // SiteInfo::MakeSecurityPrincipalKey() because we want to consider a document
473 // with OAC: 1? to have the same security principal as a document that got
474 // origin isolation through other means
475 // (features::kOriginKeyedProcessesByDefault,
476 // cross-origin isolation provided the cross-origin isolation status
477 // match...). Origin isolation is taken into account in
478 // SiteInfo::MakeSecurityPrincipalKey() through the AgentClusterKey, which can
479 // be origin-keyed or site-keyed. Origin-keyed and site-keyed AgentClusterKeys
480 // are never equivalent.
481 AgentClusterKey::OACStatus oac_status_ =
482 AgentClusterKey::OACStatus::kSiteKeyedByDefault;
W. James MacLean2a84fbf2023-05-12 18:13:43483
W. James MacLeanc79153d2022-02-10 19:17:34484 // When true, indicates this SiteInfo is for a origin-restricted-sandboxed
485 // iframe.
486 bool is_sandboxed_ = false;
487
W. James MacLean37dd4aade2022-07-28 15:40:51488 // When kIsolateSandboxedIframes is active using per-document grouping, each
489 // isolated frame gets its own SiteInfo with a unique document identifier,
490 // which in practice is the `navigation_id` for the NavigationRequest that led
491 // to the creation of the SiteInstance. This value will be used in comparing
492 // SiteInfos unless it is kInvalidUniqueSandboxId. It should be noted that the
493 // value of `unique_sandbox_id_` will change for any cross-document
494 // navigation, even if it's same-origin and/or stays in the same
495 // RenderFrameHost.
496 int unique_sandbox_id_;
497
Sharon Yangd70a5392021-10-26 23:06:32498 // The StoragePartitionConfig to use when loading content belonging to this
499 // SiteInfo.
500 StoragePartitionConfig storage_partition_config_;
501
Robbie McElratheae661e2023-08-10 19:05:28502 // Indicates the web-exposed isolation mode of the BrowsingInstance that
503 // agents with this SiteInfo belongs to. The level of isolation which a page
504 // opts-into has implications for the set of other pages which can live in
505 // this SiteInstance, process allocation decisions, and API exposure in the
506 // page's JavaScript context.
Sharon Yangd70a5392021-10-26 23:06:32507 WebExposedIsolationInfo web_exposed_isolation_info_ =
508 WebExposedIsolationInfo::CreateNonIsolated();
509
Robbie McElratheae661e2023-08-10 19:05:28510 // Indicates the web-exposed isolation capability of agents with this
511 // SiteInfo, ignoring the 'cross-origin-isolated' permissions policy. This is
512 // a function of `web_exposed_isolation_info_` and the origins belonging to
513 // this SiteInstance.
514 //
515 // This may be a lower isolation level than `web_exposed_isolation_info_`
516 // because "Isolated Application" cannot be delegated cross-origin.
517 WebExposedIsolationLevel web_exposed_isolation_level_ =
518 WebExposedIsolationLevel::kNotIsolated;
519
Sharon Yangd70a5392021-10-26 23:06:32520 // Indicates this SiteInfo is for a <webview> guest.
521 bool is_guest_ = false;
522
523 // Indicates that there is a request to require a dedicated process for this
524 // SiteInfo due to a hint from the Cross-Origin-Opener-Policy header.
525 bool does_site_request_dedicated_process_for_coop_ = false;
526
527 // Indicates that JIT is disabled for this SiteInfo.
528 bool is_jit_disabled_ = false;
529
Ellyc737a6302024-08-19 15:30:51530 // Indicates that v8 optimizations are disabled for this SiteInfo.
531 bool are_v8_optimizations_disabled_ = false;
532
Sharon Yangd70a5392021-10-26 23:06:32533 // Indicates that this SiteInfo is for PDF content.
534 bool is_pdf_ = false;
Adithya Srinivasanf6377b12022-08-31 21:58:44535
536 // Indicates that this SiteInfo is for content inside a fenced frame. We use
537 // just a bool as opposed to a GUID here in order to group same-origin fenced
538 // frames together. See more details around fenced frame process isolation
539 // here:
540 // https://github.com/WICG/fenced-frame/blob/master/explainer/process_isolation.md.
541 bool is_fenced_ = false;
Sharon Yangd70a5392021-10-26 23:06:32542};
543
544CONTENT_EXPORT std::ostream& operator<<(std::ostream& out,
545 const SiteInfo& site_info);
546
547} // namespace content
548
549#endif // CONTENT_BROWSER_SITE_INFO_H_