OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/manifest.h" | 5 #include "extensions/common/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/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 Manifest::Manifest(Location location, scoped_ptr<base::DictionaryValue> value) | 111 Manifest::Manifest(Location location, scoped_ptr<base::DictionaryValue> value) |
112 : location_(location), | 112 : location_(location), |
113 value_(value.Pass()), | 113 value_(value.Pass()), |
114 type_(TYPE_UNKNOWN) { | 114 type_(TYPE_UNKNOWN) { |
115 if (value_->HasKey(keys::kTheme)) { | 115 if (value_->HasKey(keys::kTheme)) { |
116 type_ = TYPE_THEME; | 116 type_ = TYPE_THEME; |
117 } else if (value_->HasKey(keys::kExport)) { | 117 } else if (value_->HasKey(keys::kExport)) { |
118 type_ = TYPE_SHARED_MODULE; | 118 type_ = TYPE_SHARED_MODULE; |
119 } else if (value_->HasKey(keys::kApp)) { | 119 } else if (value_->HasKey(keys::kApp)) { |
120 if (value_->Get(keys::kWebURLs, NULL) || | 120 if (value_->Get(keys::kWebURLs, nullptr) || |
121 value_->Get(keys::kLaunchWebURL, NULL)) { | 121 value_->Get(keys::kLaunchWebURL, nullptr)) { |
122 type_ = TYPE_HOSTED_APP; | 122 type_ = TYPE_HOSTED_APP; |
123 } else if (value_->Get(keys::kPlatformAppBackground, NULL)) { | 123 } else if (value_->Get(keys::kPlatformAppBackground, nullptr)) { |
124 type_ = TYPE_PLATFORM_APP; | 124 type_ = TYPE_PLATFORM_APP; |
125 } else { | 125 } else { |
126 type_ = TYPE_LEGACY_PACKAGED_APP; | 126 type_ = TYPE_LEGACY_PACKAGED_APP; |
127 } | 127 } |
128 } else { | 128 } else { |
129 type_ = TYPE_EXTENSION; | 129 type_ = TYPE_EXTENSION; |
130 } | 130 } |
131 CHECK_NE(type_, TYPE_UNKNOWN); | 131 CHECK_NE(type_, TYPE_UNKNOWN); |
132 } | 132 } |
133 | 133 |
(...skipping 12 matching lines...) Expand all Loading... |
146 // checking to let developers know when they screw up. | 146 // checking to let developers know when they screw up. |
147 | 147 |
148 const FeatureProvider* manifest_feature_provider = | 148 const FeatureProvider* manifest_feature_provider = |
149 FeatureProvider::GetManifestFeatures(); | 149 FeatureProvider::GetManifestFeatures(); |
150 const std::vector<std::string>& feature_names = | 150 const std::vector<std::string>& feature_names = |
151 manifest_feature_provider->GetAllFeatureNames(); | 151 manifest_feature_provider->GetAllFeatureNames(); |
152 for (std::vector<std::string>::const_iterator feature_name = | 152 for (std::vector<std::string>::const_iterator feature_name = |
153 feature_names.begin(); | 153 feature_names.begin(); |
154 feature_name != feature_names.end(); ++feature_name) { | 154 feature_name != feature_names.end(); ++feature_name) { |
155 // Use Get instead of HasKey because the former uses path expansion. | 155 // Use Get instead of HasKey because the former uses path expansion. |
156 if (!value_->Get(*feature_name, NULL)) | 156 if (!value_->Get(*feature_name, nullptr)) |
157 continue; | 157 continue; |
158 | 158 |
159 Feature* feature = manifest_feature_provider->GetFeature(*feature_name); | 159 Feature* feature = manifest_feature_provider->GetFeature(*feature_name); |
160 Feature::Availability result = feature->IsAvailableToManifest( | 160 Feature::Availability result = feature->IsAvailableToManifest( |
161 extension_id_, type_, location_, GetManifestVersion()); | 161 extension_id_, type_, location_, GetManifestVersion()); |
162 if (!result.is_available()) | 162 if (!result.is_available()) |
163 warnings->push_back(InstallWarning(result.message(), *feature_name)); | 163 warnings->push_back(InstallWarning(result.message(), *feature_name)); |
164 } | 164 } |
165 | 165 |
166 // Also generate warnings for keys that are not features. | 166 // Also generate warnings for keys that are not features. |
167 for (base::DictionaryValue::Iterator it(*value_); !it.IsAtEnd(); | 167 for (base::DictionaryValue::Iterator it(*value_); !it.IsAtEnd(); |
168 it.Advance()) { | 168 it.Advance()) { |
169 if (!manifest_feature_provider->GetFeature(it.key())) { | 169 if (!manifest_feature_provider->GetFeature(it.key())) { |
170 warnings->push_back(InstallWarning( | 170 warnings->push_back(InstallWarning( |
171 ErrorUtils::FormatErrorMessage( | 171 ErrorUtils::FormatErrorMessage( |
172 manifest_errors::kUnrecognizedManifestKey, it.key()), | 172 manifest_errors::kUnrecognizedManifestKey, it.key()), |
173 it.key())); | 173 it.key())); |
174 } | 174 } |
175 } | 175 } |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 bool Manifest::HasKey(const std::string& key) const { | 179 bool Manifest::HasKey(const std::string& key) const { |
180 return CanAccessKey(key) && value_->HasKey(key); | 180 return CanAccessKey(key) && value_->HasKey(key); |
181 } | 181 } |
182 | 182 |
183 bool Manifest::HasPath(const std::string& path) const { | 183 bool Manifest::HasPath(const std::string& path) const { |
184 base::Value* ignored = NULL; | 184 base::Value* ignored = nullptr; |
185 return CanAccessPath(path) && value_->Get(path, &ignored); | 185 return CanAccessPath(path) && value_->Get(path, &ignored); |
186 } | 186 } |
187 | 187 |
188 bool Manifest::Get( | 188 bool Manifest::Get( |
189 const std::string& path, const base::Value** out_value) const { | 189 const std::string& path, const base::Value** out_value) const { |
190 return CanAccessPath(path) && value_->Get(path, out_value); | 190 return CanAccessPath(path) && value_->Get(path, out_value); |
191 } | 191 } |
192 | 192 |
193 bool Manifest::GetBoolean( | 193 bool Manifest::GetBoolean( |
194 const std::string& path, bool* out_value) const { | 194 const std::string& path, bool* out_value) const { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 Feature* feature = FeatureProvider::GetManifestFeatures()->GetFeature(key); | 256 Feature* feature = FeatureProvider::GetManifestFeatures()->GetFeature(key); |
257 if (!feature) | 257 if (!feature) |
258 return true; | 258 return true; |
259 | 259 |
260 return feature->IsAvailableToManifest( | 260 return feature->IsAvailableToManifest( |
261 extension_id_, type_, location_, GetManifestVersion()) | 261 extension_id_, type_, location_, GetManifestVersion()) |
262 .is_available(); | 262 .is_available(); |
263 } | 263 } |
264 | 264 |
265 } // namespace extensions | 265 } // namespace extensions |
OLD | NEW |