Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Side by Side Diff: chrome/common/extensions/features/complex_feature.cc

Issue 217163003: Enable _api_features.json to block APIs from service worker contexts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment typo Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/complex_feature.h" 5 #include "chrome/common/extensions/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
13 // Verify IsBlockedInServiceWorker is consistent across all features.
not at google - send to devlin 2014/03/28 17:30:49 cool, good idea. Any chance you do the same for Ge
scheib 2014/03/28 18:15:21 Done.
14 bool first_blocked_in_service_worker =
15 features_[0]->IsBlockedInServiceWorker();
16 for (FeatureList::const_iterator it = features_.begin() + 1;
17 it != features_.end();
18 ++it) {
19 DCHECK(first_blocked_in_service_worker == (*it)->IsBlockedInServiceWorker())
20 << "Complex feature must have consistent values of "
21 "blocked_in_service_worker across all sub features.";
22 }
12 } 23 }
13 24
14 ComplexFeature::~ComplexFeature() { 25 ComplexFeature::~ComplexFeature() {
15 } 26 }
16 27
17 Feature::Availability ComplexFeature::IsAvailableToManifest( 28 Feature::Availability ComplexFeature::IsAvailableToManifest(
18 const std::string& extension_id, Manifest::Type type, Location location, 29 const std::string& extension_id, Manifest::Type type, Location location,
19 int manifest_version, Platform platform) const { 30 int manifest_version, Platform platform) const {
20 Feature::Availability first_availability = 31 Feature::Availability first_availability =
21 features_[0]->IsAvailableToManifest( 32 features_[0]->IsAvailableToManifest(
(...skipping 28 matching lines...) Expand all
50 Availability availability = 61 Availability availability =
51 (*it)->IsAvailableToContext(extension, context, url, platform); 62 (*it)->IsAvailableToContext(extension, context, url, platform);
52 if (availability.is_available()) 63 if (availability.is_available())
53 return availability; 64 return availability;
54 } 65 }
55 // If none of the SimpleFeatures are available, we return the availability 66 // If none of the SimpleFeatures are available, we return the availability
56 // info of the first SimpleFeature that was not available. 67 // info of the first SimpleFeature that was not available.
57 return first_availability; 68 return first_availability;
58 } 69 }
59 70
71 bool ComplexFeature::IsIdInWhitelist(const std::string& extension_id) const {
72 for (FeatureList::const_iterator it = features_.begin();
73 it != features_.end();
74 ++it) {
75 if ((*it)->IsIdInWhitelist(extension_id))
76 return true;
77 }
78 return false;
79 }
80
81 bool ComplexFeature::IsBlockedInServiceWorker() const {
82 // Constructor verifies that composed features are consistent, thus we can
83 // return just the first feature's value.
84 return features_[0]->IsBlockedInServiceWorker();
85 }
86
60 std::set<Feature::Context>* ComplexFeature::GetContexts() { 87 std::set<Feature::Context>* ComplexFeature::GetContexts() {
61 // TODO(justinlin): Current use cases for ComplexFeatures are simple (e.g. 88 // TODO(justinlin): Current use cases for ComplexFeatures are simple (e.g.
62 // allow API in dev channel for everyone but stable channel for a whitelist), 89 // allow API in dev channel for everyone but stable channel for a whitelist),
63 // but if they get more complicated, we need to return some meaningful context 90 // but if they get more complicated, we need to return some meaningful context
64 // set. Either that or remove this method from the Feature interface. 91 // set. Either that or remove this method from the Feature interface.
65 return features_[0]->GetContexts(); 92 return features_[0]->GetContexts();
66 } 93 }
67 94
68 bool ComplexFeature::IsInternal() const { 95 bool ComplexFeature::IsInternal() const {
69 // TODO(justinlin): Same as the above TODO. 96 // TODO(justinlin): Same as the above TODO.
70 return features_[0]->IsInternal(); 97 return features_[0]->IsInternal();
71 } 98 }
72 99
73 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result, 100 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result,
74 Manifest::Type type, 101 Manifest::Type type,
75 const GURL& url, 102 const GURL& url,
76 Context context) const { 103 Context context) const {
77 if (result == IS_AVAILABLE) 104 if (result == IS_AVAILABLE)
78 return std::string(); 105 return std::string();
79 106
80 // TODO(justinlin): Form some kind of combined availabilities/messages from 107 // TODO(justinlin): Form some kind of combined availabilities/messages from
81 // SimpleFeatures. 108 // SimpleFeatures.
82 return features_[0]->GetAvailabilityMessage(result, type, url, context); 109 return features_[0]->GetAvailabilityMessage(result, type, url, context);
83 } 110 }
84 111
85 bool ComplexFeature::IsIdInWhitelist(const std::string& extension_id) const {
86 for (FeatureList::const_iterator it = features_.begin();
87 it != features_.end(); ++it) {
88 if ((*it)->IsIdInWhitelist(extension_id))
89 return true;
90 }
91 return false;
92 }
93
94 } // namespace extensions 112 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698