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 #include "content/browser/site_instance.h" | 5 #include "content/browser/site_instance.h" |
6 | 6 |
7 #include "content/browser/browsing_instance.h" | 7 #include "content/browser/browsing_instance.h" |
8 #include "content/browser/content_browser_client.h" | 8 #include "content/browser/content_browser_client.h" |
9 #include "content/browser/renderer_host/browser_render_process_host.h" | 9 #include "content/browser/renderer_host/browser_render_process_host.h" |
10 #include "content/browser/webui/web_ui_factory.h" | 10 #include "content/browser/webui/web_ui_factory.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // with no site set at this point, so it will default to TYPE_NORMAL. This | 64 // with no site set at this point, so it will default to TYPE_NORMAL. This |
65 // may not be correct, so we'll wind up potentially creating a process that | 65 // may not be correct, so we'll wind up potentially creating a process that |
66 // we then throw away, or worse sharing a process with the wrong process type. | 66 // we then throw away, or worse sharing a process with the wrong process type. |
67 // See crbug.com/43448. | 67 // See crbug.com/43448. |
68 | 68 |
69 // Create a new process if ours went away or was reused. | 69 // Create a new process if ours went away or was reused. |
70 if (!process_) { | 70 if (!process_) { |
71 // See if we should reuse an old process | 71 // See if we should reuse an old process |
72 if (RenderProcessHost::ShouldTryToUseExistingProcessHost()) | 72 if (RenderProcessHost::ShouldTryToUseExistingProcessHost()) |
73 process_ = RenderProcessHost::GetExistingProcessHost( | 73 process_ = RenderProcessHost::GetExistingProcessHost( |
74 browsing_instance_->browser_context(), GetRendererType()); | 74 browsing_instance_->browser_context(), site_); |
75 | 75 |
76 // Otherwise (or if that fails), create a new one. | 76 // Otherwise (or if that fails), create a new one. |
77 if (!process_) { | 77 if (!process_) { |
78 if (render_process_host_factory_) { | 78 if (render_process_host_factory_) { |
79 process_ = render_process_host_factory_->CreateRenderProcessHost( | 79 process_ = render_process_host_factory_->CreateRenderProcessHost( |
80 browsing_instance_->browser_context()); | 80 browsing_instance_->browser_context()); |
81 } else { | 81 } else { |
82 process_ = | 82 process_ = |
83 new BrowserRenderProcessHost(browsing_instance_->browser_context()); | 83 new BrowserRenderProcessHost(browsing_instance_->browser_context()); |
84 } | 84 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 SiteInstance* SiteInstance::GetRelatedSiteInstance(const GURL& url) { | 119 SiteInstance* SiteInstance::GetRelatedSiteInstance(const GURL& url) { |
120 return browsing_instance_->GetSiteInstanceForURL(url); | 120 return browsing_instance_->GetSiteInstanceForURL(url); |
121 } | 121 } |
122 | 122 |
123 bool SiteInstance::HasWrongProcessForURL(const GURL& url) const { | 123 bool SiteInstance::HasWrongProcessForURL(const GURL& url) const { |
124 // Having no process isn't a problem, since we'll assign it correctly. | 124 // Having no process isn't a problem, since we'll assign it correctly. |
125 if (!HasProcess()) | 125 if (!HasProcess()) |
126 return false; | 126 return false; |
127 | 127 |
128 // If the effective URL is an extension (e.g., for hosted apps) but the | 128 // If the site URL is an extension (e.g., for hosted apps) but the |
129 // process is not (or vice versa), make sure we notice and fix it. | 129 // process is not (or vice versa), make sure we notice and fix it. |
130 GURL effective_url = GetEffectiveURL(browsing_instance_->browser_context(), | 130 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); |
131 url); | 131 content::ContentBrowserClient* browser = |
132 return effective_url.SchemeIs(chrome::kExtensionScheme) != | 132 content::GetContentClient()->browser(); |
133 process_->is_extension_process(); | 133 return !browser->IsSuitableHost(process_, site_url); |
134 } | 134 } |
135 | 135 |
136 /*static*/ | 136 /*static*/ |
137 SiteInstance* SiteInstance::CreateSiteInstance( | 137 SiteInstance* SiteInstance::CreateSiteInstance( |
138 content::BrowserContext* browser_context) { | 138 content::BrowserContext* browser_context) { |
139 return new SiteInstance(new BrowsingInstance(browser_context)); | 139 return new SiteInstance(new BrowsingInstance(browser_context)); |
140 } | 140 } |
141 | 141 |
142 /*static*/ | 142 /*static*/ |
143 SiteInstance* SiteInstance::CreateSiteInstanceForURL( | 143 SiteInstance* SiteInstance::CreateSiteInstanceForURL( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); | 213 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); |
214 } | 214 } |
215 | 215 |
216 /*static*/ | 216 /*static*/ |
217 GURL SiteInstance::GetEffectiveURL(content::BrowserContext* browser_context, | 217 GURL SiteInstance::GetEffectiveURL(content::BrowserContext* browser_context, |
218 const GURL& url) { | 218 const GURL& url) { |
219 return content::GetContentClient()->browser()-> | 219 return content::GetContentClient()->browser()-> |
220 GetEffectiveURL(browser_context, url); | 220 GetEffectiveURL(browser_context, url); |
221 } | 221 } |
222 | 222 |
223 /*static*/ | |
224 RenderProcessHost::Type SiteInstance::RendererTypeForURL(const GURL& url) { | |
225 if (!url.is_valid()) | |
226 return RenderProcessHost::TYPE_NORMAL; | |
227 | |
228 if (url.SchemeIs(chrome::kExtensionScheme)) | |
229 return RenderProcessHost::TYPE_EXTENSION; | |
230 | |
231 // TODO(erikkay) creis recommends using UseWebUIForURL instead. | |
232 if (content::WebUIFactory::Get()->HasWebUIScheme(url)) | |
233 return RenderProcessHost::TYPE_WEBUI; | |
234 | |
235 return RenderProcessHost::TYPE_NORMAL; | |
236 } | |
237 | |
238 RenderProcessHost::Type SiteInstance::GetRendererType() { | |
239 // We may not have a site at this point, which generally means this is a | |
240 // normal navigation. | |
241 if (!has_site_) | |
242 return RenderProcessHost::TYPE_NORMAL; | |
243 | |
244 return RendererTypeForURL(site_); | |
245 } | |
246 | |
247 void SiteInstance::Observe(int type, | 223 void SiteInstance::Observe(int type, |
248 const NotificationSource& source, | 224 const NotificationSource& source, |
249 const NotificationDetails& details) { | 225 const NotificationDetails& details) { |
250 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); | 226 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); |
251 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); | 227 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); |
252 if (rph == process_) | 228 if (rph == process_) |
253 process_ = NULL; | 229 process_ = NULL; |
254 } | 230 } |
OLD | NEW |