summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormef@chromium.org <mef@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-15 20:14:54 +0000
committermef@chromium.org <mef@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-15 20:14:54 +0000
commit685e7596724afc0c4559afcd42ba33fc5fb67a45 (patch)
tree561d579ed8a468a64731c7eaacdaafdc5325baf4
parentc96a81ee512a5cfb8634a65ef3c7b742535ec2e8 (diff)
downloadchromium_src-685e7596724afc0c4559afcd42ba33fc5fb67a45.zip
chromium_src-685e7596724afc0c4559afcd42ba33fc5fb67a45.tar.gz
chromium_src-685e7596724afc0c4559afcd42ba33fc5fb67a45.tar.bz2
Additional platforms support for _api_features.json.
BUG=267667 Review URL: https://codereview.chromium.org/27019008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228748 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/extensions/api/_api_features.json28
-rw-r--r--chrome/common/extensions/api/extension_api_unittest.cc2
-rw-r--r--chrome/common/extensions/features/simple_feature.cc15
-rw-r--r--chrome/common/extensions/features/simple_feature.h5
-rw-r--r--chrome/common/extensions/features/simple_feature_unittest.cc41
-rw-r--r--extensions/common/features/feature.cc6
-rw-r--r--extensions/common/features/feature.h8
7 files changed, 70 insertions, 35 deletions
diff --git a/chrome/common/extensions/api/_api_features.json b/chrome/common/extensions/api/_api_features.json
index cc6e8a4..8e58146 100644
--- a/chrome/common/extensions/api/_api_features.json
+++ b/chrome/common/extensions/api/_api_features.json
@@ -113,7 +113,7 @@
"contexts": ["blessed_extension"]
},
"chromeosInfoPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:chromeosInfoPrivate"],
"contexts": ["blessed_extension"]
},
@@ -196,12 +196,12 @@
"contexts": ["blessed_extension", "unblessed_extension", "content_script"]
},
"echoPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:echoPrivate"],
"contexts": ["blessed_extension"]
},
"enterprise.platformKeysPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:enterprise.platformKeysPrivate"],
"contexts": ["blessed_extension"]
},
@@ -268,18 +268,18 @@
"contexts": ["blessed_extension"]
},
"fileBrowserHandler": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:fileBrowserHandler"],
"contexts": ["blessed_extension"]
},
"fileBrowserHandlerInternal": {
"internal": true,
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"channel": "stable",
"contexts": ["blessed_extension", "unblessed_extension", "content_script"]
},
"fileBrowserPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:fileBrowserPrivate"],
"contexts": ["blessed_extension"]
},
@@ -326,12 +326,12 @@
"contexts": ["blessed_extension"]
},
"input.ime": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:input"],
"contexts": ["blessed_extension"]
},
"inputMethodPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:inputMethodPrivate"],
"contexts": ["blessed_extension"]
},
@@ -374,7 +374,7 @@
"contexts": ["blessed_extension"]
},
"mediaPlayerPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:mediaPlayerPrivate"],
"contexts": ["blessed_extension"]
},
@@ -391,7 +391,7 @@
"contexts": ["blessed_extension"]
},
"networkingPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:networkingPrivate"],
"contexts": ["blessed_extension"]
},
@@ -576,7 +576,7 @@
"contexts": ["blessed_extension"]
},
"terminalPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:terminalPrivate"],
"contexts": ["blessed_extension"]
},
@@ -612,17 +612,17 @@
"contexts": ["blessed_extension"]
},
"virtualKeyboardPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:virtualKeyboardPrivate"],
"contexts": ["blessed_extension"]
},
"wallpaper": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:wallpaper"],
"contexts": ["blessed_extension"]
},
"wallpaperPrivate": {
- "platform": "chromeos",
+ "platforms": ["chromeos"],
"dependencies": ["permission:wallpaperPrivate"],
"contexts": ["blessed_extension"]
},
diff --git a/chrome/common/extensions/api/extension_api_unittest.cc b/chrome/common/extensions/api/extension_api_unittest.cc
index fba0a71..0e340ba 100644
--- a/chrome/common/extensions/api/extension_api_unittest.cc
+++ b/chrome/common/extensions/api/extension_api_unittest.cc
@@ -720,7 +720,7 @@ TEST(ExtensionAPITest, DefaultConfigurationFeatures) {
Feature::BLESSED_EXTENSION_CONTEXT));
EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location());
- EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform());
+ EXPECT_TRUE(feature->platforms()->empty());
EXPECT_EQ(0, feature->min_manifest_version());
EXPECT_EQ(0, feature->max_manifest_version());
}
diff --git a/chrome/common/extensions/features/simple_feature.cc b/chrome/common/extensions/features/simple_feature.cc
index c03b03e..4f71552 100644
--- a/chrome/common/extensions/features/simple_feature.cc
+++ b/chrome/common/extensions/features/simple_feature.cc
@@ -39,6 +39,9 @@ struct Mappings {
locations["component"] = Feature::COMPONENT_LOCATION;
platforms["chromeos"] = Feature::CHROMEOS_PLATFORM;
+ platforms["linux"] = Feature::LINUX_PLATFORM;
+ platforms["macosx"] = Feature::MACOSX_PLATFORM;
+ platforms["windows"] = Feature::WIN_PLATFORM;
channels["trunk"] = VersionInfo::CHANNEL_UNKNOWN;
channels["canary"] = VersionInfo::CHANNEL_CANARY;
@@ -186,7 +189,6 @@ std::string HashExtensionId(const std::string& extension_id) {
SimpleFeature::SimpleFeature()
: location_(UNSPECIFIED_LOCATION),
- platform_(UNSPECIFIED_PLATFORM),
min_manifest_version_(0),
max_manifest_version_(0),
channel_(VersionInfo::CHANNEL_UNKNOWN),
@@ -200,7 +202,7 @@ SimpleFeature::SimpleFeature(const SimpleFeature& other)
contexts_(other.contexts_),
matches_(other.matches_),
location_(other.location_),
- platform_(other.platform_),
+ platforms_(other.platforms_),
min_manifest_version_(other.min_manifest_version_),
max_manifest_version_(other.max_manifest_version_),
channel_(other.channel_),
@@ -217,7 +219,7 @@ bool SimpleFeature::Equals(const SimpleFeature& other) const {
contexts_ == other.contexts_ &&
matches_ == other.matches_ &&
location_ == other.location_ &&
- platform_ == other.platform_ &&
+ platforms_ == other.platforms_ &&
min_manifest_version_ == other.min_manifest_version_ &&
max_manifest_version_ == other.max_manifest_version_ &&
channel_ == other.channel_ &&
@@ -235,8 +237,8 @@ std::string SimpleFeature::Parse(const base::DictionaryValue* value) {
g_mappings.Get().contexts);
ParseEnum<Location>(value, "location", &location_,
g_mappings.Get().locations);
- ParseEnum<Platform>(value, "platform", &platform_,
- g_mappings.Get().platforms);
+ ParseEnumSet<Platform>(value, "platforms", &platforms_,
+ g_mappings.Get().platforms);
value->GetInteger("min_manifest_version", &min_manifest_version_);
value->GetInteger("max_manifest_version", &max_manifest_version_);
ParseEnum<VersionInfo::Channel>(
@@ -298,7 +300,8 @@ Feature::Availability SimpleFeature::IsAvailableToManifest(
if (location_ != UNSPECIFIED_LOCATION && location_ != location)
return CreateAvailability(INVALID_LOCATION, type);
- if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform)
+ if (!platforms_.empty() &&
+ platforms_.find(platform) == platforms_.end())
return CreateAvailability(INVALID_PLATFORM, type);
if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_)
diff --git a/chrome/common/extensions/features/simple_feature.h b/chrome/common/extensions/features/simple_feature.h
index e955648..9013e18 100644
--- a/chrome/common/extensions/features/simple_feature.h
+++ b/chrome/common/extensions/features/simple_feature.h
@@ -40,8 +40,7 @@ class SimpleFeature : public Feature {
Location location() const { return location_; }
void set_location(Location location) { location_ = location; }
- Platform platform() const { return platform_; }
- void set_platform(Platform platform) { platform_ = platform; }
+ std::set<Platform>* platforms() { return &platforms_; }
int min_manifest_version() const { return min_manifest_version_; }
void set_min_manifest_version(int min_manifest_version) {
@@ -109,7 +108,7 @@ class SimpleFeature : public Feature {
std::set<Context> contexts_;
URLPatternSet matches_;
Location location_; // we only care about component/not-component now
- Platform platform_; // we only care about chromeos/not-chromeos now
+ std::set<Platform> platforms_;
int min_manifest_version_;
int max_manifest_version_;
chrome::VersionInfo::Channel channel_;
diff --git a/chrome/common/extensions/features/simple_feature_unittest.cc b/chrome/common/extensions/features/simple_feature_unittest.cc
index 4129d6f..03145a5 100644
--- a/chrome/common/extensions/features/simple_feature_unittest.cc
+++ b/chrome/common/extensions/features/simple_feature_unittest.cc
@@ -174,7 +174,7 @@ TEST_F(ExtensionSimpleFeatureTest, Context) {
SimpleFeature feature;
feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP);
- feature.set_platform(Feature::CHROMEOS_PLATFORM);
+ feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
feature.set_min_manifest_version(21);
feature.set_max_manifest_version(25);
@@ -270,7 +270,7 @@ TEST_F(ExtensionSimpleFeatureTest, Location) {
TEST_F(ExtensionSimpleFeatureTest, Platform) {
SimpleFeature feature;
- feature.set_platform(Feature::CHROMEOS_PLATFORM);
+ feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
EXPECT_EQ(Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
@@ -353,7 +353,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParseNull) {
EXPECT_TRUE(feature->extension_types()->empty());
EXPECT_TRUE(feature->GetContexts()->empty());
EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location());
- EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform());
+ EXPECT_TRUE(feature->platforms()->empty());
EXPECT_EQ(0, feature->min_manifest_version());
EXPECT_EQ(0, feature->max_manifest_version());
}
@@ -432,12 +432,35 @@ TEST_F(ExtensionSimpleFeatureTest, ParseLocation) {
EXPECT_EQ(Feature::COMPONENT_LOCATION, feature->location());
}
-TEST_F(ExtensionSimpleFeatureTest, ParsePlatform) {
+TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) {
scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
- value->SetString("platform", "chromeos");
scoped_ptr<SimpleFeature> feature(new SimpleFeature());
+ base::ListValue* platforms = new base::ListValue();
+ value->Set("platforms", platforms);
feature->Parse(value.get());
- EXPECT_EQ(Feature::CHROMEOS_PLATFORM, feature->platform());
+ EXPECT_TRUE(feature->platforms()->empty());
+
+ platforms->AppendString("chromeos");
+ feature->Parse(value.get());
+ EXPECT_FALSE(feature->platforms()->empty());
+ EXPECT_EQ(Feature::CHROMEOS_PLATFORM, *feature->platforms()->begin());
+
+ platforms->Clear();
+ platforms->AppendString("windows");
+ feature->Parse(value.get());
+ EXPECT_FALSE(feature->platforms()->empty());
+ EXPECT_EQ(Feature::WIN_PLATFORM, *feature->platforms()->begin());
+
+ platforms->Clear();
+ platforms->AppendString("windows");
+ platforms->AppendString("chromeos");
+ feature->Parse(value.get());
+ std::set<Feature::Platform> expected_platforms;
+ expected_platforms.insert(Feature::CHROMEOS_PLATFORM);
+ expected_platforms.insert(Feature::WIN_PLATFORM);
+
+ EXPECT_FALSE(feature->platforms()->empty());
+ EXPECT_EQ(expected_platforms, *feature->platforms());
}
TEST_F(ExtensionSimpleFeatureTest, ManifestVersion) {
@@ -456,7 +479,7 @@ TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
feature.extension_types()->insert(Manifest::TYPE_THEME);
feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
feature.set_location(Feature::COMPONENT_LOCATION);
- feature.set_platform(Feature::CHROMEOS_PLATFORM);
+ feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
feature.set_min_manifest_version(1);
feature.set_max_manifest_version(2);
@@ -499,7 +522,7 @@ TEST_F(ExtensionSimpleFeatureTest, Equals) {
feature.extension_types()->insert(Manifest::TYPE_THEME);
feature.GetContexts()->insert(Feature::UNBLESSED_EXTENSION_CONTEXT);
feature.set_location(Feature::COMPONENT_LOCATION);
- feature.set_platform(Feature::CHROMEOS_PLATFORM);
+ feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
feature.set_min_manifest_version(18);
feature.set_max_manifest_version(25);
@@ -522,7 +545,7 @@ TEST_F(ExtensionSimpleFeatureTest, Equals) {
EXPECT_FALSE(feature2.Equals(feature));
feature2 = feature;
- feature2.set_platform(Feature::UNSPECIFIED_PLATFORM);
+ feature.platforms()->insert(Feature::UNSPECIFIED_PLATFORM);
EXPECT_FALSE(feature2.Equals(feature));
feature2 = feature;
diff --git a/extensions/common/features/feature.cc b/extensions/common/features/feature.cc
index 705f3e5..60f7f88 100644
--- a/extensions/common/features/feature.cc
+++ b/extensions/common/features/feature.cc
@@ -17,6 +17,12 @@ namespace extensions {
Feature::Platform Feature::GetCurrentPlatform() {
#if defined(OS_CHROMEOS)
return CHROMEOS_PLATFORM;
+#elif defined(OS_LINUX)
+ return LINUX_PLATFORM;
+#elif defined(OS_MACOSX)
+ return MACOSX_PLATFORM;
+#elif defined(OS_WIN)
+ return WIN_PLATFORM;
#else
return UNSPECIFIED_PLATFORM;
#endif
diff --git a/extensions/common/features/feature.h b/extensions/common/features/feature.h
index 036fc72..0ffd91d 100644
--- a/extensions/common/features/feature.h
+++ b/extensions/common/features/feature.h
@@ -20,7 +20,8 @@ class Extension;
// Represents a single feature accessible to an extension developer, such as a
// top-level manifest key, a permission, or a programmatic API. A feature can
// express requirements for where it can be accessed, and supports testing
-// support for those requirements.
+// support for those requirements. If platforms are not specified, then feature
+// is available on all platforms.
class Feature {
public:
// The JavaScript contexts the feature is supported in.
@@ -49,7 +50,10 @@ class Feature {
// The platforms the feature is supported in.
enum Platform {
UNSPECIFIED_PLATFORM,
- CHROMEOS_PLATFORM
+ CHROMEOS_PLATFORM,
+ LINUX_PLATFORM,
+ MACOSX_PLATFORM,
+ WIN_PLATFORM
};
// Whether a feature is available in a given situation or not, and if not,