Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: chrome/browser/site_instance.cc

Issue 12451: Don't create separate SiteInstances for pages from the same domain and scheme... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/site_instance.h ('k') | chrome/browser/site_instance_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/site_instance.h" 5 #include "chrome/browser/site_instance.h"
6 6
7 #include "net/base/registry_controlled_domain.h" 7 #include "net/base/registry_controlled_domain.h"
8 8
9 SiteInstance::~SiteInstance() { 9 SiteInstance::~SiteInstance() {
10 // Now that no one is referencing us, we can safely remove ourselves from 10 // Now that no one is referencing us, we can safely remove ourselves from
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 /*static*/ 78 /*static*/
79 GURL SiteInstance::GetSiteForURL(const GURL& url) { 79 GURL SiteInstance::GetSiteForURL(const GURL& url) {
80 // URLs with no host should have an empty site. 80 // URLs with no host should have an empty site.
81 GURL site; 81 GURL site;
82 82
83 // TODO(creis): For many protocols, we should just treat the scheme as the 83 // TODO(creis): For many protocols, we should just treat the scheme as the
84 // site, since there is no host. e.g., file:, about:, chrome-resource: 84 // site, since there is no host. e.g., file:, about:, chrome-resource:
85 85
86 // If the url has a host, then determine the site. 86 // If the url has a host, then determine the site.
87 if (url.has_host()) { 87 if (url.has_host()) {
88 // Only keep the scheme, registered domain, and port as given by GetOrigin. 88 // Only keep the scheme and registered domain as given by GetOrigin. This
89 // may also include a port, which we need to drop.
89 site = url.GetOrigin(); 90 site = url.GetOrigin();
90 91
92 // Remove port, if any.
93 if (site.has_port()) {
94 GURL::Replacements rep;
95 rep.ClearPort();
96 site = site.ReplaceComponents(rep);
97 }
98
91 // If this URL has a registered domain, we only want to remember that part. 99 // If this URL has a registered domain, we only want to remember that part.
92 std::string domain = 100 std::string domain =
93 net::RegistryControlledDomainService::GetDomainAndRegistry(url); 101 net::RegistryControlledDomainService::GetDomainAndRegistry(url);
94 if (!domain.empty()) { 102 if (!domain.empty()) {
95 GURL::Replacements rep; 103 GURL::Replacements rep;
96 rep.SetHostStr(domain); 104 rep.SetHostStr(domain);
97 site = site.ReplaceComponents(rep); 105 site = site.ReplaceComponents(rep);
98 } 106 }
99 } 107 }
100 return site; 108 return site;
101 } 109 }
102 110
103 /*static*/ 111 /*static*/
104 bool SiteInstance::IsSameWebSite(const GURL& url1, const GURL& url2) { 112 bool SiteInstance::IsSameWebSite(const GURL& url1, const GURL& url2) {
105 // We infer web site boundaries based on the registered domain name of the 113 // We infer web site boundaries based on the registered domain name of the
106 // top-level page, as well as the scheme and the port. 114 // top-level page and the scheme. We do not pay attention to the port if
115 // one is present, because pages served from different ports can still
116 // access each other if they change their document.domain variable.
107 117
108 // We must treat javascript: URLs as part of the same site, regardless of 118 // We must treat javascript: URLs as part of the same site, regardless of
109 // the site. 119 // the site.
110 if (url1.SchemeIs("javascript") || url2.SchemeIs("javascript")) 120 if (url1.SchemeIs("javascript") || url2.SchemeIs("javascript"))
111 return true; 121 return true;
112 122
113 // We treat about:crash, about:hang, and about:shorthang as the same site as 123 // We treat about:crash, about:hang, and about:shorthang as the same site as
114 // any URL, since they are used as demos for crashing/hanging a process. 124 // any URL, since they are used as demos for crashing/hanging a process.
115 GURL about_crash = GURL("about:crash"); 125 GURL about_crash = GURL("about:crash");
116 GURL about_hang = GURL("about:hang"); 126 GURL about_hang = GURL("about:hang");
117 GURL about_shorthang = GURL("about:shorthang"); 127 GURL about_shorthang = GURL("about:shorthang");
118 if (url1 == about_crash || url2 == about_crash || 128 if (url1 == about_crash || url2 == about_crash ||
119 url1 == about_hang || url2 == about_hang || 129 url1 == about_hang || url2 == about_hang ||
120 url1 == about_shorthang || url2 == about_shorthang) 130 url1 == about_shorthang || url2 == about_shorthang)
121 return true; 131 return true;
122 132
123 // If either URL is invalid, they aren't part of the same site. 133 // If either URL is invalid, they aren't part of the same site.
124 if (!url1.is_valid() || !url2.is_valid()) { 134 if (!url1.is_valid() || !url2.is_valid()) {
125 return false; 135 return false;
126 } 136 }
127 137
128 // If the scheme or port differ, they aren't part of the same site. 138 // If the schemes differ, they aren't part of the same site.
129 if (url1.scheme() != url2.scheme() || url1.port() != url2.port()) { 139 if (url1.scheme() != url2.scheme()) {
130 return false; 140 return false;
131 } 141 }
132 142
133 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); 143 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2);
134 } 144 }
135 145
OLDNEW
« no previous file with comments | « chrome/browser/site_instance.h ('k') | chrome/browser/site_instance_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698