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

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

Issue 113944: Use the new CanonicalizeHostVerbose() function. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: is_valid -> is_nonempty Created 11 years, 6 months 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
« no previous file with comments | « DEPS ('k') | chrome/browser/autocomplete/autocomplete_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // It's not clear that we can reach here with an empty "host" (maybe on some 157 // It's not clear that we can reach here with an empty "host" (maybe on some
158 // kinds of garbage input?), but if we did, it couldn't be a URL. 158 // kinds of garbage input?), but if we did, it couldn't be a URL.
159 if (!parts->host.is_nonempty()) 159 if (!parts->host.is_nonempty())
160 return QUERY; 160 return QUERY;
161 // (We use the registry length later below but ask for it here so we can check 161 // (We use the registry length later below but ask for it here so we can check
162 // the host's validity at this point.) 162 // the host's validity at this point.)
163 const std::wstring host(text.substr(parts->host.begin, parts->host.len)); 163 const std::wstring host(text.substr(parts->host.begin, parts->host.len));
164 const size_t registry_length = 164 const size_t registry_length =
165 net::RegistryControlledDomainService::GetRegistryLength(host, false); 165 net::RegistryControlledDomainService::GetRegistryLength(host, false);
166 if (registry_length == std::wstring::npos) 166 if (registry_length == std::wstring::npos)
167 return QUERY; // It's not clear to me that we can reach this... 167 return QUERY; // Could be a broken IP address, etc.
168 168
169 // A space in the "host" means this is a query. (Technically, IE and GURL 169 // A space in the "host" means this is a query. (Technically, IE and GURL
170 // allow hostnames with spaces for wierd intranet machines, but it's supposed 170 // allow hostnames with spaces for wierd intranet machines, but it's supposed
171 // to be illegal and I'm not worried about users trying to type these in.) 171 // to be illegal and I'm not worried about users trying to type these in.)
172 if (host.find(' ') != std::wstring::npos) 172 if (host.find(' ') != std::wstring::npos)
173 return QUERY; 173 return QUERY;
174 174
175 // Presence of a password/port mean this is almost certainly a URL. We don't 175 // Presence of a password/port mean this is almost certainly a URL. We don't
176 // treat usernames (without passwords) as indicating a URL, because this could 176 // treat usernames (without passwords) as indicating a URL, because this could
177 // be an email address like "user@mail.com" which is more likely a search than 177 // be an email address like "user@mail.com" which is more likely a search than
178 // an HTTP auth login attempt. 178 // an HTTP auth login attempt.
179 if (parts->password.is_nonempty() || parts->port.is_nonempty()) 179 if (parts->password.is_nonempty() || parts->port.is_nonempty())
180 return URL; 180 return URL;
181 181
182 // See if the host is an IP address. 182 // See if the host is an IP address.
183 bool is_ip_address; 183 url_canon::CanonHostInfo host_info;
184 const std::string canon_host(net::CanonicalizeHost(host, &is_ip_address)); 184 net::CanonicalizeHost(host, &host_info);
185 if (is_ip_address) { 185 if (host_info.family == url_canon::CanonHostInfo::IPV4) {
186 // If the user typed a valid IPv6 address, treat it as a URL.
187 if (canon_host[0] == '[')
188 return URL;
189
190 // If the user originally typed a host that looks like an IP address (a 186 // If the user originally typed a host that looks like an IP address (a
191 // dotted quad), they probably want to open it. If the original input was 187 // dotted quad), they probably want to open it. If the original input was
192 // something else (like a single number), they probably wanted to search for 188 // something else (like a single number), they probably wanted to search for
193 // it. This is true even if the URL appears to have a path: "1.2/45" is 189 // it. This is true even if the URL appears to have a path: "1.2/45" is
194 // more likely a search (for the answer to a math problem) than a URL. 190 // more likely a search (for the answer to a math problem) than a URL.
195 url_parse::Component components[4]; 191 if (host_info.num_ipv4_components == 4)
196 const bool found_ipv4 = 192 return URL;
197 url_canon::FindIPv4Components(WideToUTF8(text).c_str(), 193 return desired_tld.empty() ? UNKNOWN : REQUESTED_URL;
198 parts->host, components); 194 }
199 DCHECK(found_ipv4); 195
200 for (size_t i = 0; i < arraysize(components); ++i) { 196 if (host_info.family == url_canon::CanonHostInfo::IPV6) {
201 if (!components[i].is_nonempty()) 197 // If the user typed a valid bracketed IPv6 address, treat it as a URL.
202 return desired_tld.empty() ? UNKNOWN : REQUESTED_URL;
203 }
204 return URL; 198 return URL;
205 } 199 }
206 200
207 // The host doesn't look like a number, so see if the user's given us a path. 201 // The host doesn't look like a number, so see if the user's given us a path.
208 if (parts->path.is_nonempty()) { 202 if (parts->path.is_nonempty()) {
209 // Most inputs with paths are URLs, even ones without known registries (e.g. 203 // Most inputs with paths are URLs, even ones without known registries (e.g.
210 // intranet URLs). However, if there's no known registry, and the path has 204 // intranet URLs). However, if there's no known registry, and the path has
211 // a space, this is more likely a query with a slash in the first term (e.g. 205 // a space, this is more likely a query with a slash in the first term (e.g.
212 // "ps/2 games") than a URL. We can still open URLs with spaces in the path 206 // "ps/2 games") than a URL. We can still open URLs with spaces in the path
213 // by escaping the space, and we will still inline autocomplete them if 207 // by escaping the space, and we will still inline autocomplete them if
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 match.contents_class.push_back( 889 match.contents_class.push_back(
896 ACMatchClassification(keyword_offset + input_.text().size(), 890 ACMatchClassification(keyword_offset + input_.text().size(),
897 ACMatchClassification::NONE)); 891 ACMatchClassification::NONE));
898 } 892 }
899 match.destination_url = 893 match.destination_url =
900 HistoryUI::GetHistoryURLWithSearchText(input_.text()); 894 HistoryUI::GetHistoryURLWithSearchText(input_.text());
901 match.transition = PageTransition::AUTO_BOOKMARK; 895 match.transition = PageTransition::AUTO_BOOKMARK;
902 match.provider = history_contents_provider_; 896 match.provider = history_contents_provider_;
903 latest_result_.AddMatch(match); 897 latest_result_.AddMatch(match);
904 } 898 }
OLDNEW
« no previous file with comments | « DEPS ('k') | chrome/browser/autocomplete/autocomplete_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698