Index: components/omnibox/autocomplete_match.cc |
diff --git a/components/omnibox/autocomplete_match.cc b/components/omnibox/autocomplete_match.cc |
index d19f8e9b56031961555e2f2db05fc075080bfaa3..efaf6829a609ed589d5851ae70e0a47244b31000 100644 |
--- a/components/omnibox/autocomplete_match.cc |
+++ b/components/omnibox/autocomplete_match.cc |
@@ -26,6 +26,26 @@ bool IsTrivialClassification(const ACMatchClassifications& classifications) { |
(classifications.back().style == ACMatchClassification::NONE)); |
} |
+// Returns true if one of the |http_following_terms| matches the beginning of |
+// the URL (sans scheme). (Recall that |http_following_terms|, for the input |
+// "http://a b" will be ["a"].) This suggests that the user wants a particular |
+// URL with a scheme in mind, hence the caller should not consider another URL |
+// like this one but with a different scheme to be a duplicate. |
+bool WordMatchesURLContent( |
+ const std::vector<base::string16>& http_following_terms, |
+ const GURL& url) { |
+ const base::string16& url_spec_without_scheme_as_utf16 = |
Peter Kasting
2015/06/09 20:36:39
If you follow my suggestion in autocomplete_input.
Mark P
2015/06/10 23:38:35
Acknowledged, but not relevant given my earlier pr
|
+ base::UTF8ToUTF16(url.spec().substr( |
+ url.scheme().length() + |
+ std::string(url::kStandardSchemeSeparator).length())); |
+ for (auto it : http_following_terms) { |
Peter Kasting
2015/06/09 20:36:39
Nit: const auto&, to avoid a copy
Mark P
2015/06/10 23:38:35
Done.
BTW, also renamed "it" to "term".
|
+ if (StartsWith(url_spec_without_scheme_as_utf16, it, false)) { |
Peter Kasting
2015/06/09 20:36:39
Nit: No {}
Mark P
2015/06/10 23:38:35
Done.
|
+ return true; |
+ } |
+ } |
+ return false; |
+} |
+ |
} // namespace |
// AutocompleteMatch ---------------------------------------------------------- |
@@ -370,6 +390,7 @@ TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword( |
// static |
GURL AutocompleteMatch::GURLToStrippedGURL( |
const GURL& url, |
+ const AutocompleteInput& input, |
TemplateURLService* template_url_service, |
const base::string16& keyword) { |
if (!url.is_valid()) |
@@ -415,8 +436,10 @@ GURL AutocompleteMatch::GURLToStrippedGURL( |
needs_replacement = true; |
} |
- // Replace https protocol with http protocol. |
- if (stripped_destination_url.SchemeIs(url::kHttpsScheme)) { |
+ // Replace https protocol with http, as long as the user didn't explicitly |
+ // specify one of the two. |
+ if (!WordMatchesURLContent(input.http_following_terms(), url) && |
+ stripped_destination_url.SchemeIs(url::kHttpsScheme)) { |
Peter Kasting
2015/06/09 20:36:39
Nit: For efficiency, reverse these subexpressions;
Mark P
2015/06/10 23:38:35
Good idea. Done.
|
replacements.SetScheme(url::kHttpScheme, |
url::Component(0, strlen(url::kHttpScheme))); |
needs_replacement = true; |
@@ -429,19 +452,21 @@ GURL AutocompleteMatch::GURLToStrippedGURL( |
} |
void AutocompleteMatch::ComputeStrippedDestinationURL( |
+ const AutocompleteInput& input, |
TemplateURLService* template_url_service) { |
- stripped_destination_url = |
- GURLToStrippedGURL(destination_url, template_url_service, keyword); |
+ stripped_destination_url = GURLToStrippedGURL( |
+ destination_url, input, template_url_service, keyword); |
} |
void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( |
- const GURL& canonical_input_url, |
+ const AutocompleteInput& input, |
TemplateURLService* template_url_service) { |
if (!allowed_to_be_default_match) { |
const GURL& stripped_canonical_input_url = |
AutocompleteMatch::GURLToStrippedGURL( |
- canonical_input_url, template_url_service, base::string16()); |
- ComputeStrippedDestinationURL(template_url_service); |
+ input.canonicalized_url(), input, template_url_service, |
+ base::string16()); |
+ ComputeStrippedDestinationURL(input, template_url_service); |
allowed_to_be_default_match = |
stripped_canonical_input_url == stripped_destination_url; |
} |