| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void set_channel(version_info::Channel channel) { | 100 void set_channel(version_info::Channel channel) { |
| 100 channel_.reset(new version_info::Channel(channel)); | 101 channel_.reset(new version_info::Channel(channel)); |
| 101 } | 102 } |
| 102 void set_command_line_switch(base::StringPiece command_line_switch); | 103 void set_command_line_switch(base::StringPiece command_line_switch); |
| 103 void set_component_extensions_auto_granted(bool granted) { | 104 void set_component_extensions_auto_granted(bool granted) { |
| 104 component_extensions_auto_granted_ = granted; | 105 component_extensions_auto_granted_ = granted; |
| 105 } | 106 } |
| 106 void set_contexts(std::initializer_list<Context> contexts); | 107 void set_contexts(std::initializer_list<Context> contexts); |
| 107 void set_dependencies(std::initializer_list<const char* const> dependencies); | 108 void set_dependencies(std::initializer_list<const char* const> dependencies); |
| 108 void set_extension_types(std::initializer_list<Manifest::Type> types); | 109 void set_extension_types(std::initializer_list<Manifest::Type> types); |
| 110 void set_session_types(std::initializer_list<FeatureSessionType> types); |
| 109 void set_internal(bool is_internal) { is_internal_ = is_internal; } | 111 void set_internal(bool is_internal) { is_internal_ = is_internal; } |
| 110 void set_location(Location location) { location_ = location; } | 112 void set_location(Location location) { location_ = location; } |
| 111 // set_matches() is an exception to pass-by-value since we construct an | 113 // set_matches() is an exception to pass-by-value since we construct an |
| 112 // URLPatternSet from the vector of strings. | 114 // URLPatternSet from the vector of strings. |
| 113 // TODO(devlin): Pass in an URLPatternSet directly. | 115 // TODO(devlin): Pass in an URLPatternSet directly. |
| 114 void set_matches(std::initializer_list<const char* const> matches); | 116 void set_matches(std::initializer_list<const char* const> matches); |
| 115 void set_max_manifest_version(int max_manifest_version) { | 117 void set_max_manifest_version(int max_manifest_version) { |
| 116 max_manifest_version_ = max_manifest_version; | 118 max_manifest_version_ = max_manifest_version; |
| 117 } | 119 } |
| 118 void set_min_manifest_version(int min_manifest_version) { | 120 void set_min_manifest_version(int min_manifest_version) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 142 } | 144 } |
| 143 bool component_extensions_auto_granted() const { | 145 bool component_extensions_auto_granted() const { |
| 144 return component_extensions_auto_granted_; | 146 return component_extensions_auto_granted_; |
| 145 } | 147 } |
| 146 const URLPatternSet& matches() const { return matches_; } | 148 const URLPatternSet& matches() const { return matches_; } |
| 147 | 149 |
| 148 std::string GetAvailabilityMessage(AvailabilityResult result, | 150 std::string GetAvailabilityMessage(AvailabilityResult result, |
| 149 Manifest::Type type, | 151 Manifest::Type type, |
| 150 const GURL& url, | 152 const GURL& url, |
| 151 Context context, | 153 Context context, |
| 152 version_info::Channel channel) const; | 154 version_info::Channel channel, |
| 155 FeatureSessionType session_type) const; |
| 153 | 156 |
| 154 // Handy utilities which construct the correct availability message. | 157 // Handy utilities which construct the correct availability message. |
| 155 Availability CreateAvailability(AvailabilityResult result) const; | 158 Availability CreateAvailability(AvailabilityResult result) const; |
| 156 Availability CreateAvailability(AvailabilityResult result, | 159 Availability CreateAvailability(AvailabilityResult result, |
| 157 Manifest::Type type) const; | 160 Manifest::Type type) const; |
| 158 Availability CreateAvailability(AvailabilityResult result, | 161 Availability CreateAvailability(AvailabilityResult result, |
| 159 const GURL& url) const; | 162 const GURL& url) const; |
| 160 Availability CreateAvailability(AvailabilityResult result, | 163 Availability CreateAvailability(AvailabilityResult result, |
| 161 Context context) const; | 164 Context context) const; |
| 162 Availability CreateAvailability(AvailabilityResult result, | 165 Availability CreateAvailability(AvailabilityResult result, |
| 163 version_info::Channel channel) const; | 166 version_info::Channel channel) const; |
| 167 Availability CreateAvailability(AvailabilityResult result, |
| 168 FeatureSessionType session_type) const; |
| 164 | 169 |
| 165 private: | 170 private: |
| 166 friend struct FeatureComparator; | 171 friend struct FeatureComparator; |
| 167 friend class SimpleFeatureTest; | 172 friend class SimpleFeatureTest; |
| 168 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, ManifestFeatureTypes); | 173 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, ManifestFeatureTypes); |
| 169 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, PermissionFeatureTypes); | 174 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, PermissionFeatureTypes); |
| 170 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); | 175 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); |
| 171 FRIEND_TEST_ALL_PREFIXES(FeaturesGenerationTest, FeaturesTest); | 176 FRIEND_TEST_ALL_PREFIXES(FeaturesGenerationTest, FeaturesTest); |
| 172 FRIEND_TEST_ALL_PREFIXES(ManifestUnitTest, Extension); | 177 FRIEND_TEST_ALL_PREFIXES(ManifestUnitTest, Extension); |
| 173 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Blacklist); | 178 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Blacklist); |
| 174 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, CommandLineSwitch); | 179 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, CommandLineSwitch); |
| 175 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ComplexFeatureAvailability); | 180 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ComplexFeatureAvailability); |
| 176 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Context); | 181 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Context); |
| 182 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, SessionType); |
| 177 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, FeatureValidation); | 183 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, FeatureValidation); |
| 178 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdBlacklist); | 184 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdBlacklist); |
| 179 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdWhitelist); | 185 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, HashedIdWhitelist); |
| 180 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Inheritance); | 186 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Inheritance); |
| 181 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Location); | 187 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Location); |
| 182 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ManifestVersion); | 188 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ManifestVersion); |
| 183 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, PackageType); | 189 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, PackageType); |
| 184 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseContexts); | 190 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseContexts); |
| 185 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseLocation); | 191 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseLocation); |
| 186 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseManifestVersion); | 192 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, ParseManifestVersion); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 206 static bool IsValidExtensionId(const std::string& extension_id); | 212 static bool IsValidExtensionId(const std::string& extension_id); |
| 207 | 213 |
| 208 // For clarity and consistency, we handle the default value of each of these | 214 // For clarity and consistency, we handle the default value of each of these |
| 209 // members the same way: it matches everything. It is up to the higher level | 215 // members the same way: it matches everything. It is up to the higher level |
| 210 // code that reads Features out of static data to validate that data and set | 216 // code that reads Features out of static data to validate that data and set |
| 211 // sensible defaults. | 217 // sensible defaults. |
| 212 std::vector<std::string> blacklist_; | 218 std::vector<std::string> blacklist_; |
| 213 std::vector<std::string> whitelist_; | 219 std::vector<std::string> whitelist_; |
| 214 std::vector<std::string> dependencies_; | 220 std::vector<std::string> dependencies_; |
| 215 std::vector<Manifest::Type> extension_types_; | 221 std::vector<Manifest::Type> extension_types_; |
| 222 std::vector<FeatureSessionType> session_types_; |
| 216 std::vector<Context> contexts_; | 223 std::vector<Context> contexts_; |
| 217 std::vector<Platform> platforms_; | 224 std::vector<Platform> platforms_; |
| 218 URLPatternSet matches_; | 225 URLPatternSet matches_; |
| 219 Location location_; | 226 Location location_; |
| 220 int min_manifest_version_; | 227 int min_manifest_version_; |
| 221 int max_manifest_version_; | 228 int max_manifest_version_; |
| 222 bool component_extensions_auto_granted_; | 229 bool component_extensions_auto_granted_; |
| 223 bool is_internal_; | 230 bool is_internal_; |
| 224 std::string command_line_switch_; | 231 std::string command_line_switch_; |
| 225 std::unique_ptr<version_info::Channel> channel_; | 232 std::unique_ptr<version_info::Channel> channel_; |
| 226 | 233 |
| 227 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); | 234 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); |
| 228 }; | 235 }; |
| 229 | 236 |
| 230 } // namespace extensions | 237 } // namespace extensions |
| 231 | 238 |
| 232 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ | 239 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ |
| OLD | NEW |