Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/autocomplete/autocomplete.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 if (!parts->host.is_nonempty()) | 161 if (!parts->host.is_nonempty()) |
| 162 return QUERY; | 162 return QUERY; |
| 163 // (We use the registry length later below but ask for it here so we can check | 163 // (We use the registry length later below but ask for it here so we can check |
| 164 // the host's validity at this point.) | 164 // the host's validity at this point.) |
| 165 const std::wstring host(text.substr(parts->host.begin, parts->host.len)); | 165 const std::wstring host(text.substr(parts->host.begin, parts->host.len)); |
| 166 const size_t registry_length = | 166 const size_t registry_length = |
| 167 net::RegistryControlledDomainService::GetRegistryLength(host, false); | 167 net::RegistryControlledDomainService::GetRegistryLength(host, false); |
| 168 if (registry_length == std::wstring::npos) | 168 if (registry_length == std::wstring::npos) |
| 169 return QUERY; // Could be a broken IP address, etc. | 169 return QUERY; // Could be a broken IP address, etc. |
| 170 | 170 |
| 171 // A space in the "host" means this is a query. (Technically, IE and GURL | 171 // See if the hostname is valid per RFC 1738. While IE and GURL allow |
| 172 // allow hostnames with spaces for wierd intranet machines, but it's supposed | 172 // hostnames to contain many other characters (perhaps for weird intranet |
| 173 // to be illegal and I'm not worried about users trying to type these in.) | 173 // machines), it's extremely unlikely that a user would be trying to type |
| 174 if (host.find(' ') != std::wstring::npos) | 174 // those in for anything other than a search query. |
| 175 url_canon::CanonHostInfo host_info; | |
| 176 const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); | |
| 177 if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) && | |
| 178 !net::IsCanonicalizedHostRFC1738Compliant(canonicalized_host)) | |
| 175 return QUERY; | 179 return QUERY; |
| 176 | 180 |
| 177 // Presence of a password/port mean this is almost certainly a URL. We don't | 181 // Presence of a port means this is likely a URL, if the port is really a port |
| 178 // treat usernames (without passwords) as indicating a URL, because this could | 182 // number. If it's just garbage after a colon, this is a query. |
| 179 // be an email address like "user@mail.com" which is more likely a search than | 183 if (parts->port.is_nonempty()) { |
| 180 // an HTTP auth login attempt. | 184 int port; |
| 181 if (parts->password.is_nonempty() || parts->port.is_nonempty()) | 185 return (StringToInt(WideToUTF16( |
| 186 text.substr(parts->port.begin, parts->port.len)), &port) && | |
| 187 (port >= 0) && (port <= 65535)) ? URL : QUERY; | |
|
Peter Kasting
2009/10/16 01:54:10
I know you will hate this, but it doesn't really l
| |
| 188 } | |
| 189 | |
| 190 // Presence of a password means this is likely a URL. We don't treat | |
| 191 // usernames (without passwords) as indicating a URL, because this could be an | |
| 192 // email address like "user@mail.com" which is more likely a search than an | |
| 193 // HTTP auth login attempt. | |
| 194 if (parts->password.is_nonempty()) | |
| 182 return URL; | 195 return URL; |
| 183 | 196 |
| 184 // See if the host is an IP address. | 197 // See if the host is an IP address. |
| 185 url_canon::CanonHostInfo host_info; | |
| 186 net::CanonicalizeHost(host, &host_info); | |
| 187 if (host_info.family == url_canon::CanonHostInfo::IPV4) { | 198 if (host_info.family == url_canon::CanonHostInfo::IPV4) { |
| 188 // If the user originally typed a host that looks like an IP address (a | 199 // If the user originally typed a host that looks like an IP address (a |
| 189 // dotted quad), they probably want to open it. If the original input was | 200 // dotted quad), they probably want to open it. If the original input was |
| 190 // something else (like a single number), they probably wanted to search for | 201 // something else (like a single number), they probably wanted to search for |
| 191 // it. This is true even if the URL appears to have a path: "1.2/45" is | 202 // it. This is true even if the URL appears to have a path: "1.2/45" is |
| 192 // more likely a search (for the answer to a math problem) than a URL. | 203 // more likely a search (for the answer to a math problem) than a URL. |
| 193 if (host_info.num_ipv4_components == 4) | 204 if (host_info.num_ipv4_components == 4) |
| 194 return URL; | 205 return URL; |
| 195 return desired_tld.empty() ? UNKNOWN : REQUESTED_URL; | 206 return desired_tld.empty() ? UNKNOWN : REQUESTED_URL; |
| 196 } | 207 } |
| 197 | 208 if (host_info.family == url_canon::CanonHostInfo::IPV6) |
| 198 if (host_info.family == url_canon::CanonHostInfo::IPV6) { | |
| 199 // If the user typed a valid bracketed IPv6 address, treat it as a URL. | |
| 200 return URL; | 209 return URL; |
| 201 } | |
| 202 | 210 |
| 203 // The host doesn't look like a number, so see if the user's given us a path. | 211 // The host doesn't look like a number, so see if the user's given us a path. |
| 204 if (parts->path.is_nonempty()) { | 212 if (parts->path.is_nonempty()) { |
| 205 // Most inputs with paths are URLs, even ones without known registries (e.g. | 213 // Most inputs with paths are URLs, even ones without known registries (e.g. |
| 206 // intranet URLs). However, if there's no known registry, and the path has | 214 // intranet URLs). However, if there's no known registry, and the path has |
| 207 // a space, this is more likely a query with a slash in the first term (e.g. | 215 // a space, this is more likely a query with a slash in the first term (e.g. |
| 208 // "ps/2 games") than a URL. We can still open URLs with spaces in the path | 216 // "ps/2 games") than a URL. We can still open URLs with spaces in the path |
| 209 // by escaping the space, and we will still inline autocomplete them if | 217 // by escaping the space, and we will still inline autocomplete them if |
| 210 // users have typed them in the past, but we default to searching since | 218 // users have typed them in the past, but we default to searching since |
| 211 // that's the common case. | 219 // that's the common case. |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 void AutocompleteController::CheckIfDone() { | 927 void AutocompleteController::CheckIfDone() { |
| 920 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 928 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
| 921 ++i) { | 929 ++i) { |
| 922 if (!(*i)->done()) { | 930 if (!(*i)->done()) { |
| 923 done_ = false; | 931 done_ = false; |
| 924 return; | 932 return; |
| 925 } | 933 } |
| 926 } | 934 } |
| 927 done_ = true; | 935 done_ = true; |
| 928 } | 936 } |
| OLD | NEW |