summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-03 21:37:05 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-03 21:37:05 +0000
commit2a8f24e3021fbddb8b48c5f1d7a8002b1d6c78e4 (patch)
tree6db0afb317d65451452cfbaeac331bb8a46d3f6b
parent0daa69b89baf4369da28bfcfa3e06e3715afb9cb (diff)
downloadchromium_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
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc9
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc41
-rw-r--r--chrome/browser/extensions/extension_event_router.cc5
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc3
-rw-r--r--chrome/browser/extensions/extensions_service.cc7
-rw-r--r--chrome/browser/extensions/extensions_service.h4
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc3
7 files changed, 51 insertions, 21 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,
diff --git a/chrome/browser/extensions/extension_event_router.cc b/chrome/browser/extensions/extension_event_router.cc
index c033454..4fc48e3 100644
--- a/chrome/browser/extensions/extension_event_router.cc
+++ b/chrome/browser/extensions/extension_event_router.cc
@@ -168,6 +168,7 @@ void ExtensionEventRouter::DispatchEventImpl(
return;
std::set<EventListener>& listeners = it->second;
+ ExtensionsService* service = profile_->GetExtensionsService();
// Send the event only to renderers that are listening for it.
for (std::set<EventListener>::iterator listener = listeners.begin();
@@ -185,7 +186,9 @@ void ExtensionEventRouter::DispatchEventImpl(
// incognito tab event sent to a normal process, or vice versa).
bool cross_incognito = restrict_to_profile &&
listener->process->profile() != restrict_to_profile;
- if (cross_incognito && !CanCrossIncognito(profile_, listener->extension_id))
+ const Extension* extension = service->GetExtensionById(
+ listener->extension_id, false);
+ if (cross_incognito && !service->CanCrossIncognito(extension))
continue;
DispatchEvent(listener->process, listener->extension_id,
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 783a8bf..d402962 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -450,8 +450,7 @@ void ExtensionFunctionDispatcher::HandleRequest(
DCHECK(service);
const Extension* extension = service->GetExtensionById(extension_id(), false);
DCHECK(extension);
- function->set_include_incognito(service->IsIncognitoEnabled(extension) &&
- !extension->incognito_split_mode());
+ function->set_include_incognito(service->CanCrossIncognito(extension));
if (!service->ExtensionBindingsAllowed(function->source_url()) ||
!extension->HasApiPermission(function->name())) {
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 98681de..734bdef 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -1336,6 +1336,13 @@ void ExtensionsService::SetIsIncognitoEnabled(const Extension* extension,
}
}
+bool ExtensionsService::CanCrossIncognito(const Extension* extension) {
+ // We allow the extension to see events and data from another profile iff it
+ // uses "spanning" behavior and it has incognito access. "split" mode
+ // extensions only see events for a matching profile.
+ return IsIncognitoEnabled(extension) && !extension->incognito_split_mode();
+}
+
bool ExtensionsService::AllowFileAccess(const Extension* extension) {
return (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableExtensionsFileAccessCheck) ||
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index 213471c..7cc2c9d 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -181,6 +181,10 @@ class ExtensionsService
bool IsIncognitoEnabled(const Extension* extension);
void SetIsIncognitoEnabled(const Extension* extension, bool enabled);
+ // Returns true if the given extension can see events and data from another
+ // sub-profile (incognito to original profile, or vice versa).
+ bool CanCrossIncognito(const Extension* extension);
+
// Whether this extension can inject scripts into pages with file URLs.
bool AllowFileAccess(const Extension* extension);
void SetAllowFileAccess(const Extension* extension, bool allow);
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index f792b35..20eb116 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -185,8 +185,7 @@ void RenderViewContextMenu::AppendExtensionItems(
ExtensionsService* service = profile_->GetExtensionsService();
ExtensionMenuManager* manager = service->menu_manager();
const Extension* extension = service->GetExtensionById(extension_id, false);
- bool can_cross_incognito =
- ExtensionEventRouter::CanCrossIncognito(profile_, extension);
+ bool can_cross_incognito = service->CanCrossIncognito(extension);
DCHECK_GE(*index, 0);
int max_index =
IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;