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

Unified Diff: chrome/browser/extensions/api/commands/command_service.cc

Issue 143493005: Allow extensions to remove and override the bookmark shortcut key (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove use of GetActiveDesktop() Created 6 years, 10 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/extensions/api/commands/command_service.cc
diff --git a/chrome/browser/extensions/api/commands/command_service.cc b/chrome/browser/extensions/api/commands/command_service.cc
index 4c2906def1022f85f6542f1a33c54f2c0ef9dbdf..902a79d24b1ae7b4a8ab9f15839c0b3131f9e183 100644
--- a/chrome/browser/extensions/api/commands/command_service.cc
+++ b/chrome/browser/extensions/api/commands/command_service.cc
@@ -11,6 +11,7 @@
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/commands/commands.h"
#include "chrome/browser/extensions/extension_commands_global_registry.h"
@@ -20,6 +21,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/accelerator_utils.h"
#include "chrome/common/extensions/api/commands/commands_handler.h"
+#include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h"
#include "chrome/common/pref_names.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/notification_details.h"
@@ -27,6 +29,7 @@
#include "extensions/browser/extension_system.h"
#include "extensions/common/feature_switch.h"
#include "extensions/common/manifest_constants.h"
+#include "extensions/common/permissions/permissions_data.h"
using extensions::Extension;
using extensions::ExtensionPrefs;
@@ -78,7 +81,36 @@ bool InitialBindingsHaveBeenAssigned(
return assigned;
}
+bool IsReservedChromeAccelerator(const ui::Accelerator& accelerator,
+ const Extension* extension,
+ Profile* profile) {
+ if (!chrome::IsChromeAccelerator(accelerator, profile))
+ return false;
Finnur 2014/02/11 09:35:01 Ooops! Not LGTM. This is incorrect for Mac at the
Mike Wittman 2014/02/11 23:09:45 OK. I will ping this review when the Mac changes a
Finnur 2014/02/12 12:51:14 Thank you.
+
+ using extensions::SettingsOverrides;
+ using extensions::FeatureSwitch;
+ const SettingsOverrides* settings_overrides =
+ SettingsOverrides::Get(extension);
+ if (settings_overrides &&
+ SettingsOverrides::RemovesBookmarkShortcut(*settings_overrides) &&
+ (extensions::PermissionsData::HasAPIPermission(
+ extension,
+ extensions::APIPermission::kBookmarkManagerPrivate) ||
+ FeatureSwitch::enable_override_bookmarks_ui()->IsEnabled())) {
+ return accelerator !=
+ chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE);
+ }
+
+ return true;
+}
Finnur 2014/02/11 09:50:05 We need to flip this logic. Instead of current imp
Mike Wittman 2014/02/11 23:09:45 Done.
+
bool IsWhitelistedGlobalShortcut(const extensions::Command& command) {
+ // NOTE(wittman): If the restrictions on auto-assigning global shortcuts are
+ // ever relaxed in the future, then keys such as the bookmarking shortcut
+ // (IDC_BOOKMARK_PAGE) need to be evaluated on a case-by-case basis. Such keys
+ // can be auto-assigned by extensions (with the right permission), even though
+ // the shortcut is already in use by Chrome.
+
// Non-global shortcuts are always allowed.
if (!command.global())
return true;
@@ -364,8 +396,9 @@ void CommandService::AssignInitialKeybindings(const Extension* extension) {
for (; iter != commands->end(); ++iter) {
// Make sure registered Chrome shortcuts cannot be automatically assigned
// (overwritten) by extension developers. Media keys are an exception here.
- if ((!chrome::IsChromeAccelerator(iter->second.accelerator(), profile_) &&
- IsWhitelistedGlobalShortcut(iter->second)) ||
+ if ((!IsReservedChromeAccelerator(
+ iter->second.accelerator(), extension, profile_) &&
+ IsWhitelistedGlobalShortcut(iter->second)) ||
extensions::CommandService::IsMediaKey(iter->second.accelerator())) {
AddKeybindingPref(iter->second.accelerator(),
extension->id(),
@@ -378,8 +411,8 @@ void CommandService::AssignInitialKeybindings(const Extension* extension) {
const extensions::Command* browser_action_command =
CommandsInfo::GetBrowserActionCommand(extension);
if (browser_action_command) {
- if (!chrome::IsChromeAccelerator(
- browser_action_command->accelerator(), profile_)) {
+ if (!IsReservedChromeAccelerator(
+ browser_action_command->accelerator(), extension, profile_)) {
AddKeybindingPref(browser_action_command->accelerator(),
extension->id(),
browser_action_command->command_name(),
@@ -391,8 +424,8 @@ void CommandService::AssignInitialKeybindings(const Extension* extension) {
const extensions::Command* page_action_command =
CommandsInfo::GetPageActionCommand(extension);
if (page_action_command) {
- if (!chrome::IsChromeAccelerator(
- page_action_command->accelerator(), profile_)) {
+ if (!IsReservedChromeAccelerator(
+ page_action_command->accelerator(), extension, profile_)) {
AddKeybindingPref(page_action_command->accelerator(),
extension->id(),
page_action_command->command_name(),

Powered by Google App Engine
This is Rietveld 408576698