| Index: chrome/browser/autocomplete/keyword_provider.cc
|
| diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
|
| index dd2959e9eb41a0921a1f294c8847d3eeadf919ec..e34599a58d487e9e3d9e06239e491817d79b25af 100644
|
| --- a/chrome/browser/autocomplete/keyword_provider.cc
|
| +++ b/chrome/browser/autocomplete/keyword_provider.cc
|
| @@ -215,9 +215,12 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
|
| const string16& text,
|
| const string16& keyword,
|
| const AutocompleteInput& input) {
|
| + // This enclosing function is only called by omnibox_controller.cc to create
|
| + // a what-you-typed match on the keyword input. It's okay to allow this
|
| + // match to be the default match.
|
| return CreateAutocompleteMatch(
|
| GetTemplateURLService()->GetTemplateURLForKeyword(keyword), input,
|
| - keyword.length(), SplitReplacementStringFromInput(text, true), 0);
|
| + keyword.length(), SplitReplacementStringFromInput(text, true), true, 0);
|
| }
|
|
|
| void KeywordProvider::Start(const AutocompleteInput& input,
|
| @@ -318,8 +321,12 @@ void KeywordProvider::Start(const AutocompleteInput& input,
|
|
|
| // TODO(pkasting): We should probably check that if the user explicitly
|
| // typed a scheme, that scheme matches the one in |template_url|.
|
| +
|
| + // When creating an exact match (either for the keyword itself, no
|
| + // remaining query or an extension keyword, possibly with remaining
|
| + // input), allow the match to be the default match.
|
| matches_.push_back(CreateAutocompleteMatch(
|
| - template_url, input, keyword.length(), remaining_input, -1));
|
| + template_url, input, keyword.length(), remaining_input, true, -1));
|
|
|
| if (profile_ && is_extension_keyword) {
|
| if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) {
|
| @@ -364,8 +371,14 @@ void KeywordProvider::Start(const AutocompleteInput& input,
|
| matches.erase(matches.begin() + kMaxMatches, matches.end());
|
| for (TemplateURLService::TemplateURLVector::const_iterator i(
|
| matches.begin()); i != matches.end(); ++i) {
|
| + // These inexact (prefix) keyword matches probably could be allowed
|
| + // to be the default match but in practice they're always outranked
|
| + // by a verbatim match (a query from SearchProvider from non-URL-like
|
| + // inputs or a URL-what-you-typed from HistoryURLProvider for URL-like
|
| + // inputs). We set allowed_to_be_default_match to false to mirror
|
| + // this implicit consequence of the relevance scoring code.
|
| matches_.push_back(CreateAutocompleteMatch(
|
| - *i, input, keyword.length(), remaining_input, -1));
|
| + *i, input, keyword.length(), remaining_input, false, -1));
|
| }
|
| }
|
| }
|
| @@ -420,6 +433,7 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
|
| const AutocompleteInput& input,
|
| size_t prefix_length,
|
| const string16& remaining_input,
|
| + bool allowed_to_be_default_match,
|
| int relevance) {
|
| DCHECK(template_url);
|
| const bool supports_replacement =
|
| @@ -442,6 +456,7 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
|
| AutocompleteMatch match(this, relevance, false,
|
| supports_replacement ? AutocompleteMatchType::SEARCH_OTHER_ENGINE :
|
| AutocompleteMatchType::HISTORY_KEYWORD);
|
| + match.allowed_to_be_default_match = allowed_to_be_default_match;
|
| match.fill_into_edit = keyword;
|
| if (!remaining_input.empty() || !keyword_complete || supports_replacement)
|
| match.fill_into_edit.push_back(L' ');
|
| @@ -567,13 +582,16 @@ void KeywordProvider::Observe(int type,
|
| // We want to order these suggestions in descending order, so start with
|
| // the relevance of the first result (added synchronously in Start()),
|
| // and subtract 1 for each subsequent suggestion from the extension.
|
| - // We know that |complete| is true, because we wouldn't get results from
|
| - // the extension unless the full keyword had been typed.
|
| + // We recompute the first match's relevance; we know that |complete|
|
| + // is true, because we wouldn't get results from the extension unless
|
| + // the full keyword had been typed.
|
| int first_relevance = CalculateRelevance(input.type(), true, true,
|
| input.prefer_keyword(), input.allow_exact_keyword_match());
|
| + // Since these matches score less than the first match, they should
|
| + // never become the default match. Mark them as such.
|
| extension_suggest_matches_.push_back(CreateAutocompleteMatch(
|
| template_url, input, keyword.length(),
|
| - UTF8ToUTF16(suggestion.content), first_relevance - (i + 1)));
|
| + UTF8ToUTF16(suggestion.content), false, first_relevance - (i + 1)));
|
|
|
| AutocompleteMatch* match = &extension_suggest_matches_.back();
|
| match->contents.assign(UTF8ToUTF16(suggestion.description));
|
|
|