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 <map> | |
8 #include <set> | 9 #include <set> |
9 #include <string> | 10 #include <string> |
11 #include <utility> | |
10 #include <vector> | 12 #include <vector> |
11 | 13 |
12 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
13 #include "base/file_path.h" | 15 #include "base/file_path.h" |
14 #include "base/linked_ptr.h" | 16 #include "base/linked_ptr.h" |
15 #include "base/lock.h" | 17 #include "base/lock.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 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 98 |
97 // Same as above, but specifies a directory in which to search for plugins. | 99 // Same as above, but specifies a directory in which to search for plugins. |
98 void AddExtraPluginDir(const FilePath& plugin_dir); | 100 void AddExtraPluginDir(const FilePath& plugin_dir); |
99 | 101 |
100 // Get the ordered list of directories from which to load plugins | 102 // Get the ordered list of directories from which to load plugins |
101 void GetPluginDirectories(std::vector<FilePath>* plugin_dirs); | 103 void GetPluginDirectories(std::vector<FilePath>* plugin_dirs); |
102 | 104 |
103 // Register an internal plugin with the specified plugin information and | 105 // Register an internal plugin with the specified plugin information and |
104 // function pointers. An internal plugin must be registered before it can | 106 // function pointers. An internal plugin must be registered before it can |
105 // be loaded using PluginList::LoadPlugin(). | 107 // be loaded using PluginList::LoadPlugin(). |
106 void RegisterInternalPlugin(const FilePath& path); | |
jam
2011/01/19 20:22:09
why take this out? it was convenient for internal
pastarmovj
2011/01/19 23:39:17
As already mentioned in my comment to http://coder
| |
107 void RegisterInternalPlugin(const FilePath& filename, | 108 void RegisterInternalPlugin(const FilePath& filename, |
108 const std::string& name, | 109 const std::string& name, |
109 const std::string& description, | 110 const std::string& description, |
110 const std::string& mime_type, | 111 const std::string& mime_type, |
111 const PluginEntryPoints& entry_points); | 112 const PluginEntryPoints& entry_points); |
112 | 113 |
113 // Deprecated version of the above. | 114 // Deprecated version of the above. |
114 // TODO(evan): remove when NaCl is fixed. | 115 // TODO(evan): remove when NaCl is fixed. |
115 void RegisterInternalPlugin(const PluginVersionInfo& info); | 116 void RegisterInternalPlugin(const PluginVersionInfo& info); |
116 | 117 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 // Beware: when calling this from the Browser process, the group that the | 181 // Beware: when calling this from the Browser process, the group that the |
181 // returned pointer points to might disappear suddenly. This happens when | 182 // returned pointer points to might disappear suddenly. This happens when |
182 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a | 183 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a |
183 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, | 184 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, |
184 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's | 185 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's |
185 // responsibility to make sure this doesn't happen. | 186 // responsibility to make sure this doesn't happen. |
186 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info); | 187 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info); |
187 | 188 |
188 // Returns the name of the PluginGroup with the given identifier. | 189 // Returns the name of the PluginGroup with the given identifier. |
189 // If no such group exists, an empty string is returned. | 190 // If no such group exists, an empty string is returned. |
190 string16 GetPluginGroupName(std::string identifier); | 191 string16 GetPluginGroupName(std::string identifier); |
jam
2011/01/19 20:22:09
nit: while you're at it, this should be const std:
pastarmovj
2011/01/19 23:39:17
Done.
| |
191 | 192 |
192 // Returns the identifier string of the PluginGroup corresponding to the given | 193 // Returns the identifier string of the PluginGroup corresponding to the given |
193 // WebPluginInfo. If no such group exists, it is created and added to the | 194 // WebPluginInfo. If no such group exists, it is created and added to the |
194 // cache. | 195 // cache. |
195 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); | 196 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); |
196 | 197 |
197 // Load a specific plugin with full path. | 198 // Load a specific plugin with full path. |
198 void LoadPlugin(const FilePath& filename, | 199 void LoadPlugin(const FilePath& filename, |
199 std::vector<WebPluginInfo>* plugins); | 200 std::vector<WebPluginInfo>* plugins); |
200 | 201 |
201 // Enable a specific plugin, specified by path. Returns |true| iff a plugin | 202 // Enable a specific plugin, specified by path. Returns |true| iff a plugin |
202 // currently in the plugin list was actually enabled as a result; regardless | 203 // currently in the plugin list was actually enabled as a result; regardless |
203 // of return value, if a plugin is found in the future with the given name, it | 204 // of return value, if a plugin is found in the future with the given name, it |
204 // will be enabled. Note that plugins are enabled by default as far as | 205 // will be enabled. |
205 // |PluginList| is concerned. | |
206 bool EnablePlugin(const FilePath& filename); | 206 bool EnablePlugin(const FilePath& filename); |
207 | 207 |
208 // Disable a specific plugin, specified by path. Returns |true| iff a plugin | 208 // Disable a specific plugin, specified by path. Returns |true| iff a plugin |
209 // currently in the plugin list was actually disabled as a result; regardless | 209 // currently in the plugin list was actually disabled as a result; regardless |
210 // of return value, if a plugin is found in the future with the given name, it | 210 // of return value, if a plugin is found in the future with the given name, it |
211 // will be disabled. | 211 // will be disabled. |
212 bool DisablePlugin(const FilePath& filename); | 212 bool DisablePlugin(const FilePath& filename); |
213 | 213 |
214 // Enable/disable a plugin group, specified by group_name. Returns |true| iff | 214 // Enable/disable a plugin group, specified by group_name. Returns |true| iff |
215 // a plugin currently in the plugin list was actually enabled/disabled as a | 215 // a plugin currently in the plugin list was actually enabled/disabled as a |
216 // result; regardless of return value, if a plugin is found in the future with | 216 // result; regardless of return value, if a plugin is found in the future with |
217 // the given name, it will be enabled/disabled. Note that plugins are enabled | 217 // the given name, it will be enabled/disabled. |
218 // by default as far as |PluginList| is concerned. | |
219 bool EnableGroup(bool enable, const string16& name); | 218 bool EnableGroup(bool enable, const string16& name); |
220 | 219 |
221 // Disable all plugins groups that are known to be outdated, according to | 220 // Disable all plugins groups that are known to be outdated, according to |
222 // the information hardcoded in PluginGroup, to make sure that they can't | 221 // the information hardcoded in PluginGroup, to make sure that they can't |
223 // be loaded on a web page and instead show a UI to update to the latest | 222 // be loaded on a web page and instead show a UI to update to the latest |
224 // version. | 223 // version. |
225 void DisableOutdatedPluginGroups(); | 224 void DisableOutdatedPluginGroups(); |
226 | 225 |
227 ~PluginList(); | 226 virtual ~PluginList(); |
228 | 227 |
229 private: | 228 protected: |
230 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | |
231 | |
232 // Constructors are private for singletons | 229 // Constructors are private for singletons |
233 PluginList(); | 230 PluginList(); |
234 | 231 |
235 // Creates PluginGroups for the static group definitions, and adds them to | 232 // Load all plugins from the default plugins directory |
236 // the PluginGroup cache of this PluginList. | 233 virtual void LoadPlugins(bool refresh); |
237 void AddHardcodedPluginGroups(); | 234 |
235 // Allows tests to perform custom post-initialization tasks on newly created | |
236 // PluginGroups. | |
237 virtual void ProcessGroupAfterInitialize(PluginGroup* group) { } | |
238 | 238 |
239 // Adds the given WebPluginInfo to its corresponding group, creating it if | 239 // Adds the given WebPluginInfo to its corresponding group, creating it if |
240 // necessary, and returns the group. | 240 // necessary, and returns the group. |
241 // Callers need to protect calls to this method by a lock themselves. | 241 // Callers need to protect calls to this method by a lock themselves. |
242 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info); | 242 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info); |
243 | 243 |
244 // Load all plugins from the default plugins directory | 244 bool plugins_loaded_; |
245 void LoadPlugins(bool refresh); | 245 |
246 // Holds the currently available plugin groups. | |
247 PluginGroup::PluginMap plugin_groups_; | |
jam
2011/01/19 20:22:09
does this really need to be a map? we used to use
pastarmovj
2011/01/19 23:39:17
Copied from plugin_group.cc question about the typ
jam
2011/01/20 00:24:25
Sorry I don't follow here. if AddToPluginGroups f
| |
248 | |
249 private: | |
250 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | |
251 | |
252 // Creates PluginGroups for the static group definitions, and adds them to | |
253 // the PluginGroup cache of this PluginList. | |
254 void AddHardcodedPluginGroups(); | |
246 | 255 |
247 // Load all plugins from a specific directory. | 256 // Load all plugins from a specific directory. |
248 // |plugins| is updated with loaded plugin information. | 257 // |plugins| is updated with loaded plugin information. |
249 // |visited_plugins| is updated with paths to all plugins that were considered | 258 // |visited_plugins| is updated with paths to all plugins that were considered |
250 // (including those we didn't load) | 259 // (including those we didn't load) |
251 void LoadPluginsFromDir(const FilePath& path, | 260 void LoadPluginsFromDir(const FilePath& path, |
252 std::vector<WebPluginInfo>* plugins, | 261 std::vector<WebPluginInfo>* plugins, |
253 std::set<FilePath>* visited_plugins); | 262 std::set<FilePath>* visited_plugins); |
254 | 263 |
255 // Returns true if we should load the given plugin, or false otherwise. | 264 // Returns true if we should load the given plugin, or false otherwise. |
256 // plugins is the list of plugins we have crawled in the current plugin | 265 // plugins is the list of plugins we have crawled in the current plugin |
257 // loading run. | 266 // loading run. |
258 bool ShouldLoadPlugin(const WebPluginInfo& info, | 267 bool ShouldLoadPlugin(const WebPluginInfo& info, |
259 std::vector<WebPluginInfo>* plugins); | 268 std::vector<WebPluginInfo>* plugins); |
260 | 269 |
261 // Return whether a plug-in group with the given name should be disabled, | 270 // Return whether a plug-in group with the given name should be disabled, |
262 // either because it already is on the list of disabled groups, or because it | 271 // either because it already is on the list of disabled groups, or because it |
263 // is blacklisted by a policy. In the latter case, add the plugin group to the | 272 // is blacklisted by a policy. In the latter case, add the plugin group to the |
264 // list of disabled groups as well. | 273 // list of disabled groups as well. |
265 bool ShouldDisableGroup(const string16& group_name); | 274 bool ShouldDisableGroup(const string16& group_name); |
266 | 275 |
267 // Returns true if the given WebPluginInfo supports "mime-type". | 276 // Returns true if the plugin supports |mime_type|. |mime_type| should be all |
268 // mime_type should be all lower case. | 277 // lower case. |
269 static bool SupportsType(const WebPluginInfo& info, | 278 bool SupportsType(const WebPluginInfo& plugin, |
270 const std::string &mime_type, | 279 const std::string& mime_type, |
271 bool allow_wildcard); | 280 bool allow_wildcard); |
272 | 281 |
273 // Returns true if the given WebPluginInfo supports a given file extension. | 282 // Returns true if the given plugin supports a given file extension. |
274 // extension should be all lower case. | 283 // |extension| should be all lower case. If |mime_type| is not NULL, it will |
275 // If mime_type is not NULL, it will be set to the mime type if found. | 284 // be set to the MIME type if found. The MIME type which corresponds to the |
276 // The mime type which corresponds to the extension is optionally returned | 285 // extension is optionally returned back. |
277 // back. | 286 bool SupportsExtension(const WebPluginInfo& plugin, |
278 static bool SupportsExtension(const WebPluginInfo& info, | 287 const std::string& extension, |
279 const std::string &extension, | 288 std::string* actual_mime_type); |
280 std::string* actual_mime_type); | |
281 | |
282 // | 289 // |
283 // Platform functions | 290 // Platform functions |
284 // | 291 // |
285 | 292 |
286 // Do any initialization. | 293 // Do any initialization. |
287 void PlatformInit(); | 294 void PlatformInit(); |
288 | 295 |
289 // | 296 // |
290 // Command-line switches | 297 // Command-line switches |
291 // | 298 // |
292 | 299 |
293 #if defined(OS_WIN) | 300 #if defined(OS_WIN) |
294 // true if we shouldn't load the new WMP plugin. | 301 // true if we shouldn't load the new WMP plugin. |
295 bool dont_load_new_wmp_; | 302 bool dont_load_new_wmp_; |
296 | 303 |
297 // Loads plugins registered under HKCU\Software\MozillaPlugins and | 304 // Loads plugins registered under HKCU\Software\MozillaPlugins and |
298 // HKLM\Software\MozillaPlugins. | 305 // HKLM\Software\MozillaPlugins. |
299 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins, | 306 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins, |
300 std::set<FilePath>* visited_plugins); | 307 std::set<FilePath>* visited_plugins); |
301 #endif | 308 #endif |
302 | 309 |
303 // | 310 // |
304 // Internals | 311 // Internals |
305 // | 312 // |
306 | 313 |
307 bool plugins_loaded_; | |
308 | |
309 // If true, we reload plugins even if they've been loaded already. | 314 // If true, we reload plugins even if they've been loaded already. |
310 bool plugins_need_refresh_; | 315 bool plugins_need_refresh_; |
311 | 316 |
312 // Contains information about the available plugins. | |
313 std::vector<WebPluginInfo> plugins_; | |
314 | |
315 // Extra plugin paths that we want to search when loading. | 317 // Extra plugin paths that we want to search when loading. |
316 std::vector<FilePath> extra_plugin_paths_; | 318 std::vector<FilePath> extra_plugin_paths_; |
317 | 319 |
318 // Extra plugin directories that we want to search when loading. | 320 // Extra plugin directories that we want to search when loading. |
319 std::vector<FilePath> extra_plugin_dirs_; | 321 std::vector<FilePath> extra_plugin_dirs_; |
320 | 322 |
321 // Holds information about internal plugins. | 323 // Holds information about internal plugins. |
322 std::vector<PluginVersionInfo> internal_plugins_; | 324 std::vector<PluginVersionInfo> internal_plugins_; |
323 | 325 |
324 // Path names of plugins to disable (the default is to enable them all). | |
325 std::set<FilePath> disabled_plugins_; | |
326 | |
327 // Group names to disable (the default is to enable them all). | |
328 std::set<string16> disabled_groups_; | |
329 | |
330 bool disable_outdated_plugins_; | 326 bool disable_outdated_plugins_; |
331 | 327 |
332 // Holds the currently available plugin groups. | 328 std::vector<FilePath> prematurely_disabled_plugins_; |
jam
2011/01/19 20:22:09
comment please
pastarmovj
2011/01/19 23:39:17
Done.
| |
333 PluginGroup::PluginMap plugin_groups_; | 329 std::vector<string16> prematurely_disabled_groups_; |
334 | 330 |
335 int next_priority_; | 331 int next_priority_; |
336 | 332 |
337 // Need synchronization for the above members since this object can be | 333 // Need synchronization for the above members since this object can be |
338 // accessed on multiple threads. | 334 // accessed on multiple threads. |
339 Lock lock_; | 335 Lock lock_; |
340 | 336 |
341 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 337 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
342 | 338 |
343 DISALLOW_COPY_AND_ASSIGN(PluginList); | 339 DISALLOW_COPY_AND_ASSIGN(PluginList); |
344 }; | 340 }; |
345 | 341 |
346 } // namespace npapi | 342 } // namespace npapi |
347 } // namespace webkit | 343 } // namespace webkit |
348 | 344 |
349 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 345 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
OLD | NEW |