OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ |
6 #define CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ | 6 #define CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 // instances using the BrowsingInstance class. | 36 // instances using the BrowsingInstance class. |
37 // | 37 // |
38 // Four process models are currently supported: | 38 // Four process models are currently supported: |
39 // | 39 // |
40 // PROCESS PER SITE INSTANCE (the current default): SiteInstances are created | 40 // PROCESS PER SITE INSTANCE (the current default): SiteInstances are created |
41 // (1) when the user manually creates a new tab (which also creates a new | 41 // (1) when the user manually creates a new tab (which also creates a new |
42 // BrowsingInstance), and (2) when the user navigates across site boundaries | 42 // BrowsingInstance), and (2) when the user navigates across site boundaries |
43 // (which uses the same BrowsingInstance). If the user navigates within a site, | 43 // (which uses the same BrowsingInstance). If the user navigates within a site, |
44 // the same SiteInstance is used. Caveat: we currently allow renderer-initiated | 44 // the same SiteInstance is used. Caveat: we currently allow renderer-initiated |
45 // cross-site navigations to stay in the same SiteInstance, to preserve | 45 // cross-site navigations to stay in the same SiteInstance, to preserve |
46 // compatibility in cases like cross-site iframes that open popups. | 46 // compatibility in cases like cross-site iframes that open popups. This means |
| 47 // that most SiteInstances will contain pages from multiple sites. |
47 // | 48 // |
48 // SITE PER PROCESS (currently experimental): is the most granular process | 49 // SITE PER PROCESS (currently experimental): is the most granular process |
49 // model and is made possible by our support for out-of-process iframes. A | 50 // model and is made possible by our support for out-of-process iframes. A |
50 // subframe will be given a different SiteInstance if its site differs from the | 51 // subframe will be given a different SiteInstance if its site differs from the |
51 // containing document. Cross-site navigation of top-level frames or subframes | 52 // containing document. Cross-site navigation of top-level frames or subframes |
52 // will trigger a change of SiteInstances, even if the navigation is renderer | 53 // will trigger a change of SiteInstances, even if the navigation is renderer |
53 // initiated. In this model, each process can be dedicated to documents from | 54 // initiated. In this model, each process can be dedicated to documents from |
54 // just one site, allowing the same origin policy to be enforced by the sandbox. | 55 // just one site, allowing the same origin policy to be enforced by the sandbox. |
55 // | 56 // |
56 // PROCESS PER TAB: SiteInstances are created when the user manually creates a | 57 // PROCESS PER TAB: SiteInstances are created when the user manually creates a |
57 // new tab, but not when navigating across site boundaries (unless a process | 58 // new tab, but not when navigating across site boundaries (unless a process |
58 // swap is required for security reasons, such as navigating from a privileged | 59 // swap is required for security reasons, such as navigating from a privileged |
59 // WebUI page to a normal web page). This corresponds to one process per | 60 // WebUI page to a normal web page). This corresponds to one process per |
60 // BrowsingInstance. | 61 // BrowsingInstance. |
61 // | 62 // |
62 // PROCESS PER SITE: We consolidate all SiteInstances for a given site into the | 63 // PROCESS PER SITE: We consolidate all SiteInstances for a given site into the |
63 // same process, throughout the entire browser context. This ensures that only | 64 // same process, throughout the entire browser context. This ensures that only |
64 // one process will be used for each site. | 65 // one process will be used for each site. Note that there is no strict process |
| 66 // isolation of sites in this mode, so a given SiteInstance can still contain |
| 67 // pages from multiple sites. |
65 // | 68 // |
66 // Each NavigationEntry for a WebContents points to the SiteInstance that | 69 // Each NavigationEntry for a WebContents points to the SiteInstance that |
67 // rendered it. Each RenderFrameHost also points to the SiteInstance that it is | 70 // rendered it. Each RenderFrameHost also points to the SiteInstance that it is |
68 // associated with. A SiteInstance keeps track of the number of these | 71 // associated with. A SiteInstance keeps track of the number of these |
69 // references and deletes itself when the count goes to zero. This means that | 72 // references and deletes itself when the count goes to zero. This means that |
70 // a SiteInstance is only live as long as it is accessible, either from new | 73 // a SiteInstance is only live as long as it is accessible, either from new |
71 // tabs with no NavigationEntries or in NavigationEntries in the history. | 74 // tabs with no NavigationEntries or in NavigationEntries in the history. |
72 // | 75 // |
73 /////////////////////////////////////////////////////////////////////////////// | 76 /////////////////////////////////////////////////////////////////////////////// |
74 class CONTENT_EXPORT SiteInstance : public base::RefCounted<SiteInstance> { | 77 class CONTENT_EXPORT SiteInstance : public base::RefCounted<SiteInstance> { |
75 public: | 78 public: |
76 // Returns a unique ID for this SiteInstance. | 79 // Returns a unique ID for this SiteInstance. |
77 virtual int32_t GetId() = 0; | 80 virtual int32_t GetId() = 0; |
78 | 81 |
79 // Whether this SiteInstance has a running process associated with it. | 82 // Whether this SiteInstance has a running process associated with it. |
80 // This may return true before the first call to GetProcess(), in cases where | 83 // This may return true before the first call to GetProcess(), in cases where |
81 // we use process-per-site and there is an existing process available. | 84 // we use process-per-site and there is an existing process available. |
82 virtual bool HasProcess() const = 0; | 85 virtual bool HasProcess() const = 0; |
83 | 86 |
84 // Returns the current RenderProcessHost being used to render pages for this | 87 // Returns the current RenderProcessHost being used to render pages for this |
85 // SiteInstance. If there is no RenderProcessHost (because either none has | 88 // SiteInstance. If there is no RenderProcessHost (because either none has |
86 // yet been created or there was one but it was cleanly destroyed (e.g. when | 89 // yet been created or there was one but it was cleanly destroyed (e.g. when |
87 // it is not actively being used)), then this method will create a new | 90 // it is not actively being used), then this method will create a new |
88 // RenderProcessHost (and a new ID). Note that renderer process crashes leave | 91 // RenderProcessHost (and a new ID). Note that renderer process crashes leave |
89 // the current RenderProcessHost (and ID) in place. | 92 // the current RenderProcessHost (and ID) in place. |
90 // | 93 // |
91 // For sites that require process-per-site mode (e.g., WebUI), this will | 94 // For sites that require process-per-site mode (e.g., WebUI), this will |
92 // ensure only one RenderProcessHost for the site exists/ within the | 95 // ensure only one RenderProcessHost for the site exists within the |
93 // BrowserContext. | 96 // BrowserContext. |
94 virtual content::RenderProcessHost* GetProcess() = 0; | 97 virtual content::RenderProcessHost* GetProcess() = 0; |
95 | 98 |
96 // Browser context to which this SiteInstance (and all related | 99 // Browser context to which this SiteInstance (and all related |
97 // SiteInstances) belongs. | 100 // SiteInstances) belongs. |
98 virtual content::BrowserContext* GetBrowserContext() const = 0; | 101 virtual content::BrowserContext* GetBrowserContext() const = 0; |
99 | 102 |
100 // Get the web site that this SiteInstance is rendering pages for. | 103 // Get the web site that this SiteInstance is rendering pages for. This |
101 // This includes the scheme and registered domain, but not the port. | 104 // includes the scheme and registered domain, but not the port. |
| 105 // |
| 106 // NOTE: In most cases, this value should not be considered authoritative |
| 107 // because a SiteInstance can usually host pages from multiple sites. It is |
| 108 // only an accurate representation of the pages within the SiteInstance in |
| 109 // the "site per process" process model, or for sites that require process |
| 110 // isolation (e.g., WebUI, extensions). |
102 virtual const GURL& GetSiteURL() const = 0; | 111 virtual const GURL& GetSiteURL() const = 0; |
103 | 112 |
104 // Gets a SiteInstance for the given URL that shares the current | 113 // Gets a SiteInstance for the given URL that shares the current |
105 // BrowsingInstance, creating a new SiteInstance if necessary. This ensures | 114 // BrowsingInstance, creating a new SiteInstance if necessary. This ensures |
106 // that a BrowsingInstance only has one SiteInstance per site, so that pages | 115 // that a BrowsingInstance only has one SiteInstance per site, so that pages |
107 // in a BrowsingInstance have the ability to script each other. | 116 // in a BrowsingInstance have the ability to script each other. |
108 virtual scoped_refptr<SiteInstance> GetRelatedSiteInstance( | 117 virtual scoped_refptr<SiteInstance> GetRelatedSiteInstance( |
109 const GURL& url) = 0; | 118 const GURL& url) = 0; |
110 | 119 |
111 // Returns whether the given SiteInstance is in the same BrowsingInstance as | 120 // Returns whether the given SiteInstance is in the same BrowsingInstance as |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 protected: | 167 protected: |
159 friend class base::RefCounted<SiteInstance>; | 168 friend class base::RefCounted<SiteInstance>; |
160 | 169 |
161 SiteInstance() {} | 170 SiteInstance() {} |
162 virtual ~SiteInstance() {} | 171 virtual ~SiteInstance() {} |
163 }; | 172 }; |
164 | 173 |
165 } // namespace content. | 174 } // namespace content. |
166 | 175 |
167 #endif // CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ | 176 #endif // CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ |
OLD | NEW |