| 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 "content/browser/browsing_instance.h" | 7 #include "content/browser/browsing_instance.h" |
| 8 #include "content/browser/child_process_security_policy_impl.h" | 8 #include "content/browser/child_process_security_policy_impl.h" |
| 9 #include "content/browser/frame_host/debug_urls.h" | 9 #include "content/browser/frame_host/debug_urls.h" |
| 10 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 GetContentClient()->browser()->SiteInstanceDeleting(this); | 37 GetContentClient()->browser()->SiteInstanceDeleting(this); |
| 38 | 38 |
| 39 if (process_) | 39 if (process_) |
| 40 process_->RemoveObserver(this); | 40 process_->RemoveObserver(this); |
| 41 | 41 |
| 42 // Now that no one is referencing us, we can safely remove ourselves from | 42 // Now that no one is referencing us, we can safely remove ourselves from |
| 43 // the BrowsingInstance. Any future visits to a page from this site | 43 // the BrowsingInstance. Any future visits to a page from this site |
| 44 // (within the same BrowsingInstance) can safely create a new SiteInstance. | 44 // (within the same BrowsingInstance) can safely create a new SiteInstance. |
| 45 if (has_site_) | 45 if (has_site_) |
| 46 browsing_instance_->UnregisterSiteInstance(this); | 46 browsing_instance_->UnregisterSiteInstance(this); |
| 47 browsing_instance_->UnregisterUsedFor(this, sites_displayed_); |
| 47 } | 48 } |
| 48 | 49 |
| 49 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::Create( | 50 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::Create( |
| 50 BrowserContext* browser_context) { | 51 BrowserContext* browser_context) { |
| 51 return make_scoped_refptr( | 52 return make_scoped_refptr( |
| 52 new SiteInstanceImpl(new BrowsingInstance(browser_context))); | 53 new SiteInstanceImpl(new BrowsingInstance(browser_context))); |
| 53 } | 54 } |
| 54 | 55 |
| 55 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::CreateForURL( | 56 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::CreateForURL( |
| 56 BrowserContext* browser_context, | 57 BrowserContext* browser_context, |
| 57 const GURL& url) { | 58 const GURL& url) { |
| 58 // This will create a new SiteInstance and BrowsingInstance. | 59 // This will create a new SiteInstance and BrowsingInstance. |
| 59 scoped_refptr<BrowsingInstance> instance( | 60 scoped_refptr<BrowsingInstance> instance( |
| 60 new BrowsingInstance(browser_context)); | 61 new BrowsingInstance(browser_context)); |
| 61 return instance->GetSiteInstanceForURL(url); | 62 return instance->GetSiteInstanceForURL(url); |
| 62 } | 63 } |
| 63 | 64 |
| 65 // static |
| 66 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::FindOrCreateForURL( |
| 67 BrowserContext* browser_context, |
| 68 const GURL& url) { |
| 69 scoped_refptr<SiteInstanceImpl> instance_found = |
| 70 BrowsingInstance::FindSiteInstance(browser_context, url); |
| 71 if (instance_found) |
| 72 return instance_found; |
| 73 return CreateForURL(browser_context, url); |
| 74 } |
| 75 |
| 64 int32_t SiteInstanceImpl::GetId() { | 76 int32_t SiteInstanceImpl::GetId() { |
| 65 return id_; | 77 return id_; |
| 66 } | 78 } |
| 67 | 79 |
| 68 bool SiteInstanceImpl::HasProcess() const { | 80 bool SiteInstanceImpl::HasProcess() const { |
| 69 if (process_ != NULL) | 81 if (process_ != NULL) |
| 70 return true; | 82 return true; |
| 71 | 83 |
| 72 // If we would use process-per-site for this site, also check if there is an | 84 // 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. | 85 // existing process that we would use if GetProcess() were called. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 274 } |
| 263 | 275 |
| 264 const GURL& SiteInstanceImpl::GetSiteURL() const { | 276 const GURL& SiteInstanceImpl::GetSiteURL() const { |
| 265 return site_; | 277 return site_; |
| 266 } | 278 } |
| 267 | 279 |
| 268 bool SiteInstanceImpl::HasSite() const { | 280 bool SiteInstanceImpl::HasSite() const { |
| 269 return has_site_; | 281 return has_site_; |
| 270 } | 282 } |
| 271 | 283 |
| 284 void SiteInstanceImpl::UsedFor(const GURL& url) { |
| 285 std::string site = GetSiteForURL(browsing_instance_->browser_context_, url) |
| 286 .possibly_invalid_spec(); |
| 287 sites_displayed_.insert(site); |
| 288 browsing_instance_->RegisterUsedFor(this, site); |
| 289 } |
| 290 |
| 272 bool SiteInstanceImpl::HasRelatedSiteInstance(const GURL& url) { | 291 bool SiteInstanceImpl::HasRelatedSiteInstance(const GURL& url) { |
| 273 return browsing_instance_->HasSiteInstance(url); | 292 return browsing_instance_->HasSiteInstance(url); |
| 274 } | 293 } |
| 275 | 294 |
| 276 scoped_refptr<SiteInstance> SiteInstanceImpl::GetRelatedSiteInstance( | 295 scoped_refptr<SiteInstance> SiteInstanceImpl::GetRelatedSiteInstance( |
| 277 const GURL& url) { | 296 const GURL& url) { |
| 278 return browsing_instance_->GetSiteInstanceForURL(url); | 297 return browsing_instance_->GetSiteInstanceForURL(url); |
| 279 } | 298 } |
| 280 | 299 |
| 281 bool SiteInstanceImpl::IsRelatedSiteInstance(const SiteInstance* instance) { | 300 bool SiteInstanceImpl::IsRelatedSiteInstance(const SiteInstance* instance) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 browsing_instance_->browser_context(), site_)) | 540 browsing_instance_->browser_context(), site_)) |
| 522 return; | 541 return; |
| 523 | 542 |
| 524 ChildProcessSecurityPolicyImpl* policy = | 543 ChildProcessSecurityPolicyImpl* policy = |
| 525 ChildProcessSecurityPolicyImpl::GetInstance(); | 544 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 526 policy->LockToOrigin(process_->GetID(), site_); | 545 policy->LockToOrigin(process_->GetID(), site_); |
| 527 } | 546 } |
| 528 } | 547 } |
| 529 | 548 |
| 530 } // namespace content | 549 } // namespace content |
| OLD | NEW |