Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: content/browser/browsing_instance.cc

Issue 1797363002: "Top Document Isolation" mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix up tests. Necessary rebase to obtain browsertest util behavior change. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/site_isolation_policy.h"
10 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/content_browser_client.h" 12 #include "content/public/browser/content_browser_client.h"
12 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
13 #include "content/public/common/url_constants.h" 14 #include "content/public/common/url_constants.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 BrowsingInstance::BrowsingInstance(BrowserContext* browser_context) 18 BrowsingInstance::BrowsingInstance(BrowserContext* browser_context)
18 : browser_context_(browser_context), 19 : browser_context_(browser_context),
19 active_contents_count_(0u) { 20 active_contents_count_(0u) {
20 } 21 }
21 22
22 bool BrowsingInstance::HasSiteInstance(const GURL& url) { 23 bool BrowsingInstance::HasSiteInstance(const GURL& url) {
23 std::string site = 24 std::string site =
24 SiteInstanceImpl::GetSiteForURL(browser_context_, url) 25 SiteInstanceImpl::GetSiteForURL(browser_context_, url)
25 .possibly_invalid_spec(); 26 .possibly_invalid_spec();
26 27
27 return site_instance_map_.find(site) != site_instance_map_.end(); 28 return site_instance_map_.find(site) != site_instance_map_.end();
28 } 29 }
29 30
30 SiteInstance* BrowsingInstance::GetSiteInstanceForURL(const GURL& url) { 31 SiteInstance* BrowsingInstance::GetSiteInstanceForURL(const GURL& url) {
31 std::string site = 32 std::string site =
32 SiteInstanceImpl::GetSiteForURL(browser_context_, url) 33 SiteInstanceImpl::GetSiteForURL(browser_context_, url)
33 .possibly_invalid_spec(); 34 .possibly_invalid_spec();
34 35
35 SiteInstanceMap::iterator i = site_instance_map_.find(site); 36 SiteInstanceMap::iterator i = site_instance_map_.find(site);
36 if (i != site_instance_map_.end()) 37 if (i != site_instance_map_.end())
37 return i->second; 38 return i->second;
38 39
39
40 // No current SiteInstance for this site, so let's create one. 40 // No current SiteInstance for this site, so let's create one.
41 SiteInstanceImpl* instance = new SiteInstanceImpl(this); 41 SiteInstanceImpl* instance = new SiteInstanceImpl(this);
42 42
43 // Set the site of this new SiteInstance, which will register it with us. 43 // Set the site of this new SiteInstance, which will register it with us.
44 instance->SetSite(url); 44 instance->SetSite(url);
45 return instance; 45 return instance;
46 } 46 }
47 47
48 SiteInstance* BrowsingInstance::GetDefaultSubframeSiteInstance() {
49 // This should only be used for --top-document-isolation mode.
50 CHECK(SiteIsolationPolicy::IsTopDocumentIsolationEnabled());
51 if (!default_subframe_site_instance_) {
52 SiteInstanceImpl* instance = new SiteInstanceImpl(this);
53 instance->set_is_default_subframe_site_instance();
54 // TODO(nick): This is a hack for now.
55 instance->SetSite(GURL("http://web-subframes.invalid"));
56 default_subframe_site_instance_ = instance;
57 }
58
59 return default_subframe_site_instance_;
60 }
61
48 void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) { 62 void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) {
49 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) 63 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)
dcheng 2016/03/29 08:09:16 Unrelated to this CL, but is there a reason Regist
ncarter (slow) 2016/03/29 16:28:33 Done locally, will upload with other reviewer fixe
ncarter (slow) 2016/03/29 23:30:57 Done.
50 ->browsing_instance_.get() == 64 ->browsing_instance_.get() ==
51 this); 65 this);
52 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); 66 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite());
67
68 // Don't register the default subframe SiteInstance, to prevent it from being
69 // returned by GetSiteInstanceForURL.
70 if (default_subframe_site_instance_ == site_instance)
71 return;
72
53 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); 73 std::string site = site_instance->GetSiteURL().possibly_invalid_spec();
54 74
55 // Only register if we don't have a SiteInstance for this site already. 75 // 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 76 // 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 77 // 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 78 // register them until DidNavigate.) If there is a previously existing
59 // SiteInstance for this site, we just won't register the new one. 79 // SiteInstance for this site, we just won't register the new one.
60 SiteInstanceMap::iterator i = site_instance_map_.find(site); 80 SiteInstanceMap::iterator i = site_instance_map_.find(site);
61 if (i == site_instance_map_.end()) { 81 if (i == site_instance_map_.end()) {
62 // Not previously registered, so register it. 82 // Not previously registered, so register it.
63 site_instance_map_[site] = site_instance; 83 site_instance_map_[site] = site_instance;
64 } 84 }
65 } 85 }
66 86
67 void BrowsingInstance::UnregisterSiteInstance(SiteInstance* site_instance) { 87 void BrowsingInstance::UnregisterSiteInstance(SiteInstance* site_instance) {
68 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) 88 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)
69 ->browsing_instance_.get() == 89 ->browsing_instance_.get() ==
70 this); 90 this);
71 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); 91 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite());
72 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); 92 std::string site = site_instance->GetSiteURL().possibly_invalid_spec();
73 93
74 // Only unregister the SiteInstance if it is the same one that is registered 94 // 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 95 // for the site. (It might have been an unregistered SiteInstance. See the
76 // comments in RegisterSiteInstance.) 96 // comments in RegisterSiteInstance.)
77 SiteInstanceMap::iterator i = site_instance_map_.find(site); 97 SiteInstanceMap::iterator i = site_instance_map_.find(site);
78 if (i != site_instance_map_.end() && i->second == site_instance) { 98 if (i != site_instance_map_.end() && i->second == site_instance) {
79 // Matches, so erase it. 99 // Matches, so erase it.
80 site_instance_map_.erase(i); 100 site_instance_map_.erase(i);
81 } 101 }
102 if (default_subframe_site_instance_ == site_instance)
103 default_subframe_site_instance_ = nullptr;
82 } 104 }
83 105
84 BrowsingInstance::~BrowsingInstance() { 106 BrowsingInstance::~BrowsingInstance() {
85 // We should only be deleted when all of the SiteInstances that refer to 107 // We should only be deleted when all of the SiteInstances that refer to
86 // us are gone. 108 // us are gone.
87 DCHECK(site_instance_map_.empty()); 109 DCHECK(site_instance_map_.empty());
88 DCHECK_EQ(0u, active_contents_count_); 110 DCHECK_EQ(0u, active_contents_count_);
89 } 111 }
90 112
91 } // namespace content 113 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698