| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 NotificationService::AllBrowserContextsAndSources()); | 49 NotificationService::AllBrowserContextsAndSources()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 SiteInstanceImpl::~SiteInstanceImpl() { | 52 SiteInstanceImpl::~SiteInstanceImpl() { |
| 53 GetContentClient()->browser()->SiteInstanceDeleting(this); | 53 GetContentClient()->browser()->SiteInstanceDeleting(this); |
| 54 | 54 |
| 55 // Now that no one is referencing us, we can safely remove ourselves from | 55 // Now that no one is referencing us, we can safely remove ourselves from |
| 56 // the BrowsingInstance. Any future visits to a page from this site | 56 // the BrowsingInstance. Any future visits to a page from this site |
| 57 // (within the same BrowsingInstance) can safely create a new SiteInstance. | 57 // (within the same BrowsingInstance) can safely create a new SiteInstance. |
| 58 if (has_site_) | 58 if (has_site_) |
| 59 browsing_instance_->UnregisterSiteInstance( | 59 browsing_instance_->UnregisterSiteInstance(this); |
| 60 static_cast<SiteInstance*>(this)); | |
| 61 } | 60 } |
| 62 | 61 |
| 63 int32 SiteInstanceImpl::GetId() { | 62 int32 SiteInstanceImpl::GetId() { |
| 64 return id_; | 63 return id_; |
| 65 } | 64 } |
| 66 | 65 |
| 67 bool SiteInstanceImpl::HasProcess() const { | 66 bool SiteInstanceImpl::HasProcess() const { |
| 68 if (process_ != NULL) | 67 if (process_ != NULL) |
| 69 return true; | 68 return true; |
| 70 | 69 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 183 |
| 185 bool SiteInstanceImpl::HasSite() const { | 184 bool SiteInstanceImpl::HasSite() const { |
| 186 return has_site_; | 185 return has_site_; |
| 187 } | 186 } |
| 188 | 187 |
| 189 bool SiteInstanceImpl::HasRelatedSiteInstance(const GURL& url) { | 188 bool SiteInstanceImpl::HasRelatedSiteInstance(const GURL& url) { |
| 190 return browsing_instance_->HasSiteInstance(url); | 189 return browsing_instance_->HasSiteInstance(url); |
| 191 } | 190 } |
| 192 | 191 |
| 193 SiteInstance* SiteInstanceImpl::GetRelatedSiteInstance(const GURL& url) { | 192 SiteInstance* SiteInstanceImpl::GetRelatedSiteInstance(const GURL& url) { |
| 194 return browsing_instance_->GetSiteInstanceForURL(url); | 193 SiteInstanceImpl* result = browsing_instance_->GetSiteInstanceForURL(url); |
| 194 if (render_process_host_factory_) |
| 195 result->set_render_process_host_factory(render_process_host_factory_); |
| 196 return result; |
| 195 } | 197 } |
| 196 | 198 |
| 197 bool SiteInstanceImpl::IsRelatedSiteInstance(const SiteInstance* instance) { | 199 bool SiteInstanceImpl::IsRelatedSiteInstance(const SiteInstance* instance) { |
| 198 return browsing_instance_ == | 200 return browsing_instance_ == |
| 199 static_cast<const SiteInstanceImpl*>(instance)->browsing_instance_; | 201 static_cast<const SiteInstanceImpl*>(instance)->browsing_instance_; |
| 200 } | 202 } |
| 201 | 203 |
| 202 bool SiteInstanceImpl::HasWrongProcessForURL(const GURL& url) { | 204 bool SiteInstanceImpl::HasWrongProcessForURL(const GURL& url) { |
| 203 // Having no process isn't a problem, since we'll assign it correctly. | 205 // Having no process isn't a problem, since we'll assign it correctly. |
| 204 // Note that HasProcess() may return true if process_ is null, in | 206 // Note that HasProcess() may return true if process_ is null, in |
| (...skipping 12 matching lines...) Expand all Loading... |
| 217 // process is not (or vice versa), make sure we notice and fix it. | 219 // process is not (or vice versa), make sure we notice and fix it. |
| 218 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); | 220 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); |
| 219 return !RenderProcessHostImpl::IsSuitableHost( | 221 return !RenderProcessHostImpl::IsSuitableHost( |
| 220 GetProcess(), browsing_instance_->browser_context(), site_url); | 222 GetProcess(), browsing_instance_->browser_context(), site_url); |
| 221 } | 223 } |
| 222 | 224 |
| 223 BrowserContext* SiteInstanceImpl::GetBrowserContext() const { | 225 BrowserContext* SiteInstanceImpl::GetBrowserContext() const { |
| 224 return browsing_instance_->browser_context(); | 226 return browsing_instance_->browser_context(); |
| 225 } | 227 } |
| 226 | 228 |
| 229 void SiteInstanceImpl::set_render_process_host_factory( |
| 230 const RenderProcessHostFactory* rph_factory) { |
| 231 render_process_host_factory_ = rph_factory; |
| 232 } |
| 233 |
| 227 /*static*/ | 234 /*static*/ |
| 228 SiteInstance* SiteInstance::Create(BrowserContext* browser_context) { | 235 SiteInstance* SiteInstance::Create(BrowserContext* browser_context) { |
| 229 return new SiteInstanceImpl(new BrowsingInstance(browser_context)); | 236 return new SiteInstanceImpl(new BrowsingInstance(browser_context)); |
| 230 } | 237 } |
| 231 | 238 |
| 232 /*static*/ | 239 /*static*/ |
| 233 SiteInstance* SiteInstance::CreateForURL(BrowserContext* browser_context, | 240 SiteInstance* SiteInstance::CreateForURL(BrowserContext* browser_context, |
| 234 const GURL& url) { | 241 const GURL& url) { |
| 235 // This BrowsingInstance may be deleted if it returns an existing | 242 // This BrowsingInstance may be deleted if it returns an existing |
| 236 // SiteInstance. | 243 // SiteInstance. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 337 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 331 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || | 338 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
| 332 command_line.HasSwitch(switches::kSitePerProcess)) { | 339 command_line.HasSwitch(switches::kSitePerProcess)) { |
| 333 ChildProcessSecurityPolicyImpl* policy = | 340 ChildProcessSecurityPolicyImpl* policy = |
| 334 ChildProcessSecurityPolicyImpl::GetInstance(); | 341 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 335 policy->LockToOrigin(process_->GetID(), site_); | 342 policy->LockToOrigin(process_->GetID(), site_); |
| 336 } | 343 } |
| 337 } | 344 } |
| 338 | 345 |
| 339 } // namespace content | 346 } // namespace content |
| OLD | NEW |