summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 03:33:16 +0000
committergroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 03:33:16 +0000
commit3ad8b535ae9eb0ad54e2c9b85d6ae5e5e03e66b8 (patch)
tree8f8802ee81529f32a249c30a936ed94ab2483557
parenteb5d608b4b2a345da0ae80097ecfc7e522301590 (diff)
downloadchromium_src-3ad8b535ae9eb0ad54e2c9b85d6ae5e5e03e66b8.zip
chromium_src-3ad8b535ae9eb0ad54e2c9b85d6ae5e5e03e66b8.tar.gz
chromium_src-3ad8b535ae9eb0ad54e2c9b85d6ae5e5e03e66b8.tar.bz2
Extension Manifest: MIME types for Intents are now a JSON array
TEST=ExtensionManifestTest.*:WebIntentsRegistryTest.* BUG=none Review URL: http://codereview.chromium.org/9139048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118027 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/extensions/extension.cc20
-rw-r--r--chrome/common/extensions/extension_constants.cc2
-rw-r--r--chrome/common/extensions/extension_constants.h1
-rw-r--r--chrome/common/extensions/extension_manifests_unittest.cc34
-rw-r--r--chrome/test/data/extensions/manifest_tests/intent_invalid_3.json3
-rw-r--r--chrome/test/data/extensions/manifest_tests/intent_invalid_4.json3
-rw-r--r--chrome/test/data/extensions/manifest_tests/intent_invalid_6.json3
-rw-r--r--chrome/test/data/extensions/manifest_tests/intent_invalid_type_element.json12
-rw-r--r--chrome/test/data/extensions/manifest_tests/intent_valid.json2
-rw-r--r--chrome/test/data/extensions/manifest_tests/intent_valid_2.json2
-rw-r--r--chrome/test/data/extensions/manifest_tests/intent_valid_minimal.json1
-rw-r--r--chrome/test/data/extensions/manifest_tests/intent_valid_multitype.json12
12 files changed, 83 insertions, 12 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 98727ba9..cafd853 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1156,10 +1156,12 @@ bool Extension::LoadWebIntentServices(const extensions::Manifest* manifest,
}
service.action = UTF8ToUTF16(*iter);
- // TODO(groby): Support an array of types.
- if (one_service->HasKey(keys::kIntentType) &&
- !one_service->GetString(keys::kIntentType, &service.type)) {
- *error = ASCIIToUTF16(errors::kInvalidIntentType);
+ ListValue* mime_types = NULL;
+ if (!one_service->HasKey(keys::kIntentType) ||
+ !one_service->GetList(keys::kIntentType, &mime_types) ||
+ mime_types->GetSize() == 0) {
+ *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidIntentType,*iter);
return false;
}
@@ -1193,7 +1195,15 @@ bool Extension::LoadWebIntentServices(const extensions::Manifest* manifest,
}
}
- intents_services_.push_back(service);
+ for (size_t i = 0; i < mime_types->GetSize(); ++i) {
+ if (!mime_types->GetString(i, &service.type)) {
+ *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidIntentTypeElement, *iter,
+ std::string(base::IntToString(i)));
+ return false;
+ }
+ intents_services_.push_back(service);
+ }
}
return true;
}
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index b68b92f..463ab35 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -246,6 +246,8 @@ const char kInvalidIntents[] =
"Invalid value for intents";
const char kInvalidIntentType[] =
"Invalid value for intents[*].type";
+const char kInvalidIntentTypeElement[] =
+ "Invalid value for intents[*].type[*]";
const char kInvalidIntentTitle[] =
"Invalid value for intents[*].title";
const char kInvalidIsolation[] =
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index f20cedf..b05c4ae 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -192,6 +192,7 @@ namespace extension_manifest_errors {
extern const char kInvalidIntentPath[];
extern const char kInvalidIntents[];
extern const char kInvalidIntentType[];
+ extern const char kInvalidIntentTypeElement[];
extern const char kInvalidIntentTitle[];
extern const char kInvalidIsolation[];
extern const char kInvalidIsolationValue[];
diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc
index f8089e2..696f64a 100644
--- a/chrome/common/extensions/extension_manifests_unittest.cc
+++ b/chrome/common/extensions/extension_manifests_unittest.cc
@@ -775,7 +775,7 @@ TEST_F(ExtensionManifestTest, TtsEngine) {
}
TEST_F(ExtensionManifestTest, WebIntents) {
- CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents");
+ CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableWebIntents);
LoadAndExpectError("intent_invalid_1.json",
extension_manifest_errors::kInvalidIntents);
@@ -812,7 +812,7 @@ TEST_F(ExtensionManifestTest, WebIntents) {
ASSERT_TRUE(extension.get() != NULL);
ASSERT_EQ(1u, extension->intents_services().size());
- EXPECT_EQ("", UTF16ToUTF8(extension->intents_services()[0].type));
+ EXPECT_EQ("*", UTF16ToUTF8(extension->intents_services()[0].type));
EXPECT_EQ("http://webintents.org/share",
UTF16ToUTF8(extension->intents_services()[0].action));
EXPECT_TRUE(extension->intents_services()[0].service_url.is_empty());
@@ -821,6 +821,36 @@ TEST_F(ExtensionManifestTest, WebIntents) {
extension->intents_services()[0].disposition);
}
+TEST_F(ExtensionManifestTest, WebIntentsWithMultipleMimeTypes) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableWebIntents);
+
+ scoped_refptr<Extension> extension(
+ LoadAndExpectSuccess("intent_valid_multitype.json"));
+ ASSERT_TRUE(extension.get() != NULL);
+
+ ASSERT_EQ(2u, extension->intents_services().size());
+
+ // One registration with multiple types generates a separate service for
+ // each MIME type.
+ for (int i = 0; i < 2; ++i) {
+ EXPECT_EQ("http://webintents.org/share",
+ UTF16ToUTF8(extension->intents_services()[i].action));
+ EXPECT_EQ("chrome-extension",
+ extension->intents_services()[i].service_url.scheme());
+ EXPECT_EQ("///services/share",
+ extension->intents_services()[i].service_url.path());
+ EXPECT_EQ("Sample Sharing Intent",
+ UTF16ToUTF8(extension->intents_services()[i].title));
+ EXPECT_EQ(webkit_glue::WebIntentServiceData::DISPOSITION_INLINE,
+ extension->intents_services()[i].disposition);
+ }
+ EXPECT_EQ("image/jpeg", UTF16ToUTF8(extension->intents_services()[0].type));
+ EXPECT_EQ("image/bmp", UTF16ToUTF8(extension->intents_services()[1].type));
+
+ LoadAndExpectError("intent_invalid_type_element.json",
+ extension_manifest_errors::kInvalidIntentTypeElement);
+}
+
TEST_F(ExtensionManifestTest, PortsInPermissions) {
// Loading as a user would shoud not trigger an error.
LoadAndExpectSuccess("ports_in_permissions.json");
diff --git a/chrome/test/data/extensions/manifest_tests/intent_invalid_3.json b/chrome/test/data/extensions/manifest_tests/intent_invalid_3.json
index 72f04c2..e723789 100644
--- a/chrome/test/data/extensions/manifest_tests/intent_invalid_3.json
+++ b/chrome/test/data/extensions/manifest_tests/intent_invalid_3.json
@@ -3,7 +3,8 @@
"version": "1",
"intents": {
"http://webintents.org/intent/share" : {
- "path" : { "shouldBeA" : "string" }
+ "path" : { "shouldBeA" : "string" },
+ "type" : [ "*" ]
}
}
}
diff --git a/chrome/test/data/extensions/manifest_tests/intent_invalid_4.json b/chrome/test/data/extensions/manifest_tests/intent_invalid_4.json
index dfb2d51..8f32f1c 100644
--- a/chrome/test/data/extensions/manifest_tests/intent_invalid_4.json
+++ b/chrome/test/data/extensions/manifest_tests/intent_invalid_4.json
@@ -3,7 +3,8 @@
"version": "1",
"intents": {
"http://webintents.org/intent/share" : {
- "disposition" : "gibberish"
+ "disposition" : "gibberish",
+ "type" : [ "*" ]
}
}
}
diff --git a/chrome/test/data/extensions/manifest_tests/intent_invalid_6.json b/chrome/test/data/extensions/manifest_tests/intent_invalid_6.json
index 585c408..75429f4 100644
--- a/chrome/test/data/extensions/manifest_tests/intent_invalid_6.json
+++ b/chrome/test/data/extensions/manifest_tests/intent_invalid_6.json
@@ -3,7 +3,8 @@
"version": "1",
"intents": {
"http://webintents.org/intent/share" : {
- "title" : { "shouldBeA" : "string" }
+ "title" : { "shouldBeA" : "string" },
+ "type" : [ "*" ]
}
}
}
diff --git a/chrome/test/data/extensions/manifest_tests/intent_invalid_type_element.json b/chrome/test/data/extensions/manifest_tests/intent_invalid_type_element.json
new file mode 100644
index 0000000..3407408
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/intent_invalid_type_element.json
@@ -0,0 +1,12 @@
+{
+ "name": "test",
+ "version": "1",
+ "intents": {
+ "http://webintents.org/share" : {
+ "type" : [ "image/png", ["image/jpeg"], "image/bmp" ],
+ "path" : "//services/share",
+ "title" : "Sample Sharing Intent",
+ "disposition" : "inline"
+ }
+ }
+}
diff --git a/chrome/test/data/extensions/manifest_tests/intent_valid.json b/chrome/test/data/extensions/manifest_tests/intent_valid.json
index 9a62df8..a5272f4 100644
--- a/chrome/test/data/extensions/manifest_tests/intent_valid.json
+++ b/chrome/test/data/extensions/manifest_tests/intent_valid.json
@@ -3,7 +3,7 @@
"version": "1",
"intents": {
"http://webintents.org/share" : {
- "type" : "image/png",
+ "type" : [ "image/png" ],
"path" : "//services/share",
"title" : "Sample Sharing Intent",
"disposition" : "inline"
diff --git a/chrome/test/data/extensions/manifest_tests/intent_valid_2.json b/chrome/test/data/extensions/manifest_tests/intent_valid_2.json
index 7a30ad7..bb02470 100644
--- a/chrome/test/data/extensions/manifest_tests/intent_valid_2.json
+++ b/chrome/test/data/extensions/manifest_tests/intent_valid_2.json
@@ -3,7 +3,7 @@
"version": "1",
"intents": {
"http://webintents.org/edit" : {
- "type" : "image/png",
+ "type" : [ "image/png" ],
"path" : "//services/edit",
"title" : "Sample Editing Intent",
"disposition" : "inline"
diff --git a/chrome/test/data/extensions/manifest_tests/intent_valid_minimal.json b/chrome/test/data/extensions/manifest_tests/intent_valid_minimal.json
index 22a9508..86761a5 100644
--- a/chrome/test/data/extensions/manifest_tests/intent_valid_minimal.json
+++ b/chrome/test/data/extensions/manifest_tests/intent_valid_minimal.json
@@ -3,6 +3,7 @@
"version": "1",
"intents": {
"http://webintents.org/share" : {
+ "type" : [ "*" ]
}
}
}
diff --git a/chrome/test/data/extensions/manifest_tests/intent_valid_multitype.json b/chrome/test/data/extensions/manifest_tests/intent_valid_multitype.json
new file mode 100644
index 0000000..02b5341
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/intent_valid_multitype.json
@@ -0,0 +1,12 @@
+{
+ "name": "test",
+ "version": "1",
+ "intents": {
+ "http://webintents.org/share" : {
+ "type" : [ "image/jpeg", "image/bmp" ],
+ "path" : "//services/share",
+ "title" : "Sample Sharing Intent",
+ "disposition" : "inline"
+ }
+ }
+}