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

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

Issue 1797363002: "Top Document Isolation" mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Two new browsertests. Created 4 years, 9 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/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"
11 #include "content/browser/renderer_host/render_process_host_impl.h" 11 #include "content/browser/renderer_host/render_process_host_impl.h"
12 #include "content/browser/storage_partition_impl.h" 12 #include "content/browser/storage_partition_impl.h"
13 #include "content/common/site_isolation_policy.h" 13 #include "content/common/site_isolation_policy.h"
14 #include "content/public/browser/content_browser_client.h" 14 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/render_process_host_factory.h" 15 #include "content/public/browser/render_process_host_factory.h"
16 #include "content/public/browser/web_ui_controller_factory.h" 16 #include "content/public/browser/web_ui_controller_factory.h"
17 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 const RenderProcessHostFactory* 22 const RenderProcessHostFactory*
23 SiteInstanceImpl::g_render_process_host_factory_ = NULL; 23 SiteInstanceImpl::g_render_process_host_factory_ = NULL;
24 int32_t SiteInstanceImpl::next_site_instance_id_ = 1; 24 int32_t SiteInstanceImpl::next_site_instance_id_ = 1;
25 25
26 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) 26 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance)
27 : id_(next_site_instance_id_++), 27 : id_(next_site_instance_id_++), browsing_instance_(browsing_instance) {
28 active_frame_count_(0),
29 browsing_instance_(browsing_instance),
30 process_(NULL),
31 has_site_(false) {
32 DCHECK(browsing_instance); 28 DCHECK(browsing_instance);
33 } 29 }
34 30
35 SiteInstanceImpl::~SiteInstanceImpl() { 31 SiteInstanceImpl::~SiteInstanceImpl() {
36 GetContentClient()->browser()->SiteInstanceDeleting(this); 32 GetContentClient()->browser()->SiteInstanceDeleting(this);
37 33
38 if (process_) 34 if (process_)
39 process_->RemoveObserver(this); 35 process_->RemoveObserver(this);
40 36
41 // Now that no one is referencing us, we can safely remove ourselves from 37 // Now that no one is referencing us, we can safely remove ourselves from
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // Remember that this SiteInstance has been used to load a URL, even if the 141 // Remember that this SiteInstance has been used to load a URL, even if the
146 // URL is invalid. 142 // URL is invalid.
147 has_site_ = true; 143 has_site_ = true;
148 BrowserContext* browser_context = browsing_instance_->browser_context(); 144 BrowserContext* browser_context = browsing_instance_->browser_context();
149 site_ = GetSiteForURL(browser_context, url); 145 site_ = GetSiteForURL(browser_context, url);
150 146
151 // Now that we have a site, register it with the BrowsingInstance. This 147 // Now that we have a site, register it with the BrowsingInstance. This
152 // ensures that we won't create another SiteInstance for this site within 148 // ensures that we won't create another SiteInstance for this site within
153 // the same BrowsingInstance, because all same-site pages within a 149 // the same BrowsingInstance, because all same-site pages within a
154 // BrowsingInstance can script each other. 150 // BrowsingInstance can script each other.
155 browsing_instance_->RegisterSiteInstance(this); 151 browsing_instance_->RegisterSiteInstance(this);
Charlie Reis 2016/03/18 21:15:13 Maybe BI ignores this call for the subframe SI?
156 152
157 if (process_) { 153 if (process_) {
158 LockToOrigin(); 154 LockToOrigin();
159 155
160 // Ensure the process is registered for this site if necessary. 156 // Ensure the process is registered for this site if necessary.
161 if (RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_)) { 157 if (RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_)) {
162 RenderProcessHostImpl::RegisterProcessHostForSite( 158 RenderProcessHostImpl::RegisterProcessHostForSite(
163 browser_context, process_, site_); 159 browser_context, process_, site_);
164 } 160 }
165 } 161 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (IsRendererDebugURL(url)) 200 if (IsRendererDebugURL(url))
205 return false; 201 return false;
206 202
207 // If the site URL is an extension (e.g., for hosted apps or WebUI) but the 203 // If the site URL is an extension (e.g., for hosted apps or WebUI) but the
208 // process is not (or vice versa), make sure we notice and fix it. 204 // process is not (or vice versa), make sure we notice and fix it.
209 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); 205 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url);
210 return !RenderProcessHostImpl::IsSuitableHost( 206 return !RenderProcessHostImpl::IsSuitableHost(
211 GetProcess(), browsing_instance_->browser_context(), site_url); 207 GetProcess(), browsing_instance_->browser_context(), site_url);
212 } 208 }
213 209
210 SiteInstance* SiteInstanceImpl::GetRelatedSiteInstanceForThirdPartySubframes(
211 const GURL& url) {
212 return browsing_instance_->GetSiteInstanceForThirdPartySubframes(url);
213 }
214
214 bool SiteInstanceImpl::RequiresDedicatedProcess() { 215 bool SiteInstanceImpl::RequiresDedicatedProcess() {
215 if (!has_site_) 216 if (!has_site_)
216 return false; 217 return false;
217 return SiteInstanceImpl::DoesSiteRequireDedicatedProcess(GetBrowserContext(), 218
218 site_); 219 if (DoesSiteRequireDedicatedProcess(GetBrowserContext(), site_))
220 return true;
221
222 if (!is_for_third_party_subframes() &&
223 SiteIsolationPolicy::UseDedicatedProcessForTopDocument()) {
Charlie Reis 2016/03/18 21:15:13 Might not need this.
224 return true;
225 }
226
227 return false;
219 } 228 }
220 229
221 void SiteInstanceImpl::IncrementActiveFrameCount() { 230 void SiteInstanceImpl::IncrementActiveFrameCount() {
222 active_frame_count_++; 231 active_frame_count_++;
223 } 232 }
224 233
225 void SiteInstanceImpl::DecrementActiveFrameCount() { 234 void SiteInstanceImpl::DecrementActiveFrameCount() {
226 if (--active_frame_count_ == 0) 235 if (--active_frame_count_ == 0)
227 FOR_EACH_OBSERVER(Observer, observers_, ActiveFrameCountIsZero(this)); 236 FOR_EACH_OBSERVER(Observer, observers_, ActiveFrameCountIsZero(this));
228 } 237 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 browser_context, effective_url)) { 381 browser_context, effective_url)) {
373 return true; 382 return true;
374 } 383 }
375 384
376 return false; 385 return false;
377 } 386 }
378 387
379 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) { 388 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) {
380 DCHECK_EQ(process_, host); 389 DCHECK_EQ(process_, host);
381 process_->RemoveObserver(this); 390 process_->RemoveObserver(this);
382 process_ = NULL; 391 process_ = nullptr;
383 } 392 }
384 393
385 void SiteInstanceImpl::RenderProcessWillExit(RenderProcessHost* host) { 394 void SiteInstanceImpl::RenderProcessWillExit(RenderProcessHost* host) {
386 // TODO(nick): http://crbug.com/575400 - RenderProcessWillExit might not serve 395 // TODO(nick): http://crbug.com/575400 - RenderProcessWillExit might not serve
387 // any purpose here. 396 // any purpose here.
388 FOR_EACH_OBSERVER(Observer, observers_, RenderProcessGone(this)); 397 FOR_EACH_OBSERVER(Observer, observers_, RenderProcessGone(this));
389 } 398 }
390 399
391 void SiteInstanceImpl::RenderProcessExited(RenderProcessHost* host, 400 void SiteInstanceImpl::RenderProcessExited(RenderProcessHost* host,
392 base::TerminationStatus status, 401 base::TerminationStatus status,
(...skipping 29 matching lines...) Expand all
422 browsing_instance_->browser_context(), site_)) 431 browsing_instance_->browser_context(), site_))
423 return; 432 return;
424 433
425 ChildProcessSecurityPolicyImpl* policy = 434 ChildProcessSecurityPolicyImpl* policy =
426 ChildProcessSecurityPolicyImpl::GetInstance(); 435 ChildProcessSecurityPolicyImpl::GetInstance();
427 policy->LockToOrigin(process_->GetID(), site_); 436 policy->LockToOrigin(process_->GetID(), site_);
428 } 437 }
429 } 438 }
430 439
431 } // namespace content 440 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698