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 #include "components/url_formatter/url_fixer.h" | 5 #include "components/url_formatter/url_fixer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // Invalid file URL, just return the input. | 194 // Invalid file URL, just return the input. |
195 return text; | 195 return text; |
196 } | 196 } |
197 | 197 |
198 // Checks |domain| to see if a valid TLD is already present. If not, appends | 198 // Checks |domain| to see if a valid TLD is already present. If not, appends |
199 // |desired_tld| to the domain, and prepends "www." unless it's already present. | 199 // |desired_tld| to the domain, and prepends "www." unless it's already present. |
200 void AddDesiredTLD(const std::string& desired_tld, std::string* domain) { | 200 void AddDesiredTLD(const std::string& desired_tld, std::string* domain) { |
201 if (desired_tld.empty() || domain->empty()) | 201 if (desired_tld.empty() || domain->empty()) |
202 return; | 202 return; |
203 | 203 |
204 // Check the TLD. If the return value is positive, we already have a TLD, so | 204 // Abort if we already have a known TLD. In the case of an invalid host, |
205 // abort. If the return value is std::string::npos, there's no valid host, | 205 // HostHasRegistryControlledDomain will return false and we will try to |
206 // but we can try to append a TLD anyway, since the host may become valid once | 206 // append a TLD (which may make it valid). For example, "999999999999" is |
207 // the TLD is attached -- for example, "999999999999" is detected as a broken | 207 // detected as a broken IP address and marked invalid, but attaching ".com" |
208 // IP address and marked invalid, but attaching ".com" makes it legal. When | 208 // makes it legal. We disallow unknown registries here so users can input |
209 // the return value is 0, there's a valid host with no known TLD, so we can | 209 // "mail.yahoo" and hit ctrl-enter to get "www.mail.yahoo.com". |
210 // definitely append the user's TLD. We disallow unknown registries here so | 210 if (net::registry_controlled_domains::HostHasRegistryControlledDomain( |
211 // users can input "mail.yahoo" and hit ctrl-enter to get | |
212 // "www.mail.yahoo.com". | |
213 const size_t registry_length = | |
214 net::registry_controlled_domains::GetRegistryLength( | |
215 *domain, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 211 *domain, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
216 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 212 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)) |
217 if ((registry_length != 0) && (registry_length != std::string::npos)) | |
218 return; | 213 return; |
219 | 214 |
220 // Add the suffix at the end of the domain. | 215 // Add the suffix at the end of the domain. |
221 const size_t domain_length(domain->length()); | 216 const size_t domain_length(domain->length()); |
222 DCHECK_GT(domain_length, 0U); | 217 DCHECK_GT(domain_length, 0U); |
223 DCHECK_NE(desired_tld[0], '.'); | 218 DCHECK_NE(desired_tld[0], '.'); |
224 if ((*domain)[domain_length - 1] != '.') | 219 if ((*domain)[domain_length - 1] != '.') |
225 domain->push_back('.'); | 220 domain->push_back('.'); |
226 domain->append(desired_tld); | 221 domain->append(desired_tld); |
227 | 222 |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 } | 673 } |
679 | 674 |
680 bool IsEquivalentScheme(const std::string& scheme1, | 675 bool IsEquivalentScheme(const std::string& scheme1, |
681 const std::string& scheme2) { | 676 const std::string& scheme2) { |
682 return scheme1 == scheme2 || | 677 return scheme1 == scheme2 || |
683 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || | 678 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || |
684 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); | 679 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); |
685 } | 680 } |
686 | 681 |
687 } // namespace url_formatter | 682 } // namespace url_formatter |
OLD | NEW |