diff options
Diffstat (limited to 'chrome/browser/autocomplete/keyword_provider.cc')
-rw-r--r-- | chrome/browser/autocomplete/keyword_provider.cc | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc index f6487a6..c2759dd 100644 --- a/chrome/browser/autocomplete/keyword_provider.cc +++ b/chrome/browser/autocomplete/keyword_provider.cc @@ -415,55 +415,6 @@ int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, 1450 : 1100; } -// static -void KeywordProvider::FillInURLAndContents(const string16& remaining_input, - const TemplateURL* element, - AutocompleteMatch* match) { - DCHECK(!element->short_name().empty()); - const TemplateURLRef& element_ref = element->url_ref(); - DCHECK(element_ref.IsValid()); - int message_id = element->IsExtensionKeyword() ? - IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH; - if (remaining_input.empty()) { - // Allow extension keyword providers to accept empty string input. This is - // useful to allow extensions to do something in the case where no input is - // entered. - if (element_ref.SupportsReplacement() && !element->IsExtensionKeyword()) { - // No query input; return a generic, no-destination placeholder. - match->contents.assign( - l10n_util::GetStringFUTF16(message_id, - element->AdjustedShortNameForLocaleDirection(), - l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))); - match->contents_class.push_back( - ACMatchClassification(0, ACMatchClassification::DIM)); - } else { - // Keyword that has no replacement text (aka a shorthand for a URL). - match->destination_url = GURL(element->url()); - match->contents.assign(element->short_name()); - AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), - match->contents.length(), ACMatchClassification::NONE, - &match->contents_class); - } - } else { - // Create destination URL by escaping user input and substituting into - // keyword template URL. The escaping here handles whitespace in user - // input, but we rely on later canonicalization functions to do more - // fixup to make the URL valid if necessary. - DCHECK(element_ref.SupportsReplacement()); - match->destination_url = GURL(element_ref.ReplaceSearchTerms( - TemplateURLRef::SearchTermsArgs(remaining_input))); - std::vector<size_t> content_param_offsets; - match->contents.assign(l10n_util::GetStringFUTF16(message_id, - element->short_name(), - remaining_input, - &content_param_offsets)); - DCHECK_EQ(2U, content_param_offsets.size()); - AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], - remaining_input.length(), match->contents.length(), - ACMatchClassification::NONE, &match->contents_class); - } -} - AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( const TemplateURL* template_url, const AutocompleteInput& input, @@ -512,6 +463,57 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( return match; } +void KeywordProvider::FillInURLAndContents(const string16& remaining_input, + const TemplateURL* element, + AutocompleteMatch* match) const { + DCHECK(!element->short_name().empty()); + const TemplateURLRef& element_ref = element->url_ref(); + DCHECK(element_ref.IsValid()); + int message_id = element->IsExtensionKeyword() ? + IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH; + if (remaining_input.empty()) { + // Allow extension keyword providers to accept empty string input. This is + // useful to allow extensions to do something in the case where no input is + // entered. + if (element_ref.SupportsReplacement() && !element->IsExtensionKeyword()) { + // No query input; return a generic, no-destination placeholder. + match->contents.assign( + l10n_util::GetStringFUTF16(message_id, + element->AdjustedShortNameForLocaleDirection(), + l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))); + match->contents_class.push_back( + ACMatchClassification(0, ACMatchClassification::DIM)); + } else { + // Keyword that has no replacement text (aka a shorthand for a URL). + match->destination_url = GURL(element->url()); + match->contents.assign(element->short_name()); + AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), + match->contents.length(), ACMatchClassification::NONE, + &match->contents_class); + } + } else { + // Create destination URL by escaping user input and substituting into + // keyword template URL. The escaping here handles whitespace in user + // input, but we rely on later canonicalization functions to do more + // fixup to make the URL valid if necessary. + DCHECK(element_ref.SupportsReplacement()); + TemplateURLRef::SearchTermsArgs search_terms_args(remaining_input); + search_terms_args.append_extra_query_params = + element == GetTemplateURLService()->GetDefaultSearchProvider(); + match->destination_url = + GURL(element_ref.ReplaceSearchTerms(search_terms_args)); + std::vector<size_t> content_param_offsets; + match->contents.assign(l10n_util::GetStringFUTF16(message_id, + element->short_name(), + remaining_input, + &content_param_offsets)); + DCHECK_EQ(2U, content_param_offsets.size()); + AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], + remaining_input.length(), match->contents.length(), + ACMatchClassification::NONE, &match->contents_class); + } +} + void KeywordProvider::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { |