Index: chrome/browser/autocomplete/autocomplete_match.cc |
diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc |
index c20cf94ebaf14a65c80448cad534a235c0fccef4..2c9e58e167dc2121886b58a08915354845bd3816 100644 |
--- a/chrome/browser/autocomplete/autocomplete_match.cc |
+++ b/chrome/browser/autocomplete/autocomplete_match.cc |
@@ -342,18 +342,36 @@ bool AutocompleteMatch::IsSpecializedSearchType(Type type) { |
type == AutocompleteMatchType::SEARCH_SUGGEST_ANSWER; |
} |
-void AutocompleteMatch::ComputeStrippedDestinationURL( |
- TemplateURLService* template_url_service) { |
- stripped_destination_url = destination_url; |
- if (!stripped_destination_url.is_valid()) |
- return; |
+// static |
+TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword( |
+ TemplateURLService* template_url_service, |
+ const base::string16& keyword, |
+ const std::string& host) { |
+ if (template_url_service == NULL) |
+ return NULL; |
+ TemplateURL* template_url = keyword.empty() ? |
+ NULL : template_url_service->GetTemplateURLForKeyword(keyword); |
+ return (template_url || host.empty()) ? |
+ template_url : template_url_service->GetTemplateURLForHost(host); |
+} |
+ |
+// static |
+GURL AutocompleteMatch::GURLToStrippedGURL( |
+ const GURL& url, |
+ TemplateURLService* template_url_service, |
+ const base::string16& keyword) { |
+ if (!url.is_valid()) |
+ return url; |
+ |
+ GURL stripped_destination_url = url; |
// If the destination URL looks like it was generated from a TemplateURL, |
// remove all substitutions other than the search terms. This allows us |
// to eliminate cases like past search URLs from history that differ only |
// by some obscure query param from each other or from the search/keyword |
// provider matches. |
- TemplateURL* template_url = GetTemplateURL(template_url_service, true); |
+ TemplateURL* template_url = GetTemplateURLWithKeyword( |
+ template_url_service, keyword, stripped_destination_url.host()); |
if (template_url != NULL && |
template_url->SupportsReplacement( |
template_url_service->search_terms_data())) { |
@@ -396,6 +414,26 @@ void AutocompleteMatch::ComputeStrippedDestinationURL( |
if (needs_replacement) |
stripped_destination_url = stripped_destination_url.ReplaceComponents( |
replacements); |
+ return stripped_destination_url; |
+} |
+ |
+void AutocompleteMatch::ComputeStrippedDestinationURL( |
+ TemplateURLService* template_url_service) { |
+ stripped_destination_url = |
+ GURLToStrippedGURL(destination_url, template_url_service, keyword); |
+} |
+ |
+void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( |
+ const GURL& canonical_input_url, |
+ 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); |
+ allowed_to_be_default_match = |
+ stripped_canonical_input_url == stripped_destination_url; |
+ } |
} |
void AutocompleteMatch::GetKeywordUIState( |
@@ -424,15 +462,10 @@ base::string16 AutocompleteMatch::GetSubstitutingExplicitlyInvokedKeyword( |
TemplateURL* AutocompleteMatch::GetTemplateURL( |
TemplateURLService* template_url_service, |
bool allow_fallback_to_destination_host) const { |
- if (template_url_service == NULL) |
- return NULL; |
- TemplateURL* template_url = keyword.empty() ? NULL : |
- template_url_service->GetTemplateURLForKeyword(keyword); |
- if (template_url == NULL && allow_fallback_to_destination_host) { |
- template_url = template_url_service->GetTemplateURLForHost( |
- destination_url.host()); |
- } |
- return template_url; |
+ return GetTemplateURLWithKeyword( |
+ template_url_service, keyword, |
+ allow_fallback_to_destination_host ? |
+ destination_url.host() : std::string()); |
} |
void AutocompleteMatch::RecordAdditionalInfo(const std::string& property, |