Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: chrome/common/extensions/manifest.cc

Issue 10217017: Allow features to refer to subkeys in _manifest_features.json. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix theme test Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/manifest.h" 5 #include "chrome/common/extensions/manifest.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/utf_string_conversions.h"
11 #include "chrome/common/extensions/extension_manifest_constants.h" 12 #include "chrome/common/extensions/extension_manifest_constants.h"
12 #include "chrome/common/extensions/extension_error_utils.h" 13 #include "chrome/common/extensions/extension_error_utils.h"
13 #include "chrome/common/extensions/simple_feature_provider.h" 14 #include "chrome/common/extensions/simple_feature_provider.h"
14 15
15 namespace errors = extension_manifest_errors; 16 namespace errors = extension_manifest_errors;
16 namespace keys = extension_manifest_keys; 17 namespace keys = extension_manifest_keys;
17 18
18 namespace extensions { 19 namespace extensions {
19 20
20 Manifest::Manifest(Extension::Location location, 21 Manifest::Manifest(Extension::Location location,
21 scoped_ptr<DictionaryValue> value) 22 scoped_ptr<DictionaryValue> value)
22 : location_(location), value_(value.Pass()) { 23 : location_(location), value_(value.Pass()) {
23 } 24 }
24 25
25 Manifest::~Manifest() { 26 Manifest::~Manifest() {
26 } 27 }
27 28
28 bool Manifest::ValidateManifest(string16* error) const { 29 void Manifest::ValidateManifest(std::vector<std::string>* warnings) const {
29 for (DictionaryValue::key_iterator key = value_->begin_keys(); 30 // Check every feature to see if its in the manifest. Note that this means
30 key != value_->end_keys(); ++key) { 31 // we will ignore keys that are not features; we do this for forward
32 // compatibility.
33 // TODO(aa): Consider having an error here in the case of strict error
34 // checking to let developers know when they screw up.
35
36 std::set<std::string> feature_names =
37 SimpleFeatureProvider::GetManifestFeatures()->GetAllFeatureNames();
38 for (std::set<std::string>::iterator feature_name = feature_names.begin();
39 feature_name != feature_names.end(); ++feature_name) {
40 // Use Get instead of HasKey because the former uses path expansion.
41 if (!value_->Get(*feature_name, NULL))
42 continue;
43
31 Feature* feature = 44 Feature* feature =
32 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*key); 45 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name);
33 if (!feature) {
34 // When validating the extension manifests, we ignore keys that are not
35 // recognized for forward compatibility.
36 // TODO(aa): Consider having an error here in the case of strict error
37 // checking to let developers know when they screw up.
38 continue;
39 }
40
41 Feature::Availability result = feature->IsAvailableToManifest( 46 Feature::Availability result = feature->IsAvailableToManifest(
42 extension_id_, GetType(), Feature::ConvertLocation(location_), 47 extension_id_, GetType(), Feature::ConvertLocation(location_),
43 GetManifestVersion()); 48 GetManifestVersion());
44 if (result != Feature::IS_AVAILABLE) { 49 if (result != Feature::IS_AVAILABLE)
45 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 50 warnings->push_back(feature->GetErrorMessage(result));
46 errors::kFeatureNotAllowed,
47 *key,
48 feature->GetErrorMessage(result));
49 return false;
50 }
51 } 51 }
52
53 return true;
54 } 52 }
55 53
56 bool Manifest::HasKey(const std::string& key) const { 54 bool Manifest::HasKey(const std::string& key) const {
57 return CanAccessKey(key) && value_->HasKey(key); 55 return CanAccessKey(key) && value_->HasKey(key);
58 } 56 }
59 57
60 bool Manifest::Get( 58 bool Manifest::Get(
61 const std::string& path, Value** out_value) const { 59 const std::string& path, Value** out_value) const {
62 return CanAccessPath(path) && value_->Get(path, out_value); 60 return CanAccessPath(path) && value_->Get(path, out_value);
63 } 61 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return GetType() == Extension::TYPE_PACKAGED_APP; 137 return GetType() == Extension::TYPE_PACKAGED_APP;
140 } 138 }
141 139
142 bool Manifest::IsHostedApp() const { 140 bool Manifest::IsHostedApp() const {
143 return GetType() == Extension::TYPE_HOSTED_APP; 141 return GetType() == Extension::TYPE_HOSTED_APP;
144 } 142 }
145 143
146 bool Manifest::CanAccessPath(const std::string& path) const { 144 bool Manifest::CanAccessPath(const std::string& path) const {
147 std::vector<std::string> components; 145 std::vector<std::string> components;
148 base::SplitString(path, '.', &components); 146 base::SplitString(path, '.', &components);
149 return CanAccessKey(components[0]); 147 std::string key;
148 for (size_t i = 0; i < components.size(); ++i) {
149 key += components[i];
150 if (!CanAccessKey(key))
151 return false;
152 key += '.';
153 }
154 return true;
150 } 155 }
151 156
152 bool Manifest::CanAccessKey(const std::string& key) const { 157 bool Manifest::CanAccessKey(const std::string& key) const {
153 Feature* feature = 158 Feature* feature =
154 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); 159 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key);
155 if (!feature) 160 if (!feature)
156 return false; 161 return true;
157 162
158 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest( 163 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest(
159 extension_id_, GetType(), Feature::ConvertLocation(location_), 164 extension_id_, GetType(), Feature::ConvertLocation(location_),
160 GetManifestVersion()); 165 GetManifestVersion());
161 } 166 }
162 167
163 } // namespace extensions 168 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698