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

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

Issue 9664053: Re-land 125247: Better error messages when using unsupported manifest features. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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') | chrome/common/extensions/manifest_unittest.cc » ('j') | 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"
(...skipping 10 matching lines...) Expand all
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 bool Manifest::ValidateManifest(string16* error) const {
29 for (DictionaryValue::key_iterator key = value_->begin_keys(); 29 for (DictionaryValue::key_iterator key = value_->begin_keys();
30 key != value_->end_keys(); ++key) { 30 key != value_->end_keys(); ++key) {
31 bool was_known = false; 31 scoped_ptr<Feature> feature =
32 if (!CanAccessKey(*key, &was_known)) { 32 ManifestFeatureProvider::GetDefaultInstance()->GetFeature(*key);
33 if (!feature.get()) {
33 // When validating the extension manifests, we ignore keys that are not 34 // When validating the extension manifests, we ignore keys that are not
34 // recognized for forward compatibility. 35 // recognized for forward compatibility.
35 if (!was_known) { 36 // TODO(aa): Consider having an error here in the case of strict error
36 // TODO(aa): Consider having an error here in the case of strict error 37 // checking to let developers know when they screw up.
37 // checking to let developers know when they screw up. 38 continue;
38 continue; 39 }
39 }
40 40
41 Feature::Availability result = feature->IsAvailable(
42 extension_id_, GetType(), Feature::ConvertLocation(location_),
43 GetManifestVersion());
44 if (result != Feature::IS_AVAILABLE) {
41 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 45 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
42 errors::kFeatureNotAllowed, *key); 46 errors::kFeatureNotAllowed,
47 *key,
48 feature->GetErrorMessage(result));
43 return false; 49 return false;
44 } 50 }
45 } 51 }
46 52
47 return true; 53 return true;
48 } 54 }
49 55
50 bool Manifest::HasKey(const std::string& key) const { 56 bool Manifest::HasKey(const std::string& key) const {
51 return CanAccessKey(key, NULL) && value_->HasKey(key); 57 return CanAccessKey(key) && value_->HasKey(key);
52 } 58 }
53 59
54 bool Manifest::Get( 60 bool Manifest::Get(
55 const std::string& path, Value** out_value) const { 61 const std::string& path, Value** out_value) const {
56 return CanAccessPath(path) && value_->Get(path, out_value); 62 return CanAccessPath(path) && value_->Get(path, out_value);
57 } 63 }
58 64
59 bool Manifest::GetBoolean( 65 bool Manifest::GetBoolean(
60 const std::string& path, bool* out_value) const { 66 const std::string& path, bool* out_value) const {
61 return CanAccessPath(path) && value_->GetBoolean(path, out_value); 67 return CanAccessPath(path) && value_->GetBoolean(path, out_value);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return GetType() == Extension::TYPE_PACKAGED_APP; 139 return GetType() == Extension::TYPE_PACKAGED_APP;
134 } 140 }
135 141
136 bool Manifest::IsHostedApp() const { 142 bool Manifest::IsHostedApp() const {
137 return GetType() == Extension::TYPE_HOSTED_APP; 143 return GetType() == Extension::TYPE_HOSTED_APP;
138 } 144 }
139 145
140 bool Manifest::CanAccessPath(const std::string& path) const { 146 bool Manifest::CanAccessPath(const std::string& path) const {
141 std::vector<std::string> components; 147 std::vector<std::string> components;
142 base::SplitString(path, '.', &components); 148 base::SplitString(path, '.', &components);
143 return CanAccessKey(components[0], NULL); 149 return CanAccessKey(components[0]);
144 } 150 }
145 151
146 bool Manifest::CanAccessKey(const std::string& key, bool *was_known) const { 152 bool Manifest::CanAccessKey(const std::string& key) const {
147 scoped_ptr<Feature> feature = 153 scoped_ptr<Feature> feature =
148 ManifestFeatureProvider::GetDefaultInstance()->GetFeature(key); 154 ManifestFeatureProvider::GetDefaultInstance()->GetFeature(key);
149 if (!feature.get()) 155 if (!feature.get())
150 return false; 156 return false;
151 157
152 if (was_known) 158 return Feature::IS_AVAILABLE == feature->IsAvailable(
153 *was_known = true; 159 extension_id_, GetType(), Feature::ConvertLocation(location_),
154 160 GetManifestVersion());
155 return feature->IsAvailable(extension_id_,
156 GetType(),
157 Feature::ConvertLocation(location_),
158 GetManifestVersion());
159 } 161 }
160 162
161 } // namespace extensions 163 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest.h ('k') | chrome/common/extensions/manifest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698