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

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

Issue 9705083: Unknown options in extension manifest file are silently ignored (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reduced to a couple lines 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
« no previous file with comments | « chrome/app/generated_resources.grd ('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 "base/stringprintf.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "chrome/common/extensions/extension_manifest_constants.h" 13 #include "chrome/common/extensions/extension_manifest_constants.h"
13 #include "chrome/common/extensions/extension_error_utils.h" 14 #include "chrome/common/extensions/extension_error_utils.h"
14 #include "chrome/common/extensions/simple_feature_provider.h" 15 #include "chrome/common/extensions/simple_feature_provider.h"
15 16
16 namespace errors = extension_manifest_errors; 17 namespace errors = extension_manifest_errors;
17 namespace keys = extension_manifest_keys; 18 namespace keys = extension_manifest_keys;
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 Manifest::Manifest(Extension::Location location, 22 Manifest::Manifest(Extension::Location location,
22 scoped_ptr<DictionaryValue> value) 23 scoped_ptr<DictionaryValue> value)
23 : location_(location), value_(value.Pass()) { 24 : location_(location), value_(value.Pass()) {
24 } 25 }
25 26
26 Manifest::~Manifest() { 27 Manifest::~Manifest() {
27 } 28 }
28 29
29 void Manifest::ValidateManifest(std::vector<std::string>* warnings) const { 30 void Manifest::ValidateManifest(std::vector<std::string>* warnings) const {
30 // Check every feature to see if its in the manifest. Note that this means 31 // Check every feature to see if its in the manifest.
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 = 32 std::set<std::string> feature_names =
37 SimpleFeatureProvider::GetManifestFeatures()->GetAllFeatureNames(); 33 SimpleFeatureProvider::GetManifestFeatures()->GetAllFeatureNames();
38 for (std::set<std::string>::iterator feature_name = feature_names.begin(); 34 for (std::set<std::string>::iterator feature_name = feature_names.begin();
39 feature_name != feature_names.end(); ++feature_name) { 35 feature_name != feature_names.end(); ++feature_name) {
40 // Use Get instead of HasKey because the former uses path expansion. 36 // Use Get instead of HasKey because the former uses path expansion.
41 if (!value_->Get(*feature_name, NULL)) 37 if (!value_->Get(*feature_name, NULL))
42 continue; 38 continue;
43 39
44 Feature* feature = 40 Feature* feature =
45 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name); 41 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name);
46 Feature::Availability result = feature->IsAvailableToManifest( 42 Feature::Availability result = feature->IsAvailableToManifest(
47 extension_id_, GetType(), Feature::ConvertLocation(location_), 43 extension_id_, GetType(), Feature::ConvertLocation(location_),
48 GetManifestVersion()); 44 GetManifestVersion());
49 if (result != Feature::IS_AVAILABLE) 45 if (result != Feature::IS_AVAILABLE)
50 warnings->push_back(feature->GetErrorMessage(result)); 46 warnings->push_back(feature->GetErrorMessage(result));
51 } 47 }
48
49 // Also generate warnings for keys that are not features.
50 for (DictionaryValue::key_iterator key = value_->begin_keys();
51 key != value_->end_keys(); ++key) {
52 if (!SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*key)) {
53 warnings->push_back(base::StringPrintf("Unrecognized manifest key '%s'.",
54 (*key).c_str()));
not at google - send to devlin 2012/05/01 04:04:01 key->c_str()
mitchellwrosen 2012/05/01 04:18:47 But key's a key_iterator, not a std::string*
55 }
56 }
52 } 57 }
53 58
54 bool Manifest::HasKey(const std::string& key) const { 59 bool Manifest::HasKey(const std::string& key) const {
55 return CanAccessKey(key) && value_->HasKey(key); 60 return CanAccessKey(key) && value_->HasKey(key);
56 } 61 }
57 62
58 bool Manifest::Get( 63 bool Manifest::Get(
59 const std::string& path, Value** out_value) const { 64 const std::string& path, Value** out_value) const {
60 return CanAccessPath(path) && value_->Get(path, out_value); 65 return CanAccessPath(path) && value_->Get(path, out_value);
61 } 66 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); 164 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key);
160 if (!feature) 165 if (!feature)
161 return true; 166 return true;
162 167
163 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest( 168 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest(
164 extension_id_, GetType(), Feature::ConvertLocation(location_), 169 extension_id_, GetType(), Feature::ConvertLocation(location_),
165 GetManifestVersion()); 170 GetManifestVersion());
166 } 171 }
167 172
168 } // namespace extensions 173 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698