OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/omnibox/browser/autocomplete_input.h" | 5 #include "components/omnibox/browser/autocomplete_input.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 const base::string16& text, | 148 const base::string16& text, |
149 const std::string& desired_tld, | 149 const std::string& desired_tld, |
150 const AutocompleteSchemeClassifier& scheme_classifier, | 150 const AutocompleteSchemeClassifier& scheme_classifier, |
151 url::Parsed* parts, | 151 url::Parsed* parts, |
152 base::string16* scheme, | 152 base::string16* scheme, |
153 GURL* canonicalized_url) { | 153 GURL* canonicalized_url) { |
154 size_t first_non_white = text.find_first_not_of(base::kWhitespaceUTF16, 0); | 154 size_t first_non_white = text.find_first_not_of(base::kWhitespaceUTF16, 0); |
155 if (first_non_white == base::string16::npos) | 155 if (first_non_white == base::string16::npos) |
156 return metrics::OmniboxInputType::INVALID; // All whitespace. | 156 return metrics::OmniboxInputType::INVALID; // All whitespace. |
157 | 157 |
158 // Treat input that beings with a colon as a query. Otherwise the URL | |
Peter Kasting
2016/09/29 04:54:12
Nit: begins
| |
159 // formatter will attempt to fix it by prepending a scheme, which the user | |
160 // probably did not want if they explicitly typed a colon at the beginning. | |
161 if (text[first_non_white] == ':') | |
162 return metrics::OmniboxInputType::QUERY; | |
Peter Kasting
2016/09/29 04:54:12
It would be nice to avoid doing this check here, a
| |
163 | |
158 // Ask our parsing back-end to help us understand what the user typed. We | 164 // Ask our parsing back-end to help us understand what the user typed. We |
159 // use the URLFixerUpper here because we want to be smart about what we | 165 // use the URLFixerUpper here because we want to be smart about what we |
160 // consider a scheme. For example, we shouldn't consider www.google.com:80 | 166 // consider a scheme. For example, we shouldn't consider www.google.com:80 |
161 // to have a scheme. | 167 // to have a scheme. |
162 url::Parsed local_parts; | 168 url::Parsed local_parts; |
163 if (!parts) | 169 if (!parts) |
164 parts = &local_parts; | 170 parts = &local_parts; |
165 const base::string16 parsed_scheme(url_formatter::SegmentURL(text, parts)); | 171 const base::string16 parsed_scheme(url_formatter::SegmentURL(text, parts)); |
166 if (scheme) | 172 if (scheme) |
167 *scheme = parsed_scheme; | 173 *scheme = parsed_scheme; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 // the option of treating it as a URL if we're wrong. | 253 // the option of treating it as a URL if we're wrong. |
248 // Note that SegmentURL() is smart so we aren't tricked by "c:\foo" or | 254 // Note that SegmentURL() is smart so we aren't tricked by "c:\foo" or |
249 // "www.example.com:81" in this case. | 255 // "www.example.com:81" in this case. |
250 return metrics::OmniboxInputType::UNKNOWN; | 256 return metrics::OmniboxInputType::UNKNOWN; |
251 } | 257 } |
252 | 258 |
253 // Either the user didn't type a scheme, in which case we need to distinguish | 259 // Either the user didn't type a scheme, in which case we need to distinguish |
254 // between an HTTP URL and a query, or the scheme is HTTP or HTTPS, in which | 260 // between an HTTP URL and a query, or the scheme is HTTP or HTTPS, in which |
255 // case we should reject invalid formulations. | 261 // case we should reject invalid formulations. |
256 | 262 |
257 // If we have an empty host it can't be a valid HTTP[S] URL. (This should | |
258 // only trigger for input that begins with a colon, which GURL will parse as a | |
259 // valid, non-standard URL; for standard URLs, an empty host would have | |
260 // resulted in an invalid |canonicalized_url| above.) | |
261 if (!canonicalized_url->has_host()) | |
262 return metrics::OmniboxInputType::QUERY; | |
263 | |
264 // Determine the host family. We get this information by (re-)canonicalizing | 263 // Determine the host family. We get this information by (re-)canonicalizing |
265 // the already-canonicalized host rather than using the user's original input, | 264 // the already-canonicalized host rather than using the user's original input, |
266 // in case fixup affected the result here (e.g. an input that looks like an | 265 // in case fixup affected the result here (e.g. an input that looks like an |
267 // IPv4 address but with a non-empty desired TLD would return IPV4 before | 266 // IPv4 address but with a non-empty desired TLD would return IPV4 before |
268 // fixup and NEUTRAL afterwards, and we want to treat it as NEUTRAL). | 267 // fixup and NEUTRAL afterwards, and we want to treat it as NEUTRAL). |
269 url::CanonHostInfo host_info; | 268 url::CanonHostInfo host_info; |
270 net::CanonicalizeHost(canonicalized_url->host(), &host_info); | 269 net::CanonicalizeHost(canonicalized_url->host(), &host_info); |
271 | 270 |
272 // Check if the canonicalized host has a known TLD, which we'll want to know | 271 // Check if the canonicalized host has a known TLD, which we'll want to know |
273 // below. | 272 // below. |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 parts_ = url::Parsed(); | 525 parts_ = url::Parsed(); |
527 scheme_.clear(); | 526 scheme_.clear(); |
528 canonicalized_url_ = GURL(); | 527 canonicalized_url_ = GURL(); |
529 prevent_inline_autocomplete_ = false; | 528 prevent_inline_autocomplete_ = false; |
530 prefer_keyword_ = false; | 529 prefer_keyword_ = false; |
531 allow_exact_keyword_match_ = false; | 530 allow_exact_keyword_match_ = false; |
532 want_asynchronous_matches_ = true; | 531 want_asynchronous_matches_ = true; |
533 from_omnibox_focus_ = false; | 532 from_omnibox_focus_ = false; |
534 terms_prefixed_by_http_or_https_.clear(); | 533 terms_prefixed_by_http_or_https_.clear(); |
535 } | 534 } |
OLD | NEW |