Chromium Code Reviews| Index: chrome/browser/autocomplete/keyword_provider.cc |
| =================================================================== |
| --- chrome/browser/autocomplete/keyword_provider.cc (revision 94623) |
| +++ chrome/browser/autocomplete/keyword_provider.cc (working copy) |
| @@ -163,10 +163,7 @@ |
| // Make sure the model is loaded. This is cheap and quickly bails out if |
| // the model is already loaded. |
| - TemplateURLService* model = |
| - profile_ ? |
| - TemplateURLServiceFactory::GetForProfile(profile_) : |
| - model_; |
| + TemplateURLService* model = GetTemplateURLService(); |
|
Peter Kasting
2011/07/29 21:08:44
Nit: I also meant for the DCHECK() and Load() call
|
| DCHECK(model); |
| model->Load(); |
| @@ -185,11 +182,12 @@ |
| !remaining_input.empty(), |
| &keyword_matches); |
| - // Prune any extension keywords that are disallowed in incognito mode (if |
| - // we're incognito), or disabled. |
| for (std::vector<string16>::iterator i(keyword_matches.begin()); |
| i != keyword_matches.end(); ) { |
| const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i)); |
| + |
| + // Prune any extension keywords that are disallowed in incognito mode (if |
| + // we're incognito), or disabled. |
| if (profile_ && |
| input.matches_requested() == AutocompleteInput::ALL_MATCHES && |
| template_url->IsExtensionKeyword()) { |
| @@ -204,6 +202,14 @@ |
| continue; |
| } |
| } |
| + |
| + // Prune any substituting keywords if there is no substitution. |
| + if (TemplateURL::SupportsReplacement(template_url) && |
| + !input.allow_exact_keyword_match()) { |
| + i = keyword_matches.erase(i); |
| + continue; |
| + } |
| + |
| ++i; |
| } |
| if (keyword_matches.empty()) |
| @@ -387,7 +393,50 @@ |
| 1450 : 1100; |
| } |
| +string16 KeywordProvider::GetKeywordForText( |
|
sky
2011/08/01 16:02:15
DOesn't match position in header.
|
| + const string16& text) const { |
|
Peter Kasting
2011/07/29 21:08:44
Nit: Indent 4
|
| + const string16 keyword(TemplateURLService::CleanUserInputKeyword(text)); |
|
Peter Kasting
2011/07/29 21:08:44
Nit: Whole function should be indented 2, not 4
|
| + |
| + if (keyword.empty()) |
| + return keyword; |
| + |
| + TemplateURLService* url_service = GetTemplateURLService(); |
| + if (!url_service) |
| + return string16(); |
| + url_service->Load(); |
| + |
| + // Don't provide a keyword if it doesn't support replacement. |
| + const TemplateURL* const template_url = |
| + url_service->GetTemplateURLForKeyword(keyword); |
|
Peter Kasting
2011/07/29 21:08:44
Nit: Indent 4 (3 places)
|
| + if (!TemplateURL::SupportsReplacement(template_url)) |
| + return string16(); |
| + |
| + // Don't provide a keyword for inactive/disabled extension keywords. |
| + if (template_url->IsExtensionKeyword()) { |
| + const Extension* extension = profile_->GetExtensionService()-> |
| + GetExtensionById(template_url->GetExtensionId(), false); |
| + if (!extension || |
| + (profile_->IsOffTheRecord() && |
|
sky
2011/08/01 16:02:15
nit: indenting off (should be one past ( on previo
|
| + !profile_->GetExtensionService()->IsIncognitoEnabled(extension->id()))) |
| + return string16(); |
| + } |
| + |
| + return keyword; |
| +} |
| + |
| +TemplateURLService* KeywordProvider::GetTemplateURLService() const { |
| + return profile_ ? TemplateURLServiceFactory::GetForProfile(profile_) : |
| + model_; |
| +} |
| + |
| AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( |
| + const string16& keyword, |
| + const AutocompleteInput& input) { |
| + return CreateAutocompleteMatch(GetTemplateURLService(), keyword, input, |
| + keyword.size(), string16(), 0); |
| +} |
| + |
| +AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( |
| TemplateURLService* model, |
| const string16& keyword, |
| const AutocompleteInput& input, |
| @@ -414,36 +463,36 @@ |
| supports_replacement, input.prefer_keyword(), |
| input.allow_exact_keyword_match()); |
| } |
| - AutocompleteMatch result(this, relevance, false, |
| + AutocompleteMatch match(this, relevance, false, |
| supports_replacement ? AutocompleteMatch::SEARCH_OTHER_ENGINE : |
| AutocompleteMatch::HISTORY_KEYWORD); |
| - result.fill_into_edit.assign(keyword); |
| + match.fill_into_edit.assign(keyword); |
| if (!remaining_input.empty() || !keyword_complete || supports_replacement) |
| - result.fill_into_edit.push_back(L' '); |
| - result.fill_into_edit.append(remaining_input); |
| + match.fill_into_edit.push_back(L' '); |
| + match.fill_into_edit.append(remaining_input); |
| // If we wanted to set |result.inline_autocomplete_offset| correctly, we'd |
| // need CleanUserInputKeyword() to return the amount of adjustment it's made |
| // to the user's input. Because right now inexact keyword matches can't score |
| // more highly than a "what you typed" match from one of the other providers, |
| // we just don't bother to do this, and leave inline autocompletion off. |
| - result.inline_autocomplete_offset = string16::npos; |
| + match.inline_autocomplete_offset = string16::npos; |
| // Create destination URL and popup entry content by substituting user input |
| // into keyword templates. |
| - FillInURLAndContents(remaining_input, element, &result); |
| + FillInURLAndContents(remaining_input, element, &match); |
| if (supports_replacement) |
| - result.template_url = element; |
| - result.transition = PageTransition::KEYWORD; |
| + match.template_url = element; |
| + match.keyword = keyword; |
| + match.transition = PageTransition::KEYWORD; |
| - return result; |
| + return match; |
| } |
| void KeywordProvider::Observe(int type, |
| const NotificationSource& source, |
| const NotificationDetails& details) { |
| - TemplateURLService* model = |
| - profile_ ? TemplateURLServiceFactory::GetForProfile(profile_) : model_; |
| + TemplateURLService* model = GetTemplateURLService(); |
| const AutocompleteInput& input = extension_suggest_last_input_; |
| switch (type) { |