| OLD | NEW |
| 1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
| 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 4 * | 4 * |
| 5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
| 6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
| 7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
| 8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
| 9 * | 9 * |
| 10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 * the provisions above, a recipient may use your version of this file under | 35 * the provisions above, a recipient may use your version of this file under |
| 36 * the terms of any one of the MPL, the GPL or the LGPL. | 36 * the terms of any one of the MPL, the GPL or the LGPL. |
| 37 * | 37 * |
| 38 * ***** END LICENSE BLOCK ***** */ | 38 * ***** END LICENSE BLOCK ***** */ |
| 39 | 39 |
| 40 #include "net/base/registry_controlled_domain.h" | 40 #include "net/base/registry_controlled_domain.h" |
| 41 | 41 |
| 42 #include "base/logging.h" | 42 #include "base/logging.h" |
| 43 #include "base/memory/singleton.h" | 43 #include "base/memory/singleton.h" |
| 44 #include "base/string_util.h" | 44 #include "base/string_util.h" |
| 45 #include "base/utf_string_conversions.h" |
| 45 #include "googleurl/src/gurl.h" | 46 #include "googleurl/src/gurl.h" |
| 46 #include "googleurl/src/url_parse.h" | 47 #include "googleurl/src/url_parse.h" |
| 47 #include "net/base/net_module.h" | 48 #include "net/base/net_module.h" |
| 48 #include "net/base/net_util.h" | 49 #include "net/base/net_util.h" |
| 49 | 50 |
| 50 #include "effective_tld_names.cc" | 51 #include "effective_tld_names.cc" |
| 51 | 52 |
| 52 namespace net { | 53 namespace net { |
| 53 | 54 |
| 54 namespace { | 55 namespace { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 75 std::string RegistryControlledDomainService::GetDomainAndRegistry( | 76 std::string RegistryControlledDomainService::GetDomainAndRegistry( |
| 76 const std::string& host) { | 77 const std::string& host) { |
| 77 url_canon::CanonHostInfo host_info; | 78 url_canon::CanonHostInfo host_info; |
| 78 const std::string canon_host(CanonicalizeHost(host, &host_info)); | 79 const std::string canon_host(CanonicalizeHost(host, &host_info)); |
| 79 if (canon_host.empty() || host_info.IsIPAddress()) | 80 if (canon_host.empty() || host_info.IsIPAddress()) |
| 80 return std::string(); | 81 return std::string(); |
| 81 return GetDomainAndRegistryImpl(canon_host); | 82 return GetDomainAndRegistryImpl(canon_host); |
| 82 } | 83 } |
| 83 | 84 |
| 84 // static | 85 // static |
| 85 std::string RegistryControlledDomainService::GetDomainAndRegistry( | |
| 86 const std::wstring& host) { | |
| 87 url_canon::CanonHostInfo host_info; | |
| 88 const std::string canon_host(CanonicalizeHost(host, &host_info)); | |
| 89 if (canon_host.empty() || host_info.IsIPAddress()) | |
| 90 return std::string(); | |
| 91 return GetDomainAndRegistryImpl(canon_host); | |
| 92 } | |
| 93 | |
| 94 // static | |
| 95 bool RegistryControlledDomainService::SameDomainOrHost(const GURL& gurl1, | 86 bool RegistryControlledDomainService::SameDomainOrHost(const GURL& gurl1, |
| 96 const GURL& gurl2) { | 87 const GURL& gurl2) { |
| 97 // See if both URLs have a known domain + registry, and those values are the | 88 // See if both URLs have a known domain + registry, and those values are the |
| 98 // same. | 89 // same. |
| 99 const std::string domain1(GetDomainAndRegistry(gurl1)); | 90 const std::string domain1(GetDomainAndRegistry(gurl1)); |
| 100 const std::string domain2(GetDomainAndRegistry(gurl2)); | 91 const std::string domain2(GetDomainAndRegistry(gurl2)); |
| 101 if (!domain1.empty() || !domain2.empty()) | 92 if (!domain1.empty() || !domain2.empty()) |
| 102 return domain1 == domain2; | 93 return domain1 == domain2; |
| 103 | 94 |
| 104 // No domains. See if the hosts are identical. | 95 // No domains. See if the hosts are identical. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 const std::string canon_host(CanonicalizeHost(host, &host_info)); | 127 const std::string canon_host(CanonicalizeHost(host, &host_info)); |
| 137 if (canon_host.empty()) | 128 if (canon_host.empty()) |
| 138 return std::string::npos; | 129 return std::string::npos; |
| 139 if (host_info.IsIPAddress()) | 130 if (host_info.IsIPAddress()) |
| 140 return 0; | 131 return 0; |
| 141 return GetInstance()->GetRegistryLengthImpl(canon_host, | 132 return GetInstance()->GetRegistryLengthImpl(canon_host, |
| 142 allow_unknown_registries); | 133 allow_unknown_registries); |
| 143 } | 134 } |
| 144 | 135 |
| 145 // static | 136 // static |
| 146 size_t RegistryControlledDomainService::GetRegistryLength( | |
| 147 const std::wstring& host, | |
| 148 bool allow_unknown_registries) { | |
| 149 url_canon::CanonHostInfo host_info; | |
| 150 const std::string canon_host(CanonicalizeHost(host, &host_info)); | |
| 151 if (canon_host.empty()) | |
| 152 return std::string::npos; | |
| 153 if (host_info.IsIPAddress()) | |
| 154 return 0; | |
| 155 return GetInstance()->GetRegistryLengthImpl(canon_host, | |
| 156 allow_unknown_registries); | |
| 157 } | |
| 158 | |
| 159 // static | |
| 160 RegistryControlledDomainService* RegistryControlledDomainService::GetInstance() | 137 RegistryControlledDomainService* RegistryControlledDomainService::GetInstance() |
| 161 { | 138 { |
| 162 if (test_instance_) | 139 if (test_instance_) |
| 163 return test_instance_; | 140 return test_instance_; |
| 164 | 141 |
| 165 return Singleton<RegistryControlledDomainService>::get(); | 142 return Singleton<RegistryControlledDomainService>::get(); |
| 166 } | 143 } |
| 167 | 144 |
| 168 RegistryControlledDomainService::RegistryControlledDomainService() | 145 RegistryControlledDomainService::RegistryControlledDomainService() |
| 169 : find_domain_function_(Perfect_Hash::FindDomain) { | 146 : find_domain_function_(Perfect_Hash::FindDomain) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 next_dot = host.find('.', curr_start); | 262 next_dot = host.find('.', curr_start); |
| 286 } | 263 } |
| 287 | 264 |
| 288 // No rule found in the registry. curr_start now points to the first | 265 // No rule found in the registry. curr_start now points to the first |
| 289 // character of the last subcomponent of the host, so if we allow unknown | 266 // character of the last subcomponent of the host, so if we allow unknown |
| 290 // registries, return the length of this subcomponent. | 267 // registries, return the length of this subcomponent. |
| 291 return allow_unknown_registries ? (host.length() - curr_start) : 0; | 268 return allow_unknown_registries ? (host.length() - curr_start) : 0; |
| 292 } | 269 } |
| 293 | 270 |
| 294 } // namespace net | 271 } // namespace net |
| OLD | NEW |