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

Side by Side Diff: net/base/registry_controlled_domains/registry_controlled_domain.cc

Issue 255333003: Renamed namespaces in src/net. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tue 04/29/2014 19:22:06.75 Created 6 years, 7 months 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 | « net/base/net_util_unittest.cc ('k') | net/base/url_util.h » ('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) 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 // NB: Modelled after Mozilla's code (originally written by Pamela Greene, 5 // NB: Modelled after Mozilla's code (originally written by Pamela Greene,
6 // later modified by others), but almost entirely rewritten for Chrome. 6 // later modified by others), but almost entirely rewritten for Chrome.
7 // (netwerk/dns/src/nsEffectiveTLDService.cpp) 7 // (netwerk/dns/src/nsEffectiveTLDService.cpp)
8 /* ***** BEGIN LICENSE BLOCK ***** 8 /* ***** BEGIN LICENSE BLOCK *****
9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
10 * 10 *
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (dot == std::string::npos) 187 if (dot == std::string::npos)
188 return host; 188 return host;
189 return host.substr(dot + 1); 189 return host.substr(dot + 1);
190 } 190 }
191 191
192 } // namespace 192 } // namespace
193 193
194 std::string GetDomainAndRegistry( 194 std::string GetDomainAndRegistry(
195 const GURL& gurl, 195 const GURL& gurl,
196 PrivateRegistryFilter filter) { 196 PrivateRegistryFilter filter) {
197 const url_parse::Component host = 197 const url::Component host = gurl.parsed_for_possibly_invalid_spec().host;
198 gurl.parsed_for_possibly_invalid_spec().host;
199 if ((host.len <= 0) || gurl.HostIsIPAddress()) 198 if ((host.len <= 0) || gurl.HostIsIPAddress())
200 return std::string(); 199 return std::string();
201 return GetDomainAndRegistryImpl(std::string( 200 return GetDomainAndRegistryImpl(std::string(
202 gurl.possibly_invalid_spec().data() + host.begin, host.len), filter); 201 gurl.possibly_invalid_spec().data() + host.begin, host.len), filter);
203 } 202 }
204 203
205 std::string GetDomainAndRegistry( 204 std::string GetDomainAndRegistry(
206 const std::string& host, 205 const std::string& host,
207 PrivateRegistryFilter filter) { 206 PrivateRegistryFilter filter) {
208 url_canon::CanonHostInfo host_info; 207 url::CanonHostInfo host_info;
209 const std::string canon_host(CanonicalizeHost(host, &host_info)); 208 const std::string canon_host(CanonicalizeHost(host, &host_info));
210 if (canon_host.empty() || host_info.IsIPAddress()) 209 if (canon_host.empty() || host_info.IsIPAddress())
211 return std::string(); 210 return std::string();
212 return GetDomainAndRegistryImpl(canon_host, filter); 211 return GetDomainAndRegistryImpl(canon_host, filter);
213 } 212 }
214 213
215 bool SameDomainOrHost( 214 bool SameDomainOrHost(
216 const GURL& gurl1, 215 const GURL& gurl1,
217 const GURL& gurl2, 216 const GURL& gurl2,
218 PrivateRegistryFilter filter) { 217 PrivateRegistryFilter filter) {
219 // See if both URLs have a known domain + registry, and those values are the 218 // See if both URLs have a known domain + registry, and those values are the
220 // same. 219 // same.
221 const std::string domain1(GetDomainAndRegistry(gurl1, filter)); 220 const std::string domain1(GetDomainAndRegistry(gurl1, filter));
222 const std::string domain2(GetDomainAndRegistry(gurl2, filter)); 221 const std::string domain2(GetDomainAndRegistry(gurl2, filter));
223 if (!domain1.empty() || !domain2.empty()) 222 if (!domain1.empty() || !domain2.empty())
224 return domain1 == domain2; 223 return domain1 == domain2;
225 224
226 // No domains. See if the hosts are identical. 225 // No domains. See if the hosts are identical.
227 const url_parse::Component host1 = 226 const url::Component host1 = gurl1.parsed_for_possibly_invalid_spec().host;
228 gurl1.parsed_for_possibly_invalid_spec().host; 227 const url::Component host2 = gurl2.parsed_for_possibly_invalid_spec().host;
229 const url_parse::Component host2 =
230 gurl2.parsed_for_possibly_invalid_spec().host;
231 if ((host1.len <= 0) || (host1.len != host2.len)) 228 if ((host1.len <= 0) || (host1.len != host2.len))
232 return false; 229 return false;
233 return !strncmp(gurl1.possibly_invalid_spec().data() + host1.begin, 230 return !strncmp(gurl1.possibly_invalid_spec().data() + host1.begin,
234 gurl2.possibly_invalid_spec().data() + host2.begin, 231 gurl2.possibly_invalid_spec().data() + host2.begin,
235 host1.len); 232 host1.len);
236 } 233 }
237 234
238 size_t GetRegistryLength( 235 size_t GetRegistryLength(
239 const GURL& gurl, 236 const GURL& gurl,
240 UnknownRegistryFilter unknown_filter, 237 UnknownRegistryFilter unknown_filter,
241 PrivateRegistryFilter private_filter) { 238 PrivateRegistryFilter private_filter) {
242 const url_parse::Component host = 239 const url::Component host = gurl.parsed_for_possibly_invalid_spec().host;
243 gurl.parsed_for_possibly_invalid_spec().host;
244 if (host.len <= 0) 240 if (host.len <= 0)
245 return std::string::npos; 241 return std::string::npos;
246 if (gurl.HostIsIPAddress()) 242 if (gurl.HostIsIPAddress())
247 return 0; 243 return 0;
248 return GetRegistryLengthImpl( 244 return GetRegistryLengthImpl(
249 std::string(gurl.possibly_invalid_spec().data() + host.begin, host.len), 245 std::string(gurl.possibly_invalid_spec().data() + host.begin, host.len),
250 unknown_filter, 246 unknown_filter,
251 private_filter); 247 private_filter);
252 } 248 }
253 249
254 size_t GetRegistryLength( 250 size_t GetRegistryLength(
255 const std::string& host, 251 const std::string& host,
256 UnknownRegistryFilter unknown_filter, 252 UnknownRegistryFilter unknown_filter,
257 PrivateRegistryFilter private_filter) { 253 PrivateRegistryFilter private_filter) {
258 url_canon::CanonHostInfo host_info; 254 url::CanonHostInfo host_info;
259 const std::string canon_host(CanonicalizeHost(host, &host_info)); 255 const std::string canon_host(CanonicalizeHost(host, &host_info));
260 if (canon_host.empty()) 256 if (canon_host.empty())
261 return std::string::npos; 257 return std::string::npos;
262 if (host_info.IsIPAddress()) 258 if (host_info.IsIPAddress())
263 return 0; 259 return 0;
264 return GetRegistryLengthImpl(canon_host, unknown_filter, private_filter); 260 return GetRegistryLengthImpl(canon_host, unknown_filter, private_filter);
265 } 261 }
266 262
267 void SetFindDomainFunctionAndStringPoolForTesting(FindDomainPtr function, 263 void SetFindDomainFunctionAndStringPoolForTesting(FindDomainPtr function,
268 const char* stringpool) { 264 const char* stringpool) {
269 g_find_domain_function = function ? function : kDefaultFindDomainFunction; 265 g_find_domain_function = function ? function : kDefaultFindDomainFunction;
270 g_stringpool = stringpool ? stringpool : kDefaultStringPool; 266 g_stringpool = stringpool ? stringpool : kDefaultStringPool;
271 } 267 }
272 268
273 } // namespace registry_controlled_domains 269 } // namespace registry_controlled_domains
274 } // namespace net 270 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util_unittest.cc ('k') | net/base/url_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698