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 // 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 Loading... |
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. Also returns true for invalid |
232 NET_EXPORT size_t GetRegistryLength(base::StringPiece host, | 232 // host names like "*.google.com" as long as it has a valid registry-controlled |
233 UnknownRegistryFilter unknown_filter, | 233 // portion (see PermissiveGetHostRegistryLength for particulars). |
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 HasRegistryControlledDomain to eliminate |
| 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 // splits the input into substrings at '.' characters, then attempts to |
| 251 // piecewise-canonicalize the substrings. After finding the registry length of |
| 252 // the concatenated piecewise string, it then maps back to the corresponding |
| 253 // length in the original input string. |
| 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. Invalid dot-separated |
| 257 // portions of the domain will be left as-is when the string is looked up in |
| 258 // the registry database (which will result in no match). |
| 259 // |
| 260 // This will handle all cases except for the pattern: |
| 261 // <invalid-host-chars> <non-literal-dot> <valid-registry-controlled-domain> |
| 262 // For example: |
| 263 // "%00foo%2Ecom" (would canonicalize to "foo.com" if the "%00" was removed) |
| 264 // A non-literal dot (like "%2E" or a fullwidth period) will normally get |
| 265 // canonicalized to a dot if the host chars were valid. But since the %2E will |
| 266 // be in the same substring as the %00, the substring will fail to |
| 267 // canonicalize, the %2E will be left escaped, and the valid registry |
| 268 // controlled domain at the end won't match. |
| 269 // |
| 270 // The string won't be trimmed, so things like trailing spaces will be |
| 271 // considered part of the host and therefore won't match any TLD. It will |
| 272 // return std::string::npos like GetRegistryLength() for empty input, but |
| 273 // because invalid portions are skipped, it won't return npos in any other case. |
| 274 NET_EXPORT size_t |
| 275 PermissiveGetHostRegistryLength(base::StringPiece host, |
| 276 UnknownRegistryFilter unknown_filter, |
| 277 PrivateRegistryFilter private_filter); |
| 278 NET_EXPORT size_t |
| 279 PermissiveGetHostRegistryLength(base::StringPiece16 host, |
| 280 UnknownRegistryFilter unknown_filter, |
| 281 PrivateRegistryFilter private_filter); |
235 | 282 |
236 typedef const struct DomainRule* (*FindDomainPtr)(const char *, unsigned int); | 283 typedef const struct DomainRule* (*FindDomainPtr)(const char *, unsigned int); |
237 | 284 |
238 // Used for unit tests. Use default domains. | 285 // Used for unit tests. Use default domains. |
239 NET_EXPORT_PRIVATE void SetFindDomainGraph(); | 286 NET_EXPORT_PRIVATE void SetFindDomainGraph(); |
240 | 287 |
241 // Used for unit tests, so that a frozen list of domains is used. | 288 // Used for unit tests, so that a frozen list of domains is used. |
242 NET_EXPORT_PRIVATE void SetFindDomainGraph(const unsigned char* domains, | 289 NET_EXPORT_PRIVATE void SetFindDomainGraph(const unsigned char* domains, |
243 size_t length); | 290 size_t length); |
| 291 |
244 } // namespace registry_controlled_domains | 292 } // namespace registry_controlled_domains |
245 } // namespace net | 293 } // namespace net |
246 | 294 |
247 #endif // NET_BASE_REGISTRY_CONTROLLED_DOMAINS_REGISTRY_CONTROLLED_DOMAIN_H_ | 295 #endif // NET_BASE_REGISTRY_CONTROLLED_DOMAINS_REGISTRY_CONTROLLED_DOMAIN_H_ |
OLD | NEW |