| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/extensions/api/commands/commands_handler.h" | 5 #include "chrome/common/extensions/api/commands/commands_handler.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/common/extensions/command.h" | 10 #include "chrome/common/extensions/command.h" |
| 11 #include "extensions/common/error_utils.h" | 11 #include "extensions/common/error_utils.h" |
| 12 #include "extensions/common/manifest_constants.h" | 12 #include "extensions/common/manifest_constants.h" |
| 13 #include "extensions/common/permissions/permissions_data.h" |
| 13 | 14 |
| 14 namespace extensions { | 15 namespace extensions { |
| 15 | 16 |
| 16 namespace keys = manifest_keys; | 17 namespace keys = manifest_keys; |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 // The maximum number of commands (including page action/browser actions) with a | 20 // The maximum number of commands (including page action/browser actions) with a |
| 20 // keybinding an extension can have. | 21 // keybinding an extension can have. |
| 21 const int kMaxCommandsWithKeybindingPerExtension = 4; | 22 const int kMaxCommandsWithKeybindingPerExtension = 4; |
| 22 } // namespace | 23 } // namespace |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (!binding->Parse(command, iter.key(), command_index, error)) | 91 if (!binding->Parse(command, iter.key(), command_index, error)) |
| 91 return false; // |error| already set. | 92 return false; // |error| already set. |
| 92 | 93 |
| 93 if (binding->accelerator().key_code() != ui::VKEY_UNKNOWN) { | 94 if (binding->accelerator().key_code() != ui::VKEY_UNKNOWN) { |
| 94 // Only media keys are allowed to work without modifiers, and because | 95 // Only media keys are allowed to work without modifiers, and because |
| 95 // media keys aren't registered exclusively they should not count towards | 96 // media keys aren't registered exclusively they should not count towards |
| 96 // the max of four shortcuts per extension. | 97 // the max of four shortcuts per extension. |
| 97 if (!Command::IsMediaKey(binding->accelerator())) | 98 if (!Command::IsMediaKey(binding->accelerator())) |
| 98 ++keybindings_found; | 99 ++keybindings_found; |
| 99 | 100 |
| 100 if (keybindings_found > kMaxCommandsWithKeybindingPerExtension) { | 101 if (keybindings_found > kMaxCommandsWithKeybindingPerExtension && |
| 102 !extension->permissions_data()->HasAPIPermission( |
| 103 APIPermission::kCommandsAccessibility)) { |
| 101 *error = ErrorUtils::FormatErrorMessageUTF16( | 104 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 102 manifest_errors::kInvalidKeyBindingTooMany, | 105 manifest_errors::kInvalidKeyBindingTooMany, |
| 103 base::IntToString(kMaxCommandsWithKeybindingPerExtension)); | 106 base::IntToString(kMaxCommandsWithKeybindingPerExtension)); |
| 104 return false; | 107 return false; |
| 105 } | 108 } |
| 106 } | 109 } |
| 107 | 110 |
| 108 std::string command_name = binding->command_name(); | 111 std::string command_name = binding->command_name(); |
| 109 if (command_name == manifest_values::kBrowserActionCommandEvent) { | 112 if (command_name == manifest_values::kBrowserActionCommandEvent) { |
| 110 commands_info->browser_action_command.reset(binding.release()); | 113 commands_info->browser_action_command.reset(binding.release()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 140 std::string(), | 143 std::string(), |
| 141 false)); | 144 false)); |
| 142 } | 145 } |
| 143 } | 146 } |
| 144 | 147 |
| 145 const std::vector<std::string> CommandsHandler::Keys() const { | 148 const std::vector<std::string> CommandsHandler::Keys() const { |
| 146 return SingleKey(keys::kCommands); | 149 return SingleKey(keys::kCommands); |
| 147 } | 150 } |
| 148 | 151 |
| 149 } // namespace extensions | 152 } // namespace extensions |
| OLD | NEW |