| 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/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 *error = errors::kPlatformAppNeedsManifestVersion2; | 132 *error = errors::kPlatformAppNeedsManifestVersion2; |
| 133 return false; | 133 return false; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Check every feature to see if its in the manifest. Note that this means | 136 // Check every feature to see if its in the manifest. Note that this means |
| 137 // we will ignore keys that are not features; we do this for forward | 137 // we will ignore keys that are not features; we do this for forward |
| 138 // compatibility. | 138 // compatibility. |
| 139 // TODO(aa): Consider having an error here in the case of strict error | 139 // TODO(aa): Consider having an error here in the case of strict error |
| 140 // checking to let developers know when they screw up. | 140 // checking to let developers know when they screw up. |
| 141 | 141 |
| 142 std::set<std::string> feature_names = | 142 BaseFeatureProvider* provider = |
| 143 BaseFeatureProvider::GetManifestFeatures()->GetAllFeatureNames(); | 143 BaseFeatureProvider::GetFeaturesByName("manifest"); |
| 144 std::set<std::string> feature_names = provider->GetAllFeatureNames(); |
| 144 for (std::set<std::string>::iterator feature_name = feature_names.begin(); | 145 for (std::set<std::string>::iterator feature_name = feature_names.begin(); |
| 145 feature_name != feature_names.end(); ++feature_name) { | 146 feature_name != feature_names.end(); ++feature_name) { |
| 146 // Use Get instead of HasKey because the former uses path expansion. | 147 // Use Get instead of HasKey because the former uses path expansion. |
| 147 if (!value_->Get(*feature_name, NULL)) | 148 if (!value_->Get(*feature_name, NULL)) |
| 148 continue; | 149 continue; |
| 149 | 150 |
| 150 Feature* feature = | 151 Feature* feature = provider->GetFeature(*feature_name); |
| 151 BaseFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name); | |
| 152 Feature::Availability result = feature->IsAvailableToManifest( | 152 Feature::Availability result = feature->IsAvailableToManifest( |
| 153 extension_id_, type_, Feature::ConvertLocation(location_), | 153 extension_id_, type_, Feature::ConvertLocation(location_), |
| 154 GetManifestVersion()); | 154 GetManifestVersion()); |
| 155 if (!result.is_available()) | 155 if (!result.is_available()) |
| 156 warnings->push_back(InstallWarning( | 156 warnings->push_back(InstallWarning( |
| 157 InstallWarning::FORMAT_TEXT, result.message())); | 157 InstallWarning::FORMAT_TEXT, result.message())); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Also generate warnings for keys that are not features. | 160 // Also generate warnings for keys that are not features. |
| 161 for (base::DictionaryValue::Iterator it(*value_); !it.IsAtEnd(); | 161 for (base::DictionaryValue::Iterator it(*value_); !it.IsAtEnd(); |
| 162 it.Advance()) { | 162 it.Advance()) { |
| 163 if (!BaseFeatureProvider::GetManifestFeatures()->GetFeature(it.key())) { | 163 if (!provider->GetFeature(it.key())) { |
| 164 warnings->push_back(InstallWarning( | 164 warnings->push_back(InstallWarning( |
| 165 InstallWarning::FORMAT_TEXT, | 165 InstallWarning::FORMAT_TEXT, |
| 166 base::StringPrintf("Unrecognized manifest key '%s'.", | 166 base::StringPrintf("Unrecognized manifest key '%s'.", |
| 167 it.key().c_str()))); | 167 it.key().c_str()))); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 return true; | 170 return true; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool Manifest::HasKey(const std::string& key) const { | 173 bool Manifest::HasKey(const std::string& key) const { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 key += components[i]; | 241 key += components[i]; |
| 242 if (!CanAccessKey(key)) | 242 if (!CanAccessKey(key)) |
| 243 return false; | 243 return false; |
| 244 key += '.'; | 244 key += '.'; |
| 245 } | 245 } |
| 246 return true; | 246 return true; |
| 247 } | 247 } |
| 248 | 248 |
| 249 bool Manifest::CanAccessKey(const std::string& key) const { | 249 bool Manifest::CanAccessKey(const std::string& key) const { |
| 250 Feature* feature = | 250 Feature* feature = |
| 251 BaseFeatureProvider::GetManifestFeatures()->GetFeature(key); | 251 BaseFeatureProvider::GetFeaturesByName("manifest")->GetFeature(key); |
| 252 if (!feature) | 252 if (!feature) |
| 253 return true; | 253 return true; |
| 254 | 254 |
| 255 return feature->IsAvailableToManifest( | 255 return feature->IsAvailableToManifest( |
| 256 extension_id_, type_, Feature::ConvertLocation(location_), | 256 extension_id_, type_, Feature::ConvertLocation(location_), |
| 257 GetManifestVersion()).is_available(); | 257 GetManifestVersion()).is_available(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace extensions | 260 } // namespace extensions |
| OLD | NEW |