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

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: Created 8 years, 8 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
« no previous file with comments | « chrome/common/extensions/manifest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/common/extensions/extension_manifest_constants.h" 11 #include "chrome/common/extensions/extension_manifest_constants.h"
12 #include "chrome/common/extensions/extension_error_utils.h" 12 #include "chrome/common/extensions/extension_error_utils.h"
13 #include "chrome/common/extensions/simple_feature_provider.h" 13 #include "chrome/common/extensions/simple_feature_provider.h"
14 14
15 namespace errors = extension_manifest_errors; 15 namespace errors = extension_manifest_errors;
16 namespace keys = extension_manifest_keys; 16 namespace keys = extension_manifest_keys;
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 Manifest::Manifest(Extension::Location location, 20 Manifest::Manifest(Extension::Location location,
21 scoped_ptr<DictionaryValue> value) 21 scoped_ptr<DictionaryValue> value)
22 : location_(location), value_(value.Pass()) { 22 : location_(location), value_(value.Pass()) {
23 } 23 }
24 24
25 Manifest::~Manifest() { 25 Manifest::~Manifest() {
26 } 26 }
27 27
28 bool Manifest::ValidateManifest(string16* error) const { 28 void Manifest::ValidateManifest(std::vector<std::string>* warnings) const {
29 for (DictionaryValue::key_iterator key = value_->begin_keys(); 29 // Check every feature to see if its in the manifest. Note that this means
30 key != value_->end_keys(); ++key) { 30 // we will ignore keys that are not features; we do this for forward
31 // compatibility.
32 // TODO(aa): Consider having an error here in the case of strict error
33 // checking to let developers know when they screw up.
34
35 std::set<std::string> feature_names =
36 SimpleFeatureProvider::GetManifestFeatures()->GetAllFeatureNames();
37 for (std::set<std::string>::iterator feature_name = feature_names.begin();
38 feature_name != feature_names.end(); ++feature_name) {
39 // Use Get instead of HasKey because the former uses path expansion.
40 if (!value_->Get(*feature_name, NULL))
41 continue;
42
31 Feature* feature = 43 Feature* feature =
32 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*key); 44 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( 45 Feature::Availability result = feature->IsAvailableToManifest(
42 extension_id_, GetType(), Feature::ConvertLocation(location_), 46 extension_id_, GetType(), Feature::ConvertLocation(location_),
43 GetManifestVersion()); 47 GetManifestVersion());
44 if (result != Feature::IS_AVAILABLE) { 48 if (result != Feature::IS_AVAILABLE)
45 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 49 warnings->push_back(feature->GetErrorMessage(result));
46 errors::kFeatureNotAllowed,
47 *key,
48 feature->GetErrorMessage(result));
49 return false;
50 }
51 } 50 }
52
53 return true;
54 } 51 }
55 52
56 bool Manifest::HasKey(const std::string& key) const { 53 bool Manifest::HasKey(const std::string& key) const {
57 return CanAccessKey(key) && value_->HasKey(key); 54 return CanAccessKey(key) && value_->HasKey(key);
58 } 55 }
59 56
60 bool Manifest::Get( 57 bool Manifest::Get(
61 const std::string& path, Value** out_value) const { 58 const std::string& path, Value** out_value) const {
62 return CanAccessPath(path) && value_->Get(path, out_value); 59 return CanAccessPath(path) && value_->Get(path, out_value);
63 } 60 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return GetType() == Extension::TYPE_PACKAGED_APP; 136 return GetType() == Extension::TYPE_PACKAGED_APP;
140 } 137 }
141 138
142 bool Manifest::IsHostedApp() const { 139 bool Manifest::IsHostedApp() const {
143 return GetType() == Extension::TYPE_HOSTED_APP; 140 return GetType() == Extension::TYPE_HOSTED_APP;
144 } 141 }
145 142
146 bool Manifest::CanAccessPath(const std::string& path) const { 143 bool Manifest::CanAccessPath(const std::string& path) const {
147 std::vector<std::string> components; 144 std::vector<std::string> components;
148 base::SplitString(path, '.', &components); 145 base::SplitString(path, '.', &components);
149 return CanAccessKey(components[0]); 146 std::string key;
147 for (size_t i = 0; i < components.size(); ++i) {
148 key += components[i];
149 if (!CanAccessKey(key))
150 return false;
151 key += '.';
152 }
153 return true;
150 } 154 }
151 155
152 bool Manifest::CanAccessKey(const std::string& key) const { 156 bool Manifest::CanAccessKey(const std::string& key) const {
153 Feature* feature = 157 Feature* feature =
154 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); 158 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key);
155 if (!feature) 159 if (!feature)
156 return false; 160 return true;
Matt Perry 2012/04/25 01:06:26 This is technically a change in functionality (nee
157 161
158 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest( 162 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest(
159 extension_id_, GetType(), Feature::ConvertLocation(location_), 163 extension_id_, GetType(), Feature::ConvertLocation(location_),
160 GetManifestVersion()); 164 GetManifestVersion());
161 } 165 }
162 166
163 } // namespace extensions 167 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698