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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 gurl.parsed_for_possibly_invalid_spec().host; | 56 gurl.parsed_for_possibly_invalid_spec().host; |
57 if ((host.len <= 0) || gurl.HostIsIPAddress()) | 57 if ((host.len <= 0) || gurl.HostIsIPAddress()) |
58 return std::string(); | 58 return std::string(); |
59 return GetDomainAndRegistryImpl(std::string( | 59 return GetDomainAndRegistryImpl(std::string( |
60 gurl.possibly_invalid_spec().data() + host.begin, host.len)); | 60 gurl.possibly_invalid_spec().data() + host.begin, host.len)); |
61 } | 61 } |
62 | 62 |
63 // static | 63 // static |
64 std::string RegistryControlledDomainService::GetDomainAndRegistry( | 64 std::string RegistryControlledDomainService::GetDomainAndRegistry( |
65 const std::string& host) { | 65 const std::string& host) { |
66 bool is_ip_address; | 66 url_canon::CanonHostInfo host_info; |
67 const std::string canon_host(net::CanonicalizeHost(host, &is_ip_address)); | 67 const std::string canon_host(net::CanonicalizeHost(host, &host_info)); |
68 if (canon_host.empty() || is_ip_address) | 68 if (canon_host.empty() || host_info.IsIPAddress()) |
69 return std::string(); | 69 return std::string(); |
70 return GetDomainAndRegistryImpl(canon_host); | 70 return GetDomainAndRegistryImpl(canon_host); |
71 } | 71 } |
72 | 72 |
73 // static | 73 // static |
74 std::string RegistryControlledDomainService::GetDomainAndRegistry( | 74 std::string RegistryControlledDomainService::GetDomainAndRegistry( |
75 const std::wstring& host) { | 75 const std::wstring& host) { |
76 bool is_ip_address; | 76 url_canon::CanonHostInfo host_info; |
77 const std::string canon_host(net::CanonicalizeHost(host, &is_ip_address)); | 77 const std::string canon_host(net::CanonicalizeHost(host, &host_info)); |
78 if (canon_host.empty() || is_ip_address) | 78 if (canon_host.empty() || host_info.IsIPAddress()) |
79 return std::string(); | 79 return std::string(); |
80 return GetDomainAndRegistryImpl(canon_host); | 80 return GetDomainAndRegistryImpl(canon_host); |
81 } | 81 } |
82 | 82 |
83 // static | 83 // static |
84 bool RegistryControlledDomainService::SameDomainOrHost(const GURL& gurl1, | 84 bool RegistryControlledDomainService::SameDomainOrHost(const GURL& gurl1, |
85 const GURL& gurl2) { | 85 const GURL& gurl2) { |
86 // See if both URLs have a known domain + registry, and those values are the | 86 // See if both URLs have a known domain + registry, and those values are the |
87 // same. | 87 // same. |
88 const std::string domain1(GetDomainAndRegistry(gurl1)); | 88 const std::string domain1(GetDomainAndRegistry(gurl1)); |
(...skipping 25 matching lines...) Expand all Loading... |
114 return 0; | 114 return 0; |
115 return GetInstance()->GetRegistryLengthImpl( | 115 return GetInstance()->GetRegistryLengthImpl( |
116 std::string(gurl.possibly_invalid_spec().data() + host.begin, host.len), | 116 std::string(gurl.possibly_invalid_spec().data() + host.begin, host.len), |
117 allow_unknown_registries); | 117 allow_unknown_registries); |
118 } | 118 } |
119 | 119 |
120 // static | 120 // static |
121 size_t RegistryControlledDomainService::GetRegistryLength( | 121 size_t RegistryControlledDomainService::GetRegistryLength( |
122 const std::string& host, | 122 const std::string& host, |
123 bool allow_unknown_registries) { | 123 bool allow_unknown_registries) { |
124 bool is_ip_address; | 124 url_canon::CanonHostInfo host_info; |
125 const std::string canon_host(net::CanonicalizeHost(host, &is_ip_address)); | 125 const std::string canon_host(net::CanonicalizeHost(host, &host_info)); |
126 if (canon_host.empty()) | 126 if (canon_host.empty()) |
127 return std::string::npos; | 127 return std::string::npos; |
128 if (is_ip_address) | 128 if (host_info.IsIPAddress()) |
129 return 0; | 129 return 0; |
130 return GetInstance()->GetRegistryLengthImpl(canon_host, | 130 return GetInstance()->GetRegistryLengthImpl(canon_host, |
131 allow_unknown_registries); | 131 allow_unknown_registries); |
132 } | 132 } |
133 | 133 |
134 // static | 134 // static |
135 size_t RegistryControlledDomainService::GetRegistryLength( | 135 size_t RegistryControlledDomainService::GetRegistryLength( |
136 const std::wstring& host, | 136 const std::wstring& host, |
137 bool allow_unknown_registries) { | 137 bool allow_unknown_registries) { |
138 bool is_ip_address; | 138 url_canon::CanonHostInfo host_info; |
139 const std::string canon_host(net::CanonicalizeHost(host, &is_ip_address)); | 139 const std::string canon_host(net::CanonicalizeHost(host, &host_info)); |
140 if (canon_host.empty()) | 140 if (canon_host.empty()) |
141 return std::string::npos; | 141 return std::string::npos; |
142 if (is_ip_address) | 142 if (host_info.IsIPAddress()) |
143 return 0; | 143 return 0; |
144 return GetInstance()->GetRegistryLengthImpl(canon_host, | 144 return GetInstance()->GetRegistryLengthImpl(canon_host, |
145 allow_unknown_registries); | 145 allow_unknown_registries); |
146 } | 146 } |
147 | 147 |
148 // static | 148 // static |
149 std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( | 149 std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( |
150 const std::string& host) { | 150 const std::string& host) { |
151 DCHECK(!host.empty()); | 151 DCHECK(!host.empty()); |
152 | 152 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 // and an exception (ex *.google.com and !google.com). Sets are immutable, | 309 // and an exception (ex *.google.com and !google.com). Sets are immutable, |
310 // we'll erase the old one, and insert a new one with the new attributes. | 310 // we'll erase the old one, and insert a new one with the new attributes. |
311 rule.attributes.Combine(prev_rule->attributes); | 311 rule.attributes.Combine(prev_rule->attributes); |
312 domain_set_.erase(prev_rule); | 312 domain_set_.erase(prev_rule); |
313 } | 313 } |
314 | 314 |
315 domain_set_.insert(rule); | 315 domain_set_.insert(rule); |
316 } | 316 } |
317 | 317 |
318 } // namespace net | 318 } // namespace net |
OLD | NEW |