blob: a68c0d7acfb0fc1c84dc26dbd3950fb2f7cd9fdb [file] [log] [blame]
[email protected]144a8102012-01-14 01:05:311// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]b6583592012-01-25 19:52:335#include "content/browser/site_instance_impl.h"
initial.commit09911bf2008-07-26 23:55:296
avicb129c02017-05-03 06:49:297#include "base/memory/ptr_util.h"
[email protected]39365212011-02-24 01:01:008#include "content/browser/browsing_instance.h"
[email protected]b9535422012-02-09 01:47:599#include "content/browser/child_process_security_policy_impl.h"
[email protected]c02f1ba2014-02-03 06:53:5310#include "content/browser/frame_host/debug_urls.h"
nick9f34e2892016-01-12 21:01:0711#include "content/browser/frame_host/frame_tree_node.h"
[email protected]f3b1a082011-11-18 00:34:3012#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]4c3a23582012-08-18 08:54:3413#include "content/browser/storage_partition_impl.h"
nickd30fd962015-07-27 21:51:0814#include "content/common/site_isolation_policy.h"
[email protected]87f3c082011-10-19 18:07:4415#include "content/public/browser/content_browser_client.h"
[email protected]f3b1a082011-11-18 00:34:3016#include "content/public/browser/render_process_host_factory.h"
[email protected]41fb79a52012-06-29 16:34:3317#include "content/public/browser/web_ui_controller_factory.h"
[email protected]a1d29162011-10-14 17:14:0318#include "content/public/common/url_constants.h"
[email protected]be28b5f42012-07-20 11:31:2519#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
initial.commit09911bf2008-07-26 23:55:2920
[email protected]46488322012-10-30 03:22:2021namespace content {
[email protected]b6583592012-01-25 19:52:3322
avib7348942015-12-25 20:57:1023int32_t SiteInstanceImpl::next_site_instance_id_ = 1;
[email protected]992db4c2011-05-12 15:37:1524
[email protected]b6583592012-01-25 19:52:3325SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance)
[email protected]992db4c2011-05-12 15:37:1526 : id_(next_site_instance_id_++),
creiscce56cd2014-09-29 22:45:2227 active_frame_count_(0),
[email protected]992db4c2011-05-12 15:37:1528 browsing_instance_(browsing_instance),
nickd5bbd0b2016-03-31 19:52:4429 process_(nullptr),
30 has_site_(false),
clamy63960c32017-05-10 22:57:0731 process_reuse_policy_(ProcessReusePolicy::DEFAULT) {
[email protected]4566f132009-03-12 01:55:1332 DCHECK(browsing_instance);
[email protected]4566f132009-03-12 01:55:1333}
34
[email protected]b6583592012-01-25 19:52:3335SiteInstanceImpl::~SiteInstanceImpl() {
[email protected]46488322012-10-30 03:22:2036 GetContentClient()->browser()->SiteInstanceDeleting(this);
[email protected]056ad2a2011-07-12 02:13:5537
[email protected]40bfaf32013-11-19 01:35:4338 if (process_)
39 process_->RemoveObserver(this);
40
initial.commit09911bf2008-07-26 23:55:2941 // Now that no one is referencing us, we can safely remove ourselves from
42 // the BrowsingInstance. Any future visits to a page from this site
43 // (within the same BrowsingInstance) can safely create a new SiteInstance.
44 if (has_site_)
dchengbccd6b82016-03-30 16:24:1945 browsing_instance_->UnregisterSiteInstance(this);
46}
47
48scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::Create(
49 BrowserContext* browser_context) {
50 return make_scoped_refptr(
51 new SiteInstanceImpl(new BrowsingInstance(browser_context)));
52}
53
54scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::CreateForURL(
55 BrowserContext* browser_context,
56 const GURL& url) {
57 // This will create a new SiteInstance and BrowsingInstance.
58 scoped_refptr<BrowsingInstance> instance(
59 new BrowsingInstance(browser_context));
60 return instance->GetSiteInstanceForURL(url);
initial.commit09911bf2008-07-26 23:55:2961}
62
avib7348942015-12-25 20:57:1063int32_t SiteInstanceImpl::GetId() {
[email protected]b6583592012-01-25 19:52:3364 return id_;
65}
66
67bool SiteInstanceImpl::HasProcess() const {
[email protected]41fb79a52012-06-29 16:34:3368 if (process_ != NULL)
69 return true;
70
71 // If we would use process-per-site for this site, also check if there is an
72 // existing process that we would use if GetProcess() were called.
[email protected]46488322012-10-30 03:22:2073 BrowserContext* browser_context =
[email protected]41fb79a52012-06-29 16:34:3374 browsing_instance_->browser_context();
75 if (has_site_ &&
[email protected]1ae93fb12013-06-14 03:38:5676 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_) &&
[email protected]41fb79a52012-06-29 16:34:3377 RenderProcessHostImpl::GetProcessHostForSite(browser_context, site_)) {
78 return true;
79 }
80
81 return false;
[email protected]5ab79b02010-04-26 16:47:1182}
83
[email protected]41fb79a52012-06-29 16:34:3384RenderProcessHost* SiteInstanceImpl::GetProcess() {
[email protected]08c8ec7e2010-07-11 17:14:4885 // TODO(erikkay) It would be nice to ensure that the renderer type had been
86 // properly set before we get here. The default tab creation case winds up
87 // with no site set at this point, so it will default to TYPE_NORMAL. This
88 // may not be correct, so we'll wind up potentially creating a process that
89 // we then throw away, or worse sharing a process with the wrong process type.
90 // See crbug.com/43448.
91
initial.commit09911bf2008-07-26 23:55:2992 // Create a new process if ours went away or was reused.
[email protected]4566f132009-03-12 01:55:1393 if (!process_) {
[email protected]4c3a23582012-08-18 08:54:3494 BrowserContext* browser_context = browsing_instance_->browser_context();
[email protected]41fb79a52012-06-29 16:34:3395
clamy63960c32017-05-10 22:57:0796 // Check if the ProcessReusePolicy should be updated.
97 bool should_use_process_per_site =
creisa9f04ba2017-05-19 22:27:4298 has_site_ &&
99 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_);
clamy63960c32017-05-10 22:57:07100 if (should_use_process_per_site) {
101 process_reuse_policy_ = ProcessReusePolicy::PROCESS_PER_SITE;
102 } else if (process_reuse_policy_ == ProcessReusePolicy::PROCESS_PER_SITE) {
103 process_reuse_policy_ = ProcessReusePolicy::DEFAULT;
[email protected]41fb79a52012-06-29 16:34:33104 }
105
clamy63960c32017-05-10 22:57:07106 process_ = RenderProcessHostImpl::GetProcessHostForSiteInstance(
107 browser_context, this);
avi6d686db2017-01-06 02:28:57108
[email protected]41fb79a52012-06-29 16:34:33109 CHECK(process_);
[email protected]40bfaf32013-11-19 01:35:43110 process_->AddObserver(this);
[email protected]41fb79a52012-06-29 16:34:33111
112 // If we are using process-per-site, we need to register this process
113 // for the current site so that we can find it again. (If no site is set
114 // at this time, we will register it in SetSite().)
clamy63960c32017-05-10 22:57:07115 if (process_reuse_policy_ == ProcessReusePolicy::PROCESS_PER_SITE &&
116 has_site_) {
[email protected]41fb79a52012-06-29 16:34:33117 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context,
118 process_, site_);
119 }
initial.commit09911bf2008-07-26 23:55:29120
naskob8744d22014-08-28 17:07:43121 TRACE_EVENT2("navigation", "SiteInstanceImpl::GetProcess",
122 "site id", id_, "process id", process_->GetID());
[email protected]46488322012-10-30 03:22:20123 GetContentClient()->browser()->SiteInstanceGotProcess(this);
[email protected]6f371442011-11-09 06:45:46124
[email protected]313b80bd2011-11-23 03:49:10125 if (has_site_)
126 LockToOrigin();
initial.commit09911bf2008-07-26 23:55:29127 }
[email protected]4566f132009-03-12 01:55:13128 DCHECK(process_);
initial.commit09911bf2008-07-26 23:55:29129
[email protected]4566f132009-03-12 01:55:13130 return process_;
initial.commit09911bf2008-07-26 23:55:29131}
132
[email protected]b6583592012-01-25 19:52:33133void SiteInstanceImpl::SetSite(const GURL& url) {
naskob8744d22014-08-28 17:07:43134 TRACE_EVENT2("navigation", "SiteInstanceImpl::SetSite",
135 "site id", id_, "url", url.possibly_invalid_spec());
initial.commit09911bf2008-07-26 23:55:29136 // A SiteInstance's site should not change.
137 // TODO(creis): When following links or script navigations, we can currently
138 // render pages from other sites in this SiteInstance. This will eventually
139 // be fixed, but until then, we should still not set the site of a
140 // SiteInstance more than once.
141 DCHECK(!has_site_);
142
143 // Remember that this SiteInstance has been used to load a URL, even if the
144 // URL is invalid.
145 has_site_ = true;
[email protected]4c3a23582012-08-18 08:54:34146 BrowserContext* browser_context = browsing_instance_->browser_context();
[email protected]41fb79a52012-06-29 16:34:33147 site_ = GetSiteForURL(browser_context, url);
initial.commit09911bf2008-07-26 23:55:29148
149 // Now that we have a site, register it with the BrowsingInstance. This
150 // ensures that we won't create another SiteInstance for this site within
151 // the same BrowsingInstance, because all same-site pages within a
152 // BrowsingInstance can script each other.
153 browsing_instance_->RegisterSiteInstance(this);
[email protected]313b80bd2011-11-23 03:49:10154
clamy63960c32017-05-10 22:57:07155 // Update the process reuse policy based on the site.
156 bool should_use_process_per_site =
157 RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_);
158 if (should_use_process_per_site) {
159 process_reuse_policy_ = ProcessReusePolicy::PROCESS_PER_SITE;
160 }
161
[email protected]41fb79a52012-06-29 16:34:33162 if (process_) {
[email protected]313b80bd2011-11-23 03:49:10163 LockToOrigin();
[email protected]41fb79a52012-06-29 16:34:33164
165 // Ensure the process is registered for this site if necessary.
clamy63960c32017-05-10 22:57:07166 if (should_use_process_per_site) {
[email protected]41fb79a52012-06-29 16:34:33167 RenderProcessHostImpl::RegisterProcessHostForSite(
168 browser_context, process_, site_);
169 }
170 }
initial.commit09911bf2008-07-26 23:55:29171}
172
[email protected]77ab17312012-09-28 15:34:59173const GURL& SiteInstanceImpl::GetSiteURL() const {
[email protected]b6583592012-01-25 19:52:33174 return site_;
175}
176
177bool SiteInstanceImpl::HasSite() const {
178 return has_site_;
179}
180
181bool SiteInstanceImpl::HasRelatedSiteInstance(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:29182 return browsing_instance_->HasSiteInstance(url);
183}
184
dchengbccd6b82016-03-30 16:24:19185scoped_refptr<SiteInstance> SiteInstanceImpl::GetRelatedSiteInstance(
186 const GURL& url) {
initial.commit09911bf2008-07-26 23:55:29187 return browsing_instance_->GetSiteInstanceForURL(url);
188}
189
[email protected]14392a52012-05-02 20:28:44190bool SiteInstanceImpl::IsRelatedSiteInstance(const SiteInstance* instance) {
[email protected]fc72bb12013-06-02 21:13:46191 return browsing_instance_.get() == static_cast<const SiteInstanceImpl*>(
192 instance)->browsing_instance_.get();
[email protected]14392a52012-05-02 20:28:44193}
194
[email protected]d5072a82014-05-15 05:50:18195size_t SiteInstanceImpl::GetRelatedActiveContentsCount() {
196 return browsing_instance_->active_contents_count();
197}
198
[email protected]f88628d02012-11-11 17:58:59199bool SiteInstanceImpl::HasWrongProcessForURL(const GURL& url) {
[email protected]d292d8a2011-05-25 03:47:11200 // Having no process isn't a problem, since we'll assign it correctly.
[email protected]f88628d02012-11-11 17:58:59201 // Note that HasProcess() may return true if process_ is null, in
202 // process-per-site cases where there's an existing process available.
203 // We want to use such a process in the IsSuitableHost check, so we
204 // may end up assigning process_ in the GetProcess() call below.
205 if (!HasProcess())
[email protected]d292d8a2011-05-25 03:47:11206 return false;
207
[email protected]144a8102012-01-14 01:05:31208 // If the URL to navigate to can be associated with any site instance,
209 // we want to keep it in the same process.
[email protected]c02f1ba2014-02-03 06:53:53210 if (IsRendererDebugURL(url))
[email protected]144a8102012-01-14 01:05:31211 return false;
212
[email protected]88aae972011-12-16 01:14:18213 // If the site URL is an extension (e.g., for hosted apps or WebUI) but the
[email protected]d292d8a2011-05-25 03:47:11214 // process is not (or vice versa), make sure we notice and fix it.
[email protected]2a5221b2011-09-27 23:07:31215 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url);
[email protected]88aae972011-12-16 01:14:18216 return !RenderProcessHostImpl::IsSuitableHost(
[email protected]f88628d02012-11-11 17:58:59217 GetProcess(), browsing_instance_->browser_context(), site_url);
[email protected]d292d8a2011-05-25 03:47:11218}
219
nickd5bbd0b2016-03-31 19:52:44220scoped_refptr<SiteInstanceImpl>
221SiteInstanceImpl::GetDefaultSubframeSiteInstance() {
222 return browsing_instance_->GetDefaultSubframeSiteInstance();
223}
224
nickd30fd962015-07-27 21:51:08225bool SiteInstanceImpl::RequiresDedicatedProcess() {
226 if (!has_site_)
227 return false;
nickd5bbd0b2016-03-31 19:52:44228
229 return DoesSiteRequireDedicatedProcess(GetBrowserContext(), site_);
nickd30fd962015-07-27 21:51:08230}
231
avi85cacb72016-10-26 22:39:33232bool SiteInstanceImpl::IsDefaultSubframeSiteInstance() const {
clamy63960c32017-05-10 22:57:07233 return process_reuse_policy_ ==
234 ProcessReusePolicy::USE_DEFAULT_SUBFRAME_PROCESS;
avi85cacb72016-10-26 22:39:33235}
236
nick9f34e2892016-01-12 21:01:07237void SiteInstanceImpl::IncrementActiveFrameCount() {
238 active_frame_count_++;
239}
240
241void SiteInstanceImpl::DecrementActiveFrameCount() {
ericwilligers254597b2016-10-17 10:32:31242 if (--active_frame_count_ == 0) {
243 for (auto& observer : observers_)
244 observer.ActiveFrameCountIsZero(this);
245 }
nick9f34e2892016-01-12 21:01:07246}
247
[email protected]d5072a82014-05-15 05:50:18248void SiteInstanceImpl::IncrementRelatedActiveContentsCount() {
249 browsing_instance_->increment_active_contents_count();
250}
251
252void SiteInstanceImpl::DecrementRelatedActiveContentsCount() {
253 browsing_instance_->decrement_active_contents_count();
254}
255
nick9f34e2892016-01-12 21:01:07256void SiteInstanceImpl::AddObserver(Observer* observer) {
257 observers_.AddObserver(observer);
258}
259
260void SiteInstanceImpl::RemoveObserver(Observer* observer) {
261 observers_.RemoveObserver(observer);
262}
263
[email protected]4c3a23582012-08-18 08:54:34264BrowserContext* SiteInstanceImpl::GetBrowserContext() const {
[email protected]72daaa92012-01-18 13:39:02265 return browsing_instance_->browser_context();
266}
267
nickcc0d9142015-10-14 16:27:10268// static
dchengbccd6b82016-03-30 16:24:19269scoped_refptr<SiteInstance> SiteInstance::Create(
270 BrowserContext* browser_context) {
271 return SiteInstanceImpl::Create(browser_context);
initial.commit09911bf2008-07-26 23:55:29272}
273
nickcc0d9142015-10-14 16:27:10274// static
dchengbccd6b82016-03-30 16:24:19275scoped_refptr<SiteInstance> SiteInstance::CreateForURL(
276 BrowserContext* browser_context,
277 const GURL& url) {
278 return SiteInstanceImpl::CreateForURL(browser_context, url);
[email protected]d8a96622009-05-07 19:21:16279}
280
nickcc0d9142015-10-14 16:27:10281// static
[email protected]399583b2012-12-11 09:33:42282bool SiteInstance::IsSameWebSite(BrowserContext* browser_context,
[email protected]855d7d572014-08-02 11:18:17283 const GURL& real_src_url,
284 const GURL& real_dest_url) {
285 GURL src_url = SiteInstanceImpl::GetEffectiveURL(browser_context,
286 real_src_url);
287 GURL dest_url = SiteInstanceImpl::GetEffectiveURL(browser_context,
288 real_dest_url);
[email protected]399583b2012-12-11 09:33:42289
290 // We infer web site boundaries based on the registered domain name of the
291 // top-level page and the scheme. We do not pay attention to the port if
292 // one is present, because pages served from different ports can still
293 // access each other if they change their document.domain variable.
294
295 // Some special URLs will match the site instance of any other URL. This is
296 // done before checking both of them for validity, since we want these URLs
297 // to have the same site instance as even an invalid one.
[email protected]855d7d572014-08-02 11:18:17298 if (IsRendererDebugURL(src_url) || IsRendererDebugURL(dest_url))
[email protected]399583b2012-12-11 09:33:42299 return true;
300
301 // If either URL is invalid, they aren't part of the same site.
[email protected]855d7d572014-08-02 11:18:17302 if (!src_url.is_valid() || !dest_url.is_valid())
[email protected]399583b2012-12-11 09:33:42303 return false;
304
[email protected]855d7d572014-08-02 11:18:17305 // If the destination url is just a blank page, we treat them as part of the
306 // same site.
307 GURL blank_page(url::kAboutBlankURL);
308 if (dest_url == blank_page)
309 return true;
310
[email protected]399583b2012-12-11 09:33:42311 // If the schemes differ, they aren't part of the same site.
[email protected]855d7d572014-08-02 11:18:17312 if (src_url.scheme() != dest_url.scheme())
[email protected]399583b2012-12-11 09:33:42313 return false;
314
[email protected]ed32c212013-05-14 20:49:29315 return net::registry_controlled_domains::SameDomainOrHost(
[email protected]855d7d572014-08-02 11:18:17316 src_url,
317 dest_url,
[email protected]aabe1792014-01-30 21:37:46318 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
[email protected]399583b2012-12-11 09:33:42319}
320
nickcc0d9142015-10-14 16:27:10321// static
[email protected]399583b2012-12-11 09:33:42322GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context,
323 const GURL& real_url) {
[email protected]25a9e8e532012-06-22 06:16:28324 // TODO(fsamuel, creis): For some reason appID is not recognized as a host.
[email protected]6eb1a11e2013-10-09 00:54:37325 if (real_url.SchemeIs(kGuestScheme))
[email protected]25a9e8e532012-06-22 06:16:28326 return real_url;
327
[email protected]b6583592012-01-25 19:52:33328 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url);
nick1dd47922016-04-29 16:44:48329 url::Origin origin(url);
[email protected]3a8eecb2010-04-22 23:56:30330
initial.commit09911bf2008-07-26 23:55:29331 // If the url has a host, then determine the site.
nick1dd47922016-04-29 16:44:48332 if (!origin.host().empty()) {
333 // Only keep the scheme and registered domain of |origin|.
334 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
335 origin.host(),
336 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
337 std::string site = origin.scheme();
338 site += url::kStandardSchemeSeparator;
339 site += domain.empty() ? origin.host() : domain;
340 return GURL(site);
initial.commit09911bf2008-07-26 23:55:29341 }
creisf60c2cd2014-12-18 00:41:02342
343 // If there is no host but there is a scheme, return the scheme.
344 // This is useful for cases like file URLs.
345 if (url.has_scheme())
346 return GURL(url.scheme() + ":");
347
348 // Otherwise the URL should be invalid; return an empty site.
349 DCHECK(!url.is_valid());
350 return GURL();
initial.commit09911bf2008-07-26 23:55:29351}
352
nickcc0d9142015-10-14 16:27:10353// static
[email protected]4c3a23582012-08-18 08:54:34354GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context,
355 const GURL& url) {
[email protected]46488322012-10-30 03:22:20356 return GetContentClient()->browser()->
[email protected]3d7474ff2011-07-27 17:47:37357 GetEffectiveURL(browser_context, url);
[email protected]3a8eecb2010-04-22 23:56:30358}
359
nickcc0d9142015-10-14 16:27:10360// static
361bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess(
362 BrowserContext* browser_context,
nickdb193a12016-09-09 23:09:23363 const GURL& url) {
nickcc0d9142015-10-14 16:27:10364 // If --site-per-process is enabled, site isolation is enabled everywhere.
365 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites())
366 return true;
367
nickdb193a12016-09-09 23:09:23368 // Let the content embedder enable site isolation for specific URLs. Use the
369 // canonical site url for this check, so that schemes with nested origins
370 // (blob and filesystem) work properly.
371 GURL site_url = GetSiteForURL(browser_context, url);
nickcc0d9142015-10-14 16:27:10372 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() &&
373 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess(
nickdb193a12016-09-09 23:09:23374 browser_context, site_url)) {
nickcc0d9142015-10-14 16:27:10375 return true;
376 }
377
378 return false;
379}
380
[email protected]40bfaf32013-11-19 01:35:43381void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) {
382 DCHECK_EQ(process_, host);
383 process_->RemoveObserver(this);
nickd5bbd0b2016-03-31 19:52:44384 process_ = nullptr;
[email protected]4566f132009-03-12 01:55:13385}
[email protected]313b80bd2011-11-23 03:49:10386
nick9f34e2892016-01-12 21:01:07387void SiteInstanceImpl::RenderProcessWillExit(RenderProcessHost* host) {
388 // TODO(nick): http://crbug.com/575400 - RenderProcessWillExit might not serve
389 // any purpose here.
ericwilligers254597b2016-10-17 10:32:31390 for (auto& observer : observers_)
391 observer.RenderProcessGone(this);
nick9f34e2892016-01-12 21:01:07392}
393
394void SiteInstanceImpl::RenderProcessExited(RenderProcessHost* host,
395 base::TerminationStatus status,
396 int exit_code) {
ericwilligers254597b2016-10-17 10:32:31397 for (auto& observer : observers_)
398 observer.RenderProcessGone(this);
nick9f34e2892016-01-12 21:01:07399}
400
[email protected]b6583592012-01-25 19:52:33401void SiteInstanceImpl::LockToOrigin() {
nickd30fd962015-07-27 21:51:08402 // TODO(nick): When all sites are isolated, this operation provides strong
403 // protection. If only some sites are isolated, we need additional logic to
404 // prevent the non-isolated sites from requesting resources for isolated
405 // sites. https://crbug.com/509125
nickcc0d9142015-10-14 16:27:10406 if (RequiresDedicatedProcess()) {
lazyboyf5283a42015-06-24 21:53:35407 // Guest processes cannot be locked to its site because guests always have
408 // a fixed SiteInstance. The site of GURLs a guest loads doesn't match that
409 // SiteInstance. So we skip locking the guest process to the site.
410 // TODO(ncarter): Remove this exclusion once we can make origin lock per
411 // RenderFrame routing id.
412 if (site_.SchemeIs(content::kGuestScheme))
413 return;
414
lfg24d083792015-07-17 20:45:35415 // TODO(creis, nick) https://crbug.com/510588 Chrome UI pages use the same
416 // site (chrome://chrome), so they can't be locked because the site being
417 // loaded doesn't match the SiteInstance.
418 if (site_.SchemeIs(content::kChromeUIScheme))
419 return;
420
creise5d6d1732015-08-25 19:47:06421 // TODO(creis, nick): Until we can handle sites with effective URLs at the
422 // call sites of ChildProcessSecurityPolicy::CanAccessDataForOrigin, we
423 // must give the embedder a chance to exempt some sites to avoid process
424 // kills.
nick7d0984c2015-08-29 00:13:46425 if (!GetContentClient()->browser()->ShouldLockToOrigin(
426 browsing_instance_->browser_context(), site_))
creise5d6d1732015-08-25 19:47:06427 return;
428
[email protected]b9535422012-02-09 01:47:59429 ChildProcessSecurityPolicyImpl* policy =
430 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]313b80bd2011-11-23 03:49:10431 policy->LockToOrigin(process_->GetID(), site_);
432 }
433}
[email protected]46488322012-10-30 03:22:20434
435} // namespace content