| 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
| 7 #include "base/string16.h" | 7 #include "base/string16.h" |
| 8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
| 9 #include "content/browser/browsing_instance.h" | 9 #include "content/browser/browsing_instance.h" |
| 10 #include "content/browser/child_process_security_policy.h" | 10 #include "content/browser/child_process_security_policy.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 virtual content::WebUIControllerFactory* | 75 virtual content::WebUIControllerFactory* |
| 76 GetWebUIControllerFactory() OVERRIDE { | 76 GetWebUIControllerFactory() OVERRIDE { |
| 77 return &factory_; | 77 return &factory_; |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context, | 80 virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context, |
| 81 const GURL& effective_url) OVERRIDE { | 81 const GURL& effective_url) OVERRIDE { |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE { | |
| 86 return url == GURL(kSameAsAnyInstanceURL) || | |
| 87 url == GURL(chrome::kAboutCrashURL); | |
| 88 } | |
| 89 | |
| 90 virtual bool IsSuitableHost(content::RenderProcessHost* process_host, | 85 virtual bool IsSuitableHost(content::RenderProcessHost* process_host, |
| 91 const GURL& site_url) OVERRIDE { | 86 const GURL& site_url) OVERRIDE { |
| 92 return (privileged_process_id_ == process_host->GetID()) == | 87 return (privileged_process_id_ == process_host->GetID()) == |
| 93 site_url.SchemeIs(kPrivilegedScheme); | 88 site_url.SchemeIs(kPrivilegedScheme); |
| 94 } | 89 } |
| 95 | 90 |
| 96 void set_privileged_process_id(int process_id) { | 91 void set_privileged_process_id(int process_id) { |
| 97 privileged_process_id_ = process_id; | 92 privileged_process_id_ = process_id; |
| 98 } | 93 } |
| 99 | 94 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 354 |
| 360 // Test of distinguishing URLs from different sites. Most of this logic is | 355 // Test of distinguishing URLs from different sites. Most of this logic is |
| 361 // tested in RegistryControlledDomainTest. This test focuses on URLs with | 356 // tested in RegistryControlledDomainTest. This test focuses on URLs with |
| 362 // different schemes or ports. | 357 // different schemes or ports. |
| 363 TEST_F(SiteInstanceTest, IsSameWebSite) { | 358 TEST_F(SiteInstanceTest, IsSameWebSite) { |
| 364 GURL url_foo = GURL("http://foo/a.html"); | 359 GURL url_foo = GURL("http://foo/a.html"); |
| 365 GURL url_foo2 = GURL("http://foo/b.html"); | 360 GURL url_foo2 = GURL("http://foo/b.html"); |
| 366 GURL url_foo_https = GURL("https://foo/a.html"); | 361 GURL url_foo_https = GURL("https://foo/a.html"); |
| 367 GURL url_foo_port = GURL("http://foo:8080/a.html"); | 362 GURL url_foo_port = GURL("http://foo:8080/a.html"); |
| 368 GURL url_javascript = GURL("javascript:alert(1);"); | 363 GURL url_javascript = GURL("javascript:alert(1);"); |
| 369 GURL url_crash = GURL(chrome::kAboutCrashURL); | |
| 370 GURL url_browser_specified = GURL(kSameAsAnyInstanceURL); | |
| 371 | 364 |
| 372 // Same scheme and port -> same site. | 365 // Same scheme and port -> same site. |
| 373 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo2)); | 366 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo2)); |
| 374 | 367 |
| 375 // Different scheme -> different site. | 368 // Different scheme -> different site. |
| 376 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_https)); | 369 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_https)); |
| 377 | 370 |
| 378 // Different port -> same site. | 371 // Different port -> same site. |
| 379 // (Changes to document.domain make renderer ignore the port.) | 372 // (Changes to document.domain make renderer ignore the port.) |
| 380 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_port)); | 373 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_port)); |
| 381 | 374 |
| 382 // JavaScript links should be considered same site for anything. | 375 // JavaScript links should be considered same site for anything. |
| 383 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo)); | 376 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo)); |
| 384 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_https)); | 377 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_https)); |
| 385 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_port)); | 378 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_port)); |
| 386 | |
| 387 // The URLs specified by the ContentBrowserClient should also be treated as | |
| 388 // same site. | |
| 389 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_crash, url_foo)); | |
| 390 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_browser_specified, | |
| 391 url_foo)); | |
| 392 } | 379 } |
| 393 | 380 |
| 394 // Test to ensure that there is only one SiteInstance per site in a given | 381 // Test to ensure that there is only one SiteInstance per site in a given |
| 395 // BrowsingInstance, when process-per-site is not in use. | 382 // BrowsingInstance, when process-per-site is not in use. |
| 396 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 383 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
| 397 int delete_counter = 0; | 384 int delete_counter = 0; |
| 398 TestBrowsingInstance* browsing_instance = | 385 TestBrowsingInstance* browsing_instance = |
| 399 new TestBrowsingInstance(NULL, &delete_counter); | 386 new TestBrowsingInstance(NULL, &delete_counter); |
| 400 browsing_instance->set_use_process_per_site(false); | 387 browsing_instance->set_use_process_per_site(false); |
| 401 | 388 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 host.reset(instance->GetProcess()); | 598 host.reset(instance->GetProcess()); |
| 612 EXPECT_TRUE(host.get() != NULL); | 599 EXPECT_TRUE(host.get() != NULL); |
| 613 EXPECT_TRUE(instance->HasProcess()); | 600 EXPECT_TRUE(instance->HasProcess()); |
| 614 | 601 |
| 615 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); | 602 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); |
| 616 EXPECT_FALSE(instance->HasWrongProcessForURL( | 603 EXPECT_FALSE(instance->HasWrongProcessForURL( |
| 617 GURL("javascript:alert(document.location.href);"))); | 604 GURL("javascript:alert(document.location.href);"))); |
| 618 | 605 |
| 619 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); | 606 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); |
| 620 } | 607 } |
| OLD | NEW |