Index: components/omnibox/autocomplete_input.cc |
diff --git a/components/omnibox/autocomplete_input.cc b/components/omnibox/autocomplete_input.cc |
index 30af0d2ca87b02b20da811f07f041ad44b72eeab..6e33da69958f4ce3fa4bcd590a4ea6530ee872c1 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" |
@@ -29,6 +30,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 (StartsWithASCII(term, prefix, false) && |
Mark P
2015/06/12 20:23:20
This can still be a StartsWithASCII, right?
Or may
Peter Kasting
2015/06/15 20:47:16
No, this can still be StartsWithASCII().
Mark P
2015/06/15 23:37:17
Acknowledged.
|
+ (term.length() > prefix.length())) { |
+ terms_prefixed_by_http_or_https->push_back( |
+ term.substr(prefix.length())); |
+ } |
+ } |
+ } |
+} |
+ |
} // namespace |
AutocompleteInput::AutocompleteInput() |
@@ -72,6 +99,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; |
@@ -532,4 +561,5 @@ void AutocompleteInput::Clear() { |
prefer_keyword_ = false; |
allow_exact_keyword_match_ = false; |
want_asynchronous_matches_ = true; |
+ terms_prefixed_by_http_or_https_.clear(); |
} |