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/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/metrics/proto/omnibox_event.pb.h" | 10 #include "components/metrics/proto/omnibox_event.pb.h" |
11 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" | 11 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" |
12 #include "components/omnibox/browser/omnibox_field_trial.h" | 12 #include "components/omnibox/browser/omnibox_field_trial.h" |
13 #include "components/url_formatter/url_fixer.h" | 13 #include "components/url_fixer/url_fixer.h" |
14 #include "components/url_formatter/url_formatter.h" | |
15 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 15 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
17 #include "url/url_canon_ip.h" | 16 #include "url/url_canon_ip.h" |
18 #include "url/url_util.h" | 17 #include "url/url_util.h" |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 // Hardcode constant to avoid any dependencies on content/. | 21 // Hardcode constant to avoid any dependencies on content/. |
23 const char kViewSourceScheme[] = "view-source"; | 22 const char kViewSourceScheme[] = "view-source"; |
24 | 23 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return metrics::OmniboxInputType::FORCED_QUERY; | 181 return metrics::OmniboxInputType::FORCED_QUERY; |
183 } | 182 } |
184 | 183 |
185 // Ask our parsing back-end to help us understand what the user typed. We | 184 // Ask our parsing back-end to help us understand what the user typed. We |
186 // use the URLFixerUpper here because we want to be smart about what we | 185 // use the URLFixerUpper here because we want to be smart about what we |
187 // consider a scheme. For example, we shouldn't consider www.google.com:80 | 186 // consider a scheme. For example, we shouldn't consider www.google.com:80 |
188 // to have a scheme. | 187 // to have a scheme. |
189 url::Parsed local_parts; | 188 url::Parsed local_parts; |
190 if (!parts) | 189 if (!parts) |
191 parts = &local_parts; | 190 parts = &local_parts; |
192 const base::string16 parsed_scheme(url_formatter::SegmentURL(text, parts)); | 191 const base::string16 parsed_scheme(url_fixer::SegmentURL(text, parts)); |
193 if (scheme) | 192 if (scheme) |
194 *scheme = parsed_scheme; | 193 *scheme = parsed_scheme; |
195 const std::string parsed_scheme_utf8(base::UTF16ToUTF8(parsed_scheme)); | 194 const std::string parsed_scheme_utf8(base::UTF16ToUTF8(parsed_scheme)); |
196 | 195 |
197 // If we can't canonicalize the user's input, the rest of the autocomplete | 196 // If we can't canonicalize the user's input, the rest of the autocomplete |
198 // system isn't going to be able to produce a navigable URL match for it. | 197 // system isn't going to be able to produce a navigable URL match for it. |
199 // So we just return QUERY immediately in these cases. | 198 // So we just return QUERY immediately in these cases. |
200 GURL placeholder_canonicalized_url; | 199 GURL placeholder_canonicalized_url; |
201 if (!canonicalized_url) | 200 if (!canonicalized_url) |
202 canonicalized_url = &placeholder_canonicalized_url; | 201 canonicalized_url = &placeholder_canonicalized_url; |
203 *canonicalized_url = | 202 *canonicalized_url = |
204 url_formatter::FixupURL(base::UTF16ToUTF8(text), desired_tld); | 203 url_fixer::FixupURL(base::UTF16ToUTF8(text), desired_tld); |
205 if (!canonicalized_url->is_valid()) | 204 if (!canonicalized_url->is_valid()) |
206 return metrics::OmniboxInputType::QUERY; | 205 return metrics::OmniboxInputType::QUERY; |
207 | 206 |
208 if (base::LowerCaseEqualsASCII(parsed_scheme_utf8, url::kFileScheme)) { | 207 if (base::LowerCaseEqualsASCII(parsed_scheme_utf8, url::kFileScheme)) { |
209 // A user might or might not type a scheme when entering a file URL. In | 208 // A user might or might not type a scheme when entering a file URL. In |
210 // either case, |parsed_scheme_utf8| will tell us that this is a file URL, | 209 // either case, |parsed_scheme_utf8| will tell us that this is a file URL, |
211 // but |parts->scheme| might be empty, e.g. if the user typed "C:\foo". | 210 // but |parts->scheme| might be empty, e.g. if the user typed "C:\foo". |
212 return metrics::OmniboxInputType::URL; | 211 return metrics::OmniboxInputType::URL; |
213 } | 212 } |
214 | 213 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 url::Component* components[] = { | 248 url::Component* components[] = { |
250 &http_parts.username, | 249 &http_parts.username, |
251 &http_parts.password, | 250 &http_parts.password, |
252 &http_parts.host, | 251 &http_parts.host, |
253 &http_parts.port, | 252 &http_parts.port, |
254 &http_parts.path, | 253 &http_parts.path, |
255 &http_parts.query, | 254 &http_parts.query, |
256 &http_parts.ref, | 255 &http_parts.ref, |
257 }; | 256 }; |
258 for (size_t i = 0; i < arraysize(components); ++i) { | 257 for (size_t i = 0; i < arraysize(components); ++i) { |
259 url_formatter::OffsetComponent( | 258 url_fixer::OffsetComponent( |
260 -static_cast<int>(http_scheme_prefix.length()), components[i]); | 259 -static_cast<int>(http_scheme_prefix.length()), components[i]); |
261 } | 260 } |
262 | 261 |
263 *parts = http_parts; | 262 *parts = http_parts; |
264 if (scheme) | 263 if (scheme) |
265 scheme->clear(); | 264 scheme->clear(); |
266 *canonicalized_url = http_canonicalized_url; | 265 *canonicalized_url = http_canonicalized_url; |
267 | 266 |
268 return metrics::OmniboxInputType::URL; | 267 return metrics::OmniboxInputType::URL; |
269 } | 268 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { | 497 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { |
499 *host = parts.inner_parsed()->host; | 498 *host = parts.inner_parsed()->host; |
500 } | 499 } |
501 } | 500 } |
502 | 501 |
503 // static | 502 // static |
504 base::string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 503 base::string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
505 const GURL& url, | 504 const GURL& url, |
506 const base::string16& formatted_url, | 505 const base::string16& formatted_url, |
507 const AutocompleteSchemeClassifier& scheme_classifier) { | 506 const AutocompleteSchemeClassifier& scheme_classifier) { |
508 if (!url_formatter::CanStripTrailingSlash(url)) | 507 if (!net::CanStripTrailingSlash(url)) |
509 return formatted_url; | 508 return formatted_url; |
510 const base::string16 url_with_path(formatted_url + base::char16('/')); | 509 const base::string16 url_with_path(formatted_url + base::char16('/')); |
511 return (AutocompleteInput::Parse(formatted_url, std::string(), | 510 return (AutocompleteInput::Parse(formatted_url, std::string(), |
512 scheme_classifier, NULL, NULL, NULL) == | 511 scheme_classifier, NULL, NULL, NULL) == |
513 AutocompleteInput::Parse(url_with_path, std::string(), | 512 AutocompleteInput::Parse(url_with_path, std::string(), |
514 scheme_classifier, NULL, NULL, NULL)) ? | 513 scheme_classifier, NULL, NULL, NULL)) ? |
515 formatted_url : url_with_path; | 514 formatted_url : url_with_path; |
516 } | 515 } |
517 | 516 |
518 // static | 517 // static |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 parts_ = url::Parsed(); | 564 parts_ = url::Parsed(); |
566 scheme_.clear(); | 565 scheme_.clear(); |
567 canonicalized_url_ = GURL(); | 566 canonicalized_url_ = GURL(); |
568 prevent_inline_autocomplete_ = false; | 567 prevent_inline_autocomplete_ = false; |
569 prefer_keyword_ = false; | 568 prefer_keyword_ = false; |
570 allow_exact_keyword_match_ = false; | 569 allow_exact_keyword_match_ = false; |
571 want_asynchronous_matches_ = true; | 570 want_asynchronous_matches_ = true; |
572 from_omnibox_focus_ = false; | 571 from_omnibox_focus_ = false; |
573 terms_prefixed_by_http_or_https_.clear(); | 572 terms_prefixed_by_http_or_https_.clear(); |
574 } | 573 } |
OLD | NEW |