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