Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: content/browser/site_instance.cc

Issue 8033001: Delegate decision what site instances can be rendered in what process to chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 effective 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 effective_url = GetEffectiveURL(browsing_instance_->browser_context(),
131 url); 131 url);
132 return effective_url.SchemeIs(chrome::kExtensionScheme) != 132 content::ContentBrowserClient* browser =
133 content::GetContentClient()->browser();
134 return browser->ShouldRunInPrivilegedProcess(effective_url) !=
133 process_->is_extension_process(); 135 process_->is_extension_process();
jam 2011/09/26 16:28:15 note: it's not just kExtensionScheme that we don't
134 } 136 }
135 137
136 /*static*/ 138 /*static*/
137 SiteInstance* SiteInstance::CreateSiteInstance( 139 SiteInstance* SiteInstance::CreateSiteInstance(
138 content::BrowserContext* browser_context) { 140 content::BrowserContext* browser_context) {
139 return new SiteInstance(new BrowsingInstance(browser_context)); 141 return new SiteInstance(new BrowsingInstance(browser_context));
140 } 142 }
141 143
142 /*static*/ 144 /*static*/
143 SiteInstance* SiteInstance::CreateSiteInstanceForURL( 145 SiteInstance* SiteInstance::CreateSiteInstanceForURL(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); 215 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2);
214 } 216 }
215 217
216 /*static*/ 218 /*static*/
217 GURL SiteInstance::GetEffectiveURL(content::BrowserContext* browser_context, 219 GURL SiteInstance::GetEffectiveURL(content::BrowserContext* browser_context,
218 const GURL& url) { 220 const GURL& url) {
219 return content::GetContentClient()->browser()-> 221 return content::GetContentClient()->browser()->
220 GetEffectiveURL(browser_context, url); 222 GetEffectiveURL(browser_context, url);
221 } 223 }
222 224
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, 225 void SiteInstance::Observe(int type,
248 const NotificationSource& source, 226 const NotificationSource& source,
249 const NotificationDetails& details) { 227 const NotificationDetails& details) {
250 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); 228 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
251 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); 229 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr();
252 if (rph == process_) 230 if (rph == process_)
253 process_ = NULL; 231 process_ = NULL;
254 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698