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

Side by Side Diff: chrome/common/extensions/features/simple_feature.cc

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos tests Created 7 years, 6 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/features/simple_feature.h" 5 #include "chrome/common/extensions/features/simple_feature.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ParseEnum(*iter, &enum_value, mapping); 134 ParseEnum(*iter, &enum_value, mapping);
135 enum_set->insert(enum_value); 135 enum_set->insert(enum_value);
136 } 136 }
137 } 137 }
138 138
139 void ParseURLPatterns(const DictionaryValue* value, 139 void ParseURLPatterns(const DictionaryValue* value,
140 const std::string& key, 140 const std::string& key,
141 URLPatternSet* set) { 141 URLPatternSet* set) {
142 const ListValue* matches = NULL; 142 const ListValue* matches = NULL;
143 if (value->GetList(key, &matches)) { 143 if (value->GetList(key, &matches)) {
144 set->ClearPatterns();
144 for (size_t i = 0; i < matches->GetSize(); ++i) { 145 for (size_t i = 0; i < matches->GetSize(); ++i) {
145 std::string pattern; 146 std::string pattern;
146 CHECK(matches->GetString(i, &pattern)); 147 CHECK(matches->GetString(i, &pattern));
147 set->AddPattern(URLPattern(URLPattern::SCHEME_ALL, pattern)); 148 set->AddPattern(URLPattern(URLPattern::SCHEME_ALL, pattern));
148 } 149 }
149 } 150 }
150 } 151 }
151 152
152 // Gets a human-readable name for the given extension type. 153 // Gets a human-readable name for the given extension type.
153 std::string GetDisplayTypeName(Manifest::Type type) { 154 std::string GetDisplayTypeName(Manifest::Type type) {
(...skipping 26 matching lines...) Expand all
180 return base::HexEncode(id_hash.c_str(), id_hash.length()); 181 return base::HexEncode(id_hash.c_str(), id_hash.length());
181 } 182 }
182 183
183 } // namespace 184 } // namespace
184 185
185 SimpleFeature::SimpleFeature() 186 SimpleFeature::SimpleFeature()
186 : location_(UNSPECIFIED_LOCATION), 187 : location_(UNSPECIFIED_LOCATION),
187 platform_(UNSPECIFIED_PLATFORM), 188 platform_(UNSPECIFIED_PLATFORM),
188 min_manifest_version_(0), 189 min_manifest_version_(0),
189 max_manifest_version_(0), 190 max_manifest_version_(0),
190 channel_(VersionInfo::CHANNEL_UNKNOWN) { 191 channel_(VersionInfo::CHANNEL_UNKNOWN),
192 has_parent_(false),
193 channel_has_been_set_(false) {
191 } 194 }
192 195
193 SimpleFeature::SimpleFeature(const SimpleFeature& other) 196 SimpleFeature::SimpleFeature(const SimpleFeature& other)
194 : whitelist_(other.whitelist_), 197 : whitelist_(other.whitelist_),
195 extension_types_(other.extension_types_), 198 extension_types_(other.extension_types_),
196 contexts_(other.contexts_), 199 contexts_(other.contexts_),
197 matches_(other.matches_), 200 matches_(other.matches_),
198 location_(other.location_), 201 location_(other.location_),
199 platform_(other.platform_), 202 platform_(other.platform_),
200 min_manifest_version_(other.min_manifest_version_), 203 min_manifest_version_(other.min_manifest_version_),
201 max_manifest_version_(other.max_manifest_version_), 204 max_manifest_version_(other.max_manifest_version_),
202 channel_(other.channel_) { 205 channel_(other.channel_),
206 has_parent_(other.has_parent_),
207 channel_has_been_set_(other.channel_has_been_set_) {
203 } 208 }
204 209
205 SimpleFeature::~SimpleFeature() { 210 SimpleFeature::~SimpleFeature() {
206 } 211 }
207 212
208 bool SimpleFeature::Equals(const SimpleFeature& other) const { 213 bool SimpleFeature::Equals(const SimpleFeature& other) const {
209 return whitelist_ == other.whitelist_ && 214 return whitelist_ == other.whitelist_ &&
210 extension_types_ == other.extension_types_ && 215 extension_types_ == other.extension_types_ &&
211 contexts_ == other.contexts_ && 216 contexts_ == other.contexts_ &&
212 matches_ == other.matches_ && 217 matches_ == other.matches_ &&
213 location_ == other.location_ && 218 location_ == other.location_ &&
214 platform_ == other.platform_ && 219 platform_ == other.platform_ &&
215 min_manifest_version_ == other.min_manifest_version_ && 220 min_manifest_version_ == other.min_manifest_version_ &&
216 max_manifest_version_ == other.max_manifest_version_ && 221 max_manifest_version_ == other.max_manifest_version_ &&
217 channel_ == other.channel_; 222 channel_ == other.channel_ &&
223 has_parent_ == other.has_parent_ &&
224 channel_has_been_set_ == other.channel_has_been_set_;
218 } 225 }
219 226
220 std::string SimpleFeature::Parse(const DictionaryValue* value) { 227 std::string SimpleFeature::Parse(const DictionaryValue* value) {
221 ParseURLPatterns(value, "matches", &matches_); 228 ParseURLPatterns(value, "matches", &matches_);
222 ParseSet(value, "whitelist", &whitelist_); 229 ParseSet(value, "whitelist", &whitelist_);
223 ParseSet(value, "dependencies", &dependencies_); 230 ParseSet(value, "dependencies", &dependencies_);
224 ParseEnumSet<Manifest::Type>(value, "extension_types", &extension_types_, 231 ParseEnumSet<Manifest::Type>(value, "extension_types", &extension_types_,
225 g_mappings.Get().extension_types); 232 g_mappings.Get().extension_types);
226 ParseEnumSet<Context>(value, "contexts", &contexts_, 233 ParseEnumSet<Context>(value, "contexts", &contexts_,
227 g_mappings.Get().contexts); 234 g_mappings.Get().contexts);
228 ParseEnum<Location>(value, "location", &location_, 235 ParseEnum<Location>(value, "location", &location_,
229 g_mappings.Get().locations); 236 g_mappings.Get().locations);
230 ParseEnum<Platform>(value, "platform", &platform_, 237 ParseEnum<Platform>(value, "platform", &platform_,
231 g_mappings.Get().platforms); 238 g_mappings.Get().platforms);
232 value->GetInteger("min_manifest_version", &min_manifest_version_); 239 value->GetInteger("min_manifest_version", &min_manifest_version_);
233 value->GetInteger("max_manifest_version", &max_manifest_version_); 240 value->GetInteger("max_manifest_version", &max_manifest_version_);
234 ParseEnum<VersionInfo::Channel>( 241 ParseEnum<VersionInfo::Channel>(
235 value, "channel", &channel_, 242 value, "channel", &channel_,
236 g_mappings.Get().channels); 243 g_mappings.Get().channels);
244
245 no_parent_ = false;
246 value->GetBoolean("noparent", &no_parent_);
247
248 // The "trunk" channel uses VersionInfo::CHANNEL_UNKNOWN, so we need to keep
249 // track of whether the channel has been set or not separately.
250 channel_has_been_set_ |= value->HasKey("channel");
251 if (!channel_has_been_set_ && dependencies_.empty())
252 return name() + ": Must supply a value for channel or dependencies.";
253
237 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) { 254 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) {
238 return name() + ": Allowing web_page contexts requires supplying a value " + 255 return name() + ": Allowing web_page contexts requires supplying a value " +
239 "for matches."; 256 "for matches.";
240 } 257 }
258
241 return std::string(); 259 return std::string();
242 } 260 }
243 261
244 Feature::Availability SimpleFeature::IsAvailableToManifest( 262 Feature::Availability SimpleFeature::IsAvailableToManifest(
245 const std::string& extension_id, 263 const std::string& extension_id,
246 Manifest::Type type, 264 Manifest::Type type,
247 Location location, 265 Location location,
248 int manifest_version, 266 int manifest_version,
249 Platform platform) const { 267 Platform platform) const {
250 // Component extensions can access any feature. 268 // Component extensions can access any feature.
(...skipping 30 matching lines...) Expand all
281 299
282 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) 300 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform)
283 return CreateAvailability(INVALID_PLATFORM, type); 301 return CreateAvailability(INVALID_PLATFORM, type);
284 302
285 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) 303 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_)
286 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); 304 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type);
287 305
288 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) 306 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_)
289 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); 307 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type);
290 308
291 if (channel_ < Feature::GetCurrentChannel()) 309 if (channel_has_been_set_ && channel_ < Feature::GetCurrentChannel())
292 return CreateAvailability(UNSUPPORTED_CHANNEL, type); 310 return CreateAvailability(UNSUPPORTED_CHANNEL, type);
293 311
294 return CreateAvailability(IS_AVAILABLE, type); 312 return CreateAvailability(IS_AVAILABLE, type);
295 } 313 }
296 314
297 Feature::Availability SimpleFeature::IsAvailableToContext( 315 Feature::Availability SimpleFeature::IsAvailableToContext(
298 const Extension* extension, 316 const Extension* extension,
299 SimpleFeature::Context context, 317 SimpleFeature::Context context,
300 const GURL& url, 318 const GURL& url,
301 SimpleFeature::Platform platform) const { 319 SimpleFeature::Platform platform) const {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return false; 450 return false;
433 451
434 if (whitelist_.find(extension_id) != whitelist_.end() || 452 if (whitelist_.find(extension_id) != whitelist_.end() ||
435 whitelist_.find(HashExtensionId(extension_id)) != whitelist_.end()) 453 whitelist_.find(HashExtensionId(extension_id)) != whitelist_.end())
436 return true; 454 return true;
437 455
438 return false; 456 return false;
439 } 457 }
440 458
441 } // namespace extensions 459 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/features/simple_feature.h ('k') | chrome/common/extensions/features/simple_feature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698