Index: components/omnibox/autocomplete_input.cc |
diff --git a/components/omnibox/autocomplete_input.cc b/components/omnibox/autocomplete_input.cc |
index 30af0d2ca87b02b20da811f07f041ad44b72eeab..f13c2e95c36a152e3f2b7689f60d546d61e81143 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,30 @@ void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, |
*cursor_position = 0; |
} |
+// Finds all terms in |text| that start with http:// or https:// and puts the |
+// text after the prefix in |http_following_terms|. Each term has to include |
+// at least one additional character after the prefix. |
Peter Kasting
2015/06/09 20:36:39
Nit: Could say "...or https:// plus at least one m
Mark P
2015/06/10 23:38:34
Done.
|
+void PopulateHttpTerms(const base::string16& text, |
Peter Kasting
2015/06/09 20:36:38
Nit: If you change the member name, change this to
Mark P
2015/06/10 23:38:34
Selected PopulateTermsPrefixedByScheme().
|
+ std::vector<base::string16>* http_following_terms) { |
+ const base::string16& http_scheme = |
Peter Kasting
2015/06/09 20:36:38
Rather than converting these to string16s, I think
Mark P
2015/06/10 23:38:34
I don't like this idea. Everywhere in the autocom
Peter Kasting
2015/06/11 00:07:38
This isn't an intentional pattern. The intentiona
Mark P
2015/06/11 22:11:41
Okay, I did it. Easy enough.
|
+ base::UTF8ToUTF16(url::kHttpScheme) + |
+ base::UTF8ToUTF16(url::kStandardSchemeSeparator); |
+ const base::string16& https_scheme = |
+ base::UTF8ToUTF16(url::kHttpsScheme) + |
+ base::UTF8ToUTF16(url::kStandardSchemeSeparator); |
+ std::vector<base::string16> words; |
Peter Kasting
2015/06/09 20:36:38
Nit: words -> terms (for consistency)?
Mark P
2015/06/10 23:38:34
Done.
|
+ base::SplitString(text, ' ', &words); |
Peter Kasting
2015/06/09 20:36:38
Nit: Consider a comment about why we don't use ICU
Mark P
2015/06/10 23:38:34
Done.
|
+ for (auto it : words) { |
Peter Kasting
2015/06/09 20:36:38
Nit: const auto&, to avoid a copy
Mark P
2015/06/10 23:38:34
Done.
|
+ if (StartsWith(it, http_scheme, false) && |
Peter Kasting
2015/06/09 20:36:38
Nit: This is shorter overall and no less efficient
Mark P
2015/06/10 23:38:34
Done. (well, the string16 version of the above)
|
+ (it.length() > http_scheme.length())) { |
+ http_following_terms->push_back(it.substr(http_scheme.length())); |
+ } else if (StartsWith(it, https_scheme, false) && |
+ (it.length() > https_scheme.length())) { |
+ http_following_terms->push_back(it.substr(https_scheme.length())); |
+ } |
+ } |
+} |
+ |
} // namespace |
AutocompleteInput::AutocompleteInput() |
@@ -72,6 +97,7 @@ AutocompleteInput::AutocompleteInput( |
GURL canonicalized_url; |
type_ = Parse(text_, desired_tld, scheme_classifier, &parts_, &scheme_, |
&canonicalized_url); |
+ PopulateHttpTerms(text_, &http_following_terms_); |
if (type_ == metrics::OmniboxInputType::INVALID) |
return; |
@@ -532,4 +558,5 @@ void AutocompleteInput::Clear() { |
prefer_keyword_ = false; |
allow_exact_keyword_match_ = false; |
want_asynchronous_matches_ = true; |
+ http_following_terms_.clear(); |
} |