| Index: extensions/common/features/simple_feature.cc
|
| diff --git a/extensions/common/features/simple_feature.cc b/extensions/common/features/simple_feature.cc
|
| index 37a0c80dc2572469423bd7d6ceb31b2d15ca6067..048fcfb892a81b4015d02173644ccc4551e92e95 100644
|
| --- a/extensions/common/features/simple_feature.cc
|
| +++ b/extensions/common/features/simple_feature.cc
|
| @@ -53,87 +53,6 @@ Feature::Availability IsAvailableToContextForBind(const Extension* extension,
|
| return feature->IsAvailableToContext(extension, context, url, platform);
|
| }
|
|
|
| -// TODO(aa): Can we replace all this manual parsing with JSON schema stuff?
|
| -
|
| -void ParseVector(const base::Value* value,
|
| - std::vector<std::string>* vector) {
|
| - const base::ListValue* list_value = NULL;
|
| - if (!value->GetAsList(&list_value))
|
| - return;
|
| -
|
| - vector->clear();
|
| - size_t list_size = list_value->GetSize();
|
| - vector->reserve(list_size);
|
| - for (size_t i = 0; i < list_size; ++i) {
|
| - std::string str_val;
|
| - CHECK(list_value->GetString(i, &str_val));
|
| - vector->push_back(str_val);
|
| - }
|
| - std::sort(vector->begin(), vector->end());
|
| -}
|
| -
|
| -template<typename T>
|
| -void ParseEnum(const std::string& string_value,
|
| - T* enum_value,
|
| - const std::map<std::string, T>& mapping) {
|
| - const auto& iter = mapping.find(string_value);
|
| - if (iter == mapping.end())
|
| - CRASH_WITH_MINIDUMP("Enum value not found: " + string_value);
|
| - *enum_value = iter->second;
|
| -}
|
| -
|
| -template <typename T>
|
| -void ParseEnum(const base::Value* value,
|
| - T* enum_value,
|
| - const std::map<std::string, T>& mapping) {
|
| - std::string string_value;
|
| - if (!value->GetAsString(&string_value))
|
| - return;
|
| -
|
| - ParseEnum(string_value, enum_value, mapping);
|
| -}
|
| -
|
| -template<typename T>
|
| -void ParseEnumVector(const base::Value* value,
|
| - std::vector<T>* enum_vector,
|
| - const std::map<std::string, T>& mapping) {
|
| - enum_vector->clear();
|
| - std::string property_string;
|
| - if (value->GetAsString(&property_string)) {
|
| - if (property_string == "all") {
|
| - enum_vector->reserve(mapping.size());
|
| - for (const auto& it : mapping)
|
| - enum_vector->push_back(it.second);
|
| - }
|
| - std::sort(enum_vector->begin(), enum_vector->end());
|
| - return;
|
| - }
|
| -
|
| - std::vector<std::string> string_vector;
|
| - ParseVector(value, &string_vector);
|
| - enum_vector->reserve(string_vector.size());
|
| - for (const auto& str : string_vector) {
|
| - T enum_value = static_cast<T>(0);
|
| - ParseEnum(str, &enum_value, mapping);
|
| - enum_vector->push_back(enum_value);
|
| - }
|
| - std::sort(enum_vector->begin(), enum_vector->end());
|
| -}
|
| -
|
| -void ParseURLPatterns(const base::DictionaryValue* value,
|
| - const std::string& key,
|
| - URLPatternSet* set) {
|
| - const base::ListValue* matches = NULL;
|
| - if (value->GetList(key, &matches)) {
|
| - set->ClearPatterns();
|
| - for (size_t i = 0; i < matches->GetSize(); ++i) {
|
| - std::string pattern;
|
| - CHECK(matches->GetString(i, &pattern));
|
| - set->AddPattern(URLPattern(URLPattern::SCHEME_ALL, pattern));
|
| - }
|
| - }
|
| -}
|
| -
|
| // Gets a human-readable name for the given extension type, suitable for giving
|
| // to developers in an error message.
|
| std::string GetDisplayName(Manifest::Type type) {
|
| @@ -265,47 +184,6 @@ SimpleFeature::ScopedWhitelistForTest::~ScopedWhitelistForTest() {
|
| g_whitelisted_extension_id = previous_id_;
|
| }
|
|
|
| -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;
|
| - contexts["webui"] = Feature::WEBUI_CONTEXT;
|
| - contexts["extension_service_worker"] = Feature::SERVICE_WORKER_CONTEXT;
|
| -
|
| - locations["component"] = SimpleFeature::COMPONENT_LOCATION;
|
| - locations["external_component"] =
|
| - SimpleFeature::EXTERNAL_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;
|
| -
|
| - channels["trunk"] = version_info::Channel::UNKNOWN;
|
| - channels["canary"] = version_info::Channel::CANARY;
|
| - channels["dev"] = version_info::Channel::DEV;
|
| - channels["beta"] = version_info::Channel::BETA;
|
| - channels["stable"] = version_info::Channel::STABLE;
|
| - }
|
| -
|
| - 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;
|
| - std::map<std::string, version_info::Channel> channels;
|
| -};
|
| -
|
| SimpleFeature::SimpleFeature()
|
| : location_(UNSPECIFIED_LOCATION),
|
| min_manifest_version_(0),
|
| @@ -315,77 +193,6 @@ SimpleFeature::SimpleFeature()
|
|
|
| SimpleFeature::~SimpleFeature() {}
|
|
|
| -void SimpleFeature::Parse(const base::DictionaryValue* dictionary) {
|
| - static base::LazyInstance<SimpleFeature::Mappings> mappings =
|
| - LAZY_INSTANCE_INITIALIZER;
|
| -
|
| - no_parent_ = false;
|
| - for (base::DictionaryValue::Iterator it(*dictionary);
|
| - !it.IsAtEnd();
|
| - it.Advance()) {
|
| - const std::string& key = it.key();
|
| - const base::Value* value = &it.value();
|
| - if (key == "matches") {
|
| - ParseURLPatterns(dictionary, "matches", &matches_);
|
| - } else if (key == "blacklist") {
|
| - ParseVector(value, &blacklist_);
|
| - } else if (key == "whitelist") {
|
| - ParseVector(value, &whitelist_);
|
| - } else if (key == "dependencies") {
|
| - ParseVector(value, &dependencies_);
|
| - } else if (key == "extension_types") {
|
| - ParseEnumVector<Manifest::Type>(value, &extension_types_,
|
| - mappings.Get().extension_types);
|
| - } else if (key == "contexts") {
|
| - ParseEnumVector<Context>(value, &contexts_,
|
| - mappings.Get().contexts);
|
| - } else if (key == "location") {
|
| - ParseEnum<Location>(value, &location_, mappings.Get().locations);
|
| - } else if (key == "platforms") {
|
| - ParseEnumVector<Platform>(value, &platforms_,
|
| - mappings.Get().platforms);
|
| - } else if (key == "min_manifest_version") {
|
| - dictionary->GetInteger("min_manifest_version", &min_manifest_version_);
|
| - } else if (key == "max_manifest_version") {
|
| - dictionary->GetInteger("max_manifest_version", &max_manifest_version_);
|
| - } else if (key == "noparent") {
|
| - dictionary->GetBoolean("noparent", &no_parent_);
|
| - } else if (key == "component_extensions_auto_granted") {
|
| - dictionary->GetBoolean("component_extensions_auto_granted",
|
| - &component_extensions_auto_granted_);
|
| - } else if (key == "command_line_switch") {
|
| - dictionary->GetString("command_line_switch", &command_line_switch_);
|
| - } else if (key == "channel") {
|
| - channel_.reset(new version_info::Channel(version_info::Channel::UNKNOWN));
|
| - ParseEnum<version_info::Channel>(value, channel_.get(),
|
| - mappings.Get().channels);
|
| - } else if (key == "internal") {
|
| - value->GetAsBoolean(&is_internal_);
|
| - }
|
| - }
|
| -
|
| - // NOTE: ideally we'd sanity check that "matches" can be specified if and
|
| - // only if there's a "web_page" or "webui" context, but without
|
| - // (Simple)Features being aware of their own heirarchy this is impossible.
|
| - //
|
| - // For example, we might have feature "foo" available to "web_page" context
|
| - // and "matches" google.com/*. Then a sub-feature "foo.bar" might override
|
| - // "matches" to be chromium.org/*. That sub-feature doesn't need to specify
|
| - // "web_page" context because it's inherited, but we don't know that here.
|
| -}
|
| -
|
| -bool SimpleFeature::Validate(std::string* error) {
|
| - DCHECK(error);
|
| - // All features must be channel-restricted, either directly or through
|
| - // dependents.
|
| - if (!channel_ && dependencies_.empty()) {
|
| - *error = name() + ": Must supply a value for channel or dependencies.";
|
| - return false;
|
| - }
|
| -
|
| - return true;
|
| -}
|
| -
|
| Feature::Availability SimpleFeature::IsAvailableToManifest(
|
| const std::string& extension_id,
|
| Manifest::Type type,
|
|
|