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/complex_feature.h" | 5 #include "extensions/common/features/complex_feature.h" |
6 | 6 |
7 namespace extensions { | 7 namespace extensions { |
8 | 8 |
9 ComplexFeature::ComplexFeature(scoped_ptr<FeatureList> features) { | 9 ComplexFeature::ComplexFeature(scoped_ptr<FeatureList> features) { |
10 DCHECK_GT(features->size(), 0UL); | 10 DCHECK_GT(features->size(), 0UL); |
11 features_.swap(*features); | 11 features_.swap(*features); |
| 12 no_parent_ = features_[0]->no_parent(); |
12 | 13 |
13 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | 14 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
14 // Verify GetContexts, IsInternal, & IsBlockedInServiceWorker are consistent | 15 // Verify GetContexts, IsInternal, & IsBlockedInServiceWorker are consistent |
15 // across all features. | 16 // across all features. |
16 std::set<Feature::Context>* first_contexts = features_[0]->GetContexts(); | 17 std::set<Feature::Context>* first_contexts = features_[0]->GetContexts(); |
17 bool first_is_internal = features_[0]->IsInternal(); | 18 bool first_is_internal = features_[0]->IsInternal(); |
18 bool first_blocked_in_service_worker = | 19 bool first_blocked_in_service_worker = |
19 features_[0]->IsBlockedInServiceWorker(); | 20 features_[0]->IsBlockedInServiceWorker(); |
20 for (FeatureList::const_iterator it = features_.begin() + 1; | 21 for (FeatureList::const_iterator it = features_.begin() + 1; |
21 it != features_.end(); | 22 it != features_.end(); |
22 ++it) { | 23 ++it) { |
23 DCHECK(*first_contexts == *(*it)->GetContexts()) | 24 DCHECK(*first_contexts == *(*it)->GetContexts()) |
24 << "Complex feature must have consistent values of " | 25 << "Complex feature must have consistent values of " |
25 "contexts across all sub features."; | 26 "contexts across all sub features."; |
26 DCHECK(first_is_internal == (*it)->IsInternal()) | 27 DCHECK(first_is_internal == (*it)->IsInternal()) |
27 << "Complex feature must have consistent values of " | 28 << "Complex feature must have consistent values of " |
28 "internal across all sub features."; | 29 "internal across all sub features."; |
29 DCHECK(first_blocked_in_service_worker == (*it)->IsBlockedInServiceWorker()) | 30 DCHECK(first_blocked_in_service_worker == (*it)->IsBlockedInServiceWorker()) |
30 << "Complex feature must have consistent values of " | 31 << "Complex feature must have consistent values of " |
31 "blocked_in_service_worker across all sub features."; | 32 "blocked_in_service_worker across all sub features."; |
| 33 DCHECK(no_parent_ == (*it)->no_parent()) |
| 34 << "Complex feature must have consistent values of " |
| 35 "no_parent across all sub features."; |
32 } | 36 } |
33 #endif | 37 #endif |
34 } | 38 } |
35 | 39 |
36 ComplexFeature::~ComplexFeature() { | 40 ComplexFeature::~ComplexFeature() { |
37 } | 41 } |
38 | 42 |
39 Feature::Availability ComplexFeature::IsAvailableToManifest( | 43 Feature::Availability ComplexFeature::IsAvailableToManifest( |
40 const std::string& extension_id, | 44 const std::string& extension_id, |
41 Manifest::Type type, | 45 Manifest::Type type, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 Availability availability = | 79 Availability availability = |
76 (*it)->IsAvailableToContext(extension, context, url, platform); | 80 (*it)->IsAvailableToContext(extension, context, url, platform); |
77 if (availability.is_available()) | 81 if (availability.is_available()) |
78 return availability; | 82 return availability; |
79 } | 83 } |
80 // If none of the SimpleFeatures are available, we return the availability | 84 // If none of the SimpleFeatures are available, we return the availability |
81 // info of the first SimpleFeature that was not available. | 85 // info of the first SimpleFeature that was not available. |
82 return first_availability; | 86 return first_availability; |
83 } | 87 } |
84 | 88 |
| 89 bool ComplexFeature::IsIdInBlacklist(const std::string& extension_id) const { |
| 90 for (FeatureList::const_iterator it = features_.begin(); |
| 91 it != features_.end(); |
| 92 ++it) { |
| 93 if ((*it)->IsIdInBlacklist(extension_id)) |
| 94 return true; |
| 95 } |
| 96 return false; |
| 97 } |
| 98 |
85 bool ComplexFeature::IsIdInWhitelist(const std::string& extension_id) const { | 99 bool ComplexFeature::IsIdInWhitelist(const std::string& extension_id) const { |
86 for (FeatureList::const_iterator it = features_.begin(); | 100 for (FeatureList::const_iterator it = features_.begin(); |
87 it != features_.end(); | 101 it != features_.end(); |
88 ++it) { | 102 ++it) { |
89 if ((*it)->IsIdInWhitelist(extension_id)) | 103 if ((*it)->IsIdInWhitelist(extension_id)) |
90 return true; | 104 return true; |
91 } | 105 } |
92 return false; | 106 return false; |
93 } | 107 } |
94 | 108 |
(...skipping 22 matching lines...) Expand all Loading... |
117 Context context) const { | 131 Context context) const { |
118 if (result == IS_AVAILABLE) | 132 if (result == IS_AVAILABLE) |
119 return std::string(); | 133 return std::string(); |
120 | 134 |
121 // TODO(justinlin): Form some kind of combined availabilities/messages from | 135 // TODO(justinlin): Form some kind of combined availabilities/messages from |
122 // SimpleFeatures. | 136 // SimpleFeatures. |
123 return features_[0]->GetAvailabilityMessage(result, type, url, context); | 137 return features_[0]->GetAvailabilityMessage(result, type, url, context); |
124 } | 138 } |
125 | 139 |
126 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |