// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ #define CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ #include <stddef.h> #include <stdint.h> #include "base/memory/ref_counted.h" #include "base/types/id_type.h" #include "content/common/content_export.h" #include "content/public/browser/browsing_instance_id.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/site_instance_process_assignment.h" #include "content/public/browser/storage_partition_config.h" #include "url/gurl.h" namespace perfetto::protos::pbzero { class SiteInstance; } // namespace perfetto::protos::pbzero namespace content { class BrowserContext; class RenderProcessHost; class StoragePartitionConfig; SiteInstanceId; SiteInstanceGroupId; /////////////////////////////////////////////////////////////////////////////// // SiteInstance interface. // // In an ideal sense, a SiteInstance represents a group of documents and workers // that can share memory with each other, and thus must live in the same // renderer process. In the spec, this roughly corresponds to an agent cluster. // Documents that are able to synchronously script each other will always be // placed in the same SiteInstance. // // A document's SiteInstance is determined by a combination of where the // document comes from (i.e., a principal based on its "site") and which frames // have references to it (i.e., the browsing context group, or "instance"). The // site part groups together documents that can script each other, while the // instance part allows independent copies of such documents to safely live in // different processes. // // The principal is usually based on the site of the document's URL: the scheme // and "registrable domain" (i.e., eTLD+1), not the full origin. For example, // https://dev.chromium.org would have a site of https://chromium.org. This // preserves compatibility with document.domain modifications, which allow // similar origin pages to script each other. (Note that there are many // exceptions, and the policy for determining site URLs is complex.) Meanwhile, // an "instance" is represented by the BrowsingInstance class, which includes // all frames that can find each other based on how they were created (e.g., // window.open or targeted links). // // In practice, a SiteInstance may contain documents from more than a single // site, usually for compatibility or performance reasons. For example, on // platforms that do not support out-of-process iframes, cross-site iframes must // necessarily be loaded in the same process as their parent document. Chrome's // process model uses SiteInstance as the basic primitive for assigning // documents to processes, and the process model's behavior is tuned primarily // by changing how SiteInstance principals (e.g., site URLs) are defined. // // Various process models are currently supported: // // FULL SITE ISOLATION (the current default for desktop platforms): Every // document from the web uses a SiteInstance whose process is strictly locked to // a single site (scheme + eTLD+1), such that the renderer process can be // prevented from loading documents outside that site. Cross-site navigations // always change SiteInstances (usually within the same BrowsingInstance, // although sometimes the BrowsingInstance changes as well). Subframes from // other sites will use different SiteInstances (always within the same // BrowsingInstance), and thus out-of-process iframes. // // PARTIAL SITE ISOLATION (the current Google Chrome default on most Android // devices): Documents from sites that are most likely to involve login use // SiteInstances that are strictly locked to such sites, while one shared // SiteInstance within each BrowsingInstance is used for the remaining documents // from other less sensitive sites. This avoids out-of-process iframes in the // common case for performance reasons, while protecting the sites that are most // likely to be targeted in attacks. // // NO SITE ISOLATION (the current Google Chrome default on low-end Android // devices and Android WebView): No documents from the web use locked processes, // and no out-of-process iframes are created. The shared SiteInstance for each // BrowsingInstance is always used for documents from the web. // // In each model, there are many exceptions, such as always requiring locked // processes for chrome:// URLs, or allowing some special cases to share // processes with each other (e.g., file:// URLs). // // In terms of lifetime, each RenderFrameHost tracks the SiteInstance it is // associated with, to identify its principal and determine its process. Each // FrameNavigationEntry also tracks the SiteInstance that rendered it, to // prevent loading attacker-controlled data into the wrong process on a session // history navigation. A SiteInstance is jointly owned by these references and // is only alive as long as it is accessible, either from current documents or // from session history. // /////////////////////////////////////////////////////////////////////////////// class CONTENT_EXPORT SiteInstance : public base::RefCounted<SiteInstance> { … }; } // namespace content. #endif // CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_