Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2412)

Unified Diff: chrome/browser/autocomplete/keyword_provider.cc

Issue 6731036: Enabled pressing TAB to cycle through the Omnibox results. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/keyword_provider.cc
===================================================================
--- chrome/browser/autocomplete/keyword_provider.cc (revision 95169)
+++ chrome/browser/autocomplete/keyword_provider.cc (working copy)
@@ -128,6 +128,43 @@
return TemplateURL::SupportsReplacement(template_url) ? template_url : NULL;
}
+string16 KeywordProvider::GetKeywordForText(
+ const string16& text) const {
+ const string16 keyword(TemplateURLService::CleanUserInputKeyword(text));
+
+ if (keyword.empty())
+ return keyword;
+
+ TemplateURLService* url_service = GetTemplateURLService();
+ if (!url_service)
+ return string16();
+
+ // Don't provide a keyword if it doesn't support replacement.
+ const TemplateURL* const template_url =
+ url_service->GetTemplateURLForKeyword(keyword);
+ 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() &&
+ !profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())))
+ return string16();
+ }
+
+ return keyword;
+}
+
+AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
+ const string16& keyword,
+ const AutocompleteInput& input) {
+ return CreateAutocompleteMatch(GetTemplateURLService(), keyword, input,
+ keyword.size(), string16(), 0);
+}
+
void KeywordProvider::Start(const AutocompleteInput& input,
bool minimal_changes) {
// This object ensures we end keyword mode if we exit the function without
@@ -161,14 +198,7 @@
if (!ExtractKeywordFromInput(input, &keyword, &remaining_input))
return;
- // 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_;
- DCHECK(model);
- model->Load();
+ TemplateURLService* model = GetTemplateURLService();
// Get the best matches for this keyword.
//
@@ -185,11 +215,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 +235,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())
@@ -414,36 +453,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) {
@@ -520,6 +559,16 @@
}
}
+TemplateURLService* KeywordProvider::GetTemplateURLService() const {
+ TemplateURLService* service = profile_ ?
+ TemplateURLServiceFactory::GetForProfile(profile_) : model_;
+ // Make sure the model is loaded. This is cheap and quickly bails out if
+ // the model is already loaded.
+ DCHECK(service);
+ service->Load();
+ return service;
+}
+
void KeywordProvider::EnterExtensionKeywordMode(
const std::string& extension_id) {
DCHECK(current_keyword_extension_id_.empty());

Powered by Google App Engine
This is Rietveld 408576698