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

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

Issue 2433583002: Reduce buggy usage of the registry controlled domain service. (Closed)
Patch Set: Fix Created 4 years, 2 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
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.h) 7 // (netwerk/dns/src/nsEffectiveTLDService.h)
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // dots) 220 // dots)
221 // http://192.168.0.1/file.html -> 0 (IP address) 221 // http://192.168.0.1/file.html -> 0 (IP address)
222 // http://bar/file.html -> 0 (no subcomponents) 222 // http://bar/file.html -> 0 (no subcomponents)
223 // http://co.uk/file.html -> 0 (host is a registry) 223 // http://co.uk/file.html -> 0 (host is a registry)
224 // http://foo.bar/file.html -> 0 or 3, depending (no rule; assume 224 // http://foo.bar/file.html -> 0 or 3, depending (no rule; assume
225 // bar) 225 // bar)
226 NET_EXPORT size_t GetRegistryLength(const GURL& gurl, 226 NET_EXPORT size_t GetRegistryLength(const GURL& gurl,
227 UnknownRegistryFilter unknown_filter, 227 UnknownRegistryFilter unknown_filter,
228 PrivateRegistryFilter private_filter); 228 PrivateRegistryFilter private_filter);
229 229
230 // Like the GURL version, but takes a host (which is canonicalized internally) 230 // Returns true if the given host name has a registry-controlled domain. The
231 // instead of a full GURL. 231 // host name will be internally canonicalized. Invalid host names like
232 NET_EXPORT size_t GetRegistryLength(base::StringPiece host, 232 // "*.google.com" can be passed and will return true as long as it has a valid
233 UnknownRegistryFilter unknown_filter, 233 // registry-controlled portion.
Peter Kasting 2016/10/22 05:04:19 Nit: How about this last sentence: "Also returns t
234 PrivateRegistryFilter private_filter); 234 NET_EXPORT bool HostHasRegistryControlledDomain(
235 base::StringPiece host,
236 UnknownRegistryFilter unknown_filter,
237 PrivateRegistryFilter private_filter);
238
239 // Like GetRegistryLength, but takes a previously-canonicalized host instead of
240 // a GURL. Prefer the GURL version or HasRegistryControlledSuffix to eliminate
Peter Kasting 2016/10/22 05:04:19 Nit: HasRegistryControlledSuffix -> HostHasRegistr
brettw 2016/10/24 21:45:24 Done.
241 // the possibility of bugs with non-canonical hosts.
242 //
243 // If you have a non-canonical host name, use the "Permissive" version instead.
244 NET_EXPORT size_t
245 GetCanonicalHostRegistryLength(base::StringPiece canon_host,
246 UnknownRegistryFilter unknown_filter,
247 PrivateRegistryFilter private_filter);
248
249 // Like GetRegistryLength for a potentially non-canonicalized hostname. This
250 // function will perform a reverse-mapping of canonicalization transformations
251 // so that the length of the registry controlled domain indicates the length
252 // in the original string, even in the presence of things like escaped
253 // characters or re-enconding from UTF-16.
254 //
255 // It will also handle hostnames that are otherwise invalid as long as they
256 // contain a valid registry controlled domain at the end. The only thing it
257 // won't handle is if you have a non-canonical dot (perhaps escaped) separating
258 // an otherwise-valid registry-controlled domain and invalid host characters.
259 // Invalid components are skipped only when they are dot-separated.
Peter Kasting 2016/10/22 05:04:19 Nit: I'm confused. Is this paragraph simply tryin
brettw 2016/10/24 21:45:24 It actually handles more cases than your sentence,
260 //
261 // The string won't be trimmed, so things like trailing spaces will be
262 // considered part of the host and therefore won't match any TLD. An empty
263 // string will return std::string::npos like GetRegistryLength().
Peter Kasting 2016/10/22 05:04:19 Nit: Is the last sentence necessary? I mean, we a
brettw 2016/10/24 21:45:24 I expanded on this a bit.
264 NET_EXPORT size_t
265 PermissiveGetHostRegistryLength(base::StringPiece host,
266 UnknownRegistryFilter unknown_filter,
267 PrivateRegistryFilter private_filter);
268 NET_EXPORT size_t
269 PermissiveGetHostRegistryLength(base::StringPiece16 host,
270 UnknownRegistryFilter unknown_filter,
271 PrivateRegistryFilter private_filter);
235 272
236 typedef const struct DomainRule* (*FindDomainPtr)(const char *, unsigned int); 273 typedef const struct DomainRule* (*FindDomainPtr)(const char *, unsigned int);
237 274
238 // Used for unit tests. Use default domains. 275 // Used for unit tests. Use default domains.
239 NET_EXPORT_PRIVATE void SetFindDomainGraph(); 276 NET_EXPORT_PRIVATE void SetFindDomainGraph();
240 277
241 // Used for unit tests, so that a frozen list of domains is used. 278 // Used for unit tests, so that a frozen list of domains is used.
242 NET_EXPORT_PRIVATE void SetFindDomainGraph(const unsigned char* domains, 279 NET_EXPORT_PRIVATE void SetFindDomainGraph(const unsigned char* domains,
243 size_t length); 280 size_t length);
281
244 } // namespace registry_controlled_domains 282 } // namespace registry_controlled_domains
245 } // namespace net 283 } // namespace net
246 284
247 #endif // NET_BASE_REGISTRY_CONTROLLED_DOMAINS_REGISTRY_CONTROLLED_DOMAIN_H_ 285 #endif // NET_BASE_REGISTRY_CONTROLLED_DOMAINS_REGISTRY_CONTROLLED_DOMAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698