Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/autocomplete/autocomplete.cc

Issue 353010: Better handling of UNKNOWN versus QUERY in a couple ways.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (registry_length == std::wstring::npos) 175 if (registry_length == std::wstring::npos)
176 return QUERY; // Could be a broken IP address, etc. 176 return QUERY; // Could be a broken IP address, etc.
177 177
178 // See if the hostname is valid. While IE and GURL allow hostnames to contain 178 // See if the hostname is valid. While IE and GURL allow hostnames to contain
179 // many other characters (perhaps for weird intranet machines), it's extremely 179 // many other characters (perhaps for weird intranet machines), it's extremely
180 // unlikely that a user would be trying to type those in for anything other 180 // unlikely that a user would be trying to type those in for anything other
181 // than a search query. 181 // than a search query.
182 url_canon::CanonHostInfo host_info; 182 url_canon::CanonHostInfo host_info;
183 const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); 183 const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info));
184 if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) && 184 if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) &&
185 !net::IsCanonicalizedHostCompliant(canonicalized_host)) 185 !net::IsCanonicalizedHostCompliant(canonicalized_host)) {
186 return QUERY; 186 // Invalid hostname. There are several possible cases:
187 // * Our checker is too strict and the user pasted in a real-world URL
188 // that's "invalid" but resolves. To catch these, we return UNKNOWN when
189 // the user explicitly typed a scheme, so we'll still search by default
190 // but we'll show the accidental search infobar if necessary.
191 // * The user is typing a multi-word query. If we see a space anywhere in
192 // the hostname we assume this is a search and return QUERY.
193 // * Our checker is too strict and the user is typing a real-world hostname
194 // that's "invalid" but resolves. We return UNKNOWN if the TLD is known.
195 // Note that we explicitly excluded hosts with spaces above so that
196 // "toys at amazon.com" will be treated as a search.
197 // * The user is typing some garbage string. Return QUERY.
198 //
199 // Thus we fall down in the following cases:
200 // * Trying to navigate to a hostname with spaces
201 // * Trying to navigate to a hostname with invalid characters and an unknown
202 // TLD
203 // These are rare, though probably possible in intranets.
204 return (parts->scheme.is_nonempty() ||
205 ((registry_length != 0) && (host.find(' ') == std::wstring::npos))) ?
206 UNKNOWN : QUERY;
207 }
187 208
188 // Presence of a port means this is likely a URL, if the port is really a port 209 // Presence of a port means this is likely a URL, if the port is really a port
189 // number. If it's just garbage after a colon, this is a query. 210 // number. If it's just garbage after a colon, this is a query.
190 if (parts->port.is_nonempty()) { 211 if (parts->port.is_nonempty()) {
191 int port; 212 int port;
192 return (StringToInt(WideToUTF16( 213 return (StringToInt(WideToUTF16(
193 text.substr(parts->port.begin, parts->port.len)), &port) && 214 text.substr(parts->port.begin, parts->port.len)), &port) &&
194 (port >= 0) && (port <= 65535)) ? URL : QUERY; 215 (port >= 0) && (port <= 65535)) ? URL : QUERY;
195 } 216 }
196 217
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 void AutocompleteController::CheckIfDone() { 962 void AutocompleteController::CheckIfDone() {
942 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); 963 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end();
943 ++i) { 964 ++i) {
944 if (!(*i)->done()) { 965 if (!(*i)->done()) {
945 done_ = false; 966 done_ = false;
946 return; 967 return;
947 } 968 }
948 } 969 }
949 done_ = true; 970 done_ = true;
950 } 971 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698