| 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 <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 17 #include "extensions/common/features/feature.h" | 17 #include "extensions/common/features/feature.h" |
| 18 #include "extensions/common/features/simple_feature_filter.h" | 18 #include "extensions/common/features/simple_feature_filter.h" |
| 19 #include "extensions/common/manifest.h" | 19 #include "extensions/common/manifest.h" |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 | 22 |
| 23 class ComplexFeature; | 23 class ComplexFeature; |
| 24 | 24 |
| 25 class SimpleFeature : public Feature { | 25 class SimpleFeature : public Feature { |
| 26 public: | 26 public: |
| 27 SimpleFeature(); | 27 SimpleFeature(); |
| 28 virtual ~SimpleFeature(); | 28 virtual ~SimpleFeature(); |
| 29 | 29 |
| 30 // Similar to Manifest::Location, these are the classes of locations |
| 31 // supported in feature files; "component" implies |
| 32 // COMPONENT/EXTERNAL_COMPONENT manifest location types, etc. |
| 33 // |
| 34 // This is only public for testing. Production code should never access it, |
| 35 // nor should it really have any reason to access the SimpleFeature class |
| 36 // directly, it should be dealing with the Feature interface. |
| 37 enum Location { |
| 38 UNSPECIFIED_LOCATION, |
| 39 COMPONENT_LOCATION, |
| 40 POLICY_LOCATION, |
| 41 }; |
| 42 |
| 43 // Accessors defined for testing. See comment above about not directly using |
| 44 // SimpleFeature in production code. |
| 45 Location location() const { return location_; } |
| 46 void set_location(Location location) { location_ = location; } |
| 47 int min_manifest_version() const { return min_manifest_version_; } |
| 48 void set_min_manifest_version(int min_manifest_version) { |
| 49 min_manifest_version_ = min_manifest_version; |
| 50 } |
| 51 int max_manifest_version() const { return max_manifest_version_; } |
| 52 void set_max_manifest_version(int max_manifest_version) { |
| 53 max_manifest_version_ = max_manifest_version; |
| 54 } |
| 55 |
| 30 std::set<std::string>* whitelist() { return &whitelist_; } | 56 std::set<std::string>* whitelist() { return &whitelist_; } |
| 31 std::set<Manifest::Type>* extension_types() { return &extension_types_; } | 57 std::set<Manifest::Type>* extension_types() { return &extension_types_; } |
| 32 | 58 |
| 33 // Adds a filter to this feature. The feature takes ownership of the filter. | 59 // Adds a filter to this feature. The feature takes ownership of the filter. |
| 34 void AddFilter(scoped_ptr<SimpleFeatureFilter> filter); | 60 void AddFilter(scoped_ptr<SimpleFeatureFilter> filter); |
| 35 | 61 |
| 36 // Parses the JSON representation of a feature into the fields of this object. | 62 // Parses the JSON representation of a feature into the fields of this object. |
| 37 // Unspecified values in the JSON are not modified in the object. This allows | 63 // Unspecified values in the JSON are not modified in the object. This allows |
| 38 // us to implement inheritance by parsing one value after another. Returns | 64 // us to implement inheritance by parsing one value after another. Returns |
| 39 // the error found, or an empty string on success. | 65 // the error found, or an empty string on success. |
| 40 virtual std::string Parse(const base::DictionaryValue* value); | 66 virtual std::string Parse(const base::DictionaryValue* value); |
| 41 | 67 |
| 42 Location location() const { return location_; } | |
| 43 void set_location(Location location) { location_ = location; } | |
| 44 | |
| 45 std::set<Platform>* platforms() { return &platforms_; } | 68 std::set<Platform>* platforms() { return &platforms_; } |
| 46 | 69 |
| 47 int min_manifest_version() const { return min_manifest_version_; } | |
| 48 void set_min_manifest_version(int min_manifest_version) { | |
| 49 min_manifest_version_ = min_manifest_version; | |
| 50 } | |
| 51 | |
| 52 int max_manifest_version() const { return max_manifest_version_; } | |
| 53 void set_max_manifest_version(int max_manifest_version) { | |
| 54 max_manifest_version_ = max_manifest_version; | |
| 55 } | |
| 56 | |
| 57 Availability IsAvailableToContext(const Extension* extension, | 70 Availability IsAvailableToContext(const Extension* extension, |
| 58 Context context) const { | 71 Context context) const { |
| 59 return IsAvailableToContext(extension, context, GURL()); | 72 return IsAvailableToContext(extension, context, GURL()); |
| 60 } | 73 } |
| 61 Availability IsAvailableToContext(const Extension* extension, | 74 Availability IsAvailableToContext(const Extension* extension, |
| 62 Context context, | 75 Context context, |
| 63 Platform platform) const { | 76 Platform platform) const { |
| 64 return IsAvailableToContext(extension, context, GURL(), platform); | 77 return IsAvailableToContext(extension, context, GURL(), platform); |
| 65 } | 78 } |
| 66 Availability IsAvailableToContext(const Extension* extension, | 79 Availability IsAvailableToContext(const Extension* extension, |
| 67 Context context, | 80 Context context, |
| 68 const GURL& url) const { | 81 const GURL& url) const { |
| 69 return IsAvailableToContext(extension, context, url, GetCurrentPlatform()); | 82 return IsAvailableToContext(extension, context, url, GetCurrentPlatform()); |
| 70 } | 83 } |
| 71 | 84 |
| 72 // extension::Feature: | 85 // extension::Feature: |
| 73 virtual Availability IsAvailableToManifest(const std::string& extension_id, | 86 virtual Availability IsAvailableToManifest(const std::string& extension_id, |
| 74 Manifest::Type type, | 87 Manifest::Type type, |
| 75 Location location, | 88 Manifest::Location location, |
| 76 int manifest_version, | 89 int manifest_version, |
| 77 Platform platform) const OVERRIDE; | 90 Platform platform) const OVERRIDE; |
| 78 | 91 |
| 79 virtual Availability IsAvailableToContext(const Extension* extension, | 92 virtual Availability IsAvailableToContext(const Extension* extension, |
| 80 Context context, | 93 Context context, |
| 81 const GURL& url, | 94 const GURL& url, |
| 82 Platform platform) const OVERRIDE; | 95 Platform platform) const OVERRIDE; |
| 83 | 96 |
| 84 virtual std::string GetAvailabilityMessage(AvailabilityResult result, | 97 virtual std::string GetAvailabilityMessage(AvailabilityResult result, |
| 85 Manifest::Type type, | 98 Manifest::Type type, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 protected: | 111 protected: |
| 99 Availability CreateAvailability(AvailabilityResult result) const; | 112 Availability CreateAvailability(AvailabilityResult result) const; |
| 100 Availability CreateAvailability(AvailabilityResult result, | 113 Availability CreateAvailability(AvailabilityResult result, |
| 101 Manifest::Type type) const; | 114 Manifest::Type type) const; |
| 102 Availability CreateAvailability(AvailabilityResult result, | 115 Availability CreateAvailability(AvailabilityResult result, |
| 103 const GURL& url) const; | 116 const GURL& url) const; |
| 104 Availability CreateAvailability(AvailabilityResult result, | 117 Availability CreateAvailability(AvailabilityResult result, |
| 105 Context context) const; | 118 Context context) const; |
| 106 | 119 |
| 107 private: | 120 private: |
| 121 bool MatchesManifestLocation(Manifest::Location manifest_location) const; |
| 122 |
| 108 // For clarity and consistency, we handle the default value of each of these | 123 // For clarity and consistency, we handle the default value of each of these |
| 109 // members the same way: it matches everything. It is up to the higher level | 124 // members the same way: it matches everything. It is up to the higher level |
| 110 // code that reads Features out of static data to validate that data and set | 125 // code that reads Features out of static data to validate that data and set |
| 111 // sensible defaults. | 126 // sensible defaults. |
| 112 std::set<std::string> whitelist_; | 127 std::set<std::string> whitelist_; |
| 113 std::set<Manifest::Type> extension_types_; | 128 std::set<Manifest::Type> extension_types_; |
| 114 std::set<Context> contexts_; | 129 std::set<Context> contexts_; |
| 115 URLPatternSet matches_; | 130 URLPatternSet matches_; |
| 116 Location location_; // we only care about component/not-component now | 131 Location location_; |
| 117 std::set<Platform> platforms_; | 132 std::set<Platform> platforms_; |
| 118 int min_manifest_version_; | 133 int min_manifest_version_; |
| 119 int max_manifest_version_; | 134 int max_manifest_version_; |
| 120 bool has_parent_; | 135 bool has_parent_; |
| 121 | 136 |
| 122 typedef std::vector<linked_ptr<SimpleFeatureFilter> > FilterList; | 137 typedef std::vector<linked_ptr<SimpleFeatureFilter> > FilterList; |
| 123 FilterList filters_; | 138 FilterList filters_; |
| 124 | 139 |
| 125 FRIEND_TEST_ALL_PREFIXES(ExtensionSimpleFeatureTest, Context); | |
| 126 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); | 140 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); |
| 127 }; | 141 }; |
| 128 | 142 |
| 129 } // namespace extensions | 143 } // namespace extensions |
| 130 | 144 |
| 131 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ | 145 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ |
| OLD | NEW |