| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 scoped_refptr<SiteInstance> SiteInstance::CreateForURL( | 285 scoped_refptr<SiteInstance> SiteInstance::CreateForURL( |
| 286 BrowserContext* browser_context, | 286 BrowserContext* browser_context, |
| 287 const GURL& url) { | 287 const GURL& url) { |
| 288 return SiteInstanceImpl::CreateForURL(browser_context, url); | 288 return SiteInstanceImpl::CreateForURL(browser_context, url); |
| 289 } | 289 } |
| 290 | 290 |
| 291 // static | 291 // static |
| 292 bool SiteInstance::IsSameWebSite(BrowserContext* browser_context, | 292 bool SiteInstance::IsSameWebSite(BrowserContext* browser_context, |
| 293 const GURL& real_src_url, | 293 const GURL& real_src_url, |
| 294 const GURL& real_dest_url) { | 294 const GURL& real_dest_url) { |
| 295 GURL dest_url = |
| 296 SiteInstanceImpl::GetEffectiveURL(browser_context, real_dest_url); |
| 295 GURL src_url = SiteInstanceImpl::GetEffectiveURL(browser_context, | 297 GURL src_url = SiteInstanceImpl::GetEffectiveURL(browser_context, |
| 296 real_src_url); | 298 real_src_url); |
| 297 GURL dest_url = SiteInstanceImpl::GetEffectiveURL(browser_context, | |
| 298 real_dest_url); | |
| 299 | 299 |
| 300 // We infer web site boundaries based on the registered domain name of the | 300 // We infer web site boundaries based on the registered domain name of the |
| 301 // top-level page and the scheme. We do not pay attention to the port if | 301 // top-level page and the scheme. We do not pay attention to the port if |
| 302 // one is present, because pages served from different ports can still | 302 // one is present, because pages served from different ports can still |
| 303 // access each other if they change their document.domain variable. | 303 // access each other if they change their document.domain variable. |
| 304 | 304 |
| 305 // Some special URLs will match the site instance of any other URL. This is | 305 // Some special URLs will match the site instance of any other URL. This is |
| 306 // done before checking both of them for validity, since we want these URLs | 306 // done before checking both of them for validity, since we want these URLs |
| 307 // to have the same site instance as even an invalid one. | 307 // to have the same site instance as even an invalid one. |
| 308 if (IsRendererDebugURL(src_url) || IsRendererDebugURL(dest_url)) | 308 if (IsRendererDebugURL(src_url) || IsRendererDebugURL(dest_url)) |
| 309 return true; | 309 return true; |
| 310 | 310 |
| 311 // If either URL is invalid, they aren't part of the same site. | 311 // If either URL is invalid, they aren't part of the same site. |
| 312 if (!src_url.is_valid() || !dest_url.is_valid()) | 312 if (!src_url.is_valid() || !dest_url.is_valid()) |
| 313 return false; | 313 return false; |
| 314 | 314 |
| 315 // If the destination url is just a blank page, we treat them as part of the | 315 // If the destination url is just a blank page, a data: URL, or another page |
| 316 // same site. | 316 // without an origin, we can't reason about its origin. |
| 317 GURL blank_page(url::kAboutBlankURL); | 317 url::Origin dest_origin(dest_url); |
| 318 if (dest_url == blank_page) | 318 if (dest_origin.unique()) |
| 319 return true; | 319 return true; |
| 320 | 320 |
| 321 // If the schemes differ, they aren't part of the same site. | 321 // If the schemes differ, they aren't part of the same site. |
| 322 if (src_url.scheme() != dest_url.scheme()) | 322 if (src_url.scheme() != dest_origin.scheme()) |
| 323 return false; | 323 return false; |
| 324 | 324 |
| 325 return net::registry_controlled_domains::SameDomainOrHost( | 325 return net::registry_controlled_domains::SameDomainOrHost( |
| 326 src_url, | 326 src_url, dest_origin.GetURL(), |
| 327 dest_url, | |
| 328 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 327 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 329 } | 328 } |
| 330 | 329 |
| 331 // static | 330 // static |
| 332 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, | 331 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, |
| 333 const GURL& real_url) { | 332 const GURL& real_url) { |
| 334 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. | 333 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. |
| 335 if (real_url.SchemeIs(kGuestScheme)) | 334 if (real_url.SchemeIs(kGuestScheme)) |
| 336 return real_url; | 335 return real_url; |
| 337 | 336 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 browsing_instance_->browser_context(), site_)) | 435 browsing_instance_->browser_context(), site_)) |
| 437 return; | 436 return; |
| 438 | 437 |
| 439 ChildProcessSecurityPolicyImpl* policy = | 438 ChildProcessSecurityPolicyImpl* policy = |
| 440 ChildProcessSecurityPolicyImpl::GetInstance(); | 439 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 441 policy->LockToOrigin(process_->GetID(), site_); | 440 policy->LockToOrigin(process_->GetID(), site_); |
| 442 } | 441 } |
| 443 } | 442 } |
| 444 | 443 |
| 445 } // namespace content | 444 } // namespace content |
| OLD | NEW |