Chromium Code Reviews| 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_GLUE_PLUGINS_PLUGIN_LIST_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ | 
| 6 #define WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ | 6 #define WEBKIT_GLUE_PLUGINS_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/glue/plugins/plugin_group.h" | 19 #include "webkit/glue/plugins/plugin_group.h" | 
| 18 #include "webkit/glue/plugins/webplugininfo.h" | 20 #include "webkit/glue/plugins/webplugininfo.h" | 
| 19 | 21 | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 // cache. | 183 // cache. | 
| 182 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); | 184 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); | 
| 183 | 185 | 
| 184 // Load a specific plugin with full path. | 186 // Load a specific plugin with full path. | 
| 185 void LoadPlugin(const FilePath& filename, | 187 void LoadPlugin(const FilePath& filename, | 
| 186 std::vector<WebPluginInfo>* plugins); | 188 std::vector<WebPluginInfo>* plugins); | 
| 187 | 189 | 
| 188 // Enable a specific plugin, specified by path. Returns |true| iff a plugin | 190 // Enable a specific plugin, specified by path. Returns |true| iff a plugin | 
| 189 // currently in the plugin list was actually enabled as a result; regardless | 191 // currently in the plugin list was actually enabled as a result; regardless | 
| 190 // of return value, if a plugin is found in the future with the given name, it | 192 // of return value, if a plugin is found in the future with the given name, it | 
| 191 // will be enabled. Note that plugins are enabled by default as far as | 193 // will be enabled. |name| must be specified if EnablePlugin can be called | 
| 192 // |PluginList| is concerned. | 194 // for a plugin that is not yet loaded. Especially true when setting plugins | 
| 
 
Bernhard Bauer
2010/12/20 22:30:28
"Especially true"? As in, even more true than is u
 
pastarmovj
2010/12/21 16:53:02
It was really really true in this case :) Fixed.
 
 | |
| 193 bool EnablePlugin(const FilePath& filename); | 195 // as enabled by policy. | 
| 196 bool EnablePlugin(const FilePath& filename, const string16& name); | |
| 194 | 197 | 
| 195 // Disable a specific plugin, specified by path. Returns |true| iff a plugin | 198 // Disable a specific plugin, specified by path. Returns |true| iff a plugin | 
| 196 // currently in the plugin list was actually disabled as a result; regardless | 199 // currently in the plugin list was actually disabled as a result; regardless | 
| 197 // of return value, if a plugin is found in the future with the given name, it | 200 // of return value, if a plugin is found in the future with the given name, it | 
| 198 // will be disabled. | 201 // will be disabled. |name| must be specified if EnablePlugin can be called | 
| 199 bool DisablePlugin(const FilePath& filename); | 202 // for a plugin that is not yet loaded. Especially true when setting plugins | 
| 203 // as enabled b policy. | |
| 204 bool DisablePlugin(const FilePath& filename, const string16& name); | |
| 200 | 205 | 
| 201 // Enable/disable a plugin group, specified by group_name. Returns |true| iff | 206 // Enable/disable a plugin group, specified by group_name. Returns |true| iff | 
| 202 // a plugin currently in the plugin list was actually enabled/disabled as a | 207 // a plugin currently in the plugin list was actually enabled/disabled as a | 
| 203 // result; regardless of return value, if a plugin is found in the future with | 208 // result; regardless of return value, if a plugin is found in the future with | 
| 204 // the given name, it will be enabled/disabled. Note that plugins are enabled | 209 // the given name, it will be enabled/disabled. | 
| 205 // by default as far as |PluginList| is concerned. | |
| 206 bool EnableGroup(bool enable, const string16& name); | 210 bool EnableGroup(bool enable, const string16& name); | 
| 207 | 211 | 
| 208 // Disable all plugins groups that are known to be outdated, according to | 212 // Disable all plugins groups that are known to be outdated, according to | 
| 209 // the information hardcoded in PluginGroup, to make sure that they can't | 213 // the information hardcoded in PluginGroup, to make sure that they can't | 
| 210 // be loaded on a web page and instead show a UI to update to the latest | 214 // be loaded on a web page and instead show a UI to update to the latest | 
| 211 // version. | 215 // version. | 
| 212 void DisableOutdatedPluginGroups(); | 216 void DisableOutdatedPluginGroups(); | 
| 213 | 217 | 
| 214 ~PluginList(); | 218 virtual ~PluginList(); | 
| 215 | 219 | 
| 216 private: | 220 protected: | 
| 217 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | |
| 218 | |
| 219 // Constructors are private for singletons | 221 // Constructors are private for singletons | 
| 220 PluginList(); | 222 PluginList(); | 
| 221 | 223 | 
| 222 // Creates PluginGroups for the static group definitions, and adds them to | 224 // Load all plugins from the default plugins directory | 
| 223 // the PluginGroup cache of this PluginList. | 225 virtual void LoadPlugins(bool refresh); | 
| 224 void AddHardcodedPluginGroups(); | 226 | 
| 227 // Allows tests to perform custom post-initialization tasks on newly created | |
| 228 // PluginGroups. | |
| 229 virtual void ProcessGroupAfterInitialize(PluginGroup* group) { } | |
| 225 | 230 | 
| 226 // Adds the given WebPluginInfo to its corresponding group, creating it if | 231 // Adds the given WebPluginInfo to its corresponding group, creating it if | 
| 227 // necessary, and returns the group. | 232 // necessary, and returns the group. | 
| 228 // Callers need to protect calls to this method by a lock themselves. | 233 // Callers need to protect calls to this method by a lock themselves. | 
| 229 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info); | 234 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info); | 
| 230 | 235 | 
| 231 // Load all plugins from the default plugins directory | 236 bool plugins_loaded_; | 
| 232 void LoadPlugins(bool refresh); | 237 | 
| 238 // Holds the currently available plugin groups. | |
| 239 PluginGroup::PluginMap plugin_groups_; | |
| 240 | |
| 241 private: | |
| 242 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | |
| 243 | |
| 244 // Creates PluginGroups for the static group definitions, and adds them to | |
| 245 // the PluginGroup cache of this PluginList. | |
| 246 void AddHardcodedPluginGroups(); | |
| 247 | |
| 248 // Adds the Plugin given by its path and name to its corresponding group, | |
| 249 // creating it if necessary, and returns the group. this function can be | |
| 250 // called for plugins not yet registered in the system. It will create a | |
| 251 // placeholder until the complete information can be added with a call to | |
| 252 // AddToPluginGroup. | |
| 253 // Callers need to protect calls to this method by a lock themselves. | |
| 254 PluginGroup* AddPlaceholderToPluginGroups(const FilePath& filename, | |
| 255 const string16& name); | |
| 
 
