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::GetDefaultSubframeSiteInstance() { | |
|
Charlie Reis
2016/03/25 19:47:12
Can we put a CHECK(IsTopDocumentIsolationEnabled()
ncarter (slow)
2016/03/28 22:00:28
I made this the stricter variant, CHECK(IsTopDocum
Charlie Reis
2016/03/29 17:17:12
Acknowledged.
| |
| 48 if (!default_subframe_site_instance_) { | |
| 49 SiteInstanceImpl* instance = new SiteInstanceImpl(this); | |
| 50 instance->set_is_default_subframe_site_instance(); | |
| 51 // TODO(nick): This is a hack for now. | |
| 52 instance->SetSite(GURL("http://web-subframes.invalid")); | |
|
Charlie Reis
2016/03/25 19:47:12
Yeah, we can chat about what to put here long term
ncarter (slow)
2016/03/28 22:00:28
If we rip this out now, the PopupAndRedirection te
| |
| 53 default_subframe_site_instance_ = instance; | |
| 54 } | |
| 55 | |
| 56 return default_subframe_site_instance_; | |
| 57 } | |
| 58 | |
| 48 void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) { | 59 void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) { |
| 49 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) | 60 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) |
| 50 ->browsing_instance_.get() == | 61 ->browsing_instance_.get() == |
| 51 this); | 62 this); |
| 52 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); | 63 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); |
| 64 | |
| 65 // Don't register the default subframe SiteInstance, to prevent it from being | |
| 66 // returned by GetSiteInstanceForURL. | |
| 67 if (default_subframe_site_instance_ == site_instance) | |
| 68 return; | |
| 69 | |
| 53 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); | 70 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); |
| 54 | 71 |
| 55 // Only register if we don't have a SiteInstance for this site already. | 72 // 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 | 73 // 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 | 74 // tabs are navigated there at the same time. (We don't call SetSite or |
| 58 // register them until DidNavigate.) If there is a previously existing | 75 // register them until DidNavigate.) If there is a previously existing |
| 59 // SiteInstance for this site, we just won't register the new one. | 76 // SiteInstance for this site, we just won't register the new one. |
| 60 SiteInstanceMap::iterator i = site_instance_map_.find(site); | 77 SiteInstanceMap::iterator i = site_instance_map_.find(site); |
| 61 if (i == site_instance_map_.end()) { | 78 if (i == site_instance_map_.end()) { |
| 62 // Not previously registered, so register it. | 79 // Not previously registered, so register it. |
| 63 site_instance_map_[site] = site_instance; | 80 site_instance_map_[site] = site_instance; |
| 64 } | 81 } |
| 65 } | 82 } |
| 66 | 83 |
| 67 void BrowsingInstance::UnregisterSiteInstance(SiteInstance* site_instance) { | 84 void BrowsingInstance::UnregisterSiteInstance(SiteInstance* site_instance) { |
| 68 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) | 85 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) |
| 69 ->browsing_instance_.get() == | 86 ->browsing_instance_.get() == |
| 70 this); | 87 this); |
| 71 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); | 88 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); |
| 72 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); | 89 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); |
| 73 | 90 |
| 74 // Only unregister the SiteInstance if it is the same one that is registered | 91 // 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 | 92 // for the site. (It might have been an unregistered SiteInstance. See the |
| 76 // comments in RegisterSiteInstance.) | 93 // comments in RegisterSiteInstance.) |
| 77 SiteInstanceMap::iterator i = site_instance_map_.find(site); | 94 SiteInstanceMap::iterator i = site_instance_map_.find(site); |
| 78 if (i != site_instance_map_.end() && i->second == site_instance) { | 95 if (i != site_instance_map_.end() && i->second == site_instance) { |
| 79 // Matches, so erase it. | 96 // Matches, so erase it. |
| 80 site_instance_map_.erase(i); | 97 site_instance_map_.erase(i); |
| 81 } | 98 } |
| 99 if (default_subframe_site_instance_ == site_instance) | |
| 100 default_subframe_site_instance_ = nullptr; | |
| 82 } | 101 } |
| 83 | 102 |
| 84 BrowsingInstance::~BrowsingInstance() { | 103 BrowsingInstance::~BrowsingInstance() { |
| 85 // We should only be deleted when all of the SiteInstances that refer to | 104 // We should only be deleted when all of the SiteInstances that refer to |
| 86 // us are gone. | 105 // us are gone. |
| 87 DCHECK(site_instance_map_.empty()); | 106 DCHECK(site_instance_map_.empty()); |
| 88 DCHECK_EQ(0u, active_contents_count_); | 107 DCHECK_EQ(0u, active_contents_count_); |
| 89 } | 108 } |
| 90 | 109 |
| 91 } // namespace content | 110 } // namespace content |
| OLD | NEW |