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
3 // found in the LICENSE file.
5 #include "extensions/common/features/complex_feature.h"
9 ComplexFeature::ComplexFeature(scoped_ptr
<FeatureList
> features
) {
10 DCHECK_GT(features
->size(), 0UL);
11 features_
.swap(*features
);
12 no_parent_
= features_
[0]->no_parent();
14 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
15 // Verify IsInternal and IsBlockedInServiceWorker are consistent across all
17 bool first_is_internal
= features_
[0]->IsInternal();
18 bool first_blocked_in_service_worker
=
19 features_
[0]->IsBlockedInServiceWorker();
20 for (FeatureList::const_iterator it
= features_
.begin() + 1;
21 it
!= features_
.end();
23 DCHECK(first_is_internal
== (*it
)->IsInternal())
24 << "Complex feature must have consistent values of "
25 "internal across all sub features.";
26 DCHECK(first_blocked_in_service_worker
== (*it
)->IsBlockedInServiceWorker())
27 << "Complex feature must have consistent values of "
28 "blocked_in_service_worker across all sub features.";
29 DCHECK(no_parent_
== (*it
)->no_parent())
30 << "Complex feature must have consistent values of "
31 "no_parent across all sub features.";
36 ComplexFeature::~ComplexFeature() {
39 Feature::Availability
ComplexFeature::IsAvailableToManifest(
40 const std::string
& extension_id
,
42 Manifest::Location location
,
44 Platform platform
) const {
45 Feature::Availability first_availability
=
46 features_
[0]->IsAvailableToManifest(
47 extension_id
, type
, location
, manifest_version
, platform
);
48 if (first_availability
.is_available())
49 return first_availability
;
51 for (FeatureList::const_iterator it
= features_
.begin() + 1;
52 it
!= features_
.end(); ++it
) {
53 Availability availability
= (*it
)->IsAvailableToManifest(
54 extension_id
, type
, location
, manifest_version
, platform
);
55 if (availability
.is_available())
58 // If none of the SimpleFeatures are available, we return the availability
59 // info of the first SimpleFeature that was not available.
60 return first_availability
;
63 Feature::Availability
ComplexFeature::IsAvailableToContext(
64 const Extension
* extension
,
67 Platform platform
) const {
68 Feature::Availability first_availability
=
69 features_
[0]->IsAvailableToContext(extension
, context
, url
, platform
);
70 if (first_availability
.is_available())
71 return first_availability
;
73 for (FeatureList::const_iterator it
= features_
.begin() + 1;
74 it
!= features_
.end(); ++it
) {
75 Availability availability
=
76 (*it
)->IsAvailableToContext(extension
, context
, url
, platform
);
77 if (availability
.is_available())
80 // If none of the SimpleFeatures are available, we return the availability
81 // info of the first SimpleFeature that was not available.
82 return first_availability
;
85 bool ComplexFeature::IsIdInBlacklist(const std::string
& extension_id
) const {
86 for (FeatureList::const_iterator it
= features_
.begin();
87 it
!= features_
.end();
89 if ((*it
)->IsIdInBlacklist(extension_id
))
95 bool ComplexFeature::IsIdInWhitelist(const std::string
& extension_id
) const {
96 for (FeatureList::const_iterator it
= features_
.begin();
97 it
!= features_
.end();
99 if ((*it
)->IsIdInWhitelist(extension_id
))
105 bool ComplexFeature::IsBlockedInServiceWorker() const {
106 // Constructor verifies that composed features are consistent, thus we can
107 // return just the first feature's value.
108 return features_
[0]->IsBlockedInServiceWorker();
111 bool ComplexFeature::IsInternal() const {
112 // Constructor verifies that composed features are consistent, thus we can
113 // return just the first feature's value.
114 return features_
[0]->IsInternal();
117 std::string
ComplexFeature::GetAvailabilityMessage(AvailabilityResult result
,
120 Context context
) const {
121 if (result
== IS_AVAILABLE
)
122 return std::string();
124 // TODO(justinlin): Form some kind of combined availabilities/messages from
126 return features_
[0]->GetAvailabilityMessage(result
, type
, url
, context
);
129 } // namespace extensions