OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
6 #define CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ | 6 #define CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 66 |
67 // Container for AvailabiltyResult that also exposes a user-visible error | 67 // Container for AvailabiltyResult that also exposes a user-visible error |
68 // message in cases where the feature is not available. | 68 // message in cases where the feature is not available. |
69 class Availability { | 69 class Availability { |
70 public: | 70 public: |
71 AvailabilityResult result() const { return result_; } | 71 AvailabilityResult result() const { return result_; } |
72 bool is_available() const { return result_ == IS_AVAILABLE; } | 72 bool is_available() const { return result_ == IS_AVAILABLE; } |
73 const std::string& message() const { return message_; } | 73 const std::string& message() const { return message_; } |
74 | 74 |
75 private: | 75 private: |
76 friend class Feature; | 76 friend class SimpleFeature; |
77 | 77 |
78 // Instances should be created via Feature::CreateAvailability. | 78 // Instances should be created via Feature::CreateAvailability. |
79 Availability(AvailabilityResult result, const std::string& message) | 79 Availability(AvailabilityResult result, const std::string& message) |
80 : result_(result), message_(message) { } | 80 : result_(result), message_(message) { } |
81 | 81 |
82 const AvailabilityResult result_; | 82 const AvailabilityResult result_; |
83 const std::string message_; | 83 const std::string message_; |
84 }; | 84 }; |
85 | 85 |
86 Feature(); | |
87 Feature(const Feature& other); | |
88 virtual ~Feature(); | 86 virtual ~Feature(); |
89 | 87 |
90 // Gets the current channel as seen by the Feature system. | 88 // Gets the current channel as seen by the Feature system. |
91 static chrome::VersionInfo::Channel GetCurrentChannel(); | 89 static chrome::VersionInfo::Channel GetCurrentChannel(); |
92 | 90 |
93 // Sets the current channel as seen by the Feature system. In the browser | 91 // Sets the current channel as seen by the Feature system. In the browser |
94 // process this should be chrome::VersionInfo::GetChannel(), and in the | 92 // process this should be chrome::VersionInfo::GetChannel(), and in the |
95 // renderer this will need to come from an IPC. | 93 // renderer this will need to come from an IPC. |
96 static void SetCurrentChannel(chrome::VersionInfo::Channel channel); | 94 static void SetCurrentChannel(chrome::VersionInfo::Channel channel); |
97 | 95 |
(...skipping 19 matching lines...) Expand all Loading... | |
117 | 115 |
118 const std::string& name() const { return name_; } | 116 const std::string& name() const { return name_; } |
119 void set_name(const std::string& name) { name_ = name; } | 117 void set_name(const std::string& name) { name_ = name; } |
120 | 118 |
121 // Gets the platform the code is currently running on. | 119 // Gets the platform the code is currently running on. |
122 static Platform GetCurrentPlatform(); | 120 static Platform GetCurrentPlatform(); |
123 | 121 |
124 // Gets the Feature::Location value for the specified Extension::Location. | 122 // Gets the Feature::Location value for the specified Extension::Location. |
125 static Location ConvertLocation(Extension::Location extension_location); | 123 static Location ConvertLocation(Extension::Location extension_location); |
126 | 124 |
127 std::set<std::string>* whitelist() { return &whitelist_; } | 125 virtual std::set<Context>* GetContexts() = 0; |
not at google - send to devlin
2012/12/14 21:30:43
TODO(justinlin): move to APIFeature when it exists
justinlin
2012/12/14 21:56:06
Done.
| |
128 std::set<Extension::Type>* extension_types() { return &extension_types_; } | |
129 std::set<Context>* contexts() { return &contexts_; } | |
130 | |
131 Location location() const { return location_; } | |
132 void set_location(Location location) { location_ = location; } | |
133 | |
134 Platform platform() const { return platform_; } | |
135 void set_platform(Platform platform) { platform_ = platform; } | |
136 | |
137 int min_manifest_version() const { return min_manifest_version_; } | |
138 void set_min_manifest_version(int min_manifest_version) { | |
139 min_manifest_version_ = min_manifest_version; | |
140 } | |
141 | |
142 int max_manifest_version() const { return max_manifest_version_; } | |
143 void set_max_manifest_version(int max_manifest_version) { | |
144 max_manifest_version_ = max_manifest_version; | |
145 } | |
146 | |
147 // Parses the JSON representation of a feature into the fields of this object. | |
148 // Unspecified values in the JSON are not modified in the object. This allows | |
149 // us to implement inheritance by parsing one value after another. | |
150 void Parse(const DictionaryValue* value); | |
151 | |
152 // Returns true if the feature contains the same values as another. | |
153 bool Equals(const Feature& other) const; | |
154 | 126 |
155 // Returns true if the feature is available to be parsed into a new extension | 127 // Returns true if the feature is available to be parsed into a new extension |
156 // manifest. | 128 // manifest. |
157 Availability IsAvailableToManifest(const std::string& extension_id, | 129 Availability IsAvailableToManifest(const std::string& extension_id, |
158 Extension::Type type, | 130 Extension::Type type, |
159 Location location, | 131 Location location, |
160 int manifest_version) const { | 132 int manifest_version) const { |
161 return IsAvailableToManifest(extension_id, type, location, manifest_version, | 133 return IsAvailableToManifest(extension_id, type, location, manifest_version, |
162 GetCurrentPlatform()); | 134 GetCurrentPlatform()); |
163 } | 135 } |
164 Availability IsAvailableToManifest(const std::string& extension_id, | 136 virtual Availability IsAvailableToManifest(const std::string& extension_id, |
165 Extension::Type type, | 137 Extension::Type type, |
166 Location location, | 138 Location location, |
167 int manifest_version, | 139 int manifest_version, |
168 Platform platform) const; | 140 Platform platform) const = 0; |
169 | 141 |
170 // Returns true if the feature is available to be used in the specified | 142 // Returns true if the feature is available to be used in the specified |
171 // extension and context. | 143 // extension and context. |
172 Availability IsAvailableToContext(const Extension* extension, | 144 Availability IsAvailableToContext(const Extension* extension, |
173 Context context) const { | 145 Context context) const { |
174 return IsAvailableToContext(extension, context, GetCurrentPlatform()); | 146 return IsAvailableToContext(extension, context, GetCurrentPlatform()); |
175 } | 147 } |
176 virtual Availability IsAvailableToContext(const Extension* extension, | 148 virtual Availability IsAvailableToContext(const Extension* extension, |
177 Context context, | 149 Context context, |
178 Platform platform) const; | 150 Platform platform) const = 0; |
151 | |
152 virtual std::string GetAvailabilityMessage( | |
153 AvailabilityResult result, Extension::Type type) const = 0; | |
179 | 154 |
180 protected: | 155 protected: |
181 Availability CreateAvailability(AvailabilityResult result) const; | |
182 Availability CreateAvailability(AvailabilityResult result, | |
183 Extension::Type type) const; | |
184 | |
185 private: | |
186 std::string GetAvailabilityMessage( | |
187 AvailabilityResult result, Extension::Type type) const; | |
188 | |
189 std::string name_; | 156 std::string name_; |
190 | |
191 // For clarify and consistency, we handle the default value of each of these | |
192 // members the same way: it matches everything. It is up to the higher level | |
193 // code that reads Features out of static data to validate that data and set | |
194 // sensible defaults. | |
195 std::set<std::string> whitelist_; | |
196 std::set<Extension::Type> extension_types_; | |
197 std::set<Context> contexts_; | |
198 Location location_; // we only care about component/not-component now | |
199 Platform platform_; // we only care about chromeos/not-chromeos now | |
200 int min_manifest_version_; | |
201 int max_manifest_version_; | |
202 chrome::VersionInfo::Channel channel_; | |
203 }; | 157 }; |
204 | 158 |
205 } // namespace extensions | 159 } // namespace extensions |
206 | 160 |
207 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ | 161 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
OLD | NEW |