OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_LIST_H_ | 5 #ifndef WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
| 10 #include <utility> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
14 #include "base/linked_ptr.h" | 15 #include "base/linked_ptr.h" |
15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/scoped_vector.h" |
16 #include "third_party/npapi/bindings/nphostapi.h" | 18 #include "third_party/npapi/bindings/nphostapi.h" |
17 #include "webkit/plugins/npapi/plugin_group.h" | 19 #include "webkit/plugins/npapi/plugin_group.h" |
18 #include "webkit/plugins/npapi/webplugininfo.h" | 20 #include "webkit/plugins/npapi/webplugininfo.h" |
19 | 21 |
20 class GURL; | 22 class GURL; |
21 | 23 |
22 namespace base { | 24 namespace base { |
23 | 25 |
24 template <typename T> | 26 template <typename T> |
25 struct DefaultLazyInstanceTraits; | 27 struct DefaultLazyInstanceTraits; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // In Windows and Pepper plugins, the mime types are passed as a specially | 117 // In Windows and Pepper plugins, the mime types are passed as a specially |
116 // formatted list of strings. This function parses those strings into | 118 // formatted list of strings. This function parses those strings into |
117 // a WebPluginMimeType vector. | 119 // a WebPluginMimeType vector. |
118 // TODO(evan): make Pepper pass around formatted data and move this code | 120 // TODO(evan): make Pepper pass around formatted data and move this code |
119 // into plugin_list_win. | 121 // into plugin_list_win. |
120 static bool ParseMimeTypes(const std::string& mime_types, | 122 static bool ParseMimeTypes(const std::string& mime_types, |
121 const std::string& file_extensions, | 123 const std::string& file_extensions, |
122 const string16& mime_type_descriptions, | 124 const string16& mime_type_descriptions, |
123 std::vector<WebPluginMimeType>* parsed_mime_types); | 125 std::vector<WebPluginMimeType>* parsed_mime_types); |
124 | 126 |
125 // Shutdown all plugins. Should be called at process teardown. | |
126 void Shutdown(); | |
127 | |
128 // Get all the plugins. | 127 // Get all the plugins. |
129 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); | 128 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); |
130 | 129 |
131 // Get all the enabled plugins. | 130 // Get all the enabled plugins. |
132 void GetEnabledPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); | 131 void GetEnabledPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); |
133 | 132 |
134 // Returns a list in |info| containing plugins that are found for | 133 // Returns a list in |info| containing plugins that are found for |
135 // the given url and mime type (including disabled plugins, for | 134 // the given url and mime type (including disabled plugins, for |
136 // which |info->enabled| is false). The mime type which corresponds | 135 // which |info->enabled| is false). The mime type which corresponds |
137 // to the URL is optionally returned back in |actual_mime_types| (if | 136 // to the URL is optionally returned back in |actual_mime_types| (if |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Beware: when calling this from the Browser process, the group that the | 168 // Beware: when calling this from the Browser process, the group that the |
170 // returned pointer points to might disappear suddenly. This happens when | 169 // returned pointer points to might disappear suddenly. This happens when |
171 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a | 170 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a |
172 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, | 171 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, |
173 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's | 172 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's |
174 // responsibility to make sure this doesn't happen. | 173 // responsibility to make sure this doesn't happen. |
175 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info); | 174 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info); |
176 | 175 |
177 // Returns the name of the PluginGroup with the given identifier. | 176 // Returns the name of the PluginGroup with the given identifier. |
178 // If no such group exists, an empty string is returned. | 177 // If no such group exists, an empty string is returned. |
179 string16 GetPluginGroupName(std::string identifier); | 178 string16 GetPluginGroupName(const std::string& identifier); |
180 | 179 |
181 // Returns the identifier string of the PluginGroup corresponding to the given | 180 // Returns the identifier string of the PluginGroup corresponding to the given |
182 // WebPluginInfo. If no such group exists, it is created and added to the | 181 // WebPluginInfo. If no such group exists, it is created and added to the |
183 // cache. | 182 // cache. |
184 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); | 183 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); |
185 | 184 |
186 // Load a specific plugin with full path. | 185 // Load a specific plugin with full path. |
187 void LoadPlugin(const FilePath& filename, | 186 void LoadPlugin(const FilePath& filename, |
188 std::vector<WebPluginInfo>* plugins); | 187 ScopedVector<PluginGroup>* plugin_groups); |
189 | 188 |
190 // Enable a specific plugin, specified by path. Returns |true| iff a plugin | 189 // Enable a specific plugin, specified by path. Returns |true| iff a plugin |
191 // currently in the plugin list was actually enabled as a result; regardless | 190 // currently in the plugin list was actually enabled as a result; regardless |
192 // of return value, if a plugin is found in the future with the given name, it | 191 // of return value, if a plugin is found in the future with the given name, it |
193 // will be enabled. Note that plugins are enabled by default as far as | 192 // will be enabled. |
194 // |PluginList| is concerned. | |
195 bool EnablePlugin(const FilePath& filename); | 193 bool EnablePlugin(const FilePath& filename); |
196 | 194 |
197 // Disable a specific plugin, specified by path. Returns |true| iff a plugin | 195 // Disable a specific plugin, specified by path. Returns |true| iff a plugin |
198 // currently in the plugin list was actually disabled as a result; regardless | 196 // currently in the plugin list was actually disabled as a result; regardless |
199 // of return value, if a plugin is found in the future with the given name, it | 197 // of return value, if a plugin is found in the future with the given name, it |
200 // will be disabled. | 198 // will be disabled. |
201 bool DisablePlugin(const FilePath& filename); | 199 bool DisablePlugin(const FilePath& filename); |
202 | 200 |
203 // Enable/disable a plugin group, specified by group_name. Returns |true| iff | 201 // Enable/disable a plugin group, specified by group_name. Returns |true| iff |
204 // a plugin currently in the plugin list was actually enabled/disabled as a | 202 // a plugin currently in the plugin list was actually enabled/disabled as a |
205 // result; regardless of return value, if a plugin is found in the future with | 203 // result; regardless of return value, if a plugin is found in the future with |
206 // the given name, it will be enabled/disabled. Note that plugins are enabled | 204 // the given name, it will be enabled/disabled. |
207 // by default as far as |PluginList| is concerned. | |
208 bool EnableGroup(bool enable, const string16& name); | 205 bool EnableGroup(bool enable, const string16& name); |
209 | 206 |
210 // Disable all plugins groups that are known to be outdated, according to | 207 // Disable all plugins groups that are known to be outdated, according to |
211 // the information hardcoded in PluginGroup, to make sure that they can't | 208 // the information hardcoded in PluginGroup, to make sure that they can't |
212 // be loaded on a web page and instead show a UI to update to the latest | 209 // be loaded on a web page and instead show a UI to update to the latest |
213 // version. | 210 // version. |
214 void DisableOutdatedPluginGroups(); | 211 void DisableOutdatedPluginGroups(); |
215 | 212 |
216 ~PluginList(); | 213 virtual ~PluginList(); |
| 214 |
| 215 protected: |
| 216 // Constructors are private for singletons |
| 217 PluginList(); |
| 218 |
| 219 // Adds the given WebPluginInfo to its corresponding group, creating it if |
| 220 // necessary, and returns the group. |
| 221 // Callers need to protect calls to this method by a lock themselves. |
| 222 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info, |
| 223 ScopedVector<PluginGroup>* plugin_groups); |
| 224 |
| 225 // Holds the currently available plugin groups. |
| 226 ScopedVector<PluginGroup> plugin_groups_; |
217 | 227 |
218 private: | 228 private: |
| 229 friend class PluginListTest; |
219 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | 230 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); |
220 | 231 |
221 // Constructors are private for singletons | |
222 PluginList(); | |
223 | |
224 // Creates PluginGroups for the static group definitions, and adds them to | 232 // Creates PluginGroups for the static group definitions, and adds them to |
225 // the PluginGroup cache of this PluginList. | 233 // the PluginGroup cache of this PluginList. |
226 void AddHardcodedPluginGroups(); | 234 void AddHardcodedPluginGroups(); |
227 | 235 |
228 // Adds the given WebPluginInfo to its corresponding group, creating it if | 236 // Implements all IO dependant operations of the LoadPlugins method so that |
229 // necessary, and returns the group. | 237 // test classes can mock these out. Return value false means LoadPlugins |
230 // Callers need to protect calls to this method by a lock themselves. | 238 // should not go on with the loading. |
231 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info); | 239 virtual void LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups); |
232 | 240 |
233 // Load all plugins from the default plugins directory | 241 // Load all plugins from the default plugins directory |
234 void LoadPlugins(bool refresh); | 242 void LoadPlugins(bool refresh); |
235 | 243 |
236 // Load all plugins from a specific directory. | 244 // Load all plugins from a specific directory. |
237 // |plugins| is updated with loaded plugin information. | 245 // |plugins| is updated with loaded plugin information. |
238 // |visited_plugins| is updated with paths to all plugins that were considered | 246 // |visited_plugins| is updated with paths to all plugins that were considered |
239 // (including those we didn't load) | 247 // (including those we didn't load) |
240 void LoadPluginsFromDir(const FilePath& path, | 248 void LoadPluginsFromDir(const FilePath& path, |
241 std::vector<WebPluginInfo>* plugins, | 249 ScopedVector<PluginGroup>* plugin_groups, |
242 std::set<FilePath>* visited_plugins); | 250 std::set<FilePath>* visited_plugins); |
243 | 251 |
244 // Returns true if we should load the given plugin, or false otherwise. | 252 // Returns true if we should load the given plugin, or false otherwise. |
245 // plugins is the list of plugins we have crawled in the current plugin | 253 // plugins is the list of plugins we have crawled in the current plugin |
246 // loading run. | 254 // loading run. |
247 bool ShouldLoadPlugin(const WebPluginInfo& info, | 255 bool ShouldLoadPlugin(const WebPluginInfo& info, |
248 std::vector<WebPluginInfo>* plugins); | 256 ScopedVector<PluginGroup>* plugins); |
249 | 257 |
250 // Return whether a plug-in group with the given name should be disabled, | 258 // Return whether a plug-in group with the given name should be disabled, |
251 // either because it already is on the list of disabled groups, or because it | 259 // either because it already is on the list of disabled groups, or because it |
252 // is blacklisted by a policy. In the latter case, add the plugin group to the | 260 // is blacklisted by a policy. In the latter case, add the plugin group to the |
253 // list of disabled groups as well. | 261 // list of disabled groups as well. |
254 bool ShouldDisableGroup(const string16& group_name); | 262 bool ShouldDisableGroup(const string16& group_name); |
255 | 263 |
256 // Returns true if the given WebPluginInfo supports "mime-type". | 264 // Returns true if the plugin supports |mime_type|. |mime_type| should be all |
257 // mime_type should be all lower case. | 265 // lower case. |
258 static bool SupportsType(const WebPluginInfo& info, | 266 bool SupportsType(const WebPluginInfo& plugin, |
259 const std::string &mime_type, | 267 const std::string& mime_type, |
260 bool allow_wildcard); | 268 bool allow_wildcard); |
261 | 269 |
262 // Returns true if the given WebPluginInfo supports a given file extension. | 270 // Returns true if the given plugin supports a given file extension. |
263 // extension should be all lower case. | 271 // |extension| should be all lower case. If |mime_type| is not NULL, it will |
264 // If mime_type is not NULL, it will be set to the mime type if found. | 272 // be set to the MIME type if found. The MIME type which corresponds to the |
265 // The mime type which corresponds to the extension is optionally returned | 273 // extension is optionally returned back. |
266 // back. | 274 bool SupportsExtension(const WebPluginInfo& plugin, |
267 static bool SupportsExtension(const WebPluginInfo& info, | 275 const std::string& extension, |
268 const std::string &extension, | 276 std::string* actual_mime_type); |
269 std::string* actual_mime_type); | |
270 | 277 |
271 // | 278 // |
272 // Platform functions | 279 // Platform functions |
273 // | 280 // |
274 | 281 |
275 // Do any initialization. | 282 // Do any initialization. |
276 void PlatformInit(); | 283 void PlatformInit(); |
277 | 284 |
278 // | 285 // |
279 // Command-line switches | 286 // Command-line switches |
280 // | 287 // |
281 | 288 |
282 #if defined(OS_WIN) | 289 #if defined(OS_WIN) |
283 // true if we shouldn't load the new WMP plugin. | 290 // true if we shouldn't load the new WMP plugin. |
284 bool dont_load_new_wmp_; | 291 bool dont_load_new_wmp_; |
285 | 292 |
286 // Loads plugins registered under HKCU\Software\MozillaPlugins and | 293 // Loads plugins registered under HKCU\Software\MozillaPlugins and |
287 // HKLM\Software\MozillaPlugins. | 294 // HKLM\Software\MozillaPlugins. |
288 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins, | 295 void LoadPluginsFromRegistry(ScopedVector<PluginGroup>* plugins, |
289 std::set<FilePath>* visited_plugins); | 296 std::set<FilePath>* visited_plugins); |
290 #endif | 297 #endif |
291 | 298 |
292 // | 299 // |
293 // Internals | 300 // Internals |
294 // | 301 // |
295 | 302 // Set to true when the LoadPlugins method has finished. |
296 bool plugins_loaded_; | 303 bool plugins_loaded_; |
297 | 304 |
298 // If true, we reload plugins even if they've been loaded already. | 305 // If true, we reload plugins even if they've been loaded already. |
299 bool plugins_need_refresh_; | 306 bool plugins_need_refresh_; |
300 | 307 |
301 // Contains information about the available plugins. | |
302 std::vector<WebPluginInfo> plugins_; | |
303 | |
304 // Extra plugin paths that we want to search when loading. | 308 // Extra plugin paths that we want to search when loading. |
305 std::vector<FilePath> extra_plugin_paths_; | 309 std::vector<FilePath> extra_plugin_paths_; |
306 | 310 |
307 // Extra plugin directories that we want to search when loading. | 311 // Extra plugin directories that we want to search when loading. |
308 std::vector<FilePath> extra_plugin_dirs_; | 312 std::vector<FilePath> extra_plugin_dirs_; |
309 | 313 |
310 struct InternalPlugin { | 314 struct InternalPlugin { |
311 WebPluginInfo info; | 315 WebPluginInfo info; |
312 PluginEntryPoints entry_points; | 316 PluginEntryPoints entry_points; |
313 }; | 317 }; |
314 // Holds information about internal plugins. | 318 // Holds information about internal plugins. |
315 std::vector<InternalPlugin> internal_plugins_; | 319 std::vector<InternalPlugin> internal_plugins_; |
316 | 320 |
317 // Path names of plugins to disable (the default is to enable them all). | 321 // If set to true outdated plugins are disabled in the end of LoadPlugins. |
318 std::set<FilePath> disabled_plugins_; | |
319 | |
320 // Group names to disable (the default is to enable them all). | |
321 std::set<string16> disabled_groups_; | |
322 | |
323 bool disable_outdated_plugins_; | 322 bool disable_outdated_plugins_; |
324 | 323 |
325 // Holds the currently available plugin groups. | 324 // The set of plugins that have been scheduled for disabling once they get |
326 PluginGroup::PluginMap plugin_groups_; | 325 // loaded. This list is used in LoadPlugins and pruned after it. Contains |
327 | 326 // plugins that were either disabled by the user (prefs are loaded before |
328 int next_priority_; | 327 // plugins) or disabled by a policy. |
| 328 std::set<FilePath> plugins_to_disable_; |
| 329 // Equivalent to the |plugins_to_disable_| this is the set of groups |
| 330 // scheduled for disabling once they appear. This list is never completely |
| 331 // pruned but all groups that do get created are removed from it. New groups |
| 332 // might get added if they should be pruned because of plugins getting removed |
| 333 // for example. |
| 334 std::set<string16> groups_to_disable_; |
329 | 335 |
330 // Need synchronization for the above members since this object can be | 336 // Need synchronization for the above members since this object can be |
331 // accessed on multiple threads. | 337 // accessed on multiple threads. |
332 base::Lock lock_; | 338 base::Lock lock_; |
333 | 339 |
334 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 340 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
335 | 341 |
336 DISALLOW_COPY_AND_ASSIGN(PluginList); | 342 DISALLOW_COPY_AND_ASSIGN(PluginList); |
337 }; | 343 }; |
338 | 344 |
339 } // namespace npapi | 345 } // namespace npapi |
340 } // namespace webkit | 346 } // namespace webkit |
341 | 347 |
342 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 348 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
OLD | NEW |