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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) {} | 314 is_internal_(false) {} |
315 | 315 |
316 SimpleFeature::~SimpleFeature() {} | 316 SimpleFeature::~SimpleFeature() {} |
317 | 317 |
318 void SimpleFeature::Parse(const base::DictionaryValue* dictionary) { | 318 void SimpleFeature::Parse(const base::DictionaryValue* dictionary) { |
319 static base::LazyInstance<SimpleFeature::Mappings> mappings = | 319 static base::LazyInstance<SimpleFeature::Mappings> mappings = |
320 LAZY_INSTANCE_INITIALIZER; | 320 LAZY_INSTANCE_INITIALIZER; |
321 | 321 |
322 no_parent_ = false; | 322 no_parent_ = false; |
323 for (base::DictionaryValue::Iterator it(*dictionary); | 323 for (base::DictionaryValue::Iterator it(*dictionary); |
324 !it.IsAtEnd(); | 324 !it.IsAtEnd(); |
(...skipping 28 matching lines...) Expand all Loading... |
353 } else if (key == "component_extensions_auto_granted") { | 353 } else if (key == "component_extensions_auto_granted") { |
354 dictionary->GetBoolean("component_extensions_auto_granted", | 354 dictionary->GetBoolean("component_extensions_auto_granted", |
355 &component_extensions_auto_granted_); | 355 &component_extensions_auto_granted_); |
356 } else if (key == "command_line_switch") { | 356 } else if (key == "command_line_switch") { |
357 dictionary->GetString("command_line_switch", &command_line_switch_); | 357 dictionary->GetString("command_line_switch", &command_line_switch_); |
358 } else if (key == "channel") { | 358 } else if (key == "channel") { |
359 channel_.reset(new version_info::Channel(version_info::Channel::UNKNOWN)); | 359 channel_.reset(new version_info::Channel(version_info::Channel::UNKNOWN)); |
360 ParseEnum<version_info::Channel>(value, channel_.get(), | 360 ParseEnum<version_info::Channel>(value, channel_.get(), |
361 mappings.Get().channels); | 361 mappings.Get().channels); |
362 } else if (key == "internal") { | 362 } else if (key == "internal") { |
363 value->GetAsBoolean(&internal_); | 363 value->GetAsBoolean(&is_internal_); |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 // 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 |
368 // 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 |
369 // (Simple)Features being aware of their own heirarchy this is impossible. | 369 // (Simple)Features being aware of their own heirarchy this is impossible. |
370 // | 370 // |
371 // 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 |
372 // 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 |
373 // "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 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 584 |
585 Feature::Availability SimpleFeature::CreateAvailability( | 585 Feature::Availability SimpleFeature::CreateAvailability( |
586 AvailabilityResult result, | 586 AvailabilityResult result, |
587 version_info::Channel channel) const { | 587 version_info::Channel channel) const { |
588 return Availability( | 588 return Availability( |
589 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(), | 589 result, GetAvailabilityMessage(result, Manifest::TYPE_UNKNOWN, GURL(), |
590 UNSPECIFIED_CONTEXT, channel)); | 590 UNSPECIFIED_CONTEXT, channel)); |
591 } | 591 } |
592 | 592 |
593 bool SimpleFeature::IsInternal() const { | 593 bool SimpleFeature::IsInternal() const { |
594 return internal_; | 594 return is_internal_; |
595 } | 595 } |
596 | 596 |
597 bool SimpleFeature::IsIdInBlacklist(const std::string& extension_id) const { | 597 bool SimpleFeature::IsIdInBlacklist(const std::string& extension_id) const { |
598 return IsIdInList(extension_id, blacklist_); | 598 return IsIdInList(extension_id, blacklist_); |
599 } | 599 } |
600 | 600 |
601 bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id) const { | 601 bool SimpleFeature::IsIdInWhitelist(const std::string& extension_id) const { |
602 return IsIdInList(extension_id, whitelist_); | 602 return IsIdInList(extension_id, whitelist_); |
603 } | 603 } |
604 | 604 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 // static | 660 // static |
661 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { | 661 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { |
662 // 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 |
663 // 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 |
664 // 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 |
665 // leads to hash collisions. | 665 // leads to hash collisions. |
666 // 128 bits / 4 = 32 mpdecimal characters | 666 // 128 bits / 4 = 32 mpdecimal characters |
667 return (extension_id.length() == 32); | 667 return (extension_id.length() == 32); |
668 } | 668 } |
669 | 669 |
| 670 void SimpleFeature::set_matches(const std::vector<std::string>& matches) { |
| 671 matches_.ClearPatterns(); |
| 672 for (const std::string& pattern : matches) |
| 673 matches_.AddPattern(URLPattern(URLPattern::SCHEME_ALL, pattern)); |
| 674 } |
| 675 |
670 } // namespace extensions | 676 } // namespace extensions |
OLD | NEW |