OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/features/simple_feature.h" | 5 #include "extensions/common/features/simple_feature.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 std::map<std::string, Feature::Context> contexts; | 303 std::map<std::string, Feature::Context> contexts; |
304 std::map<std::string, SimpleFeature::Location> locations; | 304 std::map<std::string, SimpleFeature::Location> locations; |
305 std::map<std::string, Feature::Platform> platforms; | 305 std::map<std::string, Feature::Platform> platforms; |
306 std::map<std::string, version_info::Channel> channels; | 306 std::map<std::string, version_info::Channel> channels; |
307 }; | 307 }; |
308 | 308 |
309 SimpleFeature::SimpleFeature() | 309 SimpleFeature::SimpleFeature() |
310 : location_(UNSPECIFIED_LOCATION), | 310 : location_(UNSPECIFIED_LOCATION), |
311 min_manifest_version_(0), | 311 min_manifest_version_(0), |
312 max_manifest_version_(0), | 312 max_manifest_version_(0), |
313 component_extensions_auto_granted_(true) {} | 313 component_extensions_auto_granted_(true), |
314 internal_(false) {} | |
lazyboy
2016/07/15 22:53:40
This is exposing "internal" field to all features
Devlin
2016/07/18 17:51:58
It is, but there's nothing to say that only api fe
lazyboy
2016/07/18 17:57:43
Acknowledged.
| |
314 | 315 |
315 SimpleFeature::~SimpleFeature() {} | 316 SimpleFeature::~SimpleFeature() {} |
316 | 317 |
317 std::string SimpleFeature::Parse(const base::DictionaryValue* dictionary) { | 318 void SimpleFeature::Parse(const base::DictionaryValue* dictionary) { |
318 static base::LazyInstance<SimpleFeature::Mappings> mappings = | 319 static base::LazyInstance<SimpleFeature::Mappings> mappings = |
319 LAZY_INSTANCE_INITIALIZER; | 320 LAZY_INSTANCE_INITIALIZER; |
320 | 321 |
321 no_parent_ = false; | 322 no_parent_ = false; |
322 for (base::DictionaryValue::Iterator it(*dictionary); | 323 for (base::DictionaryValue::Iterator it(*dictionary); |
323 !it.IsAtEnd(); | 324 !it.IsAtEnd(); |
324 it.Advance()) { | 325 it.Advance()) { |
325 const std::string& key = it.key(); | 326 const std::string& key = it.key(); |
326 const base::Value* value = &it.value(); | 327 const base::Value* value = &it.value(); |
327 if (key == "matches") { | 328 if (key == "matches") { |
(...skipping 23 matching lines...) Expand all Loading... | |
351 dictionary->GetBoolean("noparent", &no_parent_); | 352 dictionary->GetBoolean("noparent", &no_parent_); |
352 } else if (key == "component_extensions_auto_granted") { | 353 } else if (key == "component_extensions_auto_granted") { |
353 dictionary->GetBoolean("component_extensions_auto_granted", | 354 dictionary->GetBoolean("component_extensions_auto_granted", |
354 &component_extensions_auto_granted_); | 355 &component_extensions_auto_granted_); |
355 } else if (key == "command_line_switch") { | 356 } else if (key == "command_line_switch") { |
356 dictionary->GetString("command_line_switch", &command_line_switch_); | 357 dictionary->GetString("command_line_switch", &command_line_switch_); |
357 } else if (key == "channel") { | 358 } else if (key == "channel") { |
358 channel_.reset(new version_info::Channel(version_info::Channel::UNKNOWN)); | 359 channel_.reset(new version_info::Channel(version_info::Channel::UNKNOWN)); |
359 ParseEnum<version_info::Channel>(value, channel_.get(), | 360 ParseEnum<version_info::Channel>(value, channel_.get(), |
360 mappings.Get().channels); | 361 mappings.Get().channels); |
362 } else if (key == "internal") { | |
363 value->GetAsBoolean(&internal_); | |
361 } | 364 } |
362 } | 365 } |
363 | 366 |
364 // NOTE: ideally we'd sanity check that "matches" can be specified if and | 367 // NOTE: ideally we'd sanity check that "matches" can be specified if and |
365 // only if there's a "web_page" or "webui" context, but without | 368 // only if there's a "web_page" or "webui" context, but without |
366 // (Simple)Features being aware of their own heirarchy this is impossible. | 369 // (Simple)Features being aware of their own heirarchy this is impossible. |
367 // | 370 // |
368 // For example, we might have feature "foo" available to "web_page" context | 371 // For example, we might have feature "foo" available to "web_page" context |
369 // and "matches" google.com/*. Then a sub-feature "foo.bar" might override | 372 // and "matches" google.com/*. Then a sub-feature "foo.bar" might override |
370 // "matches" to be chromium.org/*. That sub-feature doesn't need to specify | 373 // "matches" to be chromium.org/*. That sub-feature doesn't need to specify |
371 // "web_page" context because it's inherited, but we don't know that here. | 374 // "web_page" context because it's inherited, but we don't know that here. |
375 } | |
372 | 376 |
377 bool SimpleFeature::Validate(std::string* error) { | |
378 DCHECK(error); | |
373 // All features must be channel-restricted, either directly or through | 379 // All features must be channel-restricted, either directly or through |
374 // dependents. | 380 // dependents. |
375 if (!channel_ && dependencies_.empty()) | 381 if (!channel_ && dependencies_.empty()) { |
376 return name() + ": Must supply a value for channel or dependencies."; | 382 *error = name() + ": Must supply a value for channel or dependencies."; |
383 return false; | |
384 } | |
377 | 385 |
378 return std::string(); | 386 return true; |
379 } | 387 } |
380 | 388 |
381 Feature::Availability SimpleFeature::IsAvailableToManifest( | 389 Feature::Availability SimpleFeature::IsAvailableToManifest( |
382 const std::string& extension_id, | 390 const std::string& extension_id, |
383 Manifest::Type type, | 391 Manifest::Type type, |
384 Manifest::Location location, | 392 Manifest::Location location, |
385 int manifest_version, | 393 int manifest_version, |
386 Platform platform) const { | 394 Platform platform) const { |
387 // Check extension type first to avoid granting platform app permissions | 395 // Check extension type first to avoid granting platform app permissions |
388 // to component extensions. | 396 // to component extensions. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 | 584 |
577 Feature::Availability SimpleFeature::CreateAvailability( | 585 Feature::Availability SimpleFeature::CreateAvailability( |
578 AvailabilityResult result, | 586 AvailabilityResult result, |
579 version_info::Channel channel) const { | 587 version_info::Channel channel) const { |
580 return Availability( | 588 return Availability( |
581 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(), | 589 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(), |
582 UNSPECIFIED_CONTEXT, channel)); | 590 UNSPECIFIED_CONTEXT, channel)); |
583 } | 591 } |
584 | 592 |
585 bool SimpleFeature::IsInternal() const { | 593 bool SimpleFeature::IsInternal() const { |
586 return false; | 594 return internal_; |
587 } | 595 } |
588 | 596 |
589 bool SimpleFeature::IsIdInBlacklist(const std::string& extension_id) const { | 597 bool SimpleFeature::IsIdInBlacklist(const std::string& extension_id) const { |
590 return IsIdInList(extension_id, blacklist_); | 598 return IsIdInList(extension_id, blacklist_); |
591 } | 599 } |
592 | 600 |
593 bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id) const { | 601 bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id) const { |
594 return IsIdInList(extension_id, whitelist_); | 602 return IsIdInList(extension_id, whitelist_); |
595 } | 603 } |
596 | 604 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { | 661 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { |
654 // Belt-and-suspenders philosophy here. We should be pretty confident by this | 662 // Belt-and-suspenders philosophy here. We should be pretty confident by this |
655 // point that we've validated the extension ID format, but in case something | 663 // point that we've validated the extension ID format, but in case something |
656 // slips through, we avoid a class of attack where creative ID manipulation | 664 // slips through, we avoid a class of attack where creative ID manipulation |
657 // leads to hash collisions. | 665 // leads to hash collisions. |
658 // 128 bits / 4 = 32 mpdecimal characters | 666 // 128 bits / 4 = 32 mpdecimal characters |
659 return (extension_id.length() == 32); | 667 return (extension_id.length() == 32); |
660 } | 668 } |
661 | 669 |
662 } // namespace extensions | 670 } // namespace extensions |
OLD | NEW |