| 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/autocomplete_input.h" | 5 #include "components/omnibox/autocomplete_input.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/metrics/proto/omnibox_event.pb.h" | 9 #include "components/metrics/proto/omnibox_event.pb.h" |
| 10 #include "components/omnibox/autocomplete_scheme_classifier.h" | 10 #include "components/omnibox/autocomplete_scheme_classifier.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // system isn't going to be able to produce a navigable URL match for it. | 162 // system isn't going to be able to produce a navigable URL match for it. |
| 163 // So we just return QUERY immediately in these cases. | 163 // So we just return QUERY immediately in these cases. |
| 164 GURL placeholder_canonicalized_url; | 164 GURL placeholder_canonicalized_url; |
| 165 if (!canonicalized_url) | 165 if (!canonicalized_url) |
| 166 canonicalized_url = &placeholder_canonicalized_url; | 166 canonicalized_url = &placeholder_canonicalized_url; |
| 167 *canonicalized_url = | 167 *canonicalized_url = |
| 168 url_fixer::FixupURL(base::UTF16ToUTF8(text), desired_tld); | 168 url_fixer::FixupURL(base::UTF16ToUTF8(text), desired_tld); |
| 169 if (!canonicalized_url->is_valid()) | 169 if (!canonicalized_url->is_valid()) |
| 170 return metrics::OmniboxInputType::QUERY; | 170 return metrics::OmniboxInputType::QUERY; |
| 171 | 171 |
| 172 if (LowerCaseEqualsASCII(parsed_scheme_utf8, url::kFileScheme)) { | 172 if (base::LowerCaseEqualsASCII(parsed_scheme_utf8, url::kFileScheme)) { |
| 173 // A user might or might not type a scheme when entering a file URL. In | 173 // A user might or might not type a scheme when entering a file URL. In |
| 174 // either case, |parsed_scheme_utf8| will tell us that this is a file URL, | 174 // either case, |parsed_scheme_utf8| will tell us that this is a file URL, |
| 175 // but |parts->scheme| might be empty, e.g. if the user typed "C:\foo". | 175 // but |parts->scheme| might be empty, e.g. if the user typed "C:\foo". |
| 176 return metrics::OmniboxInputType::URL; | 176 return metrics::OmniboxInputType::URL; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it | 179 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it |
| 180 // well enough that we can fall through to the heuristics below. If it's | 180 // well enough that we can fall through to the heuristics below. If it's |
| 181 // something else, we can just determine our action based on what we do with | 181 // something else, we can just determine our action based on what we do with |
| 182 // any input of this scheme. In theory we could do better with some schemes | 182 // any input of this scheme. In theory we could do better with some schemes |
| 183 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that | 183 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that |
| 184 // until I run into some cases that really need it. | 184 // until I run into some cases that really need it. |
| 185 if (parts->scheme.is_nonempty() && | 185 if (parts->scheme.is_nonempty() && |
| 186 !LowerCaseEqualsASCII(parsed_scheme_utf8, url::kHttpScheme) && | 186 !base::LowerCaseEqualsASCII(parsed_scheme_utf8, url::kHttpScheme) && |
| 187 !LowerCaseEqualsASCII(parsed_scheme_utf8, url::kHttpsScheme)) { | 187 !base::LowerCaseEqualsASCII(parsed_scheme_utf8, url::kHttpsScheme)) { |
| 188 metrics::OmniboxInputType::Type type = | 188 metrics::OmniboxInputType::Type type = |
| 189 scheme_classifier.GetInputTypeForScheme(parsed_scheme_utf8); | 189 scheme_classifier.GetInputTypeForScheme(parsed_scheme_utf8); |
| 190 if (type != metrics::OmniboxInputType::INVALID) | 190 if (type != metrics::OmniboxInputType::INVALID) |
| 191 return type; | 191 return type; |
| 192 | 192 |
| 193 // We don't know about this scheme. It might be that the user typed a | 193 // We don't know about this scheme. It might be that the user typed a |
| 194 // URL of the form "username:password@foo.com". | 194 // URL of the form "username:password@foo.com". |
| 195 const base::string16 http_scheme_prefix = | 195 const base::string16 http_scheme_prefix = |
| 196 base::ASCIIToUTF16(std::string(url::kHttpScheme) + | 196 base::ASCIIToUTF16(std::string(url::kHttpScheme) + |
| 197 url::kStandardSchemeSeparator); | 197 url::kStandardSchemeSeparator); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 url::Parsed parts; | 428 url::Parsed parts; |
| 429 base::string16 scheme_str; | 429 base::string16 scheme_str; |
| 430 Parse(text, std::string(), scheme_classifier, &parts, &scheme_str, NULL); | 430 Parse(text, std::string(), scheme_classifier, &parts, &scheme_str, NULL); |
| 431 | 431 |
| 432 *scheme = parts.scheme; | 432 *scheme = parts.scheme; |
| 433 *host = parts.host; | 433 *host = parts.host; |
| 434 | 434 |
| 435 int after_scheme_and_colon = parts.scheme.end() + 1; | 435 int after_scheme_and_colon = parts.scheme.end() + 1; |
| 436 // For the view-source scheme, we should emphasize the scheme and host of the | 436 // For the view-source scheme, we should emphasize the scheme and host of the |
| 437 // URL qualified by the view-source prefix. | 437 // URL qualified by the view-source prefix. |
| 438 if (LowerCaseEqualsASCII(scheme_str, kViewSourceScheme) && | 438 if (base::LowerCaseEqualsASCII(scheme_str, kViewSourceScheme) && |
| 439 (static_cast<int>(text.length()) > after_scheme_and_colon)) { | 439 (static_cast<int>(text.length()) > after_scheme_and_colon)) { |
| 440 // Obtain the URL prefixed by view-source and parse it. | 440 // Obtain the URL prefixed by view-source and parse it. |
| 441 base::string16 real_url(text.substr(after_scheme_and_colon)); | 441 base::string16 real_url(text.substr(after_scheme_and_colon)); |
| 442 url::Parsed real_parts; | 442 url::Parsed real_parts; |
| 443 AutocompleteInput::Parse(real_url, std::string(), scheme_classifier, | 443 AutocompleteInput::Parse(real_url, std::string(), scheme_classifier, |
| 444 &real_parts, NULL, NULL); | 444 &real_parts, NULL, NULL); |
| 445 if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { | 445 if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { |
| 446 if (real_parts.scheme.is_nonempty()) { | 446 if (real_parts.scheme.is_nonempty()) { |
| 447 *scheme = url::Component( | 447 *scheme = url::Component( |
| 448 after_scheme_and_colon + real_parts.scheme.begin, | 448 after_scheme_and_colon + real_parts.scheme.begin, |
| 449 real_parts.scheme.len); | 449 real_parts.scheme.len); |
| 450 } else { | 450 } else { |
| 451 scheme->reset(); | 451 scheme->reset(); |
| 452 } | 452 } |
| 453 if (real_parts.host.is_nonempty()) { | 453 if (real_parts.host.is_nonempty()) { |
| 454 *host = url::Component(after_scheme_and_colon + real_parts.host.begin, | 454 *host = url::Component(after_scheme_and_colon + real_parts.host.begin, |
| 455 real_parts.host.len); | 455 real_parts.host.len); |
| 456 } else { | 456 } else { |
| 457 host->reset(); | 457 host->reset(); |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 } else if (LowerCaseEqualsASCII(scheme_str, url::kFileSystemScheme) && | 460 } else if (base::LowerCaseEqualsASCII(scheme_str, url::kFileSystemScheme) && |
| 461 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { | 461 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { |
| 462 *host = parts.inner_parsed()->host; | 462 *host = parts.inner_parsed()->host; |
| 463 } | 463 } |
| 464 } | 464 } |
| 465 | 465 |
| 466 // static | 466 // static |
| 467 base::string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 467 base::string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 468 const GURL& url, | 468 const GURL& url, |
| 469 const base::string16& formatted_url, | 469 const base::string16& formatted_url, |
| 470 const AutocompleteSchemeClassifier& scheme_classifier) { | 470 const AutocompleteSchemeClassifier& scheme_classifier) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 current_page_classification_ = metrics::OmniboxEventProto::INVALID_SPEC; | 526 current_page_classification_ = metrics::OmniboxEventProto::INVALID_SPEC; |
| 527 type_ = metrics::OmniboxInputType::INVALID; | 527 type_ = metrics::OmniboxInputType::INVALID; |
| 528 parts_ = url::Parsed(); | 528 parts_ = url::Parsed(); |
| 529 scheme_.clear(); | 529 scheme_.clear(); |
| 530 canonicalized_url_ = GURL(); | 530 canonicalized_url_ = GURL(); |
| 531 prevent_inline_autocomplete_ = false; | 531 prevent_inline_autocomplete_ = false; |
| 532 prefer_keyword_ = false; | 532 prefer_keyword_ = false; |
| 533 allow_exact_keyword_match_ = false; | 533 allow_exact_keyword_match_ = false; |
| 534 want_asynchronous_matches_ = true; | 534 want_asynchronous_matches_ = true; |
| 535 } | 535 } |
| OLD | NEW |