Chromium Code Reviews| 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 "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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 // If either URL is invalid, they aren't part of the same site. | 302 // If either URL is invalid, they aren't part of the same site. |
| 302 if (!src_url.is_valid() || !dest_url.is_valid()) | 303 if (!src_url.is_valid() || !dest_url.is_valid()) |
| 303 return false; | 304 return false; |
| 304 | 305 |
| 305 // If the destination url is just a blank page, we treat them as part of the | 306 // If the destination url is just a blank page, we treat them as part of the |
| 306 // same site. | 307 // same site. |
| 307 GURL blank_page(url::kAboutBlankURL); | 308 GURL blank_page(url::kAboutBlankURL); |
| 308 if (dest_url == blank_page) | 309 if (dest_url == blank_page) |
| 309 return true; | 310 return true; |
| 310 | 311 |
| 312 // If either URL has an isolated origin, compare origins rather than sites. | |
| 313 // This must be done before the GetEffectiveURL resolution, as isolated | |
|
Charlie Reis
2017/05/19 00:10:19
nit: We're not doing it before the GetEffectiveURL
alexmos
2017/05/24 00:28:33
This no longer applies now that I've modified GetE
| |
| 314 // origins take precedence over hosted apps. | |
| 315 url::Origin src_origin(real_src_url); | |
| 316 url::Origin dest_origin(real_dest_url); | |
| 317 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); | |
| 318 if (policy->IsIsolatedOrigin(src_origin) || | |
| 319 policy->IsIsolatedOrigin(dest_origin)) | |
| 320 return src_origin == dest_origin; | |
| 321 | |
| 311 // If the schemes differ, they aren't part of the same site. | 322 // If the schemes differ, they aren't part of the same site. |
| 323 // | |
| 324 // Note that this happens after the isolated origin check, since blob or | |
| 325 // filesystem URLs will fail this check even though they might have the | |
| 326 // same origin. | |
| 312 if (src_url.scheme() != dest_url.scheme()) | 327 if (src_url.scheme() != dest_url.scheme()) |
| 313 return false; | 328 return false; |
| 314 | 329 |
| 315 return net::registry_controlled_domains::SameDomainOrHost( | 330 return net::registry_controlled_domains::SameDomainOrHost( |
| 316 src_url, | 331 src_url, |
| 317 dest_url, | 332 dest_url, |
| 318 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 333 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 319 } | 334 } |
| 320 | 335 |
| 321 // static | 336 // static |
| 322 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, | 337 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, |
| 323 const GURL& real_url) { | 338 const GURL& real_url) { |
| 324 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. | 339 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. |
| 325 if (real_url.SchemeIs(kGuestScheme)) | 340 if (real_url.SchemeIs(kGuestScheme)) |
| 326 return real_url; | 341 return real_url; |
| 327 | 342 |
| 343 // Isolated origins should use the full origin as their site URL. This is | |
| 344 // intentionally checked before resolving the URL with GetEffectiveURL, as | |
| 345 // isolated origins must take precedence over hosted apps. | |
| 346 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); | |
| 347 url::Origin real_origin(real_url); | |
| 348 if (policy->IsIsolatedOrigin(real_origin)) | |
| 349 return real_origin.GetURL(); | |
| 350 | |
| 328 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); | 351 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); |
| 329 url::Origin origin(url); | 352 url::Origin origin(url); |
| 330 | 353 |
| 331 // If the url has a host, then determine the site. | 354 // If the url has a host, then determine the site. |
| 332 if (!origin.host().empty()) { | 355 if (!origin.host().empty()) { |
| 333 // Only keep the scheme and registered domain of |origin|. | 356 // Only keep the scheme and registered domain of |origin|. |
| 334 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( | 357 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( |
| 335 origin.host(), | 358 origin.host(), |
| 336 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 359 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 337 std::string site = origin.scheme(); | 360 std::string site = origin.scheme(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 358 } | 381 } |
| 359 | 382 |
| 360 // static | 383 // static |
| 361 bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess( | 384 bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess( |
| 362 BrowserContext* browser_context, | 385 BrowserContext* browser_context, |
| 363 const GURL& url) { | 386 const GURL& url) { |
| 364 // If --site-per-process is enabled, site isolation is enabled everywhere. | 387 // If --site-per-process is enabled, site isolation is enabled everywhere. |
| 365 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) | 388 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) |
| 366 return true; | 389 return true; |
| 367 | 390 |
| 391 // For now, always require a dedicated process for isolated origins. | |
| 392 // TODO(alexmos): revisit this for Isolate-Me. | |
|
Charlie Reis
2017/05/19 00:10:19
I may just be forgetting, but why would an Isolate
alexmos
2017/05/24 00:28:33
I was just thinking about the discussion that isol
Charlie Reis
2017/05/25 01:54:37
I see. Yeah, I think there's some flexibility in
alexmos
2017/05/25 16:58:49
Yes - I removed the comment given that this place
| |
| 393 GURL site_url = GetSiteForURL(browser_context, url); | |
| 394 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); | |
| 395 if (policy->IsIsolatedOrigin(url::Origin(site_url))) | |
| 396 return true; | |
| 397 | |
| 368 // Let the content embedder enable site isolation for specific URLs. Use the | 398 // 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 | 399 // canonical site url for this check, so that schemes with nested origins |
| 370 // (blob and filesystem) work properly. | 400 // (blob and filesystem) work properly. |
| 371 GURL site_url = GetSiteForURL(browser_context, url); | |
| 372 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() && | 401 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() && |
| 373 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess( | 402 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess( |
| 374 browser_context, site_url)) { | 403 browser_context, site_url)) { |
| 375 return true; | 404 return true; |
| 376 } | 405 } |
| 377 | 406 |
| 378 return false; | 407 return false; |
| 379 } | 408 } |
| 380 | 409 |
| 381 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) { | 410 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 browsing_instance_->browser_context(), site_)) | 455 browsing_instance_->browser_context(), site_)) |
| 427 return; | 456 return; |
| 428 | 457 |
| 429 ChildProcessSecurityPolicyImpl* policy = | 458 ChildProcessSecurityPolicyImpl* policy = |
| 430 ChildProcessSecurityPolicyImpl::GetInstance(); | 459 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 431 policy->LockToOrigin(process_->GetID(), site_); | 460 policy->LockToOrigin(process_->GetID(), site_); |
| 432 } | 461 } |
| 433 } | 462 } |
| 434 | 463 |
| 435 } // namespace content | 464 } // namespace content |
| OLD | NEW |