Pepper: Fix PPB_TrueTypeFont GetFontsInFamily function.
[chromium-blink-merge.git] / extensions / common / features / simple_feature.h
blob395a26c8ec47f4fa7e9b8fcfe21da906f089f150
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_
6 #define EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/callback_forward.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/values.h"
17 #include "extensions/common/extension.h"
18 #include "extensions/common/features/feature.h"
19 #include "extensions/common/features/simple_feature_filter.h"
20 #include "extensions/common/manifest.h"
22 namespace extensions {
24 class SimpleFeature : public Feature {
25 public:
26 SimpleFeature();
27 ~SimpleFeature() override;
29 // Similar to Manifest::Location, these are the classes of locations
30 // supported in feature files.
32 // This is only public for testing. Production code should never access it,
33 // nor should it really have any reason to access the SimpleFeature class
34 // directly, it should be dealing with the Feature interface.
35 enum Location {
36 UNSPECIFIED_LOCATION,
37 COMPONENT_LOCATION,
38 EXTERNAL_COMPONENT_LOCATION,
39 POLICY_LOCATION,
42 // Accessors defined for testing. See comment above about not directly using
43 // SimpleFeature in production code.
44 std::set<std::string>* blacklist() { return &blacklist_; }
45 const std::set<std::string>* blacklist() const { return &blacklist_; }
46 std::set<std::string>* whitelist() { return &whitelist_; }
47 const std::set<std::string>* whitelist() const { return &whitelist_; }
48 std::set<Manifest::Type>* extension_types() { return &extension_types_; }
49 const std::set<Manifest::Type>* extension_types() const {
50 return &extension_types_;
52 std::set<Context>* contexts() { return &contexts_; }
53 const std::set<Context>* contexts() const { return &contexts_; }
54 Location location() const { return location_; }
55 void set_location(Location location) { location_ = location; }
56 int min_manifest_version() const { return min_manifest_version_; }
57 void set_min_manifest_version(int min_manifest_version) {
58 min_manifest_version_ = min_manifest_version;
60 int max_manifest_version() const { return max_manifest_version_; }
61 void set_max_manifest_version(int max_manifest_version) {
62 max_manifest_version_ = max_manifest_version;
64 const std::string& command_line_switch() const {
65 return command_line_switch_;
67 void set_command_line_switch(const std::string& command_line_switch) {
68 command_line_switch_ = command_line_switch;
71 // Dependency resolution is a property of Features that is preferrably
72 // handled internally to avoid temptation, but FeatureFilters may need
73 // to know if there are any at all.
74 bool HasDependencies() const;
76 // Adds a filter to this feature. The feature takes ownership of the filter.
77 void AddFilter(scoped_ptr<SimpleFeatureFilter> filter);
79 // Parses the JSON representation of a feature into the fields of this object.
80 // Unspecified values in the JSON are not modified in the object. This allows
81 // us to implement inheritance by parsing one value after another. Returns
82 // the error found, or an empty string on success.
83 virtual std::string Parse(const base::DictionaryValue* value);
85 std::set<Platform>* platforms() { return &platforms_; }
87 Availability IsAvailableToContext(const Extension* extension,
88 Context context) const {
89 return IsAvailableToContext(extension, context, GURL());
91 Availability IsAvailableToContext(const Extension* extension,
92 Context context,
93 Platform platform) const {
94 return IsAvailableToContext(extension, context, GURL(), platform);
96 Availability IsAvailableToContext(const Extension* extension,
97 Context context,
98 const GURL& url) const {
99 return IsAvailableToContext(extension, context, url, GetCurrentPlatform());
102 // extension::Feature:
103 Availability IsAvailableToManifest(const std::string& extension_id,
104 Manifest::Type type,
105 Manifest::Location location,
106 int manifest_version,
107 Platform platform) const override;
109 Availability IsAvailableToContext(const Extension* extension,
110 Context context,
111 const GURL& url,
112 Platform platform) const override;
114 std::string GetAvailabilityMessage(AvailabilityResult result,
115 Manifest::Type type,
116 const GURL& url,
117 Context context) const override;
119 bool IsInternal() const override;
121 bool IsIdInBlacklist(const std::string& extension_id) const override;
122 bool IsIdInWhitelist(const std::string& extension_id) const override;
123 static bool IsIdInList(const std::string& extension_id,
124 const std::set<std::string>& list);
126 protected:
127 Availability CreateAvailability(AvailabilityResult result) const;
128 Availability CreateAvailability(AvailabilityResult result,
129 Manifest::Type type) const;
130 Availability CreateAvailability(AvailabilityResult result,
131 const GURL& url) const;
132 Availability CreateAvailability(AvailabilityResult result,
133 Context context) const;
135 private:
136 bool MatchesManifestLocation(Manifest::Location manifest_location) const;
138 Availability CheckDependencies(
139 const base::Callback<Availability(const Feature*)>& checker) const;
141 // For clarity and consistency, we handle the default value of each of these
142 // members the same way: it matches everything. It is up to the higher level
143 // code that reads Features out of static data to validate that data and set
144 // sensible defaults.
145 std::set<std::string> blacklist_;
146 std::set<std::string> whitelist_;
147 std::set<std::string> dependencies_;
148 std::set<Manifest::Type> extension_types_;
149 std::set<Context> contexts_;
150 URLPatternSet matches_;
151 Location location_;
152 std::set<Platform> platforms_;
153 int min_manifest_version_;
154 int max_manifest_version_;
155 bool component_extensions_auto_granted_;
156 std::string command_line_switch_;
158 ScopedVector<SimpleFeatureFilter> filters_;;
160 DISALLOW_COPY_AND_ASSIGN(SimpleFeature);
163 } // namespace extensions
165 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_