summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/common/extensions/command.cc2
-rw-r--r--chrome/common/extensions/extension.cc11
-rw-r--r--chrome/common/extensions/extension_manifest_constants.cc2
-rw-r--r--chrome/common/extensions/extension_manifest_constants.h1
-rw-r--r--chrome/common/extensions/manifest_tests/extension_manifests_command_unittest.cc20
-rw-r--r--chrome/test/data/extensions/manifest_tests/command_too_many.json27
7 files changed, 63 insertions, 1 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index c75db2d..9d47385 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1829,6 +1829,7 @@
'common/extensions/manifest_tests/extension_manifest_test.cc',
'common/extensions/manifest_tests/extension_manifests_background_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_chromepermission_unittest.cc',
+ 'common/extensions/manifest_tests/extension_manifests_command_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_contentscript_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_default_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_devtools_unittest.cc',
diff --git a/chrome/common/extensions/command.cc b/chrome/common/extensions/command.cc
index e9d58148..8751a57 100644
--- a/chrome/common/extensions/command.cc
+++ b/chrome/common/extensions/command.cc
@@ -151,7 +151,7 @@ bool Command::Parse(DictionaryValue* command,
std::string suggested_key_string;
if (command->GetString(keys::kSuggestedKey, &suggested_key_string) &&
!suggested_key_string.empty()) {
- // If only a signle string is provided, it must be default for all.
+ // If only a single string is provided, it must be default for all.
suggestions["default"] = suggested_key_string;
} else {
*error = ExtensionErrorUtils::FormatErrorMessageUTF16(
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 824d85f..ccf0990 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -68,6 +68,10 @@ const int kPEMOutputColumns = 65;
const char kOverrideExtentUrlPatternFormat[] = "chrome://%s/*";
+// The maximum number of commands (including page action/browser actions) an
+// extension can have.
+const size_t kMaxCommandsPerExtension = 4;
+
// KEY MARKERS
const char kKeyBeginHeaderMarker[] = "-----BEGIN";
const char kKeyBeginFooterMarker[] = "-----END";
@@ -1387,6 +1391,13 @@ bool Extension::LoadCommands(string16* error) {
return false;
}
+ if (commands->size() > kMaxCommandsPerExtension) {
+ *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidKeyBindingTooMany,
+ base::IntToString(kMaxCommandsPerExtension));
+ return false;
+ }
+
int command_index = 0;
for (DictionaryValue::key_iterator iter = commands->begin_keys();
iter != commands->end_keys(); ++iter) {
diff --git a/chrome/common/extensions/extension_manifest_constants.cc b/chrome/common/extensions/extension_manifest_constants.cc
index 7ebfb05..f26926e 100644
--- a/chrome/common/extensions/extension_manifest_constants.cc
+++ b/chrome/common/extensions/extension_manifest_constants.cc
@@ -305,6 +305,8 @@ const char kInvalidKeyBindingDictionary[] =
const char kInvalidKeyBindingMissingPlatform[] =
"Could not find key specification for 'command[*].*': Either specify a key "
"for '*', or specify a default key.";
+const char kInvalidKeyBindingTooMany[] =
+ "Too many commands specified for 'commands': The maximum is *.";
const char kInvalidKeyBindingUnknownPlatform[] =
"Unknown platform for 'command[*]': *. Valid values are: 'windows', 'mac'"
" 'chromeos', 'linux' and 'default'.";
diff --git a/chrome/common/extensions/extension_manifest_constants.h b/chrome/common/extensions/extension_manifest_constants.h
index fa39857..d078a95 100644
--- a/chrome/common/extensions/extension_manifest_constants.h
+++ b/chrome/common/extensions/extension_manifest_constants.h
@@ -232,6 +232,7 @@ namespace extension_manifest_errors {
extern const char kInvalidKeyBindingDescription[];
extern const char kInvalidKeyBindingDictionary[];
extern const char kInvalidKeyBindingMissingPlatform[];
+ extern const char kInvalidKeyBindingTooMany[];
extern const char kInvalidKeyBindingUnknownPlatform[];
extern const char kInvalidLaunchContainer[];
extern const char kInvalidLaunchValue[];
diff --git a/chrome/common/extensions/manifest_tests/extension_manifests_command_unittest.cc b/chrome/common/extensions/manifest_tests/extension_manifests_command_unittest.cc
new file mode 100644
index 0000000..2ffa260
--- /dev/null
+++ b/chrome/common/extensions/manifest_tests/extension_manifests_command_unittest.cc
@@ -0,0 +1,20 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
+
+#include "base/command_line.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace errors = extension_manifest_errors;
+
+TEST_F(ExtensionManifestTest, CommandManifestTooMany) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableExperimentalExtensionApis);
+
+ LoadAndExpectError("command_too_many.json",
+ errors::kInvalidKeyBindingTooMany);
+}
diff --git a/chrome/test/data/extensions/manifest_tests/command_too_many.json b/chrome/test/data/extensions/manifest_tests/command_too_many.json
new file mode 100644
index 0000000..efb7ccb
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/command_too_many.json
@@ -0,0 +1,27 @@
+{
+ "name": "Command test - too many commands",
+ "manifest_version": 2,
+ "version": "2",
+ "commands": {
+ "feature1": {
+ "suggested_key": "Ctrl+A",
+ "description": "feature1"
+ },
+ "feature2": {
+ "suggested_key": "Ctrl+B",
+ "description": "feature2"
+ },
+ "feature3": {
+ "suggested_key": "Ctrl+C",
+ "description": "feature3"
+ },
+ "feature4": {
+ "suggested_key": "Ctrl+D",
+ "description": "feature4"
+ },
+ "feature5": {
+ "suggested_key": "Ctrl+E",
+ "description": "feature5"
+ }
+ }
+ }