diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-22 19:24:59 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-22 19:24:59 +0000 |
commit | fad49bcd98da9cbaae9852975270a3cb65328a1f (patch) | |
tree | 558b9f5b25744bd1be8423a52fdcf040f55bedce /chrome/browser/autocomplete | |
parent | 509f65aa76de752c1fcfff95f1abd43e920bad59 (diff) | |
download | chromium_src-fad49bcd98da9cbaae9852975270a3cb65328a1f.zip chromium_src-fad49bcd98da9cbaae9852975270a3cb65328a1f.tar.gz chromium_src-fad49bcd98da9cbaae9852975270a3cb65328a1f.tar.bz2 |
Fix some issues with the omnibox extension API in incognito windows.
- Don't enter "keyword" mode unless the extension is enabled and allowed in
incognito.
- Show extension suggest results for incognito windows.
BUG=46933
Review URL: http://codereview.chromium.org/2810020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50498 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/keyword_provider.cc | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc index 0da37e8..1b7e2ae 100644 --- a/chrome/browser/autocomplete/keyword_provider.cc +++ b/chrome/browser/autocomplete/keyword_provider.cc @@ -11,6 +11,7 @@ #include "base/string16.h" #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/extension_omnibox_api.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" @@ -36,8 +37,11 @@ KeywordProvider::KeywordProvider(ACProviderListener* listener, Profile* profile) : AutocompleteProvider(listener, profile, "Keyword"), model_(NULL), current_input_id_(0) { + // Extension suggestions always come from the original profile, since that's + // where extensions run. We use the input ID to distinguish whether the + // suggestions are meant for us. registrar_.Add(this, NotificationType::EXTENSION_OMNIBOX_SUGGESTIONS_READY, - Source<Profile>(profile)); + Source<Profile>(profile->GetOriginalProfile())); } KeywordProvider::KeywordProvider(ACProviderListener* listener, @@ -66,6 +70,10 @@ class CompareQuality { } }; +// We need our input IDs to be unique across all profiles, so we keep a global +// UID that each provider uses. +static int global_input_uid_; + } // namespace // static @@ -96,7 +104,7 @@ void KeywordProvider::Start(const AutocompleteInput& input, // Input has changed. Increment the input ID so that we can discard any // stale extension suggestions that may be incoming. - ++current_input_id_; + current_input_id_ = ++global_input_uid_; } // Split user input into a keyword and some query input. @@ -144,13 +152,19 @@ void KeywordProvider::Start(const AutocompleteInput& input, // Any exact match is going to be the highest quality match, and thus at the // front of our vector. if (keyword_matches.front() == keyword) { - matches_.push_back(CreateAutocompleteMatch(model, keyword, input, - keyword.length(), - remaining_input, -1)); - const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); 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 (minimal_changes) { // If the input hasn't significantly changed, we can just use the // suggestions from last time. We need to readjust the relevance to @@ -173,6 +187,10 @@ 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, |