Bernhard Bauer
2010/12/20 22:30:28
Nit: align with previous parameter pls.
 
pastarmovj
2010/12/21 16:53:02
Done.
 
 | |
| 233 | 256 | 
| 234 // Load all plugins from a specific directory. | 257 // Load all plugins from a specific directory. | 
| 235 // |plugins| is updated with loaded plugin information. | 258 // |plugins| is updated with loaded plugin information. | 
| 236 // |visited_plugins| is updated with paths to all plugins that were considered | 259 // |visited_plugins| is updated with paths to all plugins that were considered | 
| 237 // (including those we didn't load) | 260 // (including those we didn't load) | 
| 238 void LoadPluginsFromDir(const FilePath& path, | 261 void LoadPluginsFromDir(const FilePath& path, | 
| 239 std::vector<WebPluginInfo>* plugins, | 262 std::vector<WebPluginInfo>* plugins, | 
| 240 std::set<FilePath>* visited_plugins); | 263 std::set<FilePath>* visited_plugins); | 
| 241 | 264 | 
| 242 // Returns true if we should load the given plugin, or false otherwise. | 265 // Returns true if we should load the given plugin, or false otherwise. | 
| 243 // plugins is the list of plugins we have crawled in the current plugin | 266 // plugins is the list of plugins we have crawled in the current plugin | 
| 244 // loading run. | 267 // loading run. | 
| 245 bool ShouldLoadPlugin(const WebPluginInfo& info, | 268 bool ShouldLoadPlugin(const WebPluginInfo& info, | 
| 246 std::vector<WebPluginInfo>* plugins); | 269 std::vector<WebPluginInfo>* plugins); | 
| 247 | 270 | 
| 248 // Return whether a plug-in group with the given name should be disabled, | 271 // Return whether a plug-in group with the given name should be disabled, | 
| 249 // either because it already is on the list of disabled groups, or because it | 272 // either because it already is on the list of disabled groups, or because it | 
| 250 // is blacklisted by a policy. In the latter case, add the plugin group to the | 273 // is blacklisted by a policy. In the latter case, add the plugin group to the | 
| 251 // list of disabled groups as well. | 274 // list of disabled groups as well. | 
| 252 bool ShouldDisableGroup(const string16& group_name); | 275 bool ShouldDisableGroup(const string16& group_name); | 
| 253 | 276 | 
| 254 // Returns true if the given WebPluginInfo supports "mime-type". | |
| 255 // mime_type should be all lower case. | |
| 256 static bool SupportsType(const WebPluginInfo& info, | |
| 257 const std::string &mime_type, | |
| 258 bool allow_wildcard); | |
| 259 | |
| 260 // Returns true if the given WebPluginInfo supports a given file extension. | |
| 261 // extension should be all lower case. | |
| 262 // If mime_type is not NULL, it will be set to the mime type if found. | |
| 263 // The mime type which corresponds to the extension is optionally returned | |
| 264 // back. | |
| 265 static bool SupportsExtension(const WebPluginInfo& info, | |
| 266 const std::string &extension, | |
| 267 std::string* actual_mime_type); | |
| 268 | |
| 269 // | 277 // | 
| 270 // Platform functions | 278 // Platform functions | 
| 271 // | 279 // | 
| 272 | 280 | 
| 273 // Do any initialization. | 281 // Do any initialization. | 
| 274 void PlatformInit(); | 282 void PlatformInit(); | 
| 275 | 283 | 
| 276 // Get the ordered list of directories from which to load plugins | 284 // Get the ordered list of directories from which to load plugins | 
| 277 void GetPluginDirectories(std::vector<FilePath>* plugin_dirs); | 285 void GetPluginDirectories(std::vector<FilePath>* plugin_dirs); | 
| 278 | 286 | 
| 279 // | 287 // | 
| 280 // Command-line switches | 288 // Command-line switches | 
| 281 // | 289 // | 
| 282 | 290 | 
| 283 #if defined(OS_WIN) | 291 #if defined(OS_WIN) | 
| 284 // true if we shouldn't load the new WMP plugin. | 292 // true if we shouldn't load the new WMP plugin. | 
| 285 bool dont_load_new_wmp_; | 293 bool dont_load_new_wmp_; | 
| 286 | 294 | 
| 287 // Loads plugins registered under HKCU\Software\MozillaPlugins and | 295 // Loads plugins registered under HKCU\Software\MozillaPlugins and | 
| 288 // HKLM\Software\MozillaPlugins. | 296 // HKLM\Software\MozillaPlugins. | 
| 289 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins, | 297 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins, | 
| 290 std::set<FilePath>* visited_plugins); | 298 std::set<FilePath>* visited_plugins); | 
| 291 #endif | 299 #endif | 
| 292 | 300 | 
| 293 // | 301 // | 
| 294 // Internals | 302 // Internals | 
| 295 // | 303 // | 
| 296 | 304 | 
| 297 bool plugins_loaded_; | |
| 298 | |
| 299 // 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. | 
| 300 bool plugins_need_refresh_; | 306 bool plugins_need_refresh_; | 
| 301 | 307 | 
| 302 // Contains information about the available plugins. | |
| 303 std::vector<WebPluginInfo> plugins_; | |
| 304 | |
| 305 // Extra plugin paths that we want to search when loading. | 308 // Extra plugin paths that we want to search when loading. | 
| 306 std::vector<FilePath> extra_plugin_paths_; | 309 std::vector<FilePath> extra_plugin_paths_; | 
| 307 | 310 | 
| 308 // Extra plugin directories that we want to search when loading. | 311 // Extra plugin directories that we want to search when loading. | 
| 309 std::vector<FilePath> extra_plugin_dirs_; | 312 std::vector<FilePath> extra_plugin_dirs_; | 
| 310 | 313 | 
| 311 // Holds information about internal plugins. | 314 // Holds information about internal plugins. | 
| 312 std::vector<PluginVersionInfo> internal_plugins_; | 315 std::vector<PluginVersionInfo> internal_plugins_; | 
| 313 | 316 | 
| 314 // Path names of plugins to disable (the default is to enable them all). | |
| 315 std::set<FilePath> disabled_plugins_; | |
| 316 | |
| 317 // Group names to disable (the default is to enable them all). | |
| 318 std::set<string16> disabled_groups_; | |
| 319 | |
| 320 bool disable_outdated_plugins_; | 317 bool disable_outdated_plugins_; | 
| 321 | 318 | 
| 322 // Holds the currently available plugin groups. | |
| 323 PluginGroup::PluginMap plugin_groups_; | |
| 324 | |
| 325 int next_priority_; | 319 int next_priority_; | 
| 326 | 320 | 
| 327 // Need synchronization for the above members since this object can be | 321 // Need synchronization for the above members since this object can be | 
| 328 // accessed on multiple threads. | 322 // accessed on multiple threads. | 
| 329 Lock lock_; | 323 mutable Lock lock_; | 
| 330 | 324 | 
| 331 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 325 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 
| 332 | 326 | 
| 333 DISALLOW_COPY_AND_ASSIGN(PluginList); | 327 DISALLOW_COPY_AND_ASSIGN(PluginList); | 
| 334 }; | 328 }; | 
| 335 | 329 | 
| 336 } // namespace NPAPI | 330 } // namespace NPAPI | 
| 337 | 331 | 
| 338 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ | 332 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ | 
| OLD | NEW |