Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete_match.cc |
| diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc |
| index 9a3d13c2705d99b78554b734701d63d0a2e052f2..19d74593c69d321ed364493ae900e0b589d7914c 100644 |
| --- a/chrome/browser/autocomplete/autocomplete_match.cc |
| +++ b/chrome/browser/autocomplete/autocomplete_match.cc |
| @@ -342,18 +342,38 @@ 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 : |
|
Peter Kasting
2014/07/09 00:46:43
Nit: Break after '?' instead of ':'
Mark P
2014/07/09 19:54:17
Done.
|
| + template_url_service->GetTemplateURLForKeyword(keyword); |
| + if (template_url == NULL && !host.empty()) { |
|
Peter Kasting
2014/07/09 00:46:43
Nit: No {}
Simpler:
return (template_url || ho
Mark P
2014/07/09 19:54:17
Okay. Done.
|
| + template_url = template_url_service->GetTemplateURLForHost(host); |
| + } |
| + return template_url; |
| +} |
| + |
| +// 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 +416,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 +464,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, |