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.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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 std::string GetDomainAndRegistry(base::StringPiece host, | 196 std::string GetDomainAndRegistry(base::StringPiece host, |
197 PrivateRegistryFilter filter) { | 197 PrivateRegistryFilter filter) { |
198 url::CanonHostInfo host_info; | 198 url::CanonHostInfo host_info; |
199 const std::string canon_host(CanonicalizeHost(host, &host_info)); | 199 const std::string canon_host(CanonicalizeHost(host, &host_info)); |
200 if (canon_host.empty() || host_info.IsIPAddress()) | 200 if (canon_host.empty() || host_info.IsIPAddress()) |
201 return std::string(); | 201 return std::string(); |
202 return GetDomainAndRegistryImpl(canon_host, filter).as_string(); | 202 return GetDomainAndRegistryImpl(canon_host, filter).as_string(); |
203 } | 203 } |
204 | 204 |
| 205 bool SameHost(const GURL& gurl1, const GURL& gurl2) { |
| 206 const url::Component host1 = gurl1.parsed_for_possibly_invalid_spec().host; |
| 207 const url::Component host2 = gurl2.parsed_for_possibly_invalid_spec().host; |
| 208 if ((host1.len <= 0) || (host1.len != host2.len)) |
| 209 return false; |
| 210 return !strncmp(gurl1.possibly_invalid_spec().data() + host1.begin, |
| 211 gurl2.possibly_invalid_spec().data() + host2.begin, |
| 212 host1.len); |
| 213 } |
| 214 |
205 bool SameDomainOrHost( | 215 bool SameDomainOrHost( |
206 const GURL& gurl1, | 216 const GURL& gurl1, |
207 const GURL& gurl2, | 217 const GURL& gurl2, |
208 PrivateRegistryFilter filter) { | 218 PrivateRegistryFilter filter) { |
209 // See if both URLs have a known domain + registry, and those values are the | 219 // See if both URLs have a known domain + registry, and those values are the |
210 // same. | 220 // same. |
211 const base::StringPiece domain1 = | 221 const base::StringPiece domain1 = |
212 GetDomainAndRegistryAsStringPiece(gurl1, filter); | 222 GetDomainAndRegistryAsStringPiece(gurl1, filter); |
213 const base::StringPiece domain2 = | 223 const base::StringPiece domain2 = |
214 GetDomainAndRegistryAsStringPiece(gurl2, filter); | 224 GetDomainAndRegistryAsStringPiece(gurl2, filter); |
215 if (!domain1.empty() || !domain2.empty()) | 225 if (!domain1.empty() || !domain2.empty()) |
216 return domain1 == domain2; | 226 return domain1 == domain2; |
217 | 227 |
218 // No domains. See if the hosts are identical. | 228 // No domains. See if the hosts are identical. |
219 const url::Component host1 = gurl1.parsed_for_possibly_invalid_spec().host; | 229 return SameHost(gurl1, gurl2); |
220 const url::Component host2 = gurl2.parsed_for_possibly_invalid_spec().host; | |
221 if ((host1.len <= 0) || (host1.len != host2.len)) | |
222 return false; | |
223 return !strncmp(gurl1.possibly_invalid_spec().data() + host1.begin, | |
224 gurl2.possibly_invalid_spec().data() + host2.begin, | |
225 host1.len); | |
226 } | 230 } |
227 | 231 |
228 bool SameDomainOrHost(const url::Origin& origin1, | 232 bool SameDomainOrHost(const url::Origin& origin1, |
229 const url::Origin& origin2, | 233 const url::Origin& origin2, |
230 PrivateRegistryFilter filter) { | 234 PrivateRegistryFilter filter) { |
231 return SameDomainOrHost(GURL(origin1.Serialize()), GURL(origin2.Serialize()), | 235 return SameDomainOrHost(GURL(origin1.Serialize()), GURL(origin2.Serialize()), |
232 filter); | 236 filter); |
233 } | 237 } |
234 | 238 |
235 size_t GetRegistryLength( | 239 size_t GetRegistryLength( |
(...skipping 27 matching lines...) Expand all Loading... |
263 | 267 |
264 void SetFindDomainGraph(const unsigned char* domains, size_t length) { | 268 void SetFindDomainGraph(const unsigned char* domains, size_t length) { |
265 CHECK(domains); | 269 CHECK(domains); |
266 CHECK_NE(length, 0u); | 270 CHECK_NE(length, 0u); |
267 g_graph = domains; | 271 g_graph = domains; |
268 g_graph_length = length; | 272 g_graph_length = length; |
269 } | 273 } |
270 | 274 |
271 } // namespace registry_controlled_domains | 275 } // namespace registry_controlled_domains |
272 } // namespace net | 276 } // namespace net |
OLD | NEW |