Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 2 | // 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 Lamy | d1f015d | 2024-07-06 14:14:10 | [diff] [blame] | 8 | #include "content/browser/agent_cluster_key.h" |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 9 | #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 McElrath | eae661e | 2023-08-10 19:05:28 | [diff] [blame] | 13 | #include "content/public/browser/web_exposed_isolation_level.h" |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 14 | #include "url/gurl.h" |
| 15 | #include "url/origin.h" |
| 16 | |
| 17 | namespace content { |
| 18 | |
| 19 | class BrowserContext; |
| 20 | class IsolationContext; |
| 21 | class StoragePartitionConfig; |
| 22 | struct 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. |
| 45 | class CONTENT_EXPORT SiteInfo { |
| 46 | public: |
Alex Moshchuk | 1b945fc | 2022-02-08 23:38:45 | [diff] [blame] | 47 | // 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 Srinivasan | eae091b | 2022-09-02 18:31:33 | [diff] [blame] | 50 | // 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 Hemery | a06697f | 2023-03-14 09:20:57 | [diff] [blame] | 53 | // |
Camille Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 54 | // `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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 61 | static SiteInfo CreateForErrorPage( |
Alex Moshchuk | 1b945fc | 2022-02-08 23:38:45 | [diff] [blame] | 62 | const StoragePartitionConfig storage_partition_config, |
Adithya Srinivasan | eae091b | 2022-09-02 18:31:33 | [diff] [blame] | 63 | bool is_guest, |
Arthur Hemery | a06697f | 2023-03-14 09:20:57 | [diff] [blame] | 64 | bool is_fenced, |
Robbie McElrath | eae661e | 2023-08-10 19:05:28 | [diff] [blame] | 65 | const WebExposedIsolationInfo& web_exposed_isolation_info, |
Camille Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 66 | WebExposedIsolationLevel web_exposed_isolation_level, |
| 67 | const std::optional<AgentClusterKey::CrossOriginIsolationKey>& |
| 68 | cross_origin_isolation_key); |
Alex Moshchuk | 1b945fc | 2022-02-08 23:38:45 | [diff] [blame] | 69 | |
| 70 | // Helper to create a SiteInfo for default SiteInstances. Default |
| 71 | // SiteInstances are used for non-isolated sites on platforms without strict |
Alex Moshchuk | 39948d2 | 2022-06-23 21:54:11 | [diff] [blame] | 72 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 75 | static SiteInfo CreateForDefaultSiteInstance( |
Alex Moshchuk | 39948d2 | 2022-06-23 21:54:11 | [diff] [blame] | 76 | const IsolationContext& isolation_context, |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 77 | const StoragePartitionConfig storage_partition_config, |
Camille Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 78 | const WebExposedIsolationInfo& web_exposed_isolation_info, |
| 79 | const std::optional<AgentClusterKey::CrossOriginIsolationKey>& |
| 80 | cross_origin_isolation_key); |
Alex Moshchuk | df15d8e | 2022-02-01 04:43:49 | [diff] [blame] | 81 | |
| 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 Moshchuk | 49b1d191 | 2021-11-19 20:04:18 | [diff] [blame] | 85 | static SiteInfo CreateForGuest( |
| 86 | BrowserContext* browser_context, |
| 87 | const StoragePartitionConfig& partition_config); |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 88 | |
| 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 Yang | b670da6b | 2023-11-21 02:01:20 | [diff] [blame] | 126 | // 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 Moshchuk | e1f71d3a | 2023-03-28 19:36:39 | [diff] [blame] | 132 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 135 | // |
| 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 Moshchuk | e1f71d3a | 2023-03-28 19:36:39 | [diff] [blame] | 144 | const GURL& site_or_regular_url); |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 145 | |
Robbie McElrath | eae661e | 2023-08-10 19:05:28 | [diff] [blame] | 146 | // 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 Yang | 01fdd49 | 2025-05-22 19:45:33 | [diff] [blame] | 163 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 182 | // 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 |
Elly | c737a630 | 2024-08-19 15:30:51 | [diff] [blame] | 187 | // new values are added. The private function MakeSecurityPrincipalKey() |
| 188 | // should be updated accordingly. |
Camille Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 189 | SiteInfo(const AgentClusterKey& agent_cluster_key, |
| 190 | const GURL& site_url, |
Arthur Hemery | 9a5d1bd | 2022-01-13 11:17:45 | [diff] [blame] | 191 | const GURL& process_lock_url, |
| 192 | bool requires_origin_keyed_process, |
Camille Lamy | 5ce9b96 | 2025-08-08 12:10:45 | [diff] [blame] | 193 | AgentClusterKey::OACStatus oac_status, |
W. James MacLean | c79153d | 2022-02-10 19:17:34 | [diff] [blame] | 194 | bool is_sandboxed, |
W. James MacLean | 37dd4aade | 2022-07-28 15:40:51 | [diff] [blame] | 195 | int unique_sandbox_id, |
Arthur Hemery | 9a5d1bd | 2022-01-13 11:17:45 | [diff] [blame] | 196 | const StoragePartitionConfig storage_partition_config, |
| 197 | const WebExposedIsolationInfo& web_exposed_isolation_info, |
Robbie McElrath | eae661e | 2023-08-10 19:05:28 | [diff] [blame] | 198 | WebExposedIsolationLevel web_exposed_isolation_level, |
Arthur Hemery | 9a5d1bd | 2022-01-13 11:17:45 | [diff] [blame] | 199 | bool is_guest, |
| 200 | bool does_site_request_dedicated_process_for_coop, |
| 201 | bool is_jit_disabled, |
Elly | c737a630 | 2024-08-19 15:30:51 | [diff] [blame] | 202 | bool are_v8_optimizations_disabled, |
Adithya Srinivasan | f6377b1 | 2022-08-31 21:58:44 | [diff] [blame] | 203 | bool is_pdf, |
Camille Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 204 | bool is_fenced); |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 205 | SiteInfo() = delete; |
| 206 | SiteInfo(const SiteInfo& rhs); |
| 207 | ~SiteInfo(); |
| 208 | |
W. James MacLean | 38f8638 | 2021-11-16 22:06:50 | [diff] [blame] | 209 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 216 | // 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 Lamy | d1f015d | 2024-07-06 14:14:10 | [diff] [blame] | 234 | // Returns the AgentClusterKey of the execution contexts within this SiteInfo. |
Camille Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 235 | const AgentClusterKey& agent_cluster_key() const { |
Camille Lamy | d1f015d | 2024-07-06 14:14:10 | [diff] [blame] | 236 | return agent_cluster_key_; |
| 237 | } |
| 238 | |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 239 | // 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 MacLean | 7f76c220 | 2021-11-15 16:27:49 | [diff] [blame] | 254 | // Returns whether this SiteInfo requires an origin-keyed process, such as for |
| 255 | // an OriginAgentCluster response header. This resolves an ambiguity of |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 256 | // 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 MacLean | 7f76c220 | 2021-11-15 16:27:49 | [diff] [blame] | 263 | bool requires_origin_keyed_process() const { |
| 264 | return requires_origin_keyed_process_; |
| 265 | } |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 266 | |
Camille Lamy | 5ce9b96 | 2025-08-08 12:10:45 | [diff] [blame] | 267 | // 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 MacLean | 2a84fbf | 2023-05-12 18:13:43 | [diff] [blame] | 283 | |
W. James MacLean | c79153d | 2022-02-10 19:17:34 | [diff] [blame] | 284 | // 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 MacLean | 37dd4aade | 2022-07-28 15:40:51 | [diff] [blame] | 288 | // 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 McElrath | eae661e | 2023-08-10 19:05:28 | [diff] [blame] | 294 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 299 | const WebExposedIsolationInfo& web_exposed_isolation_info() const { |
| 300 | return web_exposed_isolation_info_; |
| 301 | } |
| 302 | |
Robbie McElrath | eae661e | 2023-08-10 19:05:28 | [diff] [blame] | 303 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 315 | bool is_guest() const { return is_guest_; } |
| 316 | bool is_error_page() const; |
| 317 | bool is_jit_disabled() const { return is_jit_disabled_; } |
Elly | c737a630 | 2024-08-19 15:30:51 | [diff] [blame] | 318 | bool are_v8_optimizations_disabled() const { |
| 319 | return are_v8_optimizations_disabled_; |
| 320 | } |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 321 | bool is_pdf() const { return is_pdf_; } |
Adithya Srinivasan | f6377b1 | 2022-08-31 21:58:44 | [diff] [blame] | 322 | bool is_fenced() const { return is_fenced_; } |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 323 | |
| 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 MacLean | f336dd4 | 2021-12-09 21:30:49 | [diff] [blame] | 345 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 352 | // Note: equality operators are defined in terms of IsSamePrincipalWith(). |
| 353 | bool operator==(const SiteInfo& other) const; |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 354 | |
| 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 Keitel | 35be68c | 2025-05-16 15:47:52 | [diff] [blame] | 359 | std::weak_ordering operator<=>(const SiteInfo& other) const; |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 360 | |
| 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 Moshchuk | 8015afcf | 2022-01-31 22:59:25 | [diff] [blame] | 390 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 393 | 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 MacLean | f336dd4 | 2021-12-09 21:30:49 | [diff] [blame] | 434 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 438 | GURL site_url_; |
| 439 | |
Camille Lamy | d1f015d | 2024-07-06 14:14:10 | [diff] [blame] | 440 | // The AgentClusterKey for the execution context. This represents the |
Camille Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 441 | // 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 Lamy | d1f015d | 2024-07-06 14:14:10 | [diff] [blame] | 448 | // TODO(crbug.com/342365083): Documents crossOriginIsolated through the use of |
| 449 | // COOP and COEP should also use the AgentClusterKey instead of |
| 450 | // WebExposedIsolationInfo. |
Camille Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 451 | AgentClusterKey agent_cluster_key_; |
Camille Lamy | d1f015d | 2024-07-06 14:14:10 | [diff] [blame] | 452 | |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 453 | // 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 Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 457 | // TODO(crbug.com/342572253): Now that we have AgentClusterKeys for all |
| 458 | // navigation, this is redundant with the AgentClusterKey. Remove it. |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 459 | GURL process_lock_url_; |
| 460 | |
W. James MacLean | 7f76c220 | 2021-11-15 16:27:49 | [diff] [blame] | 461 | // 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 Lamy | 52a5120 | 2025-07-29 14:16:12 | [diff] [blame] | 466 | // TODO(crbug.com/342365078): Now that we have AgentClusterKeys for all |
| 467 | // navigation, this is redundant with the AgentClusterKey. Remove it. |
W. James MacLean | 7f76c220 | 2021-11-15 16:27:49 | [diff] [blame] | 468 | bool requires_origin_keyed_process_ = false; |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 469 | |
Camille Lamy | 5ce9b96 | 2025-08-08 12:10:45 | [diff] [blame] | 470 | // 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 MacLean | 2a84fbf | 2023-05-12 18:13:43 | [diff] [blame] | 483 | |
W. James MacLean | c79153d | 2022-02-10 19:17:34 | [diff] [blame] | 484 | // When true, indicates this SiteInfo is for a origin-restricted-sandboxed |
| 485 | // iframe. |
| 486 | bool is_sandboxed_ = false; |
| 487 | |
W. James MacLean | 37dd4aade | 2022-07-28 15:40:51 | [diff] [blame] | 488 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 498 | // The StoragePartitionConfig to use when loading content belonging to this |
| 499 | // SiteInfo. |
| 500 | StoragePartitionConfig storage_partition_config_; |
| 501 | |
Robbie McElrath | eae661e | 2023-08-10 19:05:28 | [diff] [blame] | 502 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 507 | WebExposedIsolationInfo web_exposed_isolation_info_ = |
| 508 | WebExposedIsolationInfo::CreateNonIsolated(); |
| 509 | |
Robbie McElrath | eae661e | 2023-08-10 19:05:28 | [diff] [blame] | 510 | // 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 520 | // 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 | |
Elly | c737a630 | 2024-08-19 15:30:51 | [diff] [blame] | 530 | // Indicates that v8 optimizations are disabled for this SiteInfo. |
| 531 | bool are_v8_optimizations_disabled_ = false; |
| 532 | |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 533 | // Indicates that this SiteInfo is for PDF content. |
| 534 | bool is_pdf_ = false; |
Adithya Srinivasan | f6377b1 | 2022-08-31 21:58:44 | [diff] [blame] | 535 | |
| 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 Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 542 | }; |
| 543 | |
| 544 | CONTENT_EXPORT std::ostream& operator<<(std::ostream& out, |
| 545 | const SiteInfo& site_info); |
| 546 | |
| 547 | } // namespace content |
| 548 | |
| 549 | #endif // CONTENT_BROWSER_SITE_INFO_H_ |