| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // The PluginList is responsible for loading our NPAPI based plugins. It does | 66 // The PluginList is responsible for loading our NPAPI based plugins. It does |
| 65 // so in whatever manner is appropriate for the platform. On Windows, it loads | 67 // so in whatever manner is appropriate for the platform. On Windows, it loads |
| 66 // plugins from a known directory by looking for DLLs which start with "NP", | 68 // plugins from a known directory by looking for DLLs which start with "NP", |
| 67 // and checking to see if they are valid NPAPI libraries. On the Mac, it walks | 69 // and checking to see if they are valid NPAPI libraries. On the Mac, it walks |
| 68 // the machine-wide and user plugin directories and loads anything that has | 70 // the machine-wide and user plugin directories and loads anything that has |
| 69 // the correct types. On Linux, it walks the plugin directories as well | 71 // the correct types. On Linux, it walks the plugin directories as well |
| 70 // (e.g. /usr/lib/browser-plugins/). | 72 // (e.g. /usr/lib/browser-plugins/). |
| 71 // This object is thread safe. | 73 // This object is thread safe. |
| 72 class PluginList { | 74 class PluginList { |
| 73 public: | 75 public: |
| 76 // Enum of possible reasons for plugin or group being disabled. Used in the |
| 77 // |disabled_plugins_| and |disabled_groups_| maps. |
| 78 enum PluginDisabledReason { USER = 0, POLICY, POLICY_AND_USER }; |
| 79 typedef std::map<FilePath, PluginDisabledReason> DisabledPlugins; |
| 80 typedef std::map<string16, PluginDisabledReason> DisabledGroups; |
| 81 |
| 74 // Gets the one instance of the PluginList. | 82 // Gets the one instance of the PluginList. |
| 75 static PluginList* Singleton(); | 83 static PluginList* Singleton(); |
| 76 | 84 |
| 77 // Returns true if we're in debug-plugin-loading mode. This is controlled | 85 // Returns true if we're in debug-plugin-loading mode. This is controlled |
| 78 // by a command line switch. | 86 // by a command line switch. |
| 79 static bool DebugPluginLoading(); | 87 static bool DebugPluginLoading(); |
| 80 | 88 |
| 81 static const PluginGroupDefinition* GetPluginGroupDefinitions(); | 89 static const PluginGroupDefinition* GetPluginGroupDefinitions(); |
| 82 static size_t GetPluginGroupDefinitionsSize(); | 90 static size_t GetPluginGroupDefinitionsSize(); |
| 83 | 91 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // If no such group exists, an empty string is returned. | 184 // If no such group exists, an empty string is returned. |
| 177 string16 GetPluginGroupName(std::string identifier); | 185 string16 GetPluginGroupName(std::string identifier); |
| 178 | 186 |
| 179 // Returns the identifier string of the PluginGroup corresponding to the given | 187 // Returns the identifier string of the PluginGroup corresponding to the given |
| 180 // WebPluginInfo. If no such group exists, it is created and added to the | 188 // WebPluginInfo. If no such group exists, it is created and added to the |
| 181 // cache. | 189 // cache. |
| 182 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); | 190 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); |
| 183 | 191 |
| 184 // Load a specific plugin with full path. | 192 // Load a specific plugin with full path. |
| 185 void LoadPlugin(const FilePath& filename, | 193 void LoadPlugin(const FilePath& filename, |
| 186 std::vector<WebPluginInfo>* plugins); | 194 std::vector<WebPluginInfo*>* plugins); |
| 187 | 195 |
| 188 // Enable a specific plugin, specified by path. Returns |true| iff a plugin | 196 // 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 | 197 // 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 | 198 // 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 | 199 // will be enabled. Note that plugins are enabled by default as far as |
| 192 // |PluginList| is concerned. | 200 // |PluginList| is concerned. |
| 193 bool EnablePlugin(const FilePath& filename); | 201 bool EnablePlugin(const FilePath& filename); |
| 194 | 202 |
| 195 // Disable a specific plugin, specified by path. Returns |true| iff a plugin | 203 // 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 | 204 // 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 | 205 // of return value, if a plugin is found in the future with the given name, it |
| 198 // will be disabled. | 206 // will be disabled. The boolean flag should be set to true if the plugin is |
| 199 bool DisablePlugin(const FilePath& filename); | 207 // disabled by a policy and not a user. |
| 208 bool DisablePlugin(const FilePath& filename, bool policy_disabled); |
| 200 | 209 |
| 201 // Enable/disable a plugin group, specified by group_name. Returns |true| iff | 210 // 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 | 211 // 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 | 212 // 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 | 213 // the given name, it will be enabled/disabled. Note that plugins are enabled |
| 205 // by default as far as |PluginList| is concerned. | 214 // by default as far as |PluginList| is concerned. |
| 206 bool EnableGroup(bool enable, const string16& name); | 215 bool EnableGroup(bool enable, const string16& name); |
| 207 | 216 |
| 208 // Disable all plugins groups that are known to be outdated, according to | 217 // 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 | 218 // 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 | 219 // be loaded on a web page and instead show a UI to update to the latest |
| 211 // version. | 220 // version. |
| 212 void DisableOutdatedPluginGroups(); | 221 void DisableOutdatedPluginGroups(); |
| 213 | 222 |
| 214 ~PluginList(); | 223 const DisabledPlugins& GetDisabledPlugins() const; |
| 224 |
| 225 const DisabledGroups& GetDisabledGroups() const; |
| 226 |
| 227 virtual ~PluginList(); |
| 215 | 228 |
| 216 private: | 229 private: |
| 217 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | 230 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); |
| 218 | 231 |
| 219 // Constructors are private for singletons | 232 // Constructors are private for singletons |
| 220 PluginList(); | 233 PluginList(); |
| 221 | 234 |
| 222 // Creates PluginGroups for the static group definitions, and adds them to | 235 // Creates PluginGroups for the static group definitions, and adds them to |
| 223 // the PluginGroup cache of this PluginList. | 236 // the PluginGroup cache of this PluginList. |
| 224 void AddHardcodedPluginGroups(); | 237 void AddHardcodedPluginGroups(); |
| 225 | 238 |
| 226 // Adds the given WebPluginInfo to its corresponding group, creating it if | 239 // Adds the given WebPluginInfo to its corresponding group, creating it if |
| 227 // necessary, and returns the group. | 240 // necessary, and returns the group. |
| 228 // 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. |
| 229 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info); | 242 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info, |
| 243 std::vector<WebPluginInfo*>* plugins); |
| 230 | 244 |
| 231 // Load all plugins from the default plugins directory | 245 // Load all plugins from the default plugins directory |
| 232 void LoadPlugins(bool refresh); | 246 void LoadPlugins(bool refresh); |
| 233 | 247 |
| 234 // Load all plugins from a specific directory. | 248 // Load all plugins from a specific directory. |
| 235 // |plugins| is updated with loaded plugin information. | 249 // |plugins| is updated with loaded plugin information. |
| 236 // |visited_plugins| is updated with paths to all plugins that were considered | 250 // |visited_plugins| is updated with paths to all plugins that were considered |
| 237 // (including those we didn't load) | 251 // (including those we didn't load) |
| 238 void LoadPluginsFromDir(const FilePath& path, | 252 void LoadPluginsFromDir(const FilePath& path, |
| 239 std::vector<WebPluginInfo>* plugins, | 253 std::vector<WebPluginInfo*>* plugins, |
| 240 std::set<FilePath>* visited_plugins); | 254 std::set<FilePath>* visited_plugins); |
| 241 | 255 |
| 242 // Returns true if we should load the given plugin, or false otherwise. | 256 // 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 | 257 // plugins is the list of plugins we have crawled in the current plugin |
| 244 // loading run. | 258 // loading run. |
| 245 bool ShouldLoadPlugin(const WebPluginInfo& info, | 259 bool ShouldLoadPlugin(const WebPluginInfo& info, |
| 246 std::vector<WebPluginInfo>* plugins); | 260 std::vector<WebPluginInfo*>* plugins); |
| 247 | 261 |
| 248 // Return whether a plug-in group with the given name should be disabled, | 262 // 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 | 263 // 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 | 264 // is blacklisted by a policy. In the latter case, add the plugin group to the |
| 251 // list of disabled groups as well. | 265 // list of disabled groups as well. |
| 252 bool ShouldDisableGroup(const string16& group_name); | 266 bool ShouldDisableGroup(const string16& group_name); |
| 253 | 267 |
| 254 // Returns true if the given WebPluginInfo supports "mime-type". | 268 // Returns true if the given WebPluginInfo supports "mime-type". |
| 255 // mime_type should be all lower case. | 269 // mime_type should be all lower case. |
| 256 static bool SupportsType(const WebPluginInfo& info, | 270 static bool SupportsType(const WebPluginInfo& info, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 279 // | 293 // |
| 280 // Command-line switches | 294 // Command-line switches |
| 281 // | 295 // |
| 282 | 296 |
| 283 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
| 284 // true if we shouldn't load the new WMP plugin. | 298 // true if we shouldn't load the new WMP plugin. |
| 285 bool dont_load_new_wmp_; | 299 bool dont_load_new_wmp_; |
| 286 | 300 |
| 287 // Loads plugins registered under HKCU\Software\MozillaPlugins and | 301 // Loads plugins registered under HKCU\Software\MozillaPlugins and |
| 288 // HKLM\Software\MozillaPlugins. | 302 // HKLM\Software\MozillaPlugins. |
| 289 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins, | 303 void LoadPluginsFromRegistry(std::set<FilePath>* visited_plugins, |
| 290 std::set<FilePath>* visited_plugins); | 304 std::vector<WebPluginInfo*>* plugins); |
| 291 #endif | 305 #endif |
| 292 | 306 |
| 293 // | 307 // |
| 294 // Internals | 308 // Internals |
| 295 // | 309 // |
| 296 | 310 |
| 297 bool plugins_loaded_; | 311 bool plugins_loaded_; |
| 298 | 312 |
| 299 // If true, we reload plugins even if they've been loaded already. | 313 // If true, we reload plugins even if they've been loaded already. |
| 300 bool plugins_need_refresh_; | 314 bool plugins_need_refresh_; |
| 301 | 315 |
| 302 // Contains information about the available plugins. | 316 // Contains information about the available plugins. |
| 303 std::vector<WebPluginInfo> plugins_; | 317 std::vector<WebPluginInfo*> plugins_; |
| 304 | 318 |
| 305 // Extra plugin paths that we want to search when loading. | 319 // Extra plugin paths that we want to search when loading. |
| 306 std::vector<FilePath> extra_plugin_paths_; | 320 std::vector<FilePath> extra_plugin_paths_; |
| 307 | 321 |
| 308 // Extra plugin directories that we want to search when loading. | 322 // Extra plugin directories that we want to search when loading. |
| 309 std::vector<FilePath> extra_plugin_dirs_; | 323 std::vector<FilePath> extra_plugin_dirs_; |
| 310 | 324 |
| 311 // Holds information about internal plugins. | 325 // Holds information about internal plugins. |
| 312 std::vector<PluginVersionInfo> internal_plugins_; | 326 std::vector<PluginVersionInfo> internal_plugins_; |
| 313 | 327 |
| 328 // An element of the disabled list saves the reason for being disabled in the |
| 329 // second element of the pair. |
| 330 typedef std::pair<FilePath, PluginDisabledReason> DisabledPluginsListElement; |
| 314 // Path names of plugins to disable (the default is to enable them all). | 331 // Path names of plugins to disable (the default is to enable them all). |
| 315 std::set<FilePath> disabled_plugins_; | 332 DisabledPlugins disabled_plugins_; |
| 316 | 333 |
| 334 typedef std::pair<string16, PluginDisabledReason> DisabledGroupsListElement; |
| 317 // Group names to disable (the default is to enable them all). | 335 // Group names to disable (the default is to enable them all). |
| 318 std::set<string16> disabled_groups_; | 336 DisabledGroups disabled_groups_; |
| 319 | 337 |
| 320 bool disable_outdated_plugins_; | 338 bool disable_outdated_plugins_; |
| 321 | 339 |
| 322 // Holds the currently available plugin groups. | 340 // Holds the currently available plugin groups. |
| 323 PluginGroup::PluginMap plugin_groups_; | 341 PluginGroup::PluginMap plugin_groups_; |
| 324 | 342 |
| 325 int next_priority_; | 343 int next_priority_; |
| 326 | 344 |
| 327 // Need synchronization for the above members since this object can be | 345 // Need synchronization for the above members since this object can be |
| 328 // accessed on multiple threads. | 346 // accessed on multiple threads. |
| 329 Lock lock_; | 347 mutable Lock lock_; |
| 330 | 348 |
| 331 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 349 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
| 332 | 350 |
| 333 DISALLOW_COPY_AND_ASSIGN(PluginList); | 351 DISALLOW_COPY_AND_ASSIGN(PluginList); |
| 334 }; | 352 }; |
| 335 | 353 |
| 336 } // namespace NPAPI | 354 } // namespace NPAPI |
| 337 | 355 |
| 338 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ | 356 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ |
| OLD | NEW |