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/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/extensions/extension_manifest_constants.h" | 13 #include "chrome/common/extensions/extension_manifest_constants.h" |
14 #include "chrome/common/extensions/features/simple_feature_provider.h" | 14 #include "chrome/common/extensions/features/base_feature_provider.h" |
15 #include "extensions/common/error_utils.h" | 15 #include "extensions/common/error_utils.h" |
16 | 16 |
17 namespace errors = extension_manifest_errors; | 17 namespace errors = extension_manifest_errors; |
18 namespace keys = extension_manifest_keys; | 18 namespace keys = extension_manifest_keys; |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 Manifest::Manifest(Extension::Location location, | 22 Manifest::Manifest(Extension::Location location, |
23 scoped_ptr<DictionaryValue> value) | 23 scoped_ptr<DictionaryValue> value) |
24 : location_(location), | 24 : location_(location), |
(...skipping 28 matching lines...) Expand all Loading... |
53 return; | 53 return; |
54 } | 54 } |
55 | 55 |
56 // Check every feature to see if its in the manifest. Note that this means | 56 // Check every feature to see if its in the manifest. Note that this means |
57 // we will ignore keys that are not features; we do this for forward | 57 // we will ignore keys that are not features; we do this for forward |
58 // compatibility. | 58 // compatibility. |
59 // TODO(aa): Consider having an error here in the case of strict error | 59 // TODO(aa): Consider having an error here in the case of strict error |
60 // checking to let developers know when they screw up. | 60 // checking to let developers know when they screw up. |
61 | 61 |
62 std::set<std::string> feature_names = | 62 std::set<std::string> feature_names = |
63 SimpleFeatureProvider::GetManifestFeatures()->GetAllFeatureNames(); | 63 BaseFeatureProvider::GetManifestFeatures()->GetAllFeatureNames(); |
64 for (std::set<std::string>::iterator feature_name = feature_names.begin(); | 64 for (std::set<std::string>::iterator feature_name = feature_names.begin(); |
65 feature_name != feature_names.end(); ++feature_name) { | 65 feature_name != feature_names.end(); ++feature_name) { |
66 // Use Get instead of HasKey because the former uses path expansion. | 66 // Use Get instead of HasKey because the former uses path expansion. |
67 if (!value_->Get(*feature_name, NULL)) | 67 if (!value_->Get(*feature_name, NULL)) |
68 continue; | 68 continue; |
69 | 69 |
70 Feature* feature = | 70 Feature* feature = |
71 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name); | 71 BaseFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name); |
72 Feature::Availability result = feature->IsAvailableToManifest( | 72 Feature::Availability result = feature->IsAvailableToManifest( |
73 extension_id_, type_, Feature::ConvertLocation(location_), | 73 extension_id_, type_, Feature::ConvertLocation(location_), |
74 GetManifestVersion()); | 74 GetManifestVersion()); |
75 if (!result.is_available()) | 75 if (!result.is_available()) |
76 warnings->push_back(Extension::InstallWarning( | 76 warnings->push_back(Extension::InstallWarning( |
77 Extension::InstallWarning::FORMAT_TEXT, result.message())); | 77 Extension::InstallWarning::FORMAT_TEXT, result.message())); |
78 } | 78 } |
79 | 79 |
80 // Also generate warnings for keys that are not features. | 80 // Also generate warnings for keys that are not features. |
81 for (DictionaryValue::key_iterator key = value_->begin_keys(); | 81 for (DictionaryValue::key_iterator key = value_->begin_keys(); |
82 key != value_->end_keys(); ++key) { | 82 key != value_->end_keys(); ++key) { |
83 if (!SimpleFeatureProvider::GetManifestFeatures()->GetFeature(*key)) { | 83 if (!BaseFeatureProvider::GetManifestFeatures()->GetFeature(*key)) { |
84 warnings->push_back(Extension::InstallWarning( | 84 warnings->push_back(Extension::InstallWarning( |
85 Extension::InstallWarning::FORMAT_TEXT, | 85 Extension::InstallWarning::FORMAT_TEXT, |
86 base::StringPrintf("Unrecognized manifest key '%s'.", | 86 base::StringPrintf("Unrecognized manifest key '%s'.", |
87 (*key).c_str()))); | 87 (*key).c_str()))); |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 bool Manifest::HasKey(const std::string& key) const { | 92 bool Manifest::HasKey(const std::string& key) const { |
93 return CanAccessKey(key) && value_->HasKey(key); | 93 return CanAccessKey(key) && value_->HasKey(key); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 key += components[i]; | 160 key += components[i]; |
161 if (!CanAccessKey(key)) | 161 if (!CanAccessKey(key)) |
162 return false; | 162 return false; |
163 key += '.'; | 163 key += '.'; |
164 } | 164 } |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 bool Manifest::CanAccessKey(const std::string& key) const { | 168 bool Manifest::CanAccessKey(const std::string& key) const { |
169 Feature* feature = | 169 Feature* feature = |
170 SimpleFeatureProvider::GetManifestFeatures()->GetFeature(key); | 170 BaseFeatureProvider::GetManifestFeatures()->GetFeature(key); |
171 if (!feature) | 171 if (!feature) |
172 return true; | 172 return true; |
173 | 173 |
174 return feature->IsAvailableToManifest( | 174 return feature->IsAvailableToManifest( |
175 extension_id_, type_, Feature::ConvertLocation(location_), | 175 extension_id_, type_, Feature::ConvertLocation(location_), |
176 GetManifestVersion()).is_available(); | 176 GetManifestVersion()).is_available(); |
177 } | 177 } |
178 | 178 |
179 } // namespace extensions | 179 } // namespace extensions |
OLD | NEW |