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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 browsing_instance_->browser_context(); | 75 browsing_instance_->browser_context(); |
76 if (has_site_ && | 76 if (has_site_ && |
77 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_) && | 77 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_) && |
78 RenderProcessHostImpl::GetProcessHostForSite(browser_context, site_)) { | 78 RenderProcessHostImpl::GetProcessHostForSite(browser_context, site_)) { |
79 return true; | 79 return true; |
80 } | 80 } |
81 | 81 |
82 return false; | 82 return false; |
83 } | 83 } |
84 | 84 |
85 namespace { | |
86 | |
87 const void* const kDefaultSubframeProcessHostHolderKey = | |
88 &kDefaultSubframeProcessHostHolderKey; | |
89 | |
90 class DefaultSubframeProcessHostHolder : public base::SupportsUserData::Data, | |
91 public RenderProcessHostObserver { | |
92 public: | |
93 explicit DefaultSubframeProcessHostHolder(BrowserContext* browser_context) | |
94 : browser_context_(browser_context) {} | |
95 ~DefaultSubframeProcessHostHolder() override {} | |
96 | |
97 // Gets the correct render process to use for this SiteInstance. | |
98 RenderProcessHost* GetProcessHost(SiteInstance* site_instance, | |
99 bool is_for_guests_only) { | |
100 StoragePartition* default_partition = | |
101 BrowserContext::GetDefaultStoragePartition(browser_context_); | |
102 StoragePartition* partition = | |
103 BrowserContext::GetStoragePartition(browser_context_, site_instance); | |
104 | |
105 // Is this the default storage partition? If it isn't, then just give it its | |
106 // own non-shared process. | |
107 if (partition != default_partition || is_for_guests_only) { | |
108 RenderProcessHostImpl* host = new RenderProcessHostImpl( | |
109 browser_context_, static_cast<StoragePartitionImpl*>(partition), | |
110 is_for_guests_only); | |
111 host->SetIsNeverSuitableForReuse(); | |
112 return host; | |
113 } | |
114 | |
115 if (host_) { | |
116 // If we already have a shared host for the default storage partition, use | |
117 // it. | |
118 return host_; | |
119 } | |
120 | |
121 host_ = new RenderProcessHostImpl( | |
122 browser_context_, static_cast<StoragePartitionImpl*>(partition), | |
123 false /* for guests only */); | |
124 host_->SetIsNeverSuitableForReuse(); | |
125 host_->AddObserver(this); | |
126 | |
127 return host_; | |
128 } | |
129 | |
130 void RenderProcessHostDestroyed(RenderProcessHost* host) override { | |
131 DCHECK_EQ(host_, host); | |
132 host_->RemoveObserver(this); | |
133 host_ = nullptr; | |
134 } | |
135 | |
136 private: | |
137 BrowserContext* browser_context_; | |
138 | |
139 // The render process for the default storage partition of this | |
ncarter (slow)
2017/01/05 22:29:05
I'd probably say "the TDI render process" or somet
Avi (use Gerrit)
2017/01/06 01:20:11
Done.
| |
140 // BrowserContext. | |
141 RenderProcessHostImpl* host_ = nullptr; | |
142 }; | |
143 | |
144 } // namespace | |
145 | |
146 RenderProcessHost* SiteInstanceImpl::GetDefaultSubframeProcessHost( | |
147 BrowserContext* browser_context, | |
148 bool is_for_guests_only) { | |
149 DefaultSubframeProcessHostHolder* holder = | |
150 static_cast<DefaultSubframeProcessHostHolder*>( | |
151 browser_context->GetUserData(&kDefaultSubframeProcessHostHolderKey)); | |
152 if (!holder) { | |
153 holder = new DefaultSubframeProcessHostHolder(browser_context); | |
154 browser_context->SetUserData(kDefaultSubframeProcessHostHolderKey, holder); | |
155 } | |
156 | |
157 return holder->GetProcessHost(this, is_for_guests_only); | |
158 } | |
159 | |
85 RenderProcessHost* SiteInstanceImpl::GetProcess() { | 160 RenderProcessHost* SiteInstanceImpl::GetProcess() { |
86 // TODO(erikkay) It would be nice to ensure that the renderer type had been | 161 // TODO(erikkay) It would be nice to ensure that the renderer type had been |
87 // properly set before we get here. The default tab creation case winds up | 162 // properly set before we get here. The default tab creation case winds up |
88 // with no site set at this point, so it will default to TYPE_NORMAL. This | 163 // with no site set at this point, so it will default to TYPE_NORMAL. This |
89 // may not be correct, so we'll wind up potentially creating a process that | 164 // may not be correct, so we'll wind up potentially creating a process that |
90 // we then throw away, or worse sharing a process with the wrong process type. | 165 // we then throw away, or worse sharing a process with the wrong process type. |
91 // See crbug.com/43448. | 166 // See crbug.com/43448. |
92 | 167 |
93 // Create a new process if ours went away or was reused. | 168 // Create a new process if ours went away or was reused. |
94 if (!process_) { | 169 if (!process_) { |
95 BrowserContext* browser_context = browsing_instance_->browser_context(); | 170 BrowserContext* browser_context = browsing_instance_->browser_context(); |
171 bool is_for_guests_only = site_.SchemeIs(kGuestScheme); | |
ncarter (slow)
2017/01/05 22:29:05
Currently, |is_for_guests_only| is mutually exclus
Avi (use Gerrit)
2017/01/06 01:20:11
Acknowledged.
| |
96 | 172 |
97 // If we should use process-per-site mode (either in general or for the | 173 // If we should use process-per-site mode (either in general or for the |
98 // given site), then look for an existing RenderProcessHost for the site. | 174 // given site), then look for an existing RenderProcessHost for the site. |
99 bool use_process_per_site = has_site_ && | 175 bool use_process_per_site = has_site_ && |
100 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_); | 176 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_); |
101 if (use_process_per_site) { | 177 if (use_process_per_site) { |
102 process_ = RenderProcessHostImpl::GetProcessHostForSite(browser_context, | 178 process_ = RenderProcessHostImpl::GetProcessHostForSite(browser_context, |
103 site_); | 179 site_); |
104 } | 180 } |
105 | 181 |
182 if (!process_ && IsDefaultSubframeSiteInstance() && | |
183 SiteIsolationPolicy::IsTopDocumentIsolationEnabled()) { | |
184 process_ = | |
185 GetDefaultSubframeProcessHost(browser_context, is_for_guests_only); | |
186 } | |
187 | |
106 // If not (or if none found), see if we should reuse an existing process. | 188 // If not (or if none found), see if we should reuse an existing process. |
107 if (!process_ && RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( | 189 if (!process_ && RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
108 browser_context, site_)) { | 190 browser_context, site_)) { |
109 process_ = RenderProcessHostImpl::GetExistingProcessHost(browser_context, | 191 process_ = RenderProcessHostImpl::GetExistingProcessHost(browser_context, |
110 site_); | 192 site_); |
111 } | 193 } |
112 | 194 |
113 // Otherwise (or if that fails), create a new one. | 195 // Otherwise (or if that fails), create a new one. |
114 if (!process_) { | 196 if (!process_) { |
115 if (g_render_process_host_factory_) { | 197 if (g_render_process_host_factory_) { |
116 process_ = g_render_process_host_factory_->CreateRenderProcessHost( | 198 process_ = g_render_process_host_factory_->CreateRenderProcessHost( |
117 browser_context, this); | 199 browser_context, this); |
118 } else { | 200 } else { |
119 StoragePartitionImpl* partition = | 201 StoragePartitionImpl* partition = |
120 static_cast<StoragePartitionImpl*>( | 202 static_cast<StoragePartitionImpl*>( |
121 BrowserContext::GetStoragePartition(browser_context, this)); | 203 BrowserContext::GetStoragePartition(browser_context, this)); |
122 process_ = new RenderProcessHostImpl(browser_context, | 204 process_ = new RenderProcessHostImpl(browser_context, partition, |
123 partition, | 205 is_for_guests_only); |
124 site_.SchemeIs(kGuestScheme)); | |
125 } | 206 } |
126 } | 207 } |
127 CHECK(process_); | 208 CHECK(process_); |
128 process_->AddObserver(this); | 209 process_->AddObserver(this); |
129 | 210 |
130 // If we are using process-per-site, we need to register this process | 211 // If we are using process-per-site, we need to register this process |
131 // for the current site so that we can find it again. (If no site is set | 212 // for the current site so that we can find it again. (If no site is set |
132 // at this time, we will register it in SetSite().) | 213 // at this time, we will register it in SetSite().) |
133 if (use_process_per_site) { | 214 if (use_process_per_site) { |
134 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, | 215 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 browsing_instance_->browser_context(), site_)) | 521 browsing_instance_->browser_context(), site_)) |
441 return; | 522 return; |
442 | 523 |
443 ChildProcessSecurityPolicyImpl* policy = | 524 ChildProcessSecurityPolicyImpl* policy = |
444 ChildProcessSecurityPolicyImpl::GetInstance(); | 525 ChildProcessSecurityPolicyImpl::GetInstance(); |
445 policy->LockToOrigin(process_->GetID(), site_); | 526 policy->LockToOrigin(process_->GetID(), site_); |
446 } | 527 } |
447 } | 528 } |
448 | 529 |
449 } // namespace content | 530 } // namespace content |
OLD | NEW |