| 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/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 bool Manifest::ValidateManifest(string16* error) 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 *error = UTF8ToUTF16(feature->GetErrorMessage(result)); |
| 46 errors::kFeatureNotAllowed, | |
| 47 *key, | |
| 48 feature->GetErrorMessage(result)); | |
| 49 return false; | 51 return false; |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 | 54 |
| 53 return true; | 55 return true; |
| 54 } | 56 } |
| 55 | 57 |
| 56 bool Manifest::HasKey(const std::string& key) const { | 58 bool Manifest::HasKey(const std::string& key) const { |
| 57 return CanAccessKey(key) && value_->HasKey(key); | 59 return CanAccessKey(key) && value_->HasKey(key); |
| 58 } | 60 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return GetType() == Extension::TYPE_PACKAGED_APP; | 141 return GetType() == Extension::TYPE_PACKAGED_APP; |
| 140 } | 142 } |
| 141 | 143 |
| 142 bool Manifest::IsHostedApp() const { | 144 bool Manifest::IsHostedApp() const { |
| 143 return GetType() == Extension::TYPE_HOSTED_APP; | 145 return GetType() == Extension::TYPE_HOSTED_APP; |
| 144 } | 146 } |
| 145 | 147 |
| 146 bool Manifest::CanAccessPath(const std::string& path) const { | 148 bool Manifest::CanAccessPath(const std::string& path) const { |
| 147 std::vector<std::string> components; | 149 std::vector<std::string> components; |
| 148 base::SplitString(path, '.', &components); | 150 base::SplitString(path, '.', &components); |
| 149 return CanAccessKey(components[0]); | 151 std::string key; |
| 152 for (size_t i = 0; i < components.size(); ++i) { |
| 153 key += components[i]; |
| 154 if (!CanAccessKey(key)) |
| 155 return false; |
| 156 key += '.'; |
| 157 } |
| 158 return true; |
| 150 } | 159 } |
| 151 | 160 |
| 152 bool Manifest::CanAccessKey(const std::string& key) const { | 161 bool Manifest::CanAccessKey(const std::string& key) const { |
| 153 Feature* feature = | 162 Feature* feature = |
| 154 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); | 163 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); |
| 155 if (!feature) | 164 if (!feature) |
| 156 return false; | 165 return true; |
| 157 | 166 |
| 158 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest( | 167 return Feature::IS_AVAILABLE == feature->IsAvailableToManifest( |
| 159 extension_id_, GetType(), Feature::ConvertLocation(location_), | 168 extension_id_, GetType(), Feature::ConvertLocation(location_), |
| 160 GetManifestVersion()); | 169 GetManifestVersion()); |
| 161 } | 170 } |
| 162 | 171 |
| 163 } // namespace extensions | 172 } // namespace extensions |
| OLD | NEW |