diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 21:37:05 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 21:37:05 +0000 |
commit | 2a8f24e3021fbddb8b48c5f1d7a8002b1d6c78e4 (patch) | |
tree | 6db0afb317d65451452cfbaeac331bb8a46d3f6b /chrome/browser/autocomplete | |
parent | 0daa69b89baf4369da28bfcfa3e06e3715afb9cb (diff) | |
download | chromium_src-2a8f24e3021fbddb8b48c5f1d7a8002b1d6c78e4.zip chromium_src-2a8f24e3021fbddb8b48c5f1d7a8002b1d6c78e4.tar.gz chromium_src-2a8f24e3021fbddb8b48c5f1d7a8002b1d6c78e4.tar.bz2 |
Fix some UI issues with omnibox extensions in incognito.
Also moved a shared method from ExtensionEventRouter to ExtensionsService.
BUG=58210
TEST=Install the extension in chrome/common/extensions/docs/examples/extensions/chrome_search. You should not see the UI artifacts described in the bug.
Review URL: http://codereview.chromium.org/4234004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_popup_model.cc | 9 | ||||
-rw-r--r-- | chrome/browser/autocomplete/keyword_provider.cc | 41 |
2 files changed, 34 insertions, 16 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index 774acd0..a14d19f 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -221,6 +221,15 @@ bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, if (!TemplateURL::SupportsReplacement(template_url)) return false; + // Don't provide a hint if this is an extension keyword not enabled for + // incognito mode (and if this is an incognito profile). + if (template_url->IsExtensionKeyword() && profile_->IsOffTheRecord()) { + const Extension* extension = profile_->GetExtensionsService()-> + GetExtensionById(template_url->GetExtensionId(), false); + if (!profile_->GetExtensionsService()->IsIncognitoEnabled(extension)) + return false; + } + keyword->assign(keyword_hint); return true; } diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc index 3111812..af9c125 100644 --- a/chrome/browser/autocomplete/keyword_provider.cc +++ b/chrome/browser/autocomplete/keyword_provider.cc @@ -168,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()); @@ -180,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(); - const 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) { @@ -221,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, |