Commit 78cf66bd authored by Alex Moshchuk's avatar Alex Moshchuk Committed by Commit Bot

Replace SiteInstance::IsSameWebSite() with a new non-static method.

Currently, SiteInstance::IsSameWebSite() is static and will need to be
modified to support dynamic isolated origins.  Those origins will
apply only to future BrowsingInstances, meaning the answer to
IsSameWebSite will depend on which frame/SiteInstance is asking this
question.  This CL replaces this method with a non-static
SiteInstance::IsSameSiteWithURL method.  This will ensure that the
internal implementation will be able to provide sufficient context
(i.e., BrowsingInstance info) in the future, without having to expose
that context outside of content/.  Note that the content-internal
version of this call, SiteInstanceImpl::IsSameWebSite, stays as-is for
now.

The only two non-test uses of this were in NaCl code.  They were
checking whether the current SiteInstance's site URL is same-site with
the URL of the NaCl file to be loaded, with both URLs expected to be
extension URLs.  There should be no behavior change in these, as the
underlying implementation doesn't change.

A few tests are also refactored to either avoid using IsSameWebSite
entirely, or, for tests inside content/, to use the internal version
of IsSameWebSite.

Bug: 905513
Change-Id: Ia2957bb1ec7a16de8c3d18ef167149f1f5a08066
Reviewed-on: https://chromium-review.googlesource.com/c/1352856Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarDerek Schuff <dschuff@chromium.org>
Reviewed-by: default avatarŁukasz Anforowicz <lukasza@chromium.org>
Commit-Queue: Alex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612495}
parent da02fb9b
......@@ -196,10 +196,10 @@ class TabManagerTest : public InProcessBrowserTest {
// The page has 2 iframes, we will use the first one.
content::RenderFrameHost* child_frame = content->GetAllFrames()[1];
// Verify that the main frame and subframe are cross-site.
EXPECT_FALSE(content::SiteInstance::IsSameWebSite(
browser()->profile(), main_frame->GetLastCommittedURL(),
child_frame->GetLastCommittedURL()));
EXPECT_NE(main_frame->GetLastCommittedURL().GetOrigin(),
child_frame->GetLastCommittedURL().GetOrigin());
if (content::AreAllSitesIsolatedForTesting()) {
EXPECT_NE(main_frame->GetSiteInstance(), child_frame->GetSiteInstance());
EXPECT_NE(main_frame->GetProcess()->GetID(),
child_frame->GetProcess()->GetID());
}
......@@ -1379,10 +1379,10 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest,
// Sanity check that in this test page the main frame and the
// subframe are cross-site.
EXPECT_FALSE(content::SiteInstance::IsSameWebSite(
browser()->profile(), main_frame->GetLastCommittedURL(),
child_frame->GetLastCommittedURL()));
EXPECT_NE(main_frame->GetLastCommittedURL().GetOrigin(),
child_frame->GetLastCommittedURL().GetOrigin());
if (content::AreAllSitesIsolatedForTesting()) {
EXPECT_NE(main_frame->GetSiteInstance(), child_frame->GetSiteInstance());
EXPECT_NE(main_frame->GetProcess()->GetID(),
child_frame->GetProcess()->GetID());
}
......
......@@ -251,10 +251,11 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, CrossSiteSubframe) {
// Do a sanity check that in this particular test page the main frame and the
// subframe are cross-site.
EXPECT_FALSE(content::SiteInstance::IsSameWebSite(
browser()->profile(), original_main_frame->GetLastCommittedURL(),
original_child_frame->GetLastCommittedURL()));
EXPECT_NE(original_main_frame->GetLastCommittedURL().GetOrigin(),
original_child_frame->GetLastCommittedURL().GetOrigin());
if (content::AreAllSitesIsolatedForTesting()) {
EXPECT_NE(original_main_frame->GetSiteInstance(),
original_child_frame->GetSiteInstance());
EXPECT_NE(original_main_frame->GetProcess()->GetID(),
original_child_frame->GetProcess()->GetID());
}
......
......@@ -245,9 +245,7 @@ void OpenNaClExecutable(
return;
}
content::SiteInstance* site_instance = rvh->GetSiteInstance();
if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(),
site_instance->GetSiteURL(),
file_url)) {
if (!site_instance->IsSameSiteWithURL(file_url)) {
NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
return;
}
......
......@@ -171,12 +171,8 @@ void NaClHostMessageFilter::LaunchNaClContinuation(
GURL gurl(original_request_list[i].resource_url);
// Important security check: Do the same check as OpenNaClExecutable()
// in nacl_file_host.cc.
if (!content::SiteInstance::IsSameWebSite(
site_instance->GetBrowserContext(),
site_instance->GetSiteURL(),
gurl)) {
if (!site_instance->IsSameSiteWithURL(gurl))
continue;
}
safe_launch_params.resource_prefetch_request_list.push_back(
original_request_list[i]);
}
......
......@@ -17,6 +17,7 @@
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "content/browser/loader/cross_site_document_resource_handler.h"
#include "content/browser/site_instance_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_entry.h"
......@@ -764,9 +765,10 @@ class CrossSiteDocumentBlockingServiceWorkerTest : public ContentBrowserTest {
// Sanity check of test setup - the 2 https servers should be cross-site
// (the second server should have a different hostname because of the call
// to SetSSLConfig with CERT_COMMON_NAME_IS_DOMAIN argument).
ASSERT_FALSE(SiteInstance::IsSameWebSite(
ASSERT_FALSE(SiteInstanceImpl::IsSameWebSite(
shell()->web_contents()->GetBrowserContext(),
GetURLOnServiceWorkerServer("/"), GetURLOnCrossOriginServer("/")));
GetURLOnServiceWorkerServer("/"), GetURLOnCrossOriginServer("/"),
true /* should_use_effective_urls */));
}
GURL GetURLOnServiceWorkerServer(const std::string& path) {
......
......@@ -333,14 +333,13 @@ bool SiteInstance::ShouldAssignSiteForURL(const GURL& url) {
return SiteInstanceImpl::ShouldAssignSiteForURL(url);
}
// static
bool SiteInstance::IsSameWebSite(BrowserContext* browser_context,
const GURL& real_src_url,
const GURL& real_dest_url) {
return SiteInstanceImpl::IsSameWebSite(browser_context, real_src_url,
real_dest_url, true);
bool SiteInstanceImpl::IsSameSiteWithURL(const GURL& url) {
return SiteInstanceImpl::IsSameWebSite(
browsing_instance_->browser_context(), site_, url,
true /* should_compare_effective_urls */);
}
// static
bool SiteInstanceImpl::IsSameWebSite(BrowserContext* browser_context,
const GURL& real_src_url,
const GURL& real_dest_url,
......
......@@ -45,10 +45,15 @@ class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance,
// not if the lock is empty or applies to an entire scheme (e.g., file://).
static bool IsOriginLockASite(const GURL& lock_url);
// See SiteInstance::IsSameWebSite.
// This version allows comparing URLs without converting them to effective
// URLs first, which is useful for avoiding OOPIFs when otherwise same-site
// URLs may look cross-site via their effective URLs.
// Return whether both URLs are part of the same web site, for the purpose of
// assigning them to processes accordingly. The decision is currently based
// on the registered domain of the URLs (google.com, bbc.co.uk), as well as
// the scheme (https, http). Note that if the destination is a blank page,
// we consider that to be part of the same web site for the purposes for
// process assignment. |should_compare_effective_urls| allows comparing URLs
// without converting them to effective URLs first. This is useful for
// avoiding OOPIFs when otherwise same-site URLs may look cross-site via
// their effective URLs.
static bool IsSameWebSite(content::BrowserContext* browser_context,
const GURL& src_url,
const GURL& dest_url,
......@@ -64,6 +69,7 @@ class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance,
bool IsRelatedSiteInstance(const SiteInstance* instance) override;
size_t GetRelatedActiveContentsCount() override;
bool RequiresDedicatedProcess() override;
bool IsSameSiteWithURL(const GURL& url) override;
// The policy to apply when selecting a RenderProcessHost for the
// SiteInstance. If no suitable RenderProcessHost for the SiteInstance exists
......
......@@ -49,6 +49,13 @@ GURL GetWebUIURL(std::string host) {
return GURL(std::string(kChromeUIScheme) + "://" + host);
}
bool IsSameWebSite(BrowserContext* context,
const GURL& url1,
const GURL& url2) {
return SiteInstanceImpl::IsSameWebSite(context, url1, url2,
true /* should_use_effective_urls */);
}
} // namespace
const char kPrivilegedScheme[] = "privileged";
......@@ -477,31 +484,29 @@ TEST_F(SiteInstanceTest, IsSameWebSite) {
GURL url_blank = GURL(url::kAboutBlankURL);
// Same scheme and port -> same site.
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, url_foo, url_foo2));
EXPECT_TRUE(IsSameWebSite(&context, url_foo, url_foo2));
// Different scheme -> different site.
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, url_foo, url_foo_https));
EXPECT_FALSE(IsSameWebSite(&context, url_foo, url_foo_https));
// Different port -> same site.
// (Changes to document.domain make renderer ignore the port.)
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, url_foo, url_foo_port));
EXPECT_TRUE(IsSameWebSite(&context, url_foo, url_foo_port));
// JavaScript links should be considered same site for anything.
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, url_javascript, url_foo));
EXPECT_TRUE(
SiteInstance::IsSameWebSite(&context, url_javascript, url_foo_https));
EXPECT_TRUE(
SiteInstance::IsSameWebSite(&context, url_javascript, url_foo_port));
EXPECT_TRUE(IsSameWebSite(&context, url_javascript, url_foo));
EXPECT_TRUE(IsSameWebSite(&context, url_javascript, url_foo_https));
EXPECT_TRUE(IsSameWebSite(&context, url_javascript, url_foo_port));
// Navigating to a blank page is considered the same site.
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, url_foo, url_blank));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, url_foo_https, url_blank));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, url_foo_port, url_blank));
EXPECT_TRUE(IsSameWebSite(&context, url_foo, url_blank));
EXPECT_TRUE(IsSameWebSite(&context, url_foo_https, url_blank));
EXPECT_TRUE(IsSameWebSite(&context, url_foo_port, url_blank));
// Navigating from a blank site is not considered to be the same site.
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, url_blank, url_foo));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, url_blank, url_foo_https));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, url_blank, url_foo_port));
EXPECT_FALSE(IsSameWebSite(&context, url_blank, url_foo));
EXPECT_FALSE(IsSameWebSite(&context, url_blank, url_foo_https));
EXPECT_FALSE(IsSameWebSite(&context, url_blank, url_foo_port));
DrainMessageLoop();
}
......@@ -512,28 +517,25 @@ TEST_F(SiteInstanceTest, IsSameWebSiteForFileURLs) {
TestBrowserContext context;
// Two identical file URLs should be same-site.
EXPECT_TRUE(SiteInstance::IsSameWebSite(
&context, GURL("file:///foo/bar.html"), GURL("file:///foo/bar.html")));
EXPECT_TRUE(IsSameWebSite(&context, GURL("file:///foo/bar.html"),
GURL("file:///foo/bar.html")));
// File URLs with the same path but different fragment are considered
// same-site.
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context,
GURL("file:///foo/bar.html"),
GURL("file:///foo/bar.html#baz")));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context,
GURL("file:///foo/bar.html#baz"),
GURL("file:///foo/bar.html")));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context,
GURL("file:///foo/bar.html#baz"),
GURL("file:///foo/bar.html#qux")));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, GURL("file:///#abc"),
GURL("file:///#def")));
EXPECT_TRUE(IsSameWebSite(&context, GURL("file:///foo/bar.html"),
GURL("file:///foo/bar.html#baz")));
EXPECT_TRUE(IsSameWebSite(&context, GURL("file:///foo/bar.html#baz"),
GURL("file:///foo/bar.html")));
EXPECT_TRUE(IsSameWebSite(&context, GURL("file:///foo/bar.html#baz"),
GURL("file:///foo/bar.html#qux")));
EXPECT_TRUE(
IsSameWebSite(&context, GURL("file:///#abc"), GURL("file:///#def")));
// Other cases are cross-site.
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, GURL("file:///foo.html"),
GURL("file:///foo/bar.html")));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, GURL("file:///#bar"),
GURL("file:///foo/#bar")));
EXPECT_FALSE(IsSameWebSite(&context, GURL("file:///foo.html"),
GURL("file:///foo/bar.html")));
EXPECT_FALSE(
IsSameWebSite(&context, GURL("file:///#bar"), GURL("file:///foo/#bar")));
}
// Test to ensure that there is only one SiteInstance per site in a given
......@@ -853,38 +855,34 @@ TEST_F(SiteInstanceTest, IsSameWebsiteForNestedURLs) {
GURL fs_foo_url("filesystem:http://foo.com/path/");
GURL fs_bar_url("filesystem:http://bar.com/path/");
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, foo_url, blob_foo_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, blob_foo_url, foo_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, foo_url, blob_bar_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, blob_foo_url, bar_url));
EXPECT_TRUE(IsSameWebSite(&context, foo_url, blob_foo_url));
EXPECT_TRUE(IsSameWebSite(&context, blob_foo_url, foo_url));
EXPECT_FALSE(IsSameWebSite(&context, foo_url, blob_bar_url));
EXPECT_FALSE(IsSameWebSite(&context, blob_foo_url, bar_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, foo_url, fs_foo_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, fs_foo_url, foo_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, foo_url, fs_bar_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, fs_foo_url, bar_url));
EXPECT_TRUE(IsSameWebSite(&context, foo_url, fs_foo_url));
EXPECT_TRUE(IsSameWebSite(&context, fs_foo_url, foo_url));
EXPECT_FALSE(IsSameWebSite(&context, foo_url, fs_bar_url));
EXPECT_FALSE(IsSameWebSite(&context, fs_foo_url, bar_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, blob_foo_url, fs_foo_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, blob_foo_url, fs_bar_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, blob_foo_url, blob_bar_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, fs_foo_url, fs_bar_url));
EXPECT_TRUE(IsSameWebSite(&context, blob_foo_url, fs_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, blob_foo_url, fs_bar_url));
EXPECT_FALSE(IsSameWebSite(&context, blob_foo_url, blob_bar_url));
EXPECT_FALSE(IsSameWebSite(&context, fs_foo_url, fs_bar_url));
// Verify that the scheme and ETLD+1 are used for comparison.
GURL www_bar_url("http://www.bar.com/");
GURL bar_org_url("http://bar.org/");
GURL https_bar_url("https://bar.com/");
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, www_bar_url, bar_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, www_bar_url, blob_bar_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, www_bar_url, fs_bar_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, bar_org_url, bar_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, bar_org_url, blob_bar_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, bar_org_url, fs_bar_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, https_bar_url, bar_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, https_bar_url, blob_bar_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, https_bar_url, fs_bar_url));
EXPECT_TRUE(IsSameWebSite(&context, www_bar_url, bar_url));
EXPECT_TRUE(IsSameWebSite(&context, www_bar_url, blob_bar_url));
EXPECT_TRUE(IsSameWebSite(&context, www_bar_url, fs_bar_url));
EXPECT_FALSE(IsSameWebSite(&context, bar_org_url, bar_url));
EXPECT_FALSE(IsSameWebSite(&context, bar_org_url, blob_bar_url));
EXPECT_FALSE(IsSameWebSite(&context, bar_org_url, fs_bar_url));
EXPECT_FALSE(IsSameWebSite(&context, https_bar_url, bar_url));
EXPECT_FALSE(IsSameWebSite(&context, https_bar_url, blob_bar_url));
EXPECT_FALSE(IsSameWebSite(&context, https_bar_url, fs_bar_url));
}
TEST_F(SiteInstanceTest, IsolatedOrigins) {
......@@ -896,7 +894,7 @@ TEST_F(SiteInstanceTest, IsolatedOrigins) {
TestBrowserContext context;
EXPECT_FALSE(policy->IsIsolatedOrigin(url::Origin::Create(isolated_foo_url)));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, foo_url, isolated_foo_url));
EXPECT_TRUE(IsSameWebSite(&context, foo_url, isolated_foo_url));
policy->AddIsolatedOrigins({url::Origin::Create(isolated_foo_url)});
EXPECT_TRUE(policy->IsIsolatedOrigin(url::Origin::Create(isolated_foo_url)));
......@@ -915,23 +913,18 @@ TEST_F(SiteInstanceTest, IsolatedOrigins) {
// IsSameWebSite should compare origins rather than sites if either URL is an
// isolated origin.
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, foo_url, isolated_foo_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, isolated_foo_url, foo_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, isolated_foo_url,
isolated_bar_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, isolated_foo_url,
isolated_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, foo_url, isolated_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, isolated_foo_url, foo_url));
EXPECT_FALSE(IsSameWebSite(&context, isolated_foo_url, isolated_bar_url));
EXPECT_TRUE(IsSameWebSite(&context, isolated_foo_url, isolated_foo_url));
// Ensure blob and filesystem URLs with isolated origins are compared
// correctly.
GURL isolated_blob_foo_url("blob:http://isolated.foo.com/uuid");
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, isolated_foo_url,
isolated_blob_foo_url));
EXPECT_TRUE(IsSameWebSite(&context, isolated_foo_url, isolated_blob_foo_url));
GURL isolated_filesystem_foo_url("filesystem:http://isolated.foo.com/bar/");
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, isolated_foo_url,
isolated_filesystem_foo_url));
EXPECT_TRUE(
IsSameWebSite(&context, isolated_foo_url, isolated_filesystem_foo_url));
// The site URL for an isolated origin should be the full origin rather than
// eTLD+1.
......@@ -1030,10 +1023,8 @@ TEST_F(SiteInstanceTest, SubdomainOnIsolatedSite) {
EXPECT_TRUE(SiteInstanceImpl::DoesSiteRequireDedicatedProcess(
&context, foo_isolated_url));
EXPECT_TRUE(
SiteInstance::IsSameWebSite(&context, isolated_url, foo_isolated_url));
EXPECT_TRUE(
SiteInstance::IsSameWebSite(&context, foo_isolated_url, isolated_url));
EXPECT_TRUE(IsSameWebSite(&context, isolated_url, foo_isolated_url));
EXPECT_TRUE(IsSameWebSite(&context, foo_isolated_url, isolated_url));
// Don't try to match subdomains on IP addresses.
GURL isolated_ip("http://127.0.0.1");
......@@ -1082,22 +1073,16 @@ TEST_F(SiteInstanceTest, SubdomainOnIsolatedOrigin) {
EXPECT_TRUE(SiteInstanceImpl::DoesSiteRequireDedicatedProcess(
&context, baz_isolated_foo_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, foo_url, isolated_foo_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, isolated_foo_url, foo_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, foo_url, bar_isolated_foo_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, bar_isolated_foo_url, foo_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, bar_isolated_foo_url,
isolated_foo_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, isolated_foo_url,
bar_isolated_foo_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, bar_isolated_foo_url,
baz_isolated_foo_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, baz_isolated_foo_url,
bar_isolated_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, foo_url, isolated_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, isolated_foo_url, foo_url));
EXPECT_FALSE(IsSameWebSite(&context, foo_url, bar_isolated_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, bar_isolated_foo_url, foo_url));
EXPECT_TRUE(IsSameWebSite(&context, bar_isolated_foo_url, isolated_foo_url));
EXPECT_TRUE(IsSameWebSite(&context, isolated_foo_url, bar_isolated_foo_url));
EXPECT_TRUE(
IsSameWebSite(&context, bar_isolated_foo_url, baz_isolated_foo_url));
EXPECT_TRUE(
IsSameWebSite(&context, baz_isolated_foo_url, bar_isolated_foo_url));
// Cleanup.
policy->RemoveIsolatedOriginForTesting(url::Origin::Create(isolated_foo_url));
......@@ -1136,18 +1121,14 @@ TEST_F(SiteInstanceTest, MultipleIsolatedOriginsWithCommonSite) {
EXPECT_TRUE(SiteInstanceImpl::DoesSiteRequireDedicatedProcess(
&context, qux_baz_bar_foo_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, foo_url, bar_foo_url));
EXPECT_FALSE(SiteInstance::IsSameWebSite(&context, foo_url, baz_bar_foo_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, foo_url, qux_baz_bar_foo_url));
EXPECT_TRUE(IsSameWebSite(&context, foo_url, bar_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, foo_url, baz_bar_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, foo_url, qux_baz_bar_foo_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, bar_foo_url, baz_bar_foo_url));
EXPECT_FALSE(
SiteInstance::IsSameWebSite(&context, bar_foo_url, qux_baz_bar_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, bar_foo_url, baz_bar_foo_url));
EXPECT_FALSE(IsSameWebSite(&context, bar_foo_url, qux_baz_bar_foo_url));
EXPECT_TRUE(SiteInstance::IsSameWebSite(&context, baz_bar_foo_url,
qux_baz_bar_foo_url));
EXPECT_TRUE(IsSameWebSite(&context, baz_bar_foo_url, qux_baz_bar_foo_url));
// Cleanup.
policy->RemoveIsolatedOriginForTesting(url::Origin::Create(foo_url));
......
......@@ -130,6 +130,18 @@ class CONTENT_EXPORT SiteInstance : public base::RefCounted<SiteInstance> {
// process. This only returns true under the "site per process" process model.
virtual bool RequiresDedicatedProcess() = 0;
// Return whether this SiteInstance and the provided |url| are part of the
// same web site, for the purpose of assigning them to processes accordingly.
// The decision is currently based on the registered domain of the URLs
// (google.com, bbc.co.uk), as well as the scheme (https, http). This ensures
// that two pages will be in the same process if they can communicate with
// other via JavaScript. (e.g., docs.google.com and mail.google.com have DOM
// access to each other if they both set their document.domain properties to
// google.com.) Note that if the destination is a blank page, we consider
// that to be part of the same web site for the purposes for process
// assignment.
virtual bool IsSameSiteWithURL(const GURL& url) = 0;
// Factory method to create a new SiteInstance. This will create a new
// new BrowsingInstance, so it should only be used when creating a new tab
// from scratch (or similar circumstances).
......@@ -151,19 +163,6 @@ class CONTENT_EXPORT SiteInstance : public base::RefCounted<SiteInstance> {
// chrome-native:// leave the site unassigned.
static bool ShouldAssignSiteForURL(const GURL& url);
// Return whether both URLs are part of the same web site, for the purpose of
// assigning them to processes accordingly. The decision is currently based
// on the registered domain of the URLs (google.com, bbc.co.uk), as well as
// the scheme (https, http). This ensures that two pages will be in
// the same process if they can communicate with other via JavaScript.
// (e.g., docs.google.com and mail.google.com have DOM access to each other
// if they both set their document.domain properties to google.com.)
// Note that if the destination is a blank page, we consider that to be part
// of the same web site for the purposes for process assignment.
static bool IsSameWebSite(content::BrowserContext* browser_context,
const GURL& src_url,
const GURL& dest_url);
// Returns the site for the given URL, which includes only the scheme and
// registered domain. Returns an empty GURL if the URL has no host. Prior to
// determining the site, |url| is resolved to an effective URL via
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment