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

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

Issue 2831683002: Introduce support for origins that require process isolation. (Closed)
Patch Set: Rebase Created 3 years, 7 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 "base/macros.h"
7 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
8 #include "content/browser/browsing_instance.h" 9 #include "content/browser/browsing_instance.h"
9 #include "content/browser/child_process_security_policy_impl.h" 10 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/browser/frame_host/debug_urls.h" 11 #include "content/browser/frame_host/debug_urls.h"
11 #include "content/browser/frame_host/frame_tree_node.h" 12 #include "content/browser/frame_host/frame_tree_node.h"
12 #include "content/browser/renderer_host/render_process_host_impl.h" 13 #include "content/browser/renderer_host/render_process_host_impl.h"
13 #include "content/browser/storage_partition_impl.h" 14 #include "content/browser/storage_partition_impl.h"
14 #include "content/common/site_isolation_policy.h" 15 #include "content/common/site_isolation_policy.h"
15 #include "content/public/browser/content_browser_client.h" 16 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/browser/render_process_host_factory.h" 17 #include "content/public/browser/render_process_host_factory.h"
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // If either URL is invalid, they aren't part of the same site. 399 // If either URL is invalid, they aren't part of the same site.
399 if (!src_url.is_valid() || !dest_url.is_valid()) 400 if (!src_url.is_valid() || !dest_url.is_valid())
400 return false; 401 return false;
401 402
402 // If the destination url is just a blank page, we treat them as part of the 403 // If the destination url is just a blank page, we treat them as part of the
403 // same site. 404 // same site.
404 GURL blank_page(url::kAboutBlankURL); 405 GURL blank_page(url::kAboutBlankURL);
405 if (dest_url == blank_page) 406 if (dest_url == blank_page)
406 return true; 407 return true;
407 408
409 // If either URL has an isolated origin, compare origins rather than sites.
410 url::Origin src_origin(src_url);
Charlie Reis 2017/05/05 23:18:51 Fun. src_url is an effective URL, so it may be a
alexmos 2017/05/16 17:26:37 Thanks for pointing this out. I agree that isolat
Charlie Reis 2017/05/19 00:10:18 I like that idea-- seems like it will help us be m
411 url::Origin dest_origin(dest_url);
412 if (SiteInstanceImpl::IsIsolatedOrigin(src_origin) ||
413 SiteInstanceImpl::IsIsolatedOrigin(dest_origin))
414 return src_origin == dest_origin;
415
408 // If the schemes differ, they aren't part of the same site. 416 // If the schemes differ, they aren't part of the same site.
417 //
418 // Note that this happens after the isolated origin check, since blob or
419 // filesystem URLs will fail this check even though they might have the
420 // same origin.
409 if (src_url.scheme() != dest_url.scheme()) 421 if (src_url.scheme() != dest_url.scheme())
410 return false; 422 return false;
411 423
412 return net::registry_controlled_domains::SameDomainOrHost( 424 return net::registry_controlled_domains::SameDomainOrHost(
413 src_url, 425 src_url,
414 dest_url, 426 dest_url,
415 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 427 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
416 } 428 }
417 429
418 // static 430 // static
419 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, 431 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context,
420 const GURL& real_url) { 432 const GURL& real_url) {
421 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. 433 // TODO(fsamuel, creis): For some reason appID is not recognized as a host.
422 if (real_url.SchemeIs(kGuestScheme)) 434 if (real_url.SchemeIs(kGuestScheme))
423 return real_url; 435 return real_url;
424 436
425 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); 437 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url);
438
439 // Isolated origins should use the full origin as their site URL.
426 url::Origin origin(url); 440 url::Origin origin(url);
441 if (SiteInstanceImpl::IsIsolatedOrigin(origin))
442 return origin.GetURL();
427 443
428 // If the url has a host, then determine the site. 444 // If the url has a host, then determine the site.
429 if (!origin.host().empty()) { 445 if (!origin.host().empty()) {
430 // Only keep the scheme and registered domain of |origin|. 446 // Only keep the scheme and registered domain of |origin|.
431 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( 447 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
432 origin.host(), 448 origin.host(),
433 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 449 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
434 std::string site = origin.scheme(); 450 std::string site = origin.scheme();
435 site += url::kStandardSchemeSeparator; 451 site += url::kStandardSchemeSeparator;
436 site += domain.empty() ? origin.host() : domain; 452 site += domain.empty() ? origin.host() : domain;
(...skipping 18 matching lines...) Expand all
455 } 471 }
456 472
457 // static 473 // static
458 bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess( 474 bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess(
459 BrowserContext* browser_context, 475 BrowserContext* browser_context,
460 const GURL& url) { 476 const GURL& url) {
461 // If --site-per-process is enabled, site isolation is enabled everywhere. 477 // If --site-per-process is enabled, site isolation is enabled everywhere.
462 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) 478 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites())
463 return true; 479 return true;
464 480
481 // For now, always require a dedicated process for isolated origins.
482 // TODO(alexmos): revisit this for Isolate-Me.
483 GURL site_url = GetSiteForURL(browser_context, url);
484 if (IsIsolatedOrigin(url::Origin(site_url)))
485 return true;
486
465 // Let the content embedder enable site isolation for specific URLs. Use the 487 // Let the content embedder enable site isolation for specific URLs. Use the
466 // canonical site url for this check, so that schemes with nested origins 488 // canonical site url for this check, so that schemes with nested origins
467 // (blob and filesystem) work properly. 489 // (blob and filesystem) work properly.
468 GURL site_url = GetSiteForURL(browser_context, url);
469 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() && 490 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() &&
470 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess( 491 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess(
471 browser_context, site_url)) { 492 browser_context, site_url)) {
472 return true; 493 return true;
473 } 494 }
474 495
475 return false; 496 return false;
476 } 497 }
477 498
499 // static
500 void SiteInstanceImpl::AddIsolatedOrigin(const url::Origin& origin) {
Charlie Reis 2017/05/05 23:18:51 Might be worth putting a UI thread check in each o
alexmos 2017/05/16 17:26:37 That was a really good idea, and it made me realiz
501 DCHECK(!origin.unique());
502 DCHECK(!IsIsolatedOrigin(origin));
503
504 GetIsolatedOrigins()->insert(origin);
505 }
506
507 void SiteInstanceImpl::AddIsolatedOriginsFromCommandLine(
508 const std::string& origin_list) {
509 for (const base::StringPiece& origin_piece :
510 base::SplitStringPiece(origin_list, ",", base::TRIM_WHITESPACE,
511 base::SPLIT_WANT_NONEMPTY)) {
512 url::Origin origin((GURL(origin_piece)));
513 if (!origin.unique())
514 SiteInstanceImpl::AddIsolatedOrigin(origin);
515 }
516 }
517
518 // static
519 bool SiteInstanceImpl::IsIsolatedOrigin(const url::Origin& origin) {
520 return GetIsolatedOrigins()->find(origin) != GetIsolatedOrigins()->end();
521 }
522
523 // static
524 SiteInstanceImpl::IsolatedOriginSet* SiteInstanceImpl::GetIsolatedOrigins() {
525 CR_DEFINE_STATIC_LOCAL(IsolatedOriginSet, isolated_origins, ());
526 return &isolated_origins;
527 }
528
478 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) { 529 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) {
479 DCHECK_EQ(process_, host); 530 DCHECK_EQ(process_, host);
480 process_->RemoveObserver(this); 531 process_->RemoveObserver(this);
481 process_ = nullptr; 532 process_ = nullptr;
482 } 533 }
483 534
484 void SiteInstanceImpl::RenderProcessWillExit(RenderProcessHost* host) { 535 void SiteInstanceImpl::RenderProcessWillExit(RenderProcessHost* host) {
485 // TODO(nick): http://crbug.com/575400 - RenderProcessWillExit might not serve 536 // TODO(nick): http://crbug.com/575400 - RenderProcessWillExit might not serve
486 // any purpose here. 537 // any purpose here.
487 for (auto& observer : observers_) 538 for (auto& observer : observers_)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 browsing_instance_->browser_context(), site_)) 574 browsing_instance_->browser_context(), site_))
524 return; 575 return;
525 576
526 ChildProcessSecurityPolicyImpl* policy = 577 ChildProcessSecurityPolicyImpl* policy =
527 ChildProcessSecurityPolicyImpl::GetInstance(); 578 ChildProcessSecurityPolicyImpl::GetInstance();
528 policy->LockToOrigin(process_->GetID(), site_); 579 policy->LockToOrigin(process_->GetID(), site_);
529 } 580 }
530 } 581 }
531 582
532 } // namespace content 583 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698