| 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 <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "components/version_info/version_info.h" |
| 20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/features/feature.h" | 22 #include "extensions/common/features/feature.h" |
| 22 #include "extensions/common/features/simple_feature_filter.h" | |
| 23 #include "extensions/common/manifest.h" | 23 #include "extensions/common/manifest.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| 27 class BaseFeatureProviderTest; | 27 class BaseFeatureProviderTest; |
| 28 class ExtensionAPITest; | 28 class ExtensionAPITest; |
| 29 class ManifestUnitTest; | 29 class ManifestUnitTest; |
| 30 class SimpleFeatureTest; | 30 class SimpleFeatureTest; |
| 31 | 31 |
| 32 class SimpleFeature : public Feature { | 32 class SimpleFeature : public Feature { |
| 33 public: | 33 public: |
| 34 // Used by tests to override the cached --whitelisted-extension-id. | 34 // Used by tests to override the cached --whitelisted-extension-id. |
| 35 class ScopedWhitelistForTest { | 35 class ScopedWhitelistForTest { |
| 36 public: | 36 public: |
| 37 explicit ScopedWhitelistForTest(const std::string& id); | 37 explicit ScopedWhitelistForTest(const std::string& id); |
| 38 ~ScopedWhitelistForTest(); | 38 ~ScopedWhitelistForTest(); |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 std::string* previous_id_; | 41 std::string* previous_id_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(ScopedWhitelistForTest); | 43 DISALLOW_COPY_AND_ASSIGN(ScopedWhitelistForTest); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 SimpleFeature(); | 46 SimpleFeature(); |
| 47 ~SimpleFeature() override; | 47 ~SimpleFeature() override; |
| 48 | 48 |
| 49 // Dependency resolution is a property of Features that is preferrably | |
| 50 // handled internally to avoid temptation, but FeatureFilters may need | |
| 51 // to know if there are any at all. | |
| 52 bool HasDependencies() const; | |
| 53 | |
| 54 // Adds a filter to this feature. The feature takes ownership of the filter. | |
| 55 void AddFilter(std::unique_ptr<SimpleFeatureFilter> filter); | |
| 56 | |
| 57 // Parses the JSON representation of a feature into the fields of this object. | 49 // Parses the JSON representation of a feature into the fields of this object. |
| 58 // Unspecified values in the JSON are not modified in the object. This allows | 50 // Unspecified values in the JSON are not modified in the object. This allows |
| 59 // us to implement inheritance by parsing one value after another. Returns | 51 // us to implement inheritance by parsing one value after another. Returns |
| 60 // the error found, or an empty string on success. | 52 // the error found, or an empty string on success. |
| 61 virtual std::string Parse(const base::DictionaryValue* dictionary); | 53 virtual std::string Parse(const base::DictionaryValue* dictionary); |
| 62 | 54 |
| 63 Availability IsAvailableToContext(const Extension* extension, | 55 Availability IsAvailableToContext(const Extension* extension, |
| 64 Context context) const { | 56 Context context) const { |
| 65 return IsAvailableToContext(extension, context, GURL()); | 57 return IsAvailableToContext(extension, context, GURL()); |
| 66 } | 58 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 80 Manifest::Type type, | 72 Manifest::Type type, |
| 81 Manifest::Location location, | 73 Manifest::Location location, |
| 82 int manifest_version, | 74 int manifest_version, |
| 83 Platform platform) const override; | 75 Platform platform) const override; |
| 84 | 76 |
| 85 Availability IsAvailableToContext(const Extension* extension, | 77 Availability IsAvailableToContext(const Extension* extension, |
| 86 Context context, | 78 Context context, |
| 87 const GURL& url, | 79 const GURL& url, |
| 88 Platform platform) const override; | 80 Platform platform) const override; |
| 89 | 81 |
| 90 std::string GetAvailabilityMessage(AvailabilityResult result, | |
| 91 Manifest::Type type, | |
| 92 const GURL& url, | |
| 93 Context context) const override; | |
| 94 | |
| 95 bool IsInternal() const override; | 82 bool IsInternal() const override; |
| 96 | 83 |
| 97 bool IsIdInBlacklist(const std::string& extension_id) const override; | 84 bool IsIdInBlacklist(const std::string& extension_id) const override; |
| 98 bool IsIdInWhitelist(const std::string& extension_id) const override; | 85 bool IsIdInWhitelist(const std::string& extension_id) const override; |
| 99 | 86 |
| 100 static bool IsIdInArray(const std::string& extension_id, | 87 static bool IsIdInArray(const std::string& extension_id, |
| 101 const char* const array[], | 88 const char* const array[], |
| 102 size_t array_length); | 89 size_t array_length); |
| 103 | 90 |
| 104 protected: | 91 protected: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 134 void set_max_manifest_version(int max_manifest_version) { | 121 void set_max_manifest_version(int max_manifest_version) { |
| 135 max_manifest_version_ = max_manifest_version; | 122 max_manifest_version_ = max_manifest_version; |
| 136 } | 123 } |
| 137 const std::string& command_line_switch() const { | 124 const std::string& command_line_switch() const { |
| 138 return command_line_switch_; | 125 return command_line_switch_; |
| 139 } | 126 } |
| 140 void set_command_line_switch(const std::string& command_line_switch) { | 127 void set_command_line_switch(const std::string& command_line_switch) { |
| 141 command_line_switch_ = command_line_switch; | 128 command_line_switch_ = command_line_switch; |
| 142 } | 129 } |
| 143 | 130 |
| 131 std::string GetAvailabilityMessage(AvailabilityResult result, |
| 132 Manifest::Type type, |
| 133 const GURL& url, |
| 134 Context context, |
| 135 version_info::Channel channel) const; |
| 136 |
| 144 // Handy utilities which construct the correct availability message. | 137 // Handy utilities which construct the correct availability message. |
| 145 Availability CreateAvailability(AvailabilityResult result) const; | 138 Availability CreateAvailability(AvailabilityResult result) const; |
| 146 Availability CreateAvailability(AvailabilityResult result, | 139 Availability CreateAvailability(AvailabilityResult result, |
| 147 Manifest::Type type) const; | 140 Manifest::Type type) const; |
| 148 Availability CreateAvailability(AvailabilityResult result, | 141 Availability CreateAvailability(AvailabilityResult result, |
| 149 const GURL& url) const; | 142 const GURL& url) const; |
| 150 Availability CreateAvailability(AvailabilityResult result, | 143 Availability CreateAvailability(AvailabilityResult result, |
| 151 Context context) const; | 144 Context context) const; |
| 145 Availability CreateAvailability(AvailabilityResult result, |
| 146 version_info::Channel channel) const; |
| 152 | 147 |
| 153 private: | 148 private: |
| 154 friend class SimpleFeatureTest; | 149 friend class SimpleFeatureTest; |
| 155 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, ManifestFeatureTypes); | 150 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, ManifestFeatureTypes); |
| 156 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, PermissionFeatureTypes); | 151 FRIEND_TEST_ALL_PREFIXES(BaseFeatureProviderTest, PermissionFeatureTypes); |
| 157 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); | 152 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); |
| 158 FRIEND_TEST_ALL_PREFIXES(ManifestUnitTest, Extension); | 153 FRIEND_TEST_ALL_PREFIXES(ManifestUnitTest, Extension); |
| 159 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Blacklist); | 154 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Blacklist); |
| 160 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, CommandLineSwitch); | 155 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, CommandLineSwitch); |
| 161 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Context); | 156 FRIEND_TEST_ALL_PREFIXES(SimpleFeatureTest, Context); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 std::vector<std::string> dependencies_; | 192 std::vector<std::string> dependencies_; |
| 198 std::vector<Manifest::Type> extension_types_; | 193 std::vector<Manifest::Type> extension_types_; |
| 199 std::vector<Context> contexts_; | 194 std::vector<Context> contexts_; |
| 200 std::vector<Platform> platforms_; | 195 std::vector<Platform> platforms_; |
| 201 URLPatternSet matches_; | 196 URLPatternSet matches_; |
| 202 Location location_; | 197 Location location_; |
| 203 int min_manifest_version_; | 198 int min_manifest_version_; |
| 204 int max_manifest_version_; | 199 int max_manifest_version_; |
| 205 bool component_extensions_auto_granted_; | 200 bool component_extensions_auto_granted_; |
| 206 std::string command_line_switch_; | 201 std::string command_line_switch_; |
| 207 | 202 std::unique_ptr<version_info::Channel> channel_; |
| 208 std::vector<std::unique_ptr<SimpleFeatureFilter>> filters_; | |
| 209 | 203 |
| 210 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); | 204 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); |
| 211 }; | 205 }; |
| 212 | 206 |
| 213 } // namespace extensions | 207 } // namespace extensions |
| 214 | 208 |
| 215 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ | 209 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ |
| OLD | NEW |