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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/browsing_instance.h" | 8 #include "content/browser/browsing_instance.h" |
9 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
10 #include "content/browser/renderer_host/render_process_host_impl.h" | 10 #include "content/browser/renderer_host/render_process_host_impl.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 SiteInstance* SiteInstance::CreateForURL(BrowserContext* browser_context, | 230 SiteInstance* SiteInstance::CreateForURL(BrowserContext* browser_context, |
231 const GURL& url) { | 231 const GURL& url) { |
232 // This BrowsingInstance may be deleted if it returns an existing | 232 // This BrowsingInstance may be deleted if it returns an existing |
233 // SiteInstance. | 233 // SiteInstance. |
234 scoped_refptr<BrowsingInstance> instance( | 234 scoped_refptr<BrowsingInstance> instance( |
235 new BrowsingInstance(browser_context)); | 235 new BrowsingInstance(browser_context)); |
236 return instance->GetSiteInstanceForURL(url); | 236 return instance->GetSiteInstanceForURL(url); |
237 } | 237 } |
238 | 238 |
239 /*static*/ | 239 /*static*/ |
240 GURL SiteInstanceImpl::GetSiteForURL(BrowserContext* browser_context, | 240 bool SiteInstance::IsSameWebSite(BrowserContext* browser_context, |
241 const GURL& real_url) { | 241 const GURL& real_url1, |
| 242 const GURL& real_url2) { |
| 243 GURL url1 = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url1); |
| 244 GURL url2 = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url2); |
| 245 |
| 246 // We infer web site boundaries based on the registered domain name of the |
| 247 // top-level page and the scheme. We do not pay attention to the port if |
| 248 // one is present, because pages served from different ports can still |
| 249 // access each other if they change their document.domain variable. |
| 250 |
| 251 // Some special URLs will match the site instance of any other URL. This is |
| 252 // done before checking both of them for validity, since we want these URLs |
| 253 // to have the same site instance as even an invalid one. |
| 254 if (IsURLSameAsAnySiteInstance(url1) || IsURLSameAsAnySiteInstance(url2)) |
| 255 return true; |
| 256 |
| 257 // If either URL is invalid, they aren't part of the same site. |
| 258 if (!url1.is_valid() || !url2.is_valid()) |
| 259 return false; |
| 260 |
| 261 // If the schemes differ, they aren't part of the same site. |
| 262 if (url1.scheme() != url2.scheme()) |
| 263 return false; |
| 264 |
| 265 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); |
| 266 } |
| 267 |
| 268 /*static*/ |
| 269 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, |
| 270 const GURL& real_url) { |
242 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. | 271 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. |
243 if (real_url.SchemeIs(chrome::kGuestScheme)) | 272 if (real_url.SchemeIs(chrome::kGuestScheme)) |
244 return real_url; | 273 return real_url; |
245 | 274 |
246 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); | 275 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); |
247 | 276 |
248 // URLs with no host should have an empty site. | 277 // URLs with no host should have an empty site. |
249 GURL site; | 278 GURL site; |
250 | 279 |
251 // TODO(creis): For many protocols, we should just treat the scheme as the | 280 // TODO(creis): For many protocols, we should just treat the scheme as the |
(...skipping 18 matching lines...) Expand all Loading... |
270 if (!domain.empty()) { | 299 if (!domain.empty()) { |
271 GURL::Replacements rep; | 300 GURL::Replacements rep; |
272 rep.SetHostStr(domain); | 301 rep.SetHostStr(domain); |
273 site = site.ReplaceComponents(rep); | 302 site = site.ReplaceComponents(rep); |
274 } | 303 } |
275 } | 304 } |
276 return site; | 305 return site; |
277 } | 306 } |
278 | 307 |
279 /*static*/ | 308 /*static*/ |
280 bool SiteInstance::IsSameWebSite(BrowserContext* browser_context, | |
281 const GURL& real_url1, | |
282 const GURL& real_url2) { | |
283 GURL url1 = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url1); | |
284 GURL url2 = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url2); | |
285 | |
286 // We infer web site boundaries based on the registered domain name of the | |
287 // top-level page and the scheme. We do not pay attention to the port if | |
288 // one is present, because pages served from different ports can still | |
289 // access each other if they change their document.domain variable. | |
290 | |
291 // Some special URLs will match the site instance of any other URL. This is | |
292 // done before checking both of them for validity, since we want these URLs | |
293 // to have the same site instance as even an invalid one. | |
294 if (IsURLSameAsAnySiteInstance(url1) || IsURLSameAsAnySiteInstance(url2)) | |
295 return true; | |
296 | |
297 // If either URL is invalid, they aren't part of the same site. | |
298 if (!url1.is_valid() || !url2.is_valid()) | |
299 return false; | |
300 | |
301 // If the schemes differ, they aren't part of the same site. | |
302 if (url1.scheme() != url2.scheme()) | |
303 return false; | |
304 | |
305 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); | |
306 } | |
307 | |
308 /*static*/ | |
309 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, | 309 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, |
310 const GURL& url) { | 310 const GURL& url) { |
311 return GetContentClient()->browser()-> | 311 return GetContentClient()->browser()-> |
312 GetEffectiveURL(browser_context, url); | 312 GetEffectiveURL(browser_context, url); |
313 } | 313 } |
314 | 314 |
315 void SiteInstanceImpl::Observe(int type, | 315 void SiteInstanceImpl::Observe(int type, |
316 const NotificationSource& source, | 316 const NotificationSource& source, |
317 const NotificationDetails& details) { | 317 const NotificationDetails& details) { |
318 DCHECK(type == NOTIFICATION_RENDERER_PROCESS_TERMINATED); | 318 DCHECK(type == NOTIFICATION_RENDERER_PROCESS_TERMINATED); |
319 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); | 319 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); |
320 if (rph == process_) | 320 if (rph == process_) |
321 process_ = NULL; | 321 process_ = NULL; |
322 } | 322 } |
323 | 323 |
324 void SiteInstanceImpl::LockToOrigin() { | 324 void SiteInstanceImpl::LockToOrigin() { |
325 // We currently only restrict this process to a particular site if the | 325 // We currently only restrict this process to a particular site if the |
326 // --enable-strict-site-isolation or --site-per-process flags are present. | 326 // --enable-strict-site-isolation or --site-per-process flags are present. |
327 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 327 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
328 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || | 328 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
329 command_line.HasSwitch(switches::kSitePerProcess)) { | 329 command_line.HasSwitch(switches::kSitePerProcess)) { |
330 ChildProcessSecurityPolicyImpl* policy = | 330 ChildProcessSecurityPolicyImpl* policy = |
331 ChildProcessSecurityPolicyImpl::GetInstance(); | 331 ChildProcessSecurityPolicyImpl::GetInstance(); |
332 policy->LockToOrigin(process_->GetID(), site_); | 332 policy->LockToOrigin(process_->GetID(), site_); |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 } // namespace content | 336 } // namespace content |
OLD | NEW |