Chromium Code Reviews| 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/browsing_instance.h" | 5 #include "content/browser/browsing_instance.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/browser/site_instance_impl.h" | 9 #include "content/browser/site_instance_impl.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 SiteInstance* BrowsingInstance::GetSiteInstanceForURL(const GURL& url) { | 30 SiteInstance* BrowsingInstance::GetSiteInstanceForURL(const GURL& url) { |
| 31 std::string site = | 31 std::string site = |
| 32 SiteInstanceImpl::GetSiteForURL(browser_context_, url) | 32 SiteInstanceImpl::GetSiteForURL(browser_context_, url) |
| 33 .possibly_invalid_spec(); | 33 .possibly_invalid_spec(); |
| 34 | 34 |
| 35 SiteInstanceMap::iterator i = site_instance_map_.find(site); | 35 SiteInstanceMap::iterator i = site_instance_map_.find(site); |
| 36 if (i != site_instance_map_.end()) | 36 if (i != site_instance_map_.end()) |
| 37 return i->second; | 37 return i->second; |
| 38 | 38 |
| 39 | |
| 40 // No current SiteInstance for this site, so let's create one. | 39 // No current SiteInstance for this site, so let's create one. |
| 41 SiteInstanceImpl* instance = new SiteInstanceImpl(this); | 40 SiteInstanceImpl* instance = new SiteInstanceImpl(this); |
| 42 | 41 |
| 43 // Set the site of this new SiteInstance, which will register it with us. | 42 // Set the site of this new SiteInstance, which will register it with us. |
| 44 instance->SetSite(url); | 43 instance->SetSite(url); |
| 45 return instance; | 44 return instance; |
| 46 } | 45 } |
| 47 | 46 |
| 47 SiteInstance* BrowsingInstance::GetSiteInstanceForThirdPartySubframes( | |
| 48 const GURL& url) { | |
| 49 // If we already have a site instance for this site, always use it instead | |
| 50 // of the site instance for third party subframes. | |
| 51 if (HasSiteInstance(url)) | |
|
Charlie Reis
2016/03/18 21:15:13
I'm going to suggest skipping this. Don't worry a
| |
| 52 return GetSiteInstanceForURL(url); | |
| 53 | |
| 54 if (!site_instance_for_third_party_subframes_) { | |
| 55 SiteInstanceImpl* instance = new SiteInstanceImpl(this); | |
| 56 instance->set_is_for_third_party_subframes(); | |
| 57 instance->SetSite(url); | |
| 58 site_instance_for_third_party_subframes_ = instance; | |
| 59 } | |
| 60 | |
| 61 return site_instance_for_third_party_subframes_; | |
| 62 } | |
| 63 | |
| 48 void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) { | 64 void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) { |
| 49 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) | 65 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) |
| 50 ->browsing_instance_.get() == | 66 ->browsing_instance_.get() == |
| 51 this); | 67 this); |
| 52 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); | 68 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); |
| 53 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); | 69 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); |
| 54 | 70 |
| 55 // Only register if we don't have a SiteInstance for this site already. | 71 // Only register if we don't have a SiteInstance for this site already. |
| 56 // It's possible to have two SiteInstances point to the same site if two | 72 // It's possible to have two SiteInstances point to the same site if two |
| 57 // tabs are navigated there at the same time. (We don't call SetSite or | 73 // tabs are navigated there at the same time. (We don't call SetSite or |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 72 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); | 88 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); |
| 73 | 89 |
| 74 // Only unregister the SiteInstance if it is the same one that is registered | 90 // Only unregister the SiteInstance if it is the same one that is registered |
| 75 // for the site. (It might have been an unregistered SiteInstance. See the | 91 // for the site. (It might have been an unregistered SiteInstance. See the |
| 76 // comments in RegisterSiteInstance.) | 92 // comments in RegisterSiteInstance.) |
| 77 SiteInstanceMap::iterator i = site_instance_map_.find(site); | 93 SiteInstanceMap::iterator i = site_instance_map_.find(site); |
| 78 if (i != site_instance_map_.end() && i->second == site_instance) { | 94 if (i != site_instance_map_.end() && i->second == site_instance) { |
| 79 // Matches, so erase it. | 95 // Matches, so erase it. |
| 80 site_instance_map_.erase(i); | 96 site_instance_map_.erase(i); |
| 81 } | 97 } |
| 98 if (site_instance_for_third_party_subframes_ == site_instance) | |
| 99 site_instance_for_third_party_subframes_ = nullptr; | |
| 82 } | 100 } |
| 83 | 101 |
| 84 BrowsingInstance::~BrowsingInstance() { | 102 BrowsingInstance::~BrowsingInstance() { |
| 85 // We should only be deleted when all of the SiteInstances that refer to | 103 // We should only be deleted when all of the SiteInstances that refer to |
| 86 // us are gone. | 104 // us are gone. |
| 87 DCHECK(site_instance_map_.empty()); | 105 DCHECK(site_instance_map_.empty()); |
| 88 DCHECK_EQ(0u, active_contents_count_); | 106 DCHECK_EQ(0u, active_contents_count_); |
| 89 } | 107 } |
| 90 | 108 |
| 91 } // namespace content | 109 } // namespace content |
| OLD | NEW |