| Index: extensions/common/features/simple_feature.cc
|
| diff --git a/extensions/common/features/simple_feature.cc b/extensions/common/features/simple_feature.cc
|
| index ebb9cb21fd43de212945780a7b52296ac0182708..6914558c7fdb3a05992fc13957e0cebb7f1915a4 100644
|
| --- a/extensions/common/features/simple_feature.cc
|
| +++ b/extensions/common/features/simple_feature.cc
|
| @@ -8,7 +8,6 @@
|
| #include <vector>
|
|
|
| #include "base/command_line.h"
|
| -#include "base/lazy_instance.h"
|
| #include "base/sha1.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| @@ -19,37 +18,6 @@ namespace extensions {
|
|
|
| namespace {
|
|
|
| -struct Mappings {
|
| - Mappings() {
|
| - extension_types["extension"] = Manifest::TYPE_EXTENSION;
|
| - extension_types["theme"] = Manifest::TYPE_THEME;
|
| - extension_types["legacy_packaged_app"] = Manifest::TYPE_LEGACY_PACKAGED_APP;
|
| - extension_types["hosted_app"] = Manifest::TYPE_HOSTED_APP;
|
| - extension_types["platform_app"] = Manifest::TYPE_PLATFORM_APP;
|
| - extension_types["shared_module"] = Manifest::TYPE_SHARED_MODULE;
|
| -
|
| - contexts["blessed_extension"] = Feature::BLESSED_EXTENSION_CONTEXT;
|
| - contexts["unblessed_extension"] = Feature::UNBLESSED_EXTENSION_CONTEXT;
|
| - contexts["content_script"] = Feature::CONTENT_SCRIPT_CONTEXT;
|
| - contexts["web_page"] = Feature::WEB_PAGE_CONTEXT;
|
| - contexts["blessed_web_page"] = Feature::BLESSED_WEB_PAGE_CONTEXT;
|
| -
|
| - locations["component"] = Feature::COMPONENT_LOCATION;
|
| -
|
| - platforms["chromeos"] = Feature::CHROMEOS_PLATFORM;
|
| - platforms["linux"] = Feature::LINUX_PLATFORM;
|
| - platforms["mac"] = Feature::MACOSX_PLATFORM;
|
| - platforms["win"] = Feature::WIN_PLATFORM;
|
| - }
|
| -
|
| - std::map<std::string, Manifest::Type> extension_types;
|
| - std::map<std::string, Feature::Context> contexts;
|
| - std::map<std::string, Feature::Location> locations;
|
| - std::map<std::string, Feature::Platform> platforms;
|
| -};
|
| -
|
| -base::LazyInstance<Mappings> g_mappings = LAZY_INSTANCE_INITIALIZER;
|
| -
|
| // TODO(aa): Can we replace all this manual parsing with JSON schema stuff?
|
|
|
| void ParseSet(const base::DictionaryValue* value,
|
| @@ -214,6 +182,40 @@ std::string HashExtensionId(const std::string& extension_id) {
|
|
|
| } // namespace
|
|
|
| +struct SimpleFeature::Mappings {
|
| + Mappings() {
|
| + extension_types["extension"] = Manifest::TYPE_EXTENSION;
|
| + extension_types["theme"] = Manifest::TYPE_THEME;
|
| + extension_types["legacy_packaged_app"] = Manifest::TYPE_LEGACY_PACKAGED_APP;
|
| + extension_types["hosted_app"] = Manifest::TYPE_HOSTED_APP;
|
| + extension_types["platform_app"] = Manifest::TYPE_PLATFORM_APP;
|
| + extension_types["shared_module"] = Manifest::TYPE_SHARED_MODULE;
|
| +
|
| + contexts["blessed_extension"] = Feature::BLESSED_EXTENSION_CONTEXT;
|
| + contexts["unblessed_extension"] = Feature::UNBLESSED_EXTENSION_CONTEXT;
|
| + contexts["content_script"] = Feature::CONTENT_SCRIPT_CONTEXT;
|
| + contexts["web_page"] = Feature::WEB_PAGE_CONTEXT;
|
| + contexts["blessed_web_page"] = Feature::BLESSED_WEB_PAGE_CONTEXT;
|
| +
|
| + locations["component"] = SimpleFeature::COMPONENT_LOCATION;
|
| + locations["policy"] = SimpleFeature::POLICY_LOCATION;
|
| +
|
| + platforms["chromeos"] = Feature::CHROMEOS_PLATFORM;
|
| + platforms["linux"] = Feature::LINUX_PLATFORM;
|
| + platforms["mac"] = Feature::MACOSX_PLATFORM;
|
| + platforms["win"] = Feature::WIN_PLATFORM;
|
| + }
|
| +
|
| + std::map<std::string, Manifest::Type> extension_types;
|
| + std::map<std::string, Feature::Context> contexts;
|
| + std::map<std::string, SimpleFeature::Location> locations;
|
| + std::map<std::string, Feature::Platform> platforms;
|
| +};
|
| +
|
| +// static
|
| +base::LazyInstance<SimpleFeature::Mappings> SimpleFeature::g_mappings =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| SimpleFeature::SimpleFeature()
|
| : location_(UNSPECIFIED_LOCATION),
|
| min_manifest_version_(0),
|
| @@ -264,7 +266,7 @@ std::string SimpleFeature::Parse(const base::DictionaryValue* value) {
|
| Feature::Availability SimpleFeature::IsAvailableToManifest(
|
| const std::string& extension_id,
|
| Manifest::Type type,
|
| - Location location,
|
| + Manifest::Location location,
|
| int manifest_version,
|
| Platform platform) const {
|
| // Check extension type first to avoid granting platform app permissions
|
| @@ -279,7 +281,8 @@ Feature::Availability SimpleFeature::IsAvailableToManifest(
|
| }
|
|
|
| // Component extensions can access any feature.
|
| - if (location == COMPONENT_LOCATION)
|
| + // TODO(kalman/asargent): Should this match EXTERNAL_COMPONENT too?
|
| + if (location == Manifest::COMPONENT)
|
| return CreateAvailability(IS_AVAILABLE, type);
|
|
|
| if (!whitelist_.empty()) {
|
| @@ -298,7 +301,7 @@ Feature::Availability SimpleFeature::IsAvailableToManifest(
|
| }
|
| }
|
|
|
| - if (location_ != UNSPECIFIED_LOCATION && location_ != location)
|
| + if (!MatchesManifestLocation(location))
|
| return CreateAvailability(INVALID_LOCATION, type);
|
|
|
| if (!platforms_.empty() &&
|
| @@ -329,12 +332,11 @@ Feature::Availability SimpleFeature::IsAvailableToContext(
|
| const GURL& url,
|
| SimpleFeature::Platform platform) const {
|
| if (extension) {
|
| - Availability result = IsAvailableToManifest(
|
| - extension->id(),
|
| - extension->GetType(),
|
| - ConvertLocation(extension->location()),
|
| - extension->manifest_version(),
|
| - platform);
|
| + Availability result = IsAvailableToManifest(extension->id(),
|
| + extension->GetType(),
|
| + extension->location(),
|
| + extension->manifest_version(),
|
| + platform);
|
| if (!result.is_available())
|
| return result;
|
| }
|
| @@ -479,4 +481,20 @@ bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id,
|
| return false;
|
| }
|
|
|
| +bool SimpleFeature::MatchesManifestLocation(
|
| + Manifest::Location manifest_location) const {
|
| + switch (location_) {
|
| + case SimpleFeature::UNSPECIFIED_LOCATION:
|
| + return true;
|
| + case SimpleFeature::COMPONENT_LOCATION:
|
| + return manifest_location == Manifest::COMPONENT ||
|
| + manifest_location == Manifest::EXTERNAL_COMPONENT;
|
| + case SimpleFeature::POLICY_LOCATION:
|
| + return manifest_location == Manifest::EXTERNAL_POLICY ||
|
| + manifest_location == Manifest::EXTERNAL_POLICY_DOWNLOAD;
|
| + }
|
| + NOTREACHED();
|
| + return false;
|
| +}
|
| +
|
| } // namespace extensions
|
|
|