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