| 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 #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 <initializer_list> | 10 #include <initializer_list> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "components/version_info/version_info.h" | 21 #include "components/version_info/version_info.h" |
| 22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/features/feature.h" | 23 #include "extensions/common/features/feature.h" |
| 24 #include "extensions/common/features/feature_session_type.h" |
| 24 #include "extensions/common/manifest.h" | 25 #include "extensions/common/manifest.h" |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| 27 | 28 |
| 28 class BaseFeatureProviderTest; | 29 class BaseFeatureProviderTest; |
| 29 class ExtensionAPITest; | 30 class ExtensionAPITest; |
| 30 class ManifestUnitTest; | 31 class ManifestUnitTest; |
| 31 class SimpleFeatureTest; | 32 class SimpleFeatureTest; |
| 32 | 33 |
| 33 class SimpleFeature : public Feature { | 34 class SimpleFeature : public Feature { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 void set_channel(version_info::Channel channel) { | 109 void set_channel(version_info::Channel channel) { |
| 109 channel_.reset(new version_info::Channel(channel)); | 110 channel_.reset(new version_info::Channel(channel)); |
| 110 } | 111 } |
| 111 void set_command_line_switch(base::StringPiece command_line_switch); | 112 void set_command_line_switch(base::StringPiece command_line_switch); |
| 112 void set_component_extensions_auto_granted(bool granted) { | 113 void set_component_extensions_auto_granted(bool granted) { |
| 113 component_extensions_auto_granted_ = granted; | 114 component_extensions_auto_granted_ = granted; |
| 114 } | 115 } |
| 115 void set_contexts(std::initializer_list<Context> contexts); | 116 void set_contexts(std::initializer_list<Context> contexts); |
| 116 void set_dependencies(std::initializer_list<const char* const> dependencies); | 117 void set_dependencies(std::initializer_list<const char* const> dependencies); |
| 117 void set_extension_types(std::initializer_list<Manifest::Type> types); | 118 void set_extension_types(std::initializer_list<Manifest::Type> types); |
| 119 void set_session_types(std::initializer_list<FeatureSessionType> types); |
| 118 void set_internal(bool is_internal) { is_internal_ = is_internal; } | 120 void set_internal(bool is_internal) { is_internal_ = is_internal; } |
| 119 void set_location(Location location) { location_ = location; } | 121 void set_location(Location location) { location_ = location; } |
| 120 // set_matches() is an exception to pass-by-value since we construct an | 122 // set_matches() is an exception to pass-by-value since we construct an |
| 121 // URLPatternSet from the vector of strings. | 123 // URLPatternSet from the vector of strings. |
| 122 // TODO(devlin): Pass in an URLPatternSet directly. | 124 // TODO(devlin): Pass in an URLPatternSet directly. |
| 123 void set_matches(std::initializer_list<const char* const> matches); | 125 void set_matches(std::initializer_list<const char* const> matches); |
| 124 void set_max_manifest_version(int max_manifest_version) { | 126 void set_max_manifest_version(int max_manifest_version) { |
| 125 max_manifest_version_ = max_manifest_version; | 127 max_manifest_version_ = max_manifest_version; |
| 126 } | 128 } |
| 127 void set_min_manifest_version(int min_manifest_version) { | 129 void set_min_manifest_version(int min_manifest_version) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 151 } | 153 } |
| 152 bool component_extensions_auto_granted() const { | 154 bool component_extensions_auto_granted() const { |
| 153 return component_extensions_auto_granted_; | 155 return component_extensions_auto_granted_; |
| 154 } | 156 } |
| 155 const URLPatternSet& matches() const { return matches_; } | 157 const URLPatternSet& matches() const { return matches_; } |
| 156 | 158 |
| 157 std::string GetAvailabilityMessage(AvailabilityResult result, | 159 std::string GetAvailabilityMessage(AvailabilityResult result, |
| 158 Manifest::Type type, | 160 Manifest::Type type, |
| 159 const GURL& url, | 161 const GURL& url, |
| 160 Context context, | 162 Context context, |
| 161 version_info::Channel channel) const; | 163 version_info::Channel channel, |
| 164 FeatureSessionType session_type) const; |
| 162 | 165 |
| 163 // Handy utilities which construct the correct availability message. | 166 // Handy utilities which construct the correct availability message. |
| 164 Availability CreateAvailability(AvailabilityResult result) const; | 167 Availability CreateAvailability(AvailabilityResult result) const; |
| 165 Availability CreateAvailability(AvailabilityResult result, | 168 Availability CreateAvailability(AvailabilityResult result, |
| 166 Manifest::Type type) const; | 169 Manifest::Type type) const; |
| 167 Availability CreateAvailability(AvailabilityResult result, | 170 Availability CreateAvailability(AvailabilityResult result, |
| 168 const GURL& url) const; | 171 const GURL& url) const; |
| 169 Availability CreateAvailability(AvailabilityResult result, | 172 Availability CreateAvailability(AvailabilityResult result, |
| 170 Context context) const; | 173 Context context) const; |
| 171 Availability CreateAvailability(AvailabilityResult result, | 174 Availability CreateAvailability(AvailabilityResult result, |
| 172 version_info::Channel channel) const; | 175 version_info::Channel channel) const; |
| 176 Availability CreateAvailability(AvailabilityResult result, |
| 177 FeatureSessionType session_type) const; |
| 173 | 178 |
| 174 private: | 179 private: |
| 175 friend struct FeatureComparator; | 180 friend struct FeatureComparator; |
| 176 friend class SimpleFeatureTest; | 181 friend class SimpleFeatureTest; |
| 177 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, ManifestFeatureTypes); | 182 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, ManifestFeatureTypes); |
| 178 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, PermissionFeatureTypes); | 183 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, PermissionFeatureTypes); |
| 179 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); | 184 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); |
| 180 FRIEND_TEST_ALL_PREFIXES(FeaturesGenerationTest, FeaturesTest); | 185 FRIEND_TEST_ALL_PREFIXES(FeaturesGenerationTest, FeaturesTest); |
| 181 FRIEND_TEST_ALL_PREFIXES(ManifestUnitTest, Extension); | 186 FRIEND_TEST_ALL_PREFIXES(ManifestUnitTest, Extension); |
| 182 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Blacklist); | 187 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Blacklist); |
| 183 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, CommandLineSwitch); | 188 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, CommandLineSwitch); |
| 184 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ComplexFeatureAvailability); | 189 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ComplexFeatureAvailability); |
| 185 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Context); | 190 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Context); |
| 191 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, SessionType); |
| 186 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, FeatureValidation); | 192 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, FeatureValidation); |
| 187 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdBlacklist); | 193 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdBlacklist); |
| 188 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdWhitelist); | 194 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdWhitelist); |
| 189 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Inheritance); | 195 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Inheritance); |
| 190 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Location); | 196 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Location); |
| 191 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ManifestVersion); | 197 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ManifestVersion); |
| 192 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, PackageType); | 198 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, PackageType); |
| 193 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseContexts); | 199 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseContexts); |
| 194 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseLocation); | 200 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseLocation); |
| 195 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseManifestVersion); | 201 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseManifestVersion); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 215 static bool IsValidExtensionId(const std::string& extension_id); | 221 static bool IsValidExtensionId(const std::string& extension_id); |
| 216 | 222 |
| 217 // For clarity and consistency, we handle the default value of each of these | 223 // For clarity and consistency, we handle the default value of each of these |
| 218 // members the same way: it matches everything. It is up to the higher level | 224 // members the same way: it matches everything. It is up to the higher level |
| 219 // code that reads Features out of static data to validate that data and set | 225 // code that reads Features out of static data to validate that data and set |
| 220 // sensible defaults. | 226 // sensible defaults. |
| 221 std::vector<std::string> blacklist_; | 227 std::vector<std::string> blacklist_; |
| 222 std::vector<std::string> whitelist_; | 228 std::vector<std::string> whitelist_; |
| 223 std::vector<std::string> dependencies_; | 229 std::vector<std::string> dependencies_; |
| 224 std::vector<Manifest::Type> extension_types_; | 230 std::vector<Manifest::Type> extension_types_; |
| 231 std::vector<FeatureSessionType> session_types_; |
| 225 std::vector<Context> contexts_; | 232 std::vector<Context> contexts_; |
| 226 std::vector<Platform> platforms_; | 233 std::vector<Platform> platforms_; |
| 227 URLPatternSet matches_; | 234 URLPatternSet matches_; |
| 228 Location location_; | 235 Location location_; |
| 229 int min_manifest_version_; | 236 int min_manifest_version_; |
| 230 int max_manifest_version_; | 237 int max_manifest_version_; |
| 231 bool component_extensions_auto_granted_; | 238 bool component_extensions_auto_granted_; |
| 232 bool is_internal_; | 239 bool is_internal_; |
| 233 std::string command_line_switch_; | 240 std::string command_line_switch_; |
| 234 std::unique_ptr<version_info::Channel> channel_; | 241 std::unique_ptr<version_info::Channel> channel_; |
| 235 | 242 |
| 236 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); | 243 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); |
| 237 }; | 244 }; |
| 238 | 245 |
| 239 } // namespace extensions | 246 } // namespace extensions |
| 240 | 247 |
| 241 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ | 248 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ |
| OLD | NEW |