Chromium Code Reviews| Index: components/omnibox/autocomplete_input.cc |
| diff --git a/components/omnibox/autocomplete_input.cc b/components/omnibox/autocomplete_input.cc |
| index a7de192d764b2c9f3c70ca3efa560e3cf7bfcb0b..8bf4acd4bd1a3c69bc1d7ece258dc0d6f5896dde 100644 |
| --- a/components/omnibox/autocomplete_input.cc |
| +++ b/components/omnibox/autocomplete_input.cc |
| @@ -4,6 +4,7 @@ |
| #include "components/omnibox/autocomplete_input.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "components/metrics/proto/omnibox_event.pb.h" |
| @@ -30,6 +31,32 @@ void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, |
| *cursor_position = 0; |
| } |
| +// Finds all terms in |text| that start with http:// or https:// plus at least |
| +// one more character and puts the text after the prefix in |
| +// |terms_prefixed_by_http_or_https|. |
| +void PopulateTermsPrefixedByHttpOrHttps( |
| + const std::string& text, |
| + std::vector<std::string>* terms_prefixed_by_http_or_https) { |
| + std::vector<std::string> terms; |
| + // Split on whitespace rather than use ICU's word iterator because, for |
| + // example, ICU's iterator may break on punctuation (such as ://) or decide |
| + // to split a single term in a hostname (if it seems to think that the |
| + // hostname is multiple words). Neither of these behaviors is desirable. |
| + base::SplitString(text, ' ', &terms); |
| + const std::string separator(url::kStandardSchemeSeparator); |
| + for (const auto& term : terms) { |
| + static const char* kSchemes[2] = { url::kHttpScheme, url::kHttpsScheme }; |
| + for (const char* scheme : kSchemes) { |
| + const std::string prefix(scheme + separator); |
| + if (base::StartsWithASCII(term, prefix, false) && |
|
brettw
2015/06/22 17:54:01
Can you use the new versions? I want to delete the
Mark P
2015/06/22 17:59:36
Done.
|
| + (term.length() > prefix.length())) { |
| + terms_prefixed_by_http_or_https->push_back( |
| + term.substr(prefix.length())); |
| + } |
| + } |
| + } |
| +} |
| + |
| } // namespace |
| AutocompleteInput::AutocompleteInput() |
| @@ -76,6 +103,8 @@ AutocompleteInput::AutocompleteInput( |
| GURL canonicalized_url; |
| type_ = Parse(text_, desired_tld, scheme_classifier, &parts_, &scheme_, |
| &canonicalized_url); |
| + PopulateTermsPrefixedByHttpOrHttps(base::UTF16ToUTF8(text_), |
| + &terms_prefixed_by_http_or_https_); |
| if (type_ == metrics::OmniboxInputType::INVALID) |
| return; |
| @@ -538,4 +567,5 @@ void AutocompleteInput::Clear() { |
| allow_exact_keyword_match_ = false; |
| want_asynchronous_matches_ = true; |
| from_omnibox_focus_ = false; |
| + terms_prefixed_by_http_or_https_.clear(); |
| } |