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/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 Loading... | |
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 Loading... | |
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 // The "trunk" channel uses VersionInfo::CHANNEL_UNKNOWN, so we need to keep | |
246 // track of whether the channel has been set or not separately. | |
247 channel_has_been_set_ |= value->HasKey("channel"); | |
248 if (!channel_has_been_set_ && dependencies_.empty()) | |
249 return name() + ": Must supply a value for channel or dependencies."; | |
not at google - send to devlin
2013/06/12 22:34:18
Maybe we should assert that Parse can only be call
cduvall
2013/06/13 01:02:28
Parse is actually called multiple times on the sam
| |
250 | |
237 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) { | 251 if (matches_.is_empty() && contexts_.count(WEB_PAGE_CONTEXT) != 0) { |
238 return name() + ": Allowing web_page contexts requires supplying a value " + | 252 return name() + ": Allowing web_page contexts requires supplying a value " + |
239 "for matches."; | 253 "for matches."; |
240 } | 254 } |
255 | |
241 return std::string(); | 256 return std::string(); |
242 } | 257 } |
243 | 258 |
244 Feature::Availability SimpleFeature::IsAvailableToManifest( | 259 Feature::Availability SimpleFeature::IsAvailableToManifest( |
245 const std::string& extension_id, | 260 const std::string& extension_id, |
246 Manifest::Type type, | 261 Manifest::Type type, |
247 Location location, | 262 Location location, |
248 int manifest_version, | 263 int manifest_version, |
249 Platform platform) const { | 264 Platform platform) const { |
250 // Component extensions can access any feature. | 265 // Component extensions can access any feature. |
(...skipping 30 matching lines...) Expand all Loading... | |
281 | 296 |
282 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) | 297 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) |
283 return CreateAvailability(INVALID_PLATFORM, type); | 298 return CreateAvailability(INVALID_PLATFORM, type); |
284 | 299 |
285 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) | 300 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) |
286 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); | 301 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); |
287 | 302 |
288 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) | 303 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) |
289 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); | 304 return CreateAvailability(INVALID_MAX_MANIFEST_VERSION, type); |
290 | 305 |
291 if (channel_ < Feature::GetCurrentChannel()) | 306 if (channel_has_been_set_ && channel_ < Feature::GetCurrentChannel()) |
292 return CreateAvailability(UNSUPPORTED_CHANNEL, type); | 307 return CreateAvailability(UNSUPPORTED_CHANNEL, type); |
293 | 308 |
294 return CreateAvailability(IS_AVAILABLE, type); | 309 return CreateAvailability(IS_AVAILABLE, type); |
295 } | 310 } |
296 | 311 |
297 Feature::Availability SimpleFeature::IsAvailableToContext( | 312 Feature::Availability SimpleFeature::IsAvailableToContext( |
298 const Extension* extension, | 313 const Extension* extension, |
299 SimpleFeature::Context context, | 314 SimpleFeature::Context context, |
300 const GURL& url, | 315 const GURL& url, |
301 SimpleFeature::Platform platform) const { | 316 SimpleFeature::Platform platform) const { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 | 431 |
417 std::set<Feature::Context>* SimpleFeature::GetContexts() { | 432 std::set<Feature::Context>* SimpleFeature::GetContexts() { |
418 return &contexts_; | 433 return &contexts_; |
419 } | 434 } |
420 | 435 |
421 bool SimpleFeature::IsInternal() const { | 436 bool SimpleFeature::IsInternal() const { |
422 NOTREACHED(); | 437 NOTREACHED(); |
423 return false; | 438 return false; |
424 } | 439 } |
425 | 440 |
441 bool SimpleFeature::HasParent() const { | |
442 return has_parent_; | |
443 } | |
444 | |
445 void SimpleFeature::SetHasParent(bool has_parent) { | |
446 has_parent_ = has_parent; | |
447 } | |
448 | |
426 bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id) const { | 449 bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id) const { |
427 // Belt-and-suspenders philosophy here. We should be pretty confident by this | 450 // Belt-and-suspenders philosophy here. We should be pretty confident by this |
428 // point that we've validated the extension ID format, but in case something | 451 // point that we've validated the extension ID format, but in case something |
429 // slips through, we avoid a class of attack where creative ID manipulation | 452 // slips through, we avoid a class of attack where creative ID manipulation |
430 // leads to hash collisions. | 453 // leads to hash collisions. |
431 if (extension_id.length() != 32) // 128 bits / 4 = 32 mpdecimal characters | 454 if (extension_id.length() != 32) // 128 bits / 4 = 32 mpdecimal characters |
432 return false; | 455 return false; |
433 | 456 |
434 if (whitelist_.find(extension_id) != whitelist_.end() || | 457 if (whitelist_.find(extension_id) != whitelist_.end() || |
435 whitelist_.find(HashExtensionId(extension_id)) != whitelist_.end()) | 458 whitelist_.find(HashExtensionId(extension_id)) != whitelist_.end()) |
436 return true; | 459 return true; |
437 | 460 |
438 return false; | 461 return false; |
439 } | 462 } |
440 | 463 |
441 } // namespace extensions | 464 } // namespace extensions |
OLD | NEW |