Chromium Code Reviews| Index: net/base/registry_controlled_domains/registry_controlled_domain.cc |
| diff --git a/net/base/registry_controlled_domains/registry_controlled_domain.cc b/net/base/registry_controlled_domains/registry_controlled_domain.cc |
| index a20af0805a4c9dd58f49016e8ff0cbdfc4d2f613..ee307b7c93ae40fa7ef20f2d900c52d3d1d06b5f 100644 |
| --- a/net/base/registry_controlled_domains/registry_controlled_domain.cc |
| +++ b/net/base/registry_controlled_domains/registry_controlled_domain.cc |
| @@ -56,46 +56,55 @@ |
| #include "effective_tld_names.cc" |
| namespace net { |
| +namespace registry_controlled_domains { |
| namespace { |
| const int kExceptionRule = 1; |
| const int kWildcardRule = 2; |
| +FindDomainPtr g_find_domain_function = Perfect_Hash::FindDomain; |
|
Ryan Sleevi
2013/05/06 21:23:13
nit: newline here before the }
nyquist
2013/05/06 22:30:56
Done.
|
| } // namespace |
| -RegistryControlledDomainService::FindDomainPtr |
| -RegistryControlledDomainService::find_domain_function_ = |
| - Perfect_Hash::FindDomain; |
| +std::string GetDomainAndRegistryImpl(const std::string& host, |
| + PrivateRegistryFilter filter); |
|
Ryan Sleevi
2013/05/06 21:23:13
style nit: indentation is wrong
style nit: Before
nyquist
2013/05/06 22:30:56
Done with indentation.
Will move methods up before
|
| + |
| +size_t GetRegistryLengthImpl(const std::string& host, |
| + UnknownRegistryFilter unknown_filter, |
| + PrivateRegistryFilter filter); |
|
Ryan Sleevi
2013/05/06 21:23:13
style nit: indentation.
nyquist
2013/05/06 22:30:56
Done.
|
| // static |
| -std::string RegistryControlledDomainService::GetDomainAndRegistry( |
| - const GURL& gurl) { |
| +std::string GetDomainAndRegistry( |
|
Ryan Sleevi
2013/05/06 21:23:13
Please remove the occurrences of "// static" in th
nyquist
2013/05/06 22:30:56
Done.
|
| + const GURL& gurl, |
| + PrivateRegistryFilter filter) { |
| const url_parse::Component host = |
| gurl.parsed_for_possibly_invalid_spec().host; |
| if ((host.len <= 0) || gurl.HostIsIPAddress()) |
| return std::string(); |
| return GetDomainAndRegistryImpl(std::string( |
| - gurl.possibly_invalid_spec().data() + host.begin, host.len)); |
| + gurl.possibly_invalid_spec().data() + host.begin, host.len), filter); |
| } |
| // static |
| -std::string RegistryControlledDomainService::GetDomainAndRegistry( |
| - const std::string& host) { |
| +std::string GetDomainAndRegistry( |
| + const std::string& host, |
| + PrivateRegistryFilter filter) { |
| url_canon::CanonHostInfo host_info; |
| const std::string canon_host(CanonicalizeHost(host, &host_info)); |
| if (canon_host.empty() || host_info.IsIPAddress()) |
| return std::string(); |
| - return GetDomainAndRegistryImpl(canon_host); |
| + return GetDomainAndRegistryImpl(canon_host, filter); |
| } |
| // static |
| -bool RegistryControlledDomainService::SameDomainOrHost(const GURL& gurl1, |
| - const GURL& gurl2) { |
| +bool SameDomainOrHost( |
| + const GURL& gurl1, |
| + const GURL& gurl2, |
| + PrivateRegistryFilter filter) { |
| // See if both URLs have a known domain + registry, and those values are the |
| // same. |
| - const std::string domain1(GetDomainAndRegistry(gurl1)); |
| - const std::string domain2(GetDomainAndRegistry(gurl2)); |
| + const std::string domain1(GetDomainAndRegistry(gurl1, filter)); |
| + const std::string domain2(GetDomainAndRegistry(gurl2, filter)); |
| if (!domain1.empty() || !domain2.empty()) |
| return domain1 == domain2; |
| @@ -112,9 +121,10 @@ bool RegistryControlledDomainService::SameDomainOrHost(const GURL& gurl1, |
| } |
| // static |
| -size_t RegistryControlledDomainService::GetRegistryLength( |
| +size_t GetRegistryLength( |
| const GURL& gurl, |
| - bool allow_unknown_registries) { |
| + UnknownRegistryFilter unknown_filter, |
| + PrivateRegistryFilter private_filter) { |
| const url_parse::Component host = |
| gurl.parsed_for_possibly_invalid_spec().host; |
| if (host.len <= 0) |
| @@ -123,35 +133,37 @@ size_t RegistryControlledDomainService::GetRegistryLength( |
| return 0; |
| return GetRegistryLengthImpl( |
| std::string(gurl.possibly_invalid_spec().data() + host.begin, host.len), |
| - allow_unknown_registries); |
| + unknown_filter, |
| + private_filter); |
| } |
| // static |
| -size_t RegistryControlledDomainService::GetRegistryLength( |
| +size_t GetRegistryLength( |
| const std::string& host, |
| - bool allow_unknown_registries) { |
| + UnknownRegistryFilter unknown_filter, |
| + PrivateRegistryFilter private_filter) { |
| url_canon::CanonHostInfo host_info; |
| const std::string canon_host(CanonicalizeHost(host, &host_info)); |
| if (canon_host.empty()) |
| return std::string::npos; |
| if (host_info.IsIPAddress()) |
| return 0; |
| - return GetRegistryLengthImpl(canon_host, allow_unknown_registries); |
| + return GetRegistryLengthImpl(canon_host, unknown_filter, private_filter); |
| } |
| // static |
| -void RegistryControlledDomainService::UseFindDomainFunction( |
| - FindDomainPtr function) { |
| - find_domain_function_ = function ? function : Perfect_Hash::FindDomain; |
| +void SetFindDomainFunctionForTesting(FindDomainPtr function) { |
| + g_find_domain_function = function ? function : Perfect_Hash::FindDomain; |
|
Ryan Sleevi
2013/05/06 21:23:13
nit: This "conflicts" with line 66, in that if you
nyquist
2013/05/06 22:30:56
Done.
|
| } |
| -// static |
| -std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( |
| - const std::string& host) { |
| +//static |
| +std::string GetDomainAndRegistryImpl( |
| + const std::string& host, PrivateRegistryFilter private_filter) { |
| DCHECK(!host.empty()); |
| // Find the length of the registry for this host. |
| - const size_t registry_length = GetRegistryLengthImpl(host, true); |
| + const size_t registry_length = |
| + GetRegistryLengthImpl(host, INCLUDE_UNKNOWN_REGISTRIES, private_filter); |
| if ((registry_length == std::string::npos) || (registry_length == 0)) |
| return std::string(); // No registry. |
| // The "2" in this next line is 1 for the dot, plus a 1-char minimum preceding |
| @@ -172,9 +184,10 @@ std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( |
| return host.substr(dot + 1); |
| } |
| -size_t RegistryControlledDomainService::GetRegistryLengthImpl( |
| +size_t GetRegistryLengthImpl( |
| const std::string& host, |
| - bool allow_unknown_registries) { |
| + UnknownRegistryFilter unknown_filter, |
| + PrivateRegistryFilter private_filter) { |
| DCHECK(!host.empty()); |
| // Skip leading dots. |
| @@ -203,12 +216,15 @@ size_t RegistryControlledDomainService::GetRegistryLengthImpl( |
| while (1) { |
| const char* domain_str = host.data() + curr_start; |
| int domain_length = host_check_len - curr_start; |
| - const DomainRule* rule = find_domain_function_(domain_str, domain_length); |
| + const DomainRule* rule = g_find_domain_function(domain_str, domain_length); |
| // We need to compare the string after finding a match because the |
| // no-collisions of perfect hashing only refers to items in the set. Since |
| // we're searching for arbitrary domains, there could be collisions. |
| + // Furthermore, if the apparent match is a private registry and we're not |
| + // including those, it can't be an actual match. |
| if (rule && |
| + (private_filter == INCLUDE_PRIVATE_REGISTRIES || !rule->is_private) && |
| base::strncasecmp(domain_str, rule->name, domain_length) == 0) { |
| // Exception rules override wildcard rules when the domain is an exact |
| // match, but wildcards take precedence when there's a subdomain. |
| @@ -248,7 +264,9 @@ size_t RegistryControlledDomainService::GetRegistryLengthImpl( |
| // No rule found in the registry. curr_start now points to the first |
| // character of the last subcomponent of the host, so if we allow unknown |
| // registries, return the length of this subcomponent. |
| - return allow_unknown_registries ? (host.length() - curr_start) : 0; |
| + return unknown_filter == INCLUDE_UNKNOWN_REGISTRIES ? |
| + (host.length() - curr_start) : 0; |
| } |
| +} // namespace registry_controlled_domains |
| } // namespace net |