| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 bool SiteInstanceImpl::HasProcess() const { | 68 bool SiteInstanceImpl::HasProcess() const { |
| 69 if (process_ != NULL) | 69 if (process_ != NULL) |
| 70 return true; | 70 return true; |
| 71 | 71 |
| 72 // If we would use process-per-site for this site, also check if there is an | 72 // If we would use process-per-site for this site, also check if there is an |
| 73 // existing process that we would use if GetProcess() were called. | 73 // existing process that we would use if GetProcess() were called. |
| 74 BrowserContext* browser_context = | 74 BrowserContext* browser_context = |
| 75 browsing_instance_->browser_context(); | 75 browsing_instance_->browser_context(); |
| 76 if (has_site_ && | 76 if (has_site_ && |
| 77 RenderProcessHostImpl::ShouldUseProcessPerSite(browser_context, site_) && | 77 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_) && |
| 78 RenderProcessHostImpl::GetProcessHostForSite(browser_context, site_)) { | 78 RenderProcessHostImpl::GetProcessHostForSite(browser_context, site_)) { |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 RenderProcessHost* SiteInstanceImpl::GetProcess() { | 85 RenderProcessHost* SiteInstanceImpl::GetProcess() { |
| 86 // TODO(erikkay) It would be nice to ensure that the renderer type had been | 86 // TODO(erikkay) It would be nice to ensure that the renderer type had been |
| 87 // properly set before we get here. The default tab creation case winds up | 87 // properly set before we get here. The default tab creation case winds up |
| 88 // with no site set at this point, so it will default to TYPE_NORMAL. This | 88 // with no site set at this point, so it will default to TYPE_NORMAL. This |
| 89 // may not be correct, so we'll wind up potentially creating a process that | 89 // may not be correct, so we'll wind up potentially creating a process that |
| 90 // we then throw away, or worse sharing a process with the wrong process type. | 90 // we then throw away, or worse sharing a process with the wrong process type. |
| 91 // See crbug.com/43448. | 91 // See crbug.com/43448. |
| 92 | 92 |
| 93 // Create a new process if ours went away or was reused. | 93 // Create a new process if ours went away or was reused. |
| 94 if (!process_) { | 94 if (!process_) { |
| 95 BrowserContext* browser_context = browsing_instance_->browser_context(); | 95 BrowserContext* browser_context = browsing_instance_->browser_context(); |
| 96 | 96 |
| 97 // If we should use process-per-site mode (either in general or for the | 97 // If we should use process-per-site mode (either in general or for the |
| 98 // given site), then look for an existing RenderProcessHost for the site. | 98 // given site), then look for an existing RenderProcessHost for the site. |
| 99 bool use_process_per_site = has_site_ && | 99 bool use_process_per_site = has_site_ && |
| 100 RenderProcessHostImpl::ShouldUseProcessPerSite(browser_context, site_); | 100 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_); |
| 101 if (use_process_per_site) { | 101 if (use_process_per_site) { |
| 102 process_ = RenderProcessHostImpl::GetProcessHostForSite(browser_context, | 102 process_ = RenderProcessHostImpl::GetProcessHostForSite(browser_context, |
| 103 site_); | 103 site_); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // 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. |
| 107 if (!process_ && RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( | 107 if (!process_ && RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
| 108 browser_context, site_)) { | 108 browser_context, site_)) { |
| 109 process_ = RenderProcessHostImpl::GetExistingProcessHost(browser_context, | 109 process_ = RenderProcessHostImpl::GetExistingProcessHost(browser_context, |
| 110 site_); | 110 site_); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // Now that we have a site, register it with the BrowsingInstance. This | 164 // Now that we have a site, register it with the BrowsingInstance. This |
| 165 // ensures that we won't create another SiteInstance for this site within | 165 // ensures that we won't create another SiteInstance for this site within |
| 166 // the same BrowsingInstance, because all same-site pages within a | 166 // the same BrowsingInstance, because all same-site pages within a |
| 167 // BrowsingInstance can script each other. | 167 // BrowsingInstance can script each other. |
| 168 browsing_instance_->RegisterSiteInstance(this); | 168 browsing_instance_->RegisterSiteInstance(this); |
| 169 | 169 |
| 170 if (process_) { | 170 if (process_) { |
| 171 LockToOrigin(); | 171 LockToOrigin(); |
| 172 | 172 |
| 173 // Ensure the process is registered for this site if necessary. | 173 // Ensure the process is registered for this site if necessary. |
| 174 if (RenderProcessHostImpl::ShouldUseProcessPerSite(browser_context, | 174 if (RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_)) { |
| 175 site_)) { | |
| 176 RenderProcessHostImpl::RegisterProcessHostForSite( | 175 RenderProcessHostImpl::RegisterProcessHostForSite( |
| 177 browser_context, process_, site_); | 176 browser_context, process_, site_); |
| 178 } | 177 } |
| 179 } | 178 } |
| 180 } | 179 } |
| 181 | 180 |
| 182 const GURL& SiteInstanceImpl::GetSiteURL() const { | 181 const GURL& SiteInstanceImpl::GetSiteURL() const { |
| 183 return site_; | 182 return site_; |
| 184 } | 183 } |
| 185 | 184 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 340 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 342 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || | 341 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
| 343 command_line.HasSwitch(switches::kSitePerProcess)) { | 342 command_line.HasSwitch(switches::kSitePerProcess)) { |
| 344 ChildProcessSecurityPolicyImpl* policy = | 343 ChildProcessSecurityPolicyImpl* policy = |
| 345 ChildProcessSecurityPolicyImpl::GetInstance(); | 344 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 346 policy->LockToOrigin(process_->GetID(), site_); | 345 policy->LockToOrigin(process_->GetID(), site_); |
| 347 } | 346 } |
| 348 } | 347 } |
| 349 | 348 |
| 350 } // namespace content | 349 } // namespace content |
| OLD | NEW |