summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/keyword_provider.cc
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-11-18 18:32:45 +0000
committerBen Murdoch <benm@google.com>2010-11-18 18:38:07 +0000
commit513209b27ff55e2841eac0e4120199c23acce758 (patch)
treeaeba30bb08c5f47c57003544e378a377c297eee6 /chrome/browser/autocomplete/keyword_provider.cc
parent164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff)
downloadexternal_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'chrome/browser/autocomplete/keyword_provider.cc')
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc42
1 files changed, 26 insertions, 16 deletions
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index 4f3ee5e..af9c125 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -10,6 +10,7 @@
#include "app/l10n_util.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/extensions/extension_omnibox_api.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/profile.h"
@@ -167,6 +168,26 @@ void KeywordProvider::Start(const AutocompleteInput& input,
std::vector<std::wstring> keyword_matches;
model->FindMatchingKeywords(keyword, !remaining_input.empty(),
&keyword_matches);
+
+ // Prune any extension keywords that are disallowed in incognito mode (if
+ // we're incognito), or disabled.
+ for (std::vector<std::wstring>::iterator i(keyword_matches.begin());
+ i != keyword_matches.end(); ) {
+ const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i));
+ if (profile_ &&
+ !input.synchronous_only() && template_url->IsExtensionKeyword()) {
+ ExtensionsService* service = profile_->GetExtensionsService();
+ const Extension* extension = service->GetExtensionById(
+ template_url->GetExtensionId(), false);
+ bool enabled = extension && (!profile_->IsOffTheRecord() ||
+ service->IsIncognitoEnabled(extension));
+ if (!enabled) {
+ i = keyword_matches.erase(i);
+ continue;
+ }
+ }
+ ++i;
+ }
if (keyword_matches.empty())
return;
std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality());
@@ -179,23 +200,16 @@ void KeywordProvider::Start(const AutocompleteInput& input,
const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword));
// TODO(pkasting): We should probably check that if the user explicitly
// typed a scheme, that scheme matches the one in |template_url|.
+ matches_.push_back(CreateAutocompleteMatch(model, keyword, input,
+ keyword.length(),
+ remaining_input, -1));
if (profile_ &&
!input.synchronous_only() && template_url->IsExtensionKeyword()) {
- // If this extension keyword is disabled, make sure we don't add any
- // matches (including the synchronous one below).
- ExtensionsService* service = profile_->GetExtensionsService();
- Extension* extension = service->GetExtensionById(
- template_url->GetExtensionId(), false);
- bool enabled = extension && (!profile_->IsOffTheRecord() ||
- service->IsIncognitoEnabled(extension));
- if (!enabled)
- return;
-
- if (extension->id() != current_keyword_extension_id_)
+ if (template_url->GetExtensionId() != current_keyword_extension_id_)
MaybeEndExtensionKeywordMode();
if (current_keyword_extension_id_.empty())
- EnterExtensionKeywordMode(extension->id());
+ EnterExtensionKeywordMode(template_url->GetExtensionId());
keyword_mode_toggle.StayInKeywordMode();
if (minimal_changes) {
@@ -220,10 +234,6 @@ void KeywordProvider::Start(const AutocompleteInput& input,
done_ = false;
}
}
-
- matches_.push_back(CreateAutocompleteMatch(model, keyword, input,
- keyword.length(),
- remaining_input, -1));
} else {
if (keyword_matches.size() > kMaxMatches) {
keyword_matches.erase(keyword_matches.begin() + kMaxMatches,