Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/extensions/features/simple_feature_provider.h" | 5 #include "chrome/common/extensions/features/simple_feature_provider.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "chrome/common/extensions/features/manifest_feature.h" | 9 #include "chrome/common/extensions/features/manifest_feature.h" |
| 10 #include "chrome/common/extensions/features/permission_feature.h" | 10 #include "chrome/common/extensions/features/permission_feature.h" |
| 11 #include "grit/common_resources.h" | 11 #include "grit/common_resources.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 template<class FeatureClass> | 18 template<class FeatureClass> |
| 19 Feature* CreateFeature() { | 19 SimpleFeature* CreateFeature() { |
| 20 return new FeatureClass(); | 20 return new FeatureClass(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 struct Static { | 23 struct Static { |
| 24 Static() | 24 Static() |
| 25 : manifest_features( | 25 : manifest_features( |
| 26 LoadProvider("manifest", | 26 LoadProvider("manifest", |
| 27 &CreateFeature<ManifestFeature>, | 27 &CreateFeature<ManifestFeature>, |
| 28 IDR_EXTENSION_MANIFEST_FEATURES)), | 28 IDR_EXTENSION_MANIFEST_FEATURES)), |
| 29 permission_features( | 29 permission_features( |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 58 } | 58 } |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; | 61 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 SimpleFeatureProvider::SimpleFeatureProvider(DictionaryValue* root, | 65 SimpleFeatureProvider::SimpleFeatureProvider(DictionaryValue* root, |
| 66 FeatureFactory factory) | 66 FeatureFactory factory) |
| 67 : factory_(factory ? factory : | 67 : factory_(factory ? factory : |
| 68 static_cast<FeatureFactory>(&CreateFeature<Feature>)) { | 68 static_cast<FeatureFactory>(&CreateFeature<SimpleFeature>)) { |
| 69 for (DictionaryValue::Iterator iter(*root); iter.HasNext(); iter.Advance()) { | 69 for (DictionaryValue::Iterator iter(*root); iter.HasNext(); iter.Advance()) { |
| 70 if (iter.value().GetType() != Value::TYPE_DICTIONARY) { | 70 if (iter.value().GetType() != Value::TYPE_DICTIONARY) { |
| 71 LOG(ERROR) << iter.key() << ": Feature description must be dictionary."; | 71 if (iter.value().GetType() != Value::TYPE_LIST) |
| 72 LOG(ERROR) << iter.key() << ": Feature description must be dictionary."; | |
| 73 else | |
| 74 DVLOG(2) << iter.key() << ": Feature is a complex feature."; | |
|
not at google - send to devlin
2012/12/12 17:42:41
I would hope this, by design, can never happen and
justinlin
2012/12/14 12:26:26
Updated.
| |
| 72 continue; | 75 continue; |
| 73 } | 76 } |
| 74 | 77 |
| 75 linked_ptr<Feature> feature((*factory_)()); | 78 linked_ptr<SimpleFeature> feature((*factory_)()); |
| 76 feature->set_name(iter.key()); | 79 feature->set_name(iter.key()); |
| 77 feature->Parse(static_cast<const DictionaryValue*>(&iter.value())); | 80 feature->Parse(static_cast<const DictionaryValue*>(&iter.value())); |
| 78 | 81 |
| 79 if (feature->extension_types()->empty()) { | 82 if (feature->extension_types()->empty()) { |
| 80 LOG(ERROR) << iter.key() << ": Simple features must specify atleast one " | 83 LOG(ERROR) << iter.key() << ": Simple features must specify at least one " |
| 81 << "value for extension_types."; | 84 << "value for extension_types."; |
| 82 continue; | 85 continue; |
| 83 } | 86 } |
| 84 | 87 |
| 85 if (!feature->contexts()->empty()) { | 88 if (!feature->contexts()->empty()) { |
| 86 LOG(ERROR) << iter.key() << ": Simple features do not support contexts."; | 89 LOG(ERROR) << iter.key() << ": Simple features do not support contexts."; |
| 87 continue; | 90 continue; |
|
not at google - send to devlin
2012/12/12 17:42:41
ah I see, this validation is here. It would be nic
justinlin
2012/12/14 12:26:26
Done.
| |
| 88 } | 91 } |
| 89 | 92 |
| 90 features_[iter.key()] = feature; | 93 features_[iter.key()] = feature; |
| 91 } | 94 } |
| 92 } | 95 } |
| 93 | 96 |
| 94 SimpleFeatureProvider::~SimpleFeatureProvider() { | 97 SimpleFeatureProvider::~SimpleFeatureProvider() { |
| 95 } | 98 } |
| 96 | 99 |
| 97 // static | 100 // static |
| 98 SimpleFeatureProvider* SimpleFeatureProvider::GetManifestFeatures() { | 101 SimpleFeatureProvider* SimpleFeatureProvider::GetManifestFeatures() { |
| 99 return g_static.Get().manifest_features.get(); | 102 return g_static.Get().manifest_features.get(); |
| 100 } | 103 } |
| 101 | 104 |
| 102 // static | 105 // static |
| 103 SimpleFeatureProvider* SimpleFeatureProvider::GetPermissionFeatures() { | 106 SimpleFeatureProvider* SimpleFeatureProvider::GetPermissionFeatures() { |
| 104 return g_static.Get().permission_features.get(); | 107 return g_static.Get().permission_features.get(); |
| 105 } | 108 } |
| 106 | 109 |
| 107 std::set<std::string> SimpleFeatureProvider::GetAllFeatureNames() const { | 110 std::set<std::string> SimpleFeatureProvider::GetAllFeatureNames() const { |
| 108 std::set<std::string> result; | 111 std::set<std::string> result; |
| 109 for (FeatureMap::const_iterator iter = features_.begin(); | 112 for (FeatureMap::const_iterator iter = features_.begin(); |
| 110 iter != features_.end(); ++iter) { | 113 iter != features_.end(); ++iter) { |
| 111 result.insert(iter->first); | 114 result.insert(iter->first); |
| 112 } | 115 } |
| 113 return result; | 116 return result; |
| 114 } | 117 } |
| 115 | 118 |
| 116 Feature* SimpleFeatureProvider::GetFeature(const std::string& name) { | 119 SimpleFeature* SimpleFeatureProvider::GetFeature(const std::string& name) { |
| 117 FeatureMap::iterator iter = features_.find(name); | 120 FeatureMap::iterator iter = features_.find(name); |
| 118 if (iter != features_.end()) | 121 if (iter != features_.end()) |
| 119 return iter->second.get(); | 122 return iter->second.get(); |
| 120 else | 123 else |
| 121 return NULL; | 124 return NULL; |
| 122 } | 125 } |
| 123 | 126 |
| 124 } // namespace | 127 } // namespace |
| OLD | NEW |