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