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 #include "content/browser/site_instance_impl.h" | 5 #include "content/browser/site_instance_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/browsing_instance.h" | 8 #include "content/browser/browsing_instance.h" |
9 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
10 #include "content/browser/renderer_host/render_process_host_impl.h" | 10 #include "content/browser/renderer_host/render_process_host_impl.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // a modifier on existing pages. | 28 // a modifier on existing pages. |
29 if (url.SchemeIs(chrome::kJavaScriptScheme)) | 29 if (url.SchemeIs(chrome::kJavaScriptScheme)) |
30 return true; | 30 return true; |
31 | 31 |
32 return url == GURL(kChromeUICrashURL) || | 32 return url == GURL(kChromeUICrashURL) || |
33 url == GURL(kChromeUIKillURL) || | 33 url == GURL(kChromeUIKillURL) || |
34 url == GURL(kChromeUIHangURL) || | 34 url == GURL(kChromeUIHangURL) || |
35 url == GURL(kChromeUIShorthangURL); | 35 url == GURL(kChromeUIShorthangURL); |
36 } | 36 } |
37 | 37 |
| 38 const RenderProcessHostFactory* |
| 39 SiteInstanceImpl::g_render_process_host_factory_ = NULL; |
38 int32 SiteInstanceImpl::next_site_instance_id_ = 1; | 40 int32 SiteInstanceImpl::next_site_instance_id_ = 1; |
39 | 41 |
40 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) | 42 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) |
41 : id_(next_site_instance_id_++), | 43 : id_(next_site_instance_id_++), |
42 browsing_instance_(browsing_instance), | 44 browsing_instance_(browsing_instance), |
43 render_process_host_factory_(NULL), | |
44 process_(NULL), | 45 process_(NULL), |
45 has_site_(false) { | 46 has_site_(false) { |
46 DCHECK(browsing_instance); | 47 DCHECK(browsing_instance); |
47 | 48 |
48 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 49 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
49 NotificationService::AllBrowserContextsAndSources()); | 50 NotificationService::AllBrowserContextsAndSources()); |
50 } | 51 } |
51 | 52 |
52 SiteInstanceImpl::~SiteInstanceImpl() { | 53 SiteInstanceImpl::~SiteInstanceImpl() { |
53 GetContentClient()->browser()->SiteInstanceDeleting(this); | 54 GetContentClient()->browser()->SiteInstanceDeleting(this); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 105 |
105 // If not (or if none found), see if we should reuse an existing process. | 106 // If not (or if none found), see if we should reuse an existing process. |
106 if (!process_ && RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( | 107 if (!process_ && RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
107 browser_context, site_)) { | 108 browser_context, site_)) { |
108 process_ = RenderProcessHostImpl::GetExistingProcessHost(browser_context, | 109 process_ = RenderProcessHostImpl::GetExistingProcessHost(browser_context, |
109 site_); | 110 site_); |
110 } | 111 } |
111 | 112 |
112 // Otherwise (or if that fails), create a new one. | 113 // Otherwise (or if that fails), create a new one. |
113 if (!process_) { | 114 if (!process_) { |
114 if (render_process_host_factory_) { | 115 if (g_render_process_host_factory_) { |
115 process_ = render_process_host_factory_->CreateRenderProcessHost( | 116 process_ = g_render_process_host_factory_->CreateRenderProcessHost( |
116 browser_context); | 117 browser_context); |
117 } else { | 118 } else { |
118 StoragePartitionImpl* partition = | 119 StoragePartitionImpl* partition = |
119 static_cast<StoragePartitionImpl*>( | 120 static_cast<StoragePartitionImpl*>( |
120 BrowserContext::GetStoragePartition(browser_context, this)); | 121 BrowserContext::GetStoragePartition(browser_context, this)); |
121 bool supports_browser_plugin = GetContentClient()->browser()-> | 122 bool supports_browser_plugin = GetContentClient()->browser()-> |
122 SupportsBrowserPlugin(browser_context, site_); | 123 SupportsBrowserPlugin(browser_context, site_); |
123 process_ = | 124 process_ = |
124 new RenderProcessHostImpl(browser_context, partition, | 125 new RenderProcessHostImpl(browser_context, partition, |
125 supports_browser_plugin, | 126 supports_browser_plugin, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (IsURLSameAsAnySiteInstance(url)) | 214 if (IsURLSameAsAnySiteInstance(url)) |
214 return false; | 215 return false; |
215 | 216 |
216 // If the site URL is an extension (e.g., for hosted apps or WebUI) but the | 217 // If the site URL is an extension (e.g., for hosted apps or WebUI) but the |
217 // process is not (or vice versa), make sure we notice and fix it. | 218 // process is not (or vice versa), make sure we notice and fix it. |
218 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); | 219 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); |
219 return !RenderProcessHostImpl::IsSuitableHost( | 220 return !RenderProcessHostImpl::IsSuitableHost( |
220 GetProcess(), browsing_instance_->browser_context(), site_url); | 221 GetProcess(), browsing_instance_->browser_context(), site_url); |
221 } | 222 } |
222 | 223 |
| 224 void SiteInstanceImpl::set_render_process_host_factory( |
| 225 const RenderProcessHostFactory* rph_factory) { |
| 226 g_render_process_host_factory_ = rph_factory; |
| 227 } |
| 228 |
223 BrowserContext* SiteInstanceImpl::GetBrowserContext() const { | 229 BrowserContext* SiteInstanceImpl::GetBrowserContext() const { |
224 return browsing_instance_->browser_context(); | 230 return browsing_instance_->browser_context(); |
225 } | 231 } |
226 | 232 |
227 /*static*/ | 233 /*static*/ |
228 SiteInstance* SiteInstance::Create(BrowserContext* browser_context) { | 234 SiteInstance* SiteInstance::Create(BrowserContext* browser_context) { |
229 return new SiteInstanceImpl(new BrowsingInstance(browser_context)); | 235 return new SiteInstanceImpl(new BrowsingInstance(browser_context)); |
230 } | 236 } |
231 | 237 |
232 /*static*/ | 238 /*static*/ |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 341 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
336 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || | 342 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
337 command_line.HasSwitch(switches::kSitePerProcess)) { | 343 command_line.HasSwitch(switches::kSitePerProcess)) { |
338 ChildProcessSecurityPolicyImpl* policy = | 344 ChildProcessSecurityPolicyImpl* policy = |
339 ChildProcessSecurityPolicyImpl::GetInstance(); | 345 ChildProcessSecurityPolicyImpl::GetInstance(); |
340 policy->LockToOrigin(process_->GetID(), site_); | 346 policy->LockToOrigin(process_->GetID(), site_); |
341 } | 347 } |
342 } | 348 } |
343 | 349 |
344 } // namespace content | 350 } // namespace content |
OLD | NEW |