OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 5 #ifndef WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "webkit/plugins/npapi/webplugininfo.h" | 17 #include "webkit/plugins/webplugininfo.h" |
18 | 18 |
19 class FilePath; | 19 class FilePath; |
20 class PluginExceptionsTableModelTest; | 20 class PluginExceptionsTableModelTest; |
21 class Version; | 21 class Version; |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class DictionaryValue; | 24 class DictionaryValue; |
25 } | 25 } |
26 | 26 |
27 namespace webkit { | 27 namespace webkit { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 // Tests whether |plugin_name| within the plugin group |group_name| is | 110 // Tests whether |plugin_name| within the plugin group |group_name| is |
111 // disabled by policy. | 111 // disabled by policy. |
112 static bool IsPluginFileNameDisabledByPolicy(const string16& plugin_name, | 112 static bool IsPluginFileNameDisabledByPolicy(const string16& plugin_name, |
113 const string16& group_name); | 113 const string16& group_name); |
114 | 114 |
115 // Tests whether |plugin_name| is enabled by policy. | 115 // Tests whether |plugin_name| is enabled by policy. |
116 static bool IsPluginNameEnabledByPolicy(const string16& plugin_name); | 116 static bool IsPluginNameEnabledByPolicy(const string16& plugin_name); |
117 | 117 |
118 // Returns true if the given plugin matches this group. | 118 // Returns true if the given plugin matches this group. |
119 bool Match(const WebPluginInfo& plugin) const; | 119 bool Match(const webkit::WebPluginInfo& plugin) const; |
120 | 120 |
121 // Adds the given plugin to this group. | 121 // Adds the given plugin to this group. |
122 void AddPlugin(const WebPluginInfo& plugin); | 122 void AddPlugin(const webkit::WebPluginInfo& plugin); |
123 | 123 |
124 // Removes a plugin from the group by its path. | 124 // Removes a plugin from the group by its path. |
125 bool RemovePlugin(const FilePath& filename); | 125 bool RemovePlugin(const FilePath& filename); |
126 | 126 |
127 // The two following functions enable/disable a plugin given its filename. The | 127 // The two following functions enable/disable a plugin given its filename. The |
128 // function returns true if the plugin could be enabled/disabled. Plugins | 128 // function returns true if the plugin could be enabled/disabled. Plugins |
129 // might not get enabled/disabled if they are controlled by policy or are | 129 // might not get enabled/disabled if they are controlled by policy or are |
130 // already in the wanted state. | 130 // already in the wanted state. |
131 bool EnablePlugin(const FilePath& filename); | 131 bool EnablePlugin(const FilePath& filename); |
132 bool DisablePlugin(const FilePath& filename); | 132 bool DisablePlugin(const FilePath& filename); |
(...skipping 16 matching lines...) Expand all Loading... |
149 // Sets a unique identifier for this group or if none is set an empty string. | 149 // Sets a unique identifier for this group or if none is set an empty string. |
150 void set_identifier(const std::string& identifier) { | 150 void set_identifier(const std::string& identifier) { |
151 identifier_ = identifier; | 151 identifier_ = identifier; |
152 } | 152 } |
153 | 153 |
154 // Returns this group's name, or the filename without extension if the name | 154 // Returns this group's name, or the filename without extension if the name |
155 // is empty. | 155 // is empty. |
156 string16 GetGroupName() const; | 156 string16 GetGroupName() const; |
157 | 157 |
158 // Returns all plugins added to the group. | 158 // Returns all plugins added to the group. |
159 const std::vector<WebPluginInfo>& web_plugins_info() const { | 159 const std::vector<webkit::WebPluginInfo>& web_plugins_info() const { |
160 return web_plugin_infos_; | 160 return web_plugin_infos_; |
161 } | 161 } |
162 | 162 |
163 // Checks whether a plugin exists in the group with the given path. | 163 // Checks whether a plugin exists in the group with the given path. |
164 bool ContainsPlugin(const FilePath& path) const; | 164 bool ContainsPlugin(const FilePath& path) const; |
165 | 165 |
166 // Returns the description of the highest-priority plug-in in the group. | 166 // Returns the description of the highest-priority plug-in in the group. |
167 const string16& description() const { return description_; } | 167 const string16& description() const { return description_; } |
168 | 168 |
169 // Returns a DictionaryValue with data to display in the UI. | 169 // Returns a DictionaryValue with data to display in the UI. |
(...skipping 21 matching lines...) Expand all Loading... |
191 bool IsEmpty() const; | 191 bool IsEmpty() const; |
192 | 192 |
193 // Disables all plugins in this group that are older than the | 193 // Disables all plugins in this group that are older than the |
194 // minimum version. | 194 // minimum version. |
195 void DisableOutdatedPlugins(); | 195 void DisableOutdatedPlugins(); |
196 | 196 |
197 // Parse a version string as used by a plug-in. This method is more lenient | 197 // Parse a version string as used by a plug-in. This method is more lenient |
198 // in accepting weird version strings than Version::GetFromString(). | 198 // in accepting weird version strings than Version::GetFromString(). |
199 static Version* CreateVersionFromString(const string16& version_string); | 199 static Version* CreateVersionFromString(const string16& version_string); |
200 | 200 |
201 std::vector<WebPluginInfo> web_plugin_infos() { return web_plugin_infos_; } | 201 std::vector<webkit::WebPluginInfo> web_plugin_infos() { |
| 202 return web_plugin_infos_; |
| 203 } |
202 | 204 |
203 private: | 205 private: |
204 friend class PluginList; | 206 friend class PluginList; |
205 friend class MockPluginList; | 207 friend class MockPluginList; |
206 friend class PluginGroupTest; | 208 friend class PluginGroupTest; |
207 friend class ::PluginExceptionsTableModelTest; | 209 friend class ::PluginExceptionsTableModelTest; |
208 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); | 210 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); |
209 | 211 |
210 // Generates the (short) identifier string for the given plugin. | 212 // Generates the (short) identifier string for the given plugin. |
211 static std::string GetIdentifier(const WebPluginInfo& wpi); | 213 static std::string GetIdentifier(const webkit::WebPluginInfo& wpi); |
212 | 214 |
213 // Generates the long identifier (based on the full file path) for the given | 215 // Generates the long identifier (based on the full file path) for the given |
214 // plugin, to be called when the short identifier is not unique. | 216 // plugin, to be called when the short identifier is not unique. |
215 static std::string GetLongIdentifier(const WebPluginInfo& wpi); | 217 static std::string GetLongIdentifier(const webkit::WebPluginInfo& wpi); |
216 | 218 |
217 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes | 219 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes |
218 // ownership of the created PluginGroup. | 220 // ownership of the created PluginGroup. |
219 static PluginGroup* FromPluginGroupDefinition( | 221 static PluginGroup* FromPluginGroupDefinition( |
220 const PluginGroupDefinition& definition); | 222 const PluginGroupDefinition& definition); |
221 | 223 |
222 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of | 224 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of |
223 // the created PluginGroup. | 225 // the created PluginGroup. |
224 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi); | 226 static PluginGroup* FromWebPluginInfo(const webkit::WebPluginInfo& wpi); |
225 | 227 |
226 // Returns |true| if |version| is contained in [low, high) of |range|. | 228 // Returns |true| if |version| is contained in [low, high) of |range|. |
227 static bool IsVersionInRange(const Version& version, | 229 static bool IsVersionInRange(const Version& version, |
228 const VersionRange& range); | 230 const VersionRange& range); |
229 | 231 |
230 // Returns |true| iff |plugin_version| is both contained in |version_range| | 232 // Returns |true| iff |plugin_version| is both contained in |version_range| |
231 // and declared outdated (== vulnerable) by it. | 233 // and declared outdated (== vulnerable) by it. |
232 static bool IsPluginOutdated(const Version& plugin_version, | 234 static bool IsPluginOutdated(const Version& plugin_version, |
233 const VersionRange& version_range); | 235 const VersionRange& version_range); |
234 | 236 |
235 PluginGroup(const string16& group_name, | 237 PluginGroup(const string16& group_name, |
236 const string16& name_matcher, | 238 const string16& name_matcher, |
237 const std::string& update_url, | 239 const std::string& update_url, |
238 const std::string& identifier); | 240 const std::string& identifier); |
239 | 241 |
240 void InitFrom(const PluginGroup& other); | 242 void InitFrom(const PluginGroup& other); |
241 | 243 |
242 // Set the description and version for this plugin group from the | 244 // Set the description and version for this plugin group from the |
243 // given plug-in. | 245 // given plug-in. |
244 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin); | 246 void UpdateDescriptionAndVersion(const webkit::WebPluginInfo& plugin); |
245 | 247 |
246 // Updates the active plugin in the group. The active plugin is the first | 248 // Updates the active plugin in the group. The active plugin is the first |
247 // enabled one, or if all plugins are disabled, simply the first one. | 249 // enabled one, or if all plugins are disabled, simply the first one. |
248 void UpdateActivePlugin(const WebPluginInfo& plugin); | 250 void UpdateActivePlugin(const webkit::WebPluginInfo& plugin); |
249 | 251 |
250 // Resets the group state to its default value (as if the group was empty). | 252 // Resets the group state to its default value (as if the group was empty). |
251 // After calling this method, calling |UpdateActivePlugin| with all plugins | 253 // After calling this method, calling |UpdateActivePlugin| with all plugins |
252 // in a row will correctly set the group state. | 254 // in a row will correctly set the group state. |
253 void ResetGroupState(); | 255 void ResetGroupState(); |
254 | 256 |
255 // Enables the plugin if not already enabled and if policy allows it to. | 257 // Enables the plugin if not already enabled and if policy allows it to. |
256 // Returns true on success. Does not update the group state. | 258 // Returns true on success. Does not update the group state. |
257 static bool Enable(WebPluginInfo* plugin, int reason); | 259 static bool Enable(webkit::WebPluginInfo* plugin, int reason); |
258 | 260 |
259 // Disables the plugin if not already disabled and if policy allows it to. | 261 // Disables the plugin if not already disabled and if policy allows it to. |
260 // Returns true on success. Does not update the group state. | 262 // Returns true on success. Does not update the group state. |
261 static bool Disable(WebPluginInfo* plugin, int reason); | 263 static bool Disable(webkit::WebPluginInfo* plugin, int reason); |
262 | 264 |
263 // Helper function to implement the functions above. | 265 // Helper function to implement the functions above. |
264 static bool SetPluginState(WebPluginInfo* plugin, | 266 static bool SetPluginState(webkit::WebPluginInfo* plugin, |
265 int new_reason, | 267 int new_reason, |
266 bool state_changes); | 268 bool state_changes); |
267 | 269 |
268 // Returns a non-const vector of all plugins in the group. This is only used | 270 // Returns a non-const vector of all plugins in the group. This is only used |
269 // by PluginList. | 271 // by PluginList. |
270 std::vector<WebPluginInfo>& GetPluginsContainer() { | 272 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { |
271 return web_plugin_infos_; | 273 return web_plugin_infos_; |
272 } | 274 } |
273 | 275 |
274 // Checks if |name| matches any of the patterns in |pattern_set|. | 276 // Checks if |name| matches any of the patterns in |pattern_set|. |
275 static bool IsStringMatchedInSet(const string16& name, | 277 static bool IsStringMatchedInSet(const string16& name, |
276 const std::set<string16>* pattern_set); | 278 const std::set<string16>* pattern_set); |
277 | 279 |
278 static std::set<string16>* policy_disabled_plugin_patterns_; | 280 static std::set<string16>* policy_disabled_plugin_patterns_; |
279 static std::set<string16>* policy_disabled_plugin_exception_patterns_; | 281 static std::set<string16>* policy_disabled_plugin_exception_patterns_; |
280 static std::set<string16>* policy_enabled_plugin_patterns_; | 282 static std::set<string16>* policy_enabled_plugin_patterns_; |
281 | 283 |
282 std::string identifier_; | 284 std::string identifier_; |
283 string16 group_name_; | 285 string16 group_name_; |
284 string16 name_matcher_; | 286 string16 name_matcher_; |
285 string16 description_; | 287 string16 description_; |
286 std::string update_url_; | 288 std::string update_url_; |
287 bool enabled_; | 289 bool enabled_; |
288 std::vector<VersionRange> version_ranges_; | 290 std::vector<VersionRange> version_ranges_; |
289 scoped_ptr<Version> version_; | 291 scoped_ptr<Version> version_; |
290 std::vector<WebPluginInfo> web_plugin_infos_; | 292 std::vector<webkit::WebPluginInfo> web_plugin_infos_; |
291 }; | 293 }; |
292 | 294 |
293 } // namespace npapi | 295 } // namespace npapi |
294 } // namespace webkit | 296 } // namespace webkit |
295 | 297 |
296 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 298 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
OLD | NEW |