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

Side by Side Diff: extensions/common/features/simple_feature.h

Issue 2151583003: [Extensions] Add extension feature generation code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add GYP support Created 4 years, 5 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
OLDNEW
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 #ifndef EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ 5 #ifndef EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_
6 #define EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ 6 #define EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 const GURL& url) const { 66 const GURL& url) const {
67 return IsAvailableToContext(extension, context, url, GetCurrentPlatform()); 67 return IsAvailableToContext(extension, context, url, GetCurrentPlatform());
68 } 68 }
69 69
70 // extension::Feature: 70 // extension::Feature:
71 Availability IsAvailableToManifest(const std::string& extension_id, 71 Availability IsAvailableToManifest(const std::string& extension_id,
72 Manifest::Type type, 72 Manifest::Type type,
73 Manifest::Location location, 73 Manifest::Location location,
74 int manifest_version, 74 int manifest_version,
75 Platform platform) const override; 75 Platform platform) const override;
76
77 Availability IsAvailableToContext(const Extension* extension, 76 Availability IsAvailableToContext(const Extension* extension,
78 Context context, 77 Context context,
79 const GURL& url, 78 const GURL& url,
80 Platform platform) const override; 79 Platform platform) const override;
81
82 bool IsInternal() const override; 80 bool IsInternal() const override;
83
84 bool IsIdInBlacklist(const std::string& extension_id) const override; 81 bool IsIdInBlacklist(const std::string& extension_id) const override;
85 bool IsIdInWhitelist(const std::string& extension_id) const override; 82 bool IsIdInWhitelist(const std::string& extension_id) const override;
86 83
87 static bool IsIdInArray(const std::string& extension_id, 84 static bool IsIdInArray(const std::string& extension_id,
88 const char* const array[], 85 const char* const array[],
89 size_t array_length); 86 size_t array_length);
90 87
91 protected:
92 // Similar to Manifest::Location, these are the classes of locations 88 // Similar to Manifest::Location, these are the classes of locations
93 // supported in feature files. Production code should never directly access 89 // supported in feature files. These should only be used this class and in
asargent_no_longer_on_chrome 2016/07/19 05:33:16 typo: "only be used this class"
Devlin 2016/07/19 16:23:35 Done.
94 // these. 90 // generated files.
95 enum Location { 91 enum Location {
96 UNSPECIFIED_LOCATION, 92 UNSPECIFIED_LOCATION,
97 COMPONENT_LOCATION, 93 COMPONENT_LOCATION,
98 EXTERNAL_COMPONENT_LOCATION, 94 EXTERNAL_COMPONENT_LOCATION,
99 POLICY_LOCATION, 95 POLICY_LOCATION,
100 }; 96 };
101 97
102 // Accessors defined for testing. 98 // Setters used by generated code to create the feature.
103 std::vector<std::string>* blacklist() { return &blacklist_; } 99 void set_blacklist(const std::vector<std::string>& blacklist) {
104 const std::vector<std::string>* blacklist() const { return &blacklist_; } 100 blacklist_ = blacklist;
105 std::vector<std::string>* whitelist() { return &whitelist_; }
106 const std::vector<std::string>* whitelist() const { return &whitelist_; }
107 std::vector<Manifest::Type>* extension_types() { return &extension_types_; }
108 const std::vector<Manifest::Type>* extension_types() const {
109 return &extension_types_;
110 } 101 }
111 std::vector<Context>* contexts() { return &contexts_; } 102 void set_channel(version_info::Channel channel) {
112 const std::vector<Context>* contexts() const { return &contexts_; } 103 channel_.reset(new version_info::Channel(channel));
113 std::vector<Platform>* platforms() { return &platforms_; }
114 Location location() const { return location_; }
115 void set_location(Location location) { location_ = location; }
116 int min_manifest_version() const { return min_manifest_version_; }
117 void set_min_manifest_version(int min_manifest_version) {
118 min_manifest_version_ = min_manifest_version;
119 }
120 int max_manifest_version() const { return max_manifest_version_; }
121 void set_max_manifest_version(int max_manifest_version) {
122 max_manifest_version_ = max_manifest_version;
123 }
124 const std::string& command_line_switch() const {
125 return command_line_switch_;
126 } 104 }
127 void set_command_line_switch(const std::string& command_line_switch) { 105 void set_command_line_switch(const std::string& command_line_switch) {
128 command_line_switch_ = command_line_switch; 106 command_line_switch_ = command_line_switch;
129 } 107 }
108 void set_component_extensions_auto_granted(bool granted) {
109 component_extensions_auto_granted_ = granted;
110 }
111 void set_contexts(const std::vector<Context>& contexts) {
112 contexts_ = contexts;
113 }
114 void set_dependencies(const std::vector<std::string>& dependencies) {
115 dependencies_ = dependencies;
116 }
117 void set_extension_types(const std::vector<Manifest::Type> types) {
118 extension_types_ = types;
119 }
120 void set_internal(bool is_internal) { is_internal_ = is_internal; }
121 void set_location(Location location) { location_ = location; }
122 void set_matches(const std::vector<std::string>& matches);
123 void set_max_manifest_version(int max_manifest_version) {
124 max_manifest_version_ = max_manifest_version;
125 }
126 void set_min_manifest_version(int min_manifest_version) {
127 min_manifest_version_ = min_manifest_version;
128 }
129 void set_platforms(const std::vector<Platform>& platforms) {
130 platforms_ = platforms;
131 }
132 void set_whitelist(const std::vector<std::string>& whitelist) {
133 whitelist_ = whitelist;
134 }
135
136 protected:
137 // Accessors used by subclasses in feature verification.
138 const std::vector<std::string>& blacklist() const { return blacklist_; }
139 const std::vector<std::string>& whitelist() const { return whitelist_; }
140 const std::vector<Manifest::Type>& extension_types() const {
141 return extension_types_;
142 }
143 const std::vector<Platform>& platforms() const { return platforms_; }
144 const std::vector<Context>& contexts() const { return contexts_; }
145 const std::vector<std::string>& dependencies() const { return dependencies_; }
146 bool has_channel() const { return channel_.get() != nullptr; }
147 version_info::Channel channel() const { return *channel_; }
148 Location location() const { return location_; }
149 int min_manifest_version() const { return min_manifest_version_; }
150 int max_manifest_version() const { return max_manifest_version_; }
151 const std::string& command_line_switch() const {
152 return command_line_switch_;
153 }
154 bool component_extensions_auto_granted() const {
155 return component_extensions_auto_granted_;
156 }
157 const URLPatternSet& matches() const { return matches_; }
130 158
131 std::string GetAvailabilityMessage(AvailabilityResult result, 159 std::string GetAvailabilityMessage(AvailabilityResult result,
132 Manifest::Type type, 160 Manifest::Type type,
133 const GURL& url, 161 const GURL& url,
134 Context context, 162 Context context,
135 version_info::Channel channel) const; 163 version_info::Channel channel) const;
136 164
137 // Handy utilities which construct the correct availability message. 165 // Handy utilities which construct the correct availability message.
138 Availability CreateAvailability(AvailabilityResult result) const; 166 Availability CreateAvailability(AvailabilityResult result) const;
139 Availability CreateAvailability(AvailabilityResult result, 167 Availability CreateAvailability(AvailabilityResult result,
140 Manifest::Type type) const; 168 Manifest::Type type) const;
141 Availability CreateAvailability(AvailabilityResult result, 169 Availability CreateAvailability(AvailabilityResult result,
142 const GURL& url) const; 170 const GURL& url) const;
143 Availability CreateAvailability(AvailabilityResult result, 171 Availability CreateAvailability(AvailabilityResult result,
144 Context context) const; 172 Context context) const;
145 Availability CreateAvailability(AvailabilityResult result, 173 Availability CreateAvailability(AvailabilityResult result,
146 version_info::Channel channel) const; 174 version_info::Channel channel) const;
147 175
148 private: 176 private:
177 friend struct FeatureComparator;
149 friend class SimpleFeatureTest; 178 friend class SimpleFeatureTest;
150 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, ManifestFeatureTypes); 179 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, ManifestFeatureTypes);
151 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, PermissionFeatureTypes); 180 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, PermissionFeatureTypes);
152 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); 181 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures);
182 FRIEND_TEST_ALL_PREFIXES(FeaturesGenerationTest, FeaturesTest);
153 FRIEND_TEST_ALL_PREFIXES(ManifestUnitTest, Extension); 183 FRIEND_TEST_ALL_PREFIXES(ManifestUnitTest, Extension);
154 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Blacklist); 184 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Blacklist);
155 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, CommandLineSwitch); 185 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, CommandLineSwitch);
156 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Context); 186 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Context);
157 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdBlacklist); 187 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdBlacklist);
158 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdWhitelist); 188 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdWhitelist);
159 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Inheritance); 189 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Inheritance);
160 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Location); 190 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Location);
161 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ManifestVersion); 191 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ManifestVersion);
162 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, PackageType); 192 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, PackageType);
(...skipping 28 matching lines...) Expand all
191 std::vector<std::string> whitelist_; 221 std::vector<std::string> whitelist_;
192 std::vector<std::string> dependencies_; 222 std::vector<std::string> dependencies_;
193 std::vector<Manifest::Type> extension_types_; 223 std::vector<Manifest::Type> extension_types_;
194 std::vector<Context> contexts_; 224 std::vector<Context> contexts_;
195 std::vector<Platform> platforms_; 225 std::vector<Platform> platforms_;
196 URLPatternSet matches_; 226 URLPatternSet matches_;
197 Location location_; 227 Location location_;
198 int min_manifest_version_; 228 int min_manifest_version_;
199 int max_manifest_version_; 229 int max_manifest_version_;
200 bool component_extensions_auto_granted_; 230 bool component_extensions_auto_granted_;
231 bool is_internal_;
201 std::string command_line_switch_; 232 std::string command_line_switch_;
202 std::unique_ptr<version_info::Channel> channel_; 233 std::unique_ptr<version_info::Channel> channel_;
203 234
204 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); 235 DISALLOW_COPY_AND_ASSIGN(SimpleFeature);
205 }; 236 };
206 237
207 } // namespace extensions 238 } // namespace extensions
208 239
209 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ 240 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698