OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_RENDERER_HOST_SITE_INSTANCE_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_SITE_INSTANCE_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_SITE_INSTANCE_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_SITE_INSTANCE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "content/browser/renderer_host/render_process_host.h" | 9 #include "content/browser/renderer_host/render_process_host.h" |
10 #include "content/common/notification_observer.h" | 10 #include "content/common/notification_observer.h" |
11 #include "content/common/notification_registrar.h" | 11 #include "content/common/notification_registrar.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 | 13 |
14 class BrowsingInstance; | 14 class BrowsingInstance; |
15 | 15 |
| 16 namespace content { |
| 17 class BrowserContext; |
| 18 } |
| 19 |
16 /////////////////////////////////////////////////////////////////////////////// | 20 /////////////////////////////////////////////////////////////////////////////// |
17 // | 21 // |
18 // SiteInstance class | 22 // SiteInstance class |
19 // | 23 // |
20 // A SiteInstance is a data structure that is associated with all pages in a | 24 // A SiteInstance is a data structure that is associated with all pages in a |
21 // given instance of a web site. Here, a web site is identified by its | 25 // given instance of a web site. Here, a web site is identified by its |
22 // registered domain name and scheme. An instance includes all pages | 26 // registered domain name and scheme. An instance includes all pages |
23 // that are connected (i.e., either a user or a script navigated from one | 27 // that are connected (i.e., either a user or a script navigated from one |
24 // to the other). We represent instances using the BrowsingInstance class. | 28 // to the other). We represent instances using the BrowsingInstance class. |
25 // | 29 // |
26 // In --process-per-tab, one SiteInstance is created for each tab (i.e., in the | 30 // In --process-per-tab, one SiteInstance is created for each tab (i.e., in the |
27 // TabContents constructor), unless the tab is created by script (i.e., in | 31 // TabContents constructor), unless the tab is created by script (i.e., in |
28 // TabContents::CreateNewView). This corresponds to one process per | 32 // TabContents::CreateNewView). This corresponds to one process per |
29 // BrowsingInstance. | 33 // BrowsingInstance. |
30 // | 34 // |
31 // In process-per-site-instance (the current default process model), | 35 // In process-per-site-instance (the current default process model), |
32 // SiteInstances are created (1) when the user manually creates a new tab | 36 // SiteInstances are created (1) when the user manually creates a new tab |
33 // (which also creates a new BrowsingInstance), and (2) when the user navigates | 37 // (which also creates a new BrowsingInstance), and (2) when the user navigates |
34 // across site boundaries (which uses the same BrowsingInstance). If the user | 38 // across site boundaries (which uses the same BrowsingInstance). If the user |
35 // navigates within a site, or opens links in new tabs within a site, the same | 39 // navigates within a site, or opens links in new tabs within a site, the same |
36 // SiteInstance is used. | 40 // SiteInstance is used. |
37 // | 41 // |
38 // In --process-per-site, we consolidate all SiteInstances for a given site, | 42 // In --process-per-site, we consolidate all SiteInstances for a given site, |
39 // throughout the entire profile. This ensures that only one process will be | 43 // throughout the entire browser context. This ensures that only one process |
40 // dedicated to each site. | 44 // will be dedicated to each site. |
41 // | 45 // |
42 // Each NavigationEntry for a TabContents points to the SiteInstance that | 46 // Each NavigationEntry for a TabContents points to the SiteInstance that |
43 // rendered it. Each RenderViewHost also points to the SiteInstance that it is | 47 // rendered it. Each RenderViewHost also points to the SiteInstance that it is |
44 // associated with. A SiteInstance keeps track of the number of these | 48 // associated with. A SiteInstance keeps track of the number of these |
45 // references and deletes itself when the count goes to zero. This means that | 49 // references and deletes itself when the count goes to zero. This means that |
46 // a SiteInstance is only live as long as it is accessible, either from new | 50 // a SiteInstance is only live as long as it is accessible, either from new |
47 // tabs with no NavigationEntries or in NavigationEntries in the history. | 51 // tabs with no NavigationEntries or in NavigationEntries in the history. |
48 // | 52 // |
49 /////////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////////// |
50 class SiteInstance : public base::RefCounted<SiteInstance>, | 54 class SiteInstance : public base::RefCounted<SiteInstance>, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 116 |
113 // Factory method to create a new SiteInstance. This will create a new | 117 // Factory method to create a new SiteInstance. This will create a new |
114 // new BrowsingInstance, so it should only be used when creating a new tab | 118 // new BrowsingInstance, so it should only be used when creating a new tab |
115 // from scratch (or similar circumstances). Callers should ensure that | 119 // from scratch (or similar circumstances). Callers should ensure that |
116 // this SiteInstance becomes ref counted, by storing it in a scoped_refptr. | 120 // this SiteInstance becomes ref counted, by storing it in a scoped_refptr. |
117 // | 121 // |
118 // The render process host factory may be NULL. See SiteInstance constructor. | 122 // The render process host factory may be NULL. See SiteInstance constructor. |
119 // | 123 // |
120 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as | 124 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as |
121 // Darin suggests. | 125 // Darin suggests. |
122 static SiteInstance* CreateSiteInstance(Profile* profile); | 126 static SiteInstance* CreateSiteInstance( |
| 127 content::BrowserContext* browser_context); |
123 | 128 |
124 // Factory method to get the appropriate SiteInstance for the given URL, in | 129 // Factory method to get the appropriate SiteInstance for the given URL, in |
125 // a new BrowsingInstance. Use this instead of CreateSiteInstance when you | 130 // a new BrowsingInstance. Use this instead of CreateSiteInstance when you |
126 // know the URL, since it allows special site grouping rules to be applied | 131 // know the URL, since it allows special site grouping rules to be applied |
127 // (for example, to group chrome-ui pages into the same instance). | 132 // (for example, to group chrome-ui pages into the same instance). |
128 static SiteInstance* CreateSiteInstanceForURL(Profile* profile, | 133 static SiteInstance* CreateSiteInstanceForURL( |
129 const GURL& url); | 134 content::BrowserContext* browser_context, const GURL& url); |
130 | 135 |
131 // Returns the site for the given URL, which includes only the scheme and | 136 // Returns the site for the given URL, which includes only the scheme and |
132 // registered domain. Returns an empty GURL if the URL has no host. | 137 // registered domain. Returns an empty GURL if the URL has no host. |
133 static GURL GetSiteForURL(Profile* profile, const GURL& url); | 138 static GURL GetSiteForURL(content::BrowserContext* context, const GURL& url); |
134 | 139 |
135 // Return whether both URLs are part of the same web site, for the purpose of | 140 // Return whether both URLs are part of the same web site, for the purpose of |
136 // assigning them to processes accordingly. The decision is currently based | 141 // assigning them to processes accordingly. The decision is currently based |
137 // on the registered domain of the URLs (google.com, bbc.co.uk), as well as | 142 // on the registered domain of the URLs (google.com, bbc.co.uk), as well as |
138 // the scheme (https, http). This ensures that two pages will be in | 143 // the scheme (https, http). This ensures that two pages will be in |
139 // the same process if they can communicate with other via JavaScript. | 144 // the same process if they can communicate with other via JavaScript. |
140 // (e.g., docs.google.com and mail.google.com have DOM access to each other | 145 // (e.g., docs.google.com and mail.google.com have DOM access to each other |
141 // if they both set their document.domain properties to google.com.) | 146 // if they both set their document.domain properties to google.com.) |
142 static bool IsSameWebSite(Profile* profile, | 147 static bool IsSameWebSite(content::BrowserContext* browser_context, |
143 const GURL& url1, const GURL& url2); | 148 const GURL& url1, const GURL& url2); |
144 | 149 |
145 // Returns the renderer type for this URL. | 150 // Returns the renderer type for this URL. |
146 static RenderProcessHost::Type RendererTypeForURL(const GURL& url); | 151 static RenderProcessHost::Type RendererTypeForURL(const GURL& url); |
147 | 152 |
148 protected: | 153 protected: |
149 friend class base::RefCounted<SiteInstance>; | 154 friend class base::RefCounted<SiteInstance>; |
150 friend class BrowsingInstance; | 155 friend class BrowsingInstance; |
151 | 156 |
152 // Virtual to allow tests to extend it. | 157 // Virtual to allow tests to extend it. |
153 virtual ~SiteInstance(); | 158 virtual ~SiteInstance(); |
154 | 159 |
155 // Create a new SiteInstance. Protected to give access to BrowsingInstance | 160 // Create a new SiteInstance. Protected to give access to BrowsingInstance |
156 // and tests; most callers should use CreateSiteInstance or | 161 // and tests; most callers should use CreateSiteInstance or |
157 // GetRelatedSiteInstance instead. | 162 // GetRelatedSiteInstance instead. |
158 explicit SiteInstance(BrowsingInstance* browsing_instance); | 163 explicit SiteInstance(BrowsingInstance* browsing_instance); |
159 | 164 |
160 // Get the effective URL for the given actual URL. | 165 // Get the effective URL for the given actual URL. |
161 static GURL GetEffectiveURL(Profile* profile, const GURL& url); | 166 static GURL GetEffectiveURL(content::BrowserContext* browser_context, |
| 167 const GURL& url); |
162 | 168 |
163 // Returns the type of renderer process this instance belongs in, for grouping | 169 // Returns the type of renderer process this instance belongs in, for grouping |
164 // purposes. | 170 // purposes. |
165 RenderProcessHost::Type GetRendererType(); | 171 RenderProcessHost::Type GetRendererType(); |
166 | 172 |
167 private: | 173 private: |
168 // NotificationObserver implementation. | 174 // NotificationObserver implementation. |
169 virtual void Observe(int type, | 175 virtual void Observe(int type, |
170 const NotificationSource& source, | 176 const NotificationSource& source, |
171 const NotificationDetails& details); | 177 const NotificationDetails& details); |
(...skipping 27 matching lines...) Expand all Loading... |
199 // The web site that this SiteInstance is rendering pages for. | 205 // The web site that this SiteInstance is rendering pages for. |
200 GURL site_; | 206 GURL site_; |
201 | 207 |
202 // Whether SetSite has been called. | 208 // Whether SetSite has been called. |
203 bool has_site_; | 209 bool has_site_; |
204 | 210 |
205 DISALLOW_COPY_AND_ASSIGN(SiteInstance); | 211 DISALLOW_COPY_AND_ASSIGN(SiteInstance); |
206 }; | 212 }; |
207 | 213 |
208 #endif // CONTENT_BROWSER_RENDERER_HOST_SITE_INSTANCE_H_ | 214 #endif // CONTENT_BROWSER_RENDERER_HOST_SITE_INSTANCE_H_ |
OLD | NEW |