Index: components/omnibox/autocomplete_input.cc |
diff --git a/components/omnibox/autocomplete_input.cc b/components/omnibox/autocomplete_input.cc |
index 30af0d2ca87b02b20da811f07f041ad44b72eeab..1e13c970764ad915cd1248acd6679c806d9bf98d 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,35 @@ 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 PopulateTermsPrefixedByScheme( |
+ const base::string16& text, |
+ std::vector<base::string16>* terms_prefixed_by_http_or_https) { |
Peter Kasting
2015/06/11 05:21:44
Nit: Call this |terms_prefixed_by_scheme| to match
Mark P
2015/06/11 22:11:41
I'd rather the increase in precision of http_or_ht
|
+ base::string16 kPrefixes[2] = { |
Peter Kasting
2015/06/11 05:21:44
Even if you were to stick with string16 (which I d
Mark P
2015/06/11 22:11:41
Acknowledged. Now obsolete.
|
+ base::UTF8ToUTF16(url::kHttpScheme) + |
+ base::UTF8ToUTF16(url::kStandardSchemeSeparator), |
+ base::UTF8ToUTF16(url::kHttpsScheme) + |
+ base::UTF8ToUTF16(url::kStandardSchemeSeparator) |
+ }; |
+ std::vector<base::string16> terms; |
+ // Split on whitespace rather than use ICU's word iterator because, for |
+ // examples, ICU's iterator may break on punctuation (such as ://) or decide |
Peter Kasting
2015/06/11 05:21:44
Nit: example
Mark P
2015/06/11 22:11:41
Done.
|
+ // to split a single term in a hostname (if it seems to think that the |
+ // hostname is multiple words). Neither of these behaviors are desirable. |
Peter Kasting
2015/06/11 05:21:44
Nit: are -> is ("neither" is singular)
Mark P
2015/06/11 22:11:41
Done.
|
+ base::SplitString(text, ' ', &terms); |
+ for (const auto& term : terms) { |
+ for (const auto& prefix : kPrefixes) { |
+ if (StartsWith(term, prefix, false) && |
+ (term.length() > prefix.length())) { |
+ terms_prefixed_by_http_or_https->push_back( |
+ term.substr(prefix.length())); |
+ } |
+ } |
+ } |
+} |
+ |
} // namespace |
AutocompleteInput::AutocompleteInput() |
@@ -72,6 +102,7 @@ AutocompleteInput::AutocompleteInput( |
GURL canonicalized_url; |
type_ = Parse(text_, desired_tld, scheme_classifier, &parts_, &scheme_, |
&canonicalized_url); |
+ PopulateTermsPrefixedByScheme(text_, &terms_prefixed_by_http_or_https_); |
if (type_ == metrics::OmniboxInputType::INVALID) |
return; |
@@ -532,4 +563,5 @@ void AutocompleteInput::Clear() { |
prefer_keyword_ = false; |
allow_exact_keyword_match_ = false; |
want_asynchronous_matches_ = true; |
+ terms_prefixed_by_http_or_https_.clear(); |
} |