 Chromium Code Reviews
 Chromium Code Reviews Issue 1911573002:
  Teach SiteInstance::GetSiteForURL() about blob and filesystem URLs.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1911573002:
  Teach SiteInstance::GetSiteForURL() about blob and filesystem URLs.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 "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" | 
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 } | 327 } | 
| 328 | 328 | 
| 329 // static | 329 // static | 
| 330 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, | 330 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, | 
| 331 const GURL& real_url) { | 331 const GURL& real_url) { | 
| 332 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. | 332 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. | 
| 333 if (real_url.SchemeIs(kGuestScheme)) | 333 if (real_url.SchemeIs(kGuestScheme)) | 
| 334 return real_url; | 334 return real_url; | 
| 335 | 335 | 
| 336 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); | 336 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); | 
| 337 url::Origin origin(url); | |
| 337 | 338 | 
| 338 // If the url has a host, then determine the site. | 339 // If the url has a host, then determine the site. | 
| 339 if (url.has_host()) { | 340 if (!origin.host().empty()) { | 
| 340 // Only keep the scheme and registered domain as given by GetOrigin. This | 341 // Only keep the scheme and registered domain of |origin|. | 
| 341 // may also include a port, which we need to drop. | 342 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( | 
| 342 GURL site = url.GetOrigin(); | 343 origin.host(), | 
| 343 | 344 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 
| 344 // Remove port, if any. | 345 std::string site = origin.scheme(); | 
| 345 if (site.has_port()) { | 346 site += url::kStandardSchemeSeparator; | 
| 346 GURL::Replacements rep; | 347 site += domain.empty() ? origin.host() : domain; | 
| 
Charlie Reis
2016/04/22 18:11:09
nit: Maybe add a comment for which case this is fo
 | |
| 347 rep.ClearPort(); | 348 return GURL(site); | 
| 348 site = site.ReplaceComponents(rep); | |
| 349 } | |
| 350 | |
| 351 // If this URL has a registered domain, we only want to remember that part. | |
| 352 std::string domain = | |
| 353 net::registry_controlled_domains::GetDomainAndRegistry( | |
| 354 url, | |
| 355 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | |
| 356 if (!domain.empty()) { | |
| 357 GURL::Replacements rep; | |
| 358 rep.SetHostStr(domain); | |
| 359 site = site.ReplaceComponents(rep); | |
| 360 } | |
| 361 return site; | |
| 362 } | 349 } | 
| 363 | 350 | 
| 364 // If there is no host but there is a scheme, return the scheme. | 351 // If there is no host but there is a scheme, return the scheme. | 
| 365 // This is useful for cases like file URLs. | 352 // This is useful for cases like file URLs. | 
| 366 if (url.has_scheme()) | 353 if (url.has_scheme()) | 
| 367 return GURL(url.scheme() + ":"); | 354 return GURL(url.scheme() + ":"); | 
| 368 | 355 | 
| 369 // Otherwise the URL should be invalid; return an empty site. | 356 // Otherwise the URL should be invalid; return an empty site. | 
| 370 DCHECK(!url.is_valid()); | 357 DCHECK(!url.is_valid()); | 
| 371 return GURL(); | 358 return GURL(); | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 browsing_instance_->browser_context(), site_)) | 429 browsing_instance_->browser_context(), site_)) | 
| 443 return; | 430 return; | 
| 444 | 431 | 
| 445 ChildProcessSecurityPolicyImpl* policy = | 432 ChildProcessSecurityPolicyImpl* policy = | 
| 446 ChildProcessSecurityPolicyImpl::GetInstance(); | 433 ChildProcessSecurityPolicyImpl::GetInstance(); | 
| 447 policy->LockToOrigin(process_->GetID(), site_); | 434 policy->LockToOrigin(process_->GetID(), site_); | 
| 448 } | 435 } | 
| 449 } | 436 } | 
| 450 | 437 | 
| 451 } // namespace content | 438 } // namespace content | 
| OLD | NEW |