| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_PLUGIN_PLUGIN_LIST_H__ | 5 #ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H__ |
| 6 #define WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H__ | 6 #define WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H__ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/lock.h" |
| 14 #include "webkit/glue/webplugininfo.h" | 15 #include "webkit/glue/webplugininfo.h" |
| 15 #include "webkit/glue/plugins/nphostapi.h" | 16 #include "webkit/glue/plugins/nphostapi.h" |
| 16 | 17 |
| 17 class GURL; | 18 class GURL; |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 | 21 |
| 21 template <typename T> | 22 template <typename T> |
| 22 struct DefaultLazyInstanceTraits; | 23 struct DefaultLazyInstanceTraits; |
| 23 | 24 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 PluginEntryPoints entry_points; | 60 PluginEntryPoints entry_points; |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 // The PluginList is responsible for loading our NPAPI based plugins. It does | 63 // The PluginList is responsible for loading our NPAPI based plugins. It does |
| 63 // so in whatever manner is appropriate for the platform. On Windows, it loads | 64 // so in whatever manner is appropriate for the platform. On Windows, it loads |
| 64 // plugins from a known directory by looking for DLLs which start with "NP", | 65 // plugins from a known directory by looking for DLLs which start with "NP", |
| 65 // and checking to see if they are valid NPAPI libraries. On the Mac, it walks | 66 // and checking to see if they are valid NPAPI libraries. On the Mac, it walks |
| 66 // the machine-wide and user plugin directories and loads anything that has | 67 // the machine-wide and user plugin directories and loads anything that has |
| 67 // the correct types. On Linux, it walks the plugin directories as well | 68 // the correct types. On Linux, it walks the plugin directories as well |
| 68 // (e.g. /usr/lib/browser-plugins/). | 69 // (e.g. /usr/lib/browser-plugins/). |
| 70 // This object is thread safe. |
| 69 class PluginList { | 71 class PluginList { |
| 70 public: | 72 public: |
| 71 // Gets the one instance of the PluginList. Accessing the singleton causes | 73 // Gets the one instance of the PluginList. |
| 72 // the PluginList to look on disk for existing plugins. It does not actually | |
| 73 // load libraries, that will only happen when you initialize the plugin for | |
| 74 // the first time. | |
| 75 static PluginList* Singleton(); | 74 static PluginList* Singleton(); |
| 76 | 75 |
| 76 // Returns true iff the plugin list has been loaded already. |
| 77 bool PluginsLoaded(); |
| 78 |
| 77 // Clear the plugins_loaded_ bit to force a refresh next time we retrieve | 79 // Clear the plugins_loaded_ bit to force a refresh next time we retrieve |
| 78 // plugins. | 80 // plugins. |
| 79 static void ResetPluginsLoaded(); | 81 void ResetPluginsLoaded(); |
| 80 | 82 |
| 81 // Add an extra plugin to load when we actually do the loading. This is | 83 // Add an extra plugin to load when we actually do the loading. Must be |
| 82 // static because we want to be able to add to it without searching the disk | 84 // called before the plugins have been loaded. |
| 83 // for plugins. Must be called before the plugins have been loaded. | 85 void AddExtraPluginPath(const FilePath& plugin_path); |
| 84 static void AddExtraPluginPath(const FilePath& plugin_path); | |
| 85 | 86 |
| 86 // Same as above, but specifies a directory in which to search for plugins. | 87 // Same as above, but specifies a directory in which to search for plugins. |
| 87 static void AddExtraPluginDir(const FilePath& plugin_dir); | 88 void AddExtraPluginDir(const FilePath& plugin_dir); |
| 88 | 89 |
| 89 // Register an internal plugin with the specified plugin information and | 90 // Register an internal plugin with the specified plugin information and |
| 90 // function pointers. An internal plugin must be registered before it can | 91 // function pointers. An internal plugin must be registered before it can |
| 91 // be loaded using PluginList::LoadPlugin(). | 92 // be loaded using PluginList::LoadPlugin(). |
| 92 static void RegisterInternalPlugin(const PluginVersionInfo& info); | 93 void RegisterInternalPlugin(const PluginVersionInfo& info); |
| 93 | 94 |
| 94 // Creates a WebPluginInfo structure given a plugin's path. On success | 95 // Creates a WebPluginInfo structure given a plugin's path. On success |
| 95 // returns true, with the information being put into "info". If it's an | 96 // returns true, with the information being put into "info". If it's an |
| 96 // internal plugin, "entry_points" is filled in as well with a | 97 // internal plugin, "entry_points" is filled in as well with a |
| 97 // internally-owned PluginEntryPoints pointer. | 98 // internally-owned PluginEntryPoints pointer. |
| 98 // Returns false if the library couldn't be found, or if it's not a plugin. | 99 // Returns false if the library couldn't be found, or if it's not a plugin. |
| 99 static bool ReadPluginInfo(const FilePath& filename, | 100 bool ReadPluginInfo(const FilePath& filename, |
| 100 WebPluginInfo* info, | 101 WebPluginInfo* info, |
| 101 const PluginEntryPoints** entry_points); | 102 const PluginEntryPoints** entry_points); |
| 102 | 103 |
| 103 // Populate a WebPluginInfo from a PluginVersionInfo. | 104 // Populate a WebPluginInfo from a PluginVersionInfo. |
| 104 static bool CreateWebPluginInfo(const PluginVersionInfo& pvi, | 105 static bool CreateWebPluginInfo(const PluginVersionInfo& pvi, |
| 105 WebPluginInfo* info); | 106 WebPluginInfo* info); |
| 106 | 107 |
| 107 // Shutdown all plugins. Should be called at process teardown. | 108 // Shutdown all plugins. Should be called at process teardown. |
| 108 void Shutdown(); | 109 void Shutdown(); |
| 109 | 110 |
| 110 // Get all the plugins | 111 // Get all the plugins |
| 111 bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); | 112 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); |
| 112 | 113 |
| 113 // Returns true if a plugin is found for the given url and mime type. | 114 // Returns true if a plugin is found for the given url and mime type. |
| 114 // The mime type which corresponds to the URL is optionally returned | 115 // The mime type which corresponds to the URL is optionally returned |
| 115 // back. | 116 // back. |
| 116 // The allow_wildcard parameter controls whether this function returns | 117 // The allow_wildcard parameter controls whether this function returns |
| 117 // plugins which support wildcard mime types (* as the mime type). | 118 // plugins which support wildcard mime types (* as the mime type). |
| 118 bool GetPluginInfo(const GURL& url, | 119 bool GetPluginInfo(const GURL& url, |
| 119 const std::string& mime_type, | 120 const std::string& mime_type, |
| 120 const std::string& clsid, | 121 const std::string& clsid, |
| 121 bool allow_wildcard, | 122 bool allow_wildcard, |
| 122 WebPluginInfo* info, | 123 WebPluginInfo* info, |
| 123 std::string* actual_mime_type); | 124 std::string* actual_mime_type); |
| 124 | 125 |
| 125 // Get plugin info by plugin path. Returns true if the plugin is found and | 126 // Get plugin info by plugin path. Returns true if the plugin is found and |
| 126 // WebPluginInfo has been filled in |info|. | 127 // WebPluginInfo has been filled in |info|. |
| 127 bool GetPluginInfoByPath(const FilePath& plugin_path, | 128 bool GetPluginInfoByPath(const FilePath& plugin_path, |
| 128 WebPluginInfo* info); | 129 WebPluginInfo* info); |
| 129 | 130 |
| 130 // Load a specific plugin with full path. | 131 // Load a specific plugin with full path. |
| 131 void LoadPlugin(const FilePath& filename); | 132 void LoadPlugin(const FilePath& filename, |
| 133 std::vector<WebPluginInfo>* plugins); |
| 132 | 134 |
| 133 private: | 135 private: |
| 134 // Constructors are private for singletons | 136 // Constructors are private for singletons |
| 135 PluginList(); | 137 PluginList(); |
| 136 | 138 |
| 137 // Load all plugins from the default plugins directory | 139 // Load all plugins from the default plugins directory |
| 138 void LoadPlugins(bool refresh); | 140 void LoadPlugins(bool refresh); |
| 139 | 141 |
| 140 // Load all plugins from a specific directory | 142 // Load all plugins from a specific directory |
| 141 void LoadPluginsFromDir(const FilePath& path); | 143 void LoadPluginsFromDir(const FilePath& path, |
| 144 std::vector<WebPluginInfo>* plugins); |
| 142 | 145 |
| 143 // Returns true if we should load the given plugin, or false otherwise. | 146 // Returns true if we should load the given plugin, or false otherwise. |
| 144 bool ShouldLoadPlugin(const WebPluginInfo& info); | 147 // plugins is the list of plugins we have crawled in the current plugin |
| 148 // loading run. |
| 149 bool ShouldLoadPlugin(const WebPluginInfo& info, |
| 150 std::vector<WebPluginInfo>* plugins); |
| 145 | 151 |
| 146 // Load internal plugins. | 152 // Load internal plugins. |
| 147 void LoadInternalPlugins(); | 153 void LoadInternalPlugins(std::vector<WebPluginInfo>* plugins); |
| 148 | 154 |
| 149 // Find a plugin by mime type, and clsid. | 155 // Find a plugin by mime type, and clsid. |
| 150 // If clsid is empty, we will just find the plugin that supports mime type. | 156 // If clsid is empty, we will just find the plugin that supports mime type. |
| 151 // Otherwise, if mime_type is application/x-oleobject etc that's supported by | 157 // Otherwise, if mime_type is application/x-oleobject etc that's supported by |
| 152 // by our activex shim, we need to check if the specified ActiveX exists. | 158 // by our activex shim, we need to check if the specified ActiveX exists. |
| 153 // If not we will not return the activex shim, instead we will let the | 159 // If not we will not return the activex shim, instead we will let the |
| 154 // default plugin handle activex installation. | 160 // default plugin handle activex installation. |
| 155 // The allow_wildcard parameter controls whether this function returns | 161 // The allow_wildcard parameter controls whether this function returns |
| 156 // plugins which support wildcard mime types (* as the mime type) | 162 // plugins which support wildcard mime types (* as the mime type) |
| 157 bool FindPlugin(const std::string &mime_type, const std::string& clsid, | 163 bool FindPlugin(const std::string &mime_type, const std::string& clsid, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 215 |
| 210 // Extra plugin paths that we want to search when loading. | 216 // Extra plugin paths that we want to search when loading. |
| 211 std::vector<FilePath> extra_plugin_paths_; | 217 std::vector<FilePath> extra_plugin_paths_; |
| 212 | 218 |
| 213 // Extra plugin directories that we want to search when loading. | 219 // Extra plugin directories that we want to search when loading. |
| 214 std::vector<FilePath> extra_plugin_dirs_; | 220 std::vector<FilePath> extra_plugin_dirs_; |
| 215 | 221 |
| 216 // Holds information about internal plugins. | 222 // Holds information about internal plugins. |
| 217 std::vector<PluginVersionInfo> internal_plugins_; | 223 std::vector<PluginVersionInfo> internal_plugins_; |
| 218 | 224 |
| 225 // Need synchronization for the above members since this object can be |
| 226 // accessed on multiple threads. |
| 227 Lock lock_; |
| 228 |
| 219 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 229 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
| 220 | 230 |
| 221 DISALLOW_EVIL_CONSTRUCTORS(PluginList); | 231 DISALLOW_COPY_AND_ASSIGN(PluginList); |
| 222 }; | 232 }; |
| 223 | 233 |
| 224 } // namespace NPAPI | 234 } // namespace NPAPI |
| 225 | 235 |
| 226 #endif // WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H__ | 236 #endif // WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H__ |
| OLD | NEW |