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 f64d4bb93599a9b703725986b52cda50c27f3971..3ecf4706cc55dd8d62cbcd2a291c3f30dea69c8d 100644 |
| --- a/chrome/browser/autocomplete/autocomplete_match.cc |
| +++ b/chrome/browser/autocomplete/autocomplete_match.cc |
| @@ -358,11 +358,31 @@ bool AutocompleteMatch::IsSearchType(Type type) { |
| type == SEARCH_OTHER_ENGINE; |
| } |
| -void AutocompleteMatch::ComputeStrippedDestinationURL() { |
| +void AutocompleteMatch::ComputeStrippedDestinationURL(Profile* profile) { |
| stripped_destination_url = destination_url; |
| if (!stripped_destination_url.is_valid()) |
| return; |
| + // Attempt to normalize URL for de-dupping purpose by removing non-essential |
| + // term substitutions like aqs/oq/aq. |
|
Peter Kasting
2012/10/26 22:13:49
Nit: URL -> the URL, purpose -> purposes.
Don't r
Bart N.
2012/10/26 23:36:55
Done.
|
| + // We try to find a template URL using this match's keyword. If not found, |
| + // we pick a template that matches the destination URL's host. |
|
Peter Kasting
2012/10/26 22:13:49
Nit: This part can be omitted as it's documented i
Bart N.
2012/10/26 23:36:55
Done.
|
| + // Finally, we check if the template supports substitutions and if so, |
| + // we use it to generate a stripped destination URL. |
| + TemplateURL* template_url = GetTemplateURL(profile, true); |
| + if (template_url != NULL && template_url->SupportsReplacement()) { |
| + string16 search_terms; |
| + if (template_url->ExtractSearchTermsFromURL(stripped_destination_url, |
| + &search_terms)) { |
| + // Rewrite the URL by using the extracted search terms and ignoring other |
| + // arguments (it's OK, because it doesn't affect the destination URL and |
| + // is sufficient from de-dupping perspective). |
|
Peter Kasting
2012/10/26 22:13:49
Nit: I'd remove this comment entirely; the suggest
Bart N.
2012/10/26 23:36:55
Done.
|
| + stripped_destination_url = |
| + GURL(template_url->url_ref().ReplaceSearchTerms( |
| + TemplateURLRef::SearchTermsArgs(search_terms))); |
| + } |
| + } |
| + |
| // |replacements| keeps all the substitions we're going to make to |
| // from {destination_url} to {stripped_destination_url}. |need_replacement| |
| // is a helper variable that helps us keep track of whether we need |
| @@ -373,7 +393,7 @@ void AutocompleteMatch::ComputeStrippedDestinationURL() { |
| // Remove the www. prefix from the host. |
| static const char prefix[] = "www."; |
| static const size_t prefix_len = arraysize(prefix) - 1; |
| - std::string host = destination_url.host(); |
| + std::string host = stripped_destination_url.host(); |
| if (host.compare(0, prefix_len, prefix) == 0) { |
| host = host.substr(prefix_len); |
| replacements.SetHostStr(host); |
| @@ -389,7 +409,8 @@ void AutocompleteMatch::ComputeStrippedDestinationURL() { |
| } |
| if (needs_replacement) |
| - stripped_destination_url = destination_url.ReplaceComponents(replacements); |
| + stripped_destination_url = stripped_destination_url.ReplaceComponents( |
| + replacements); |
| } |
| void AutocompleteMatch::GetKeywordUIState(Profile* profile, |
| @@ -409,10 +430,21 @@ string16 AutocompleteMatch::GetSubstitutingExplicitlyInvokedKeyword( |
| } |
| TemplateURL* AutocompleteMatch::GetTemplateURL(Profile* profile) const { |
| + return GetTemplateURL(profile, false); |
| +} |
| + |
| +TemplateURL* AutocompleteMatch::GetTemplateURL(Profile* profile, |
| + bool use_host) const { |
| DCHECK(profile); |
| - return keyword.empty() ? NULL : |
| - TemplateURLServiceFactory::GetForProfile(profile)-> |
| - GetTemplateURLForKeyword(keyword); |
| + TemplateURLService* template_url_service = |
| + TemplateURLServiceFactory::GetForProfile(profile); |
| + TemplateURL* template_url = keyword.empty() ? NULL : |
| + template_url_service->GetTemplateURLForKeyword(keyword); |
| + if (use_host && template_url == NULL) { |
| + template_url = template_url_service->GetTemplateURLForHost( |
| + destination_url.host()); |
| + } |
| + return template_url; |
| } |
| void AutocompleteMatch::RecordAdditionalInfo(const std::string& property, |