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

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

Issue 12253022: Manifest handler for all keys background-related. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 int loc2_rank = GetLocationRank(loc2); 88 int loc2_rank = GetLocationRank(loc2);
89 89
90 // If two different locations have the same rank, then we can not 90 // If two different locations have the same rank, then we can not
91 // deterministicly choose a location. 91 // deterministicly choose a location.
92 CHECK(loc1_rank != loc2_rank); 92 CHECK(loc1_rank != loc2_rank);
93 93
94 // Highest rank has highest priority. 94 // Highest rank has highest priority.
95 return (loc1_rank > loc2_rank ? loc1 : loc2 ); 95 return (loc1_rank > loc2_rank ? loc1 : loc2 );
96 } 96 }
97 97
98 Manifest::Manifest(Location location, scoped_ptr<DictionaryValue> value) 98 Manifest::Manifest(Location location, scoped_ptr<base::DictionaryValue> value)
99 : location_(location), 99 : location_(location),
100 value_(value.Pass()), 100 value_(value.Pass()),
101 type_(TYPE_UNKNOWN) { 101 type_(TYPE_UNKNOWN) {
102 if (value_->HasKey(keys::kTheme)) { 102 if (value_->HasKey(keys::kTheme)) {
103 type_ = TYPE_THEME; 103 type_ = TYPE_THEME;
104 } else if (value_->HasKey(keys::kApp)) { 104 } else if (value_->HasKey(keys::kApp)) {
105 if (value_->Get(keys::kWebURLs, NULL) || 105 if (value_->Get(keys::kWebURLs, NULL) ||
106 value_->Get(keys::kLaunchWebURL, NULL)) { 106 value_->Get(keys::kLaunchWebURL, NULL)) {
107 type_ = TYPE_HOSTED_APP; 107 type_ = TYPE_HOSTED_APP;
108 } else if (value_->Get(keys::kPlatformAppBackground, NULL)) { 108 } else if (value_->Get(keys::kPlatformAppBackground, NULL)) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 BaseFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name); 146 BaseFeatureProvider::GetManifestFeatures()->GetFeature(*feature_name);
147 Feature::Availability result = feature->IsAvailableToManifest( 147 Feature::Availability result = feature->IsAvailableToManifest(
148 extension_id_, type_, Feature::ConvertLocation(location_), 148 extension_id_, type_, Feature::ConvertLocation(location_),
149 GetManifestVersion()); 149 GetManifestVersion());
150 if (!result.is_available()) 150 if (!result.is_available())
151 warnings->push_back(InstallWarning( 151 warnings->push_back(InstallWarning(
152 InstallWarning::FORMAT_TEXT, result.message())); 152 InstallWarning::FORMAT_TEXT, result.message()));
153 } 153 }
154 154
155 // Also generate warnings for keys that are not features. 155 // Also generate warnings for keys that are not features.
156 for (DictionaryValue::key_iterator key = value_->begin_keys(); 156 for (base::DictionaryValue::key_iterator key = value_->begin_keys();
157 key != value_->end_keys(); ++key) { 157 key != value_->end_keys(); ++key) {
158 if (!BaseFeatureProvider::GetManifestFeatures()->GetFeature(*key)) { 158 if (!BaseFeatureProvider::GetManifestFeatures()->GetFeature(*key)) {
159 warnings->push_back(InstallWarning( 159 warnings->push_back(InstallWarning(
160 InstallWarning::FORMAT_TEXT, 160 InstallWarning::FORMAT_TEXT,
161 base::StringPrintf("Unrecognized manifest key '%s'.", 161 base::StringPrintf("Unrecognized manifest key '%s'.",
162 (*key).c_str()))); 162 (*key).c_str())));
163 } 163 }
164 } 164 }
165 } 165 }
166 166
167 bool Manifest::HasKey(const std::string& key) const { 167 bool Manifest::HasKey(const std::string& key) const {
168 return CanAccessKey(key) && value_->HasKey(key); 168 return CanAccessKey(key) && value_->HasKey(key);
169 } 169 }
170 170
171 bool Manifest::HasPath(const std::string& path) const { 171 bool Manifest::HasPath(const std::string& path) const {
172 Value* ignored = NULL; 172 base::Value* ignored = NULL;
173 return CanAccessPath(path) && value_->Get(path, &ignored); 173 return CanAccessPath(path) && value_->Get(path, &ignored);
174 } 174 }
175 175
176 bool Manifest::Get( 176 bool Manifest::Get(
177 const std::string& path, Value** out_value) const { 177 const std::string& path, const base::Value** out_value) const {
178 return CanAccessPath(path) && value_->Get(path, out_value); 178 return CanAccessPath(path) && value_->Get(path, out_value);
179 } 179 }
180 180
181 bool Manifest::GetBoolean( 181 bool Manifest::GetBoolean(
182 const std::string& path, bool* out_value) const { 182 const std::string& path, bool* out_value) const {
183 return CanAccessPath(path) && value_->GetBoolean(path, out_value); 183 return CanAccessPath(path) && value_->GetBoolean(path, out_value);
184 } 184 }
185 185
186 bool Manifest::GetInteger( 186 bool Manifest::GetInteger(
187 const std::string& path, int* out_value) const { 187 const std::string& path, int* out_value) const {
188 return CanAccessPath(path) && value_->GetInteger(path, out_value); 188 return CanAccessPath(path) && value_->GetInteger(path, out_value);
189 } 189 }
190 190
191 bool Manifest::GetString( 191 bool Manifest::GetString(
192 const std::string& path, std::string* out_value) const { 192 const std::string& path, std::string* out_value) const {
193 return CanAccessPath(path) && value_->GetString(path, out_value); 193 return CanAccessPath(path) && value_->GetString(path, out_value);
194 } 194 }
195 195
196 bool Manifest::GetString( 196 bool Manifest::GetString(
197 const std::string& path, string16* out_value) const { 197 const std::string& path, string16* out_value) const {
198 return CanAccessPath(path) && value_->GetString(path, out_value); 198 return CanAccessPath(path) && value_->GetString(path, out_value);
199 } 199 }
200 200
201 bool Manifest::GetDictionary( 201 bool Manifest::GetDictionary(
202 const std::string& path, const DictionaryValue** out_value) const { 202 const std::string& path, const base::DictionaryValue** out_value) const {
203 return GetDictionary(path, const_cast<DictionaryValue**>(out_value));
204 }
205
206 bool Manifest::GetDictionary(
207 const std::string& path, DictionaryValue** out_value) const {
208 return CanAccessPath(path) && value_->GetDictionary(path, out_value); 203 return CanAccessPath(path) && value_->GetDictionary(path, out_value);
209 } 204 }
210 205
211 bool Manifest::GetList( 206 bool Manifest::GetList(
212 const std::string& path, const ListValue** out_value) const { 207 const std::string& path, const base::ListValue** out_value) const {
213 return GetList(path, const_cast<ListValue**>(out_value));
214 }
215
216 bool Manifest::GetList(
217 const std::string& path, ListValue** out_value) const {
218 return CanAccessPath(path) && value_->GetList(path, out_value); 208 return CanAccessPath(path) && value_->GetList(path, out_value);
219 } 209 }
220 210
221 Manifest* Manifest::DeepCopy() const { 211 Manifest* Manifest::DeepCopy() const {
222 Manifest* manifest = new Manifest( 212 Manifest* manifest = new Manifest(
223 location_, scoped_ptr<DictionaryValue>(value_->DeepCopy())); 213 location_, scoped_ptr<base::DictionaryValue>(value_->DeepCopy()));
224 manifest->set_extension_id(extension_id_); 214 manifest->set_extension_id(extension_id_);
225 return manifest; 215 return manifest;
226 } 216 }
227 217
228 bool Manifest::Equals(const Manifest* other) const { 218 bool Manifest::Equals(const Manifest* other) const {
229 return other && value_->Equals(other->value()); 219 return other && value_->Equals(other->value());
230 } 220 }
231 221
232 int Manifest::GetManifestVersion() const { 222 int Manifest::GetManifestVersion() const {
233 // Platform apps were launched after manifest version 2 was the preferred 223 // Platform apps were launched after manifest version 2 was the preferred
(...skipping 21 matching lines...) Expand all
255 BaseFeatureProvider::GetManifestFeatures()->GetFeature(key); 245 BaseFeatureProvider::GetManifestFeatures()->GetFeature(key);
256 if (!feature) 246 if (!feature)
257 return true; 247 return true;
258 248
259 return feature->IsAvailableToManifest( 249 return feature->IsAvailableToManifest(
260 extension_id_, type_, Feature::ConvertLocation(location_), 250 extension_id_, type_, Feature::ConvertLocation(location_),
261 GetManifestVersion()).is_available(); 251 GetManifestVersion()).is_available();
262 } 252 }
263 253
264 } // namespace extensions 254 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698