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

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: Suppress tests under --site-per-process 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) {
(...skipping 17 matching lines...) Expand all
37 return i->second; 38 return i->second;
38 39
39 // No current SiteInstance for this site, so let's create one. 40 // No current SiteInstance for this site, so let's create one.
40 scoped_refptr<SiteInstanceImpl> instance = new SiteInstanceImpl(this); 41 scoped_refptr<SiteInstanceImpl> instance = new SiteInstanceImpl(this);
41 42
42 // 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.
43 instance->SetSite(url); 44 instance->SetSite(url);
44 return instance; 45 return instance;
45 } 46 }
46 47
48 scoped_refptr<SiteInstanceImpl>
49 BrowsingInstance::GetDefaultSubframeSiteInstance() {
50 // This should only be used for --top-document-isolation mode.
51 CHECK(SiteIsolationPolicy::IsTopDocumentIsolationEnabled());
52 if (!default_subframe_site_instance_) {
53 SiteInstanceImpl* instance = new SiteInstanceImpl(this);
54 instance->set_is_default_subframe_site_instance();
55
56 // TODO(nick): This is a hack for now.
57 instance->SetSite(GURL("http://web-subframes.invalid"));
58
59 default_subframe_site_instance_ = instance;
60 }
61
62 return make_scoped_refptr(default_subframe_site_instance_);
63 }
64
47 void BrowsingInstance::RegisterSiteInstance(SiteInstanceImpl* site_instance) { 65 void BrowsingInstance::RegisterSiteInstance(SiteInstanceImpl* site_instance) {
48 DCHECK(site_instance->browsing_instance_.get() == this); 66 DCHECK(site_instance->browsing_instance_.get() == this);
49 DCHECK(site_instance->HasSite()); 67 DCHECK(site_instance->HasSite());
68
69 // Don't register the default subframe SiteInstance, to prevent it from being
70 // returned by GetSiteInstanceForURL.
71 if (default_subframe_site_instance_ == site_instance)
72 return;
73
50 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); 74 std::string site = site_instance->GetSiteURL().possibly_invalid_spec();
51 75
52 // Only register if we don't have a SiteInstance for this site already. 76 // Only register if we don't have a SiteInstance for this site already.
53 // It's possible to have two SiteInstances point to the same site if two 77 // It's possible to have two SiteInstances point to the same site if two
54 // tabs are navigated there at the same time. (We don't call SetSite or 78 // tabs are navigated there at the same time. (We don't call SetSite or
55 // register them until DidNavigate.) If there is a previously existing 79 // register them until DidNavigate.) If there is a previously existing
56 // SiteInstance for this site, we just won't register the new one. 80 // SiteInstance for this site, we just won't register the new one.
57 SiteInstanceMap::iterator i = site_instance_map_.find(site); 81 SiteInstanceMap::iterator i = site_instance_map_.find(site);
58 if (i == site_instance_map_.end()) { 82 if (i == site_instance_map_.end()) {
59 // Not previously registered, so register it. 83 // Not previously registered, so register it.
60 site_instance_map_[site] = site_instance; 84 site_instance_map_[site] = site_instance;
61 } 85 }
62 } 86 }
63 87
64 void BrowsingInstance::UnregisterSiteInstance(SiteInstanceImpl* site_instance) { 88 void BrowsingInstance::UnregisterSiteInstance(SiteInstanceImpl* site_instance) {
65 DCHECK(site_instance->browsing_instance_.get() == this); 89 DCHECK(site_instance->browsing_instance_.get() == this);
66 DCHECK(site_instance->HasSite()); 90 DCHECK(site_instance->HasSite());
67 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); 91 std::string site = site_instance->GetSiteURL().possibly_invalid_spec();
68 92
69 // Only unregister the SiteInstance if it is the same one that is registered 93 // Only unregister the SiteInstance if it is the same one that is registered
70 // for the site. (It might have been an unregistered SiteInstance. See the 94 // for the site. (It might have been an unregistered SiteInstance. See the
71 // comments in RegisterSiteInstance.) 95 // comments in RegisterSiteInstance.)
72 SiteInstanceMap::iterator i = site_instance_map_.find(site); 96 SiteInstanceMap::iterator i = site_instance_map_.find(site);
73 if (i != site_instance_map_.end() && i->second == site_instance) { 97 if (i != site_instance_map_.end() && i->second == site_instance) {
74 // Matches, so erase it. 98 // Matches, so erase it.
75 site_instance_map_.erase(i); 99 site_instance_map_.erase(i);
76 } 100 }
101 if (default_subframe_site_instance_ == site_instance)
102 default_subframe_site_instance_ = nullptr;
77 } 103 }
78 104
79 BrowsingInstance::~BrowsingInstance() { 105 BrowsingInstance::~BrowsingInstance() {
80 // We should only be deleted when all of the SiteInstances that refer to 106 // We should only be deleted when all of the SiteInstances that refer to
81 // us are gone. 107 // us are gone.
82 DCHECK(site_instance_map_.empty()); 108 DCHECK(site_instance_map_.empty());
83 DCHECK_EQ(0u, active_contents_count_); 109 DCHECK_EQ(0u, active_contents_count_);
84 } 110 }
85 111
86 } // namespace content 112 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browsing_instance.h ('k') | content/browser/frame_host/navigator_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698