| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_COMMON_PLUGIN_LIST_H_ | 5 #ifndef CONTENT_COMMON_PLUGIN_LIST_H_ |
| 6 #define CONTENT_COMMON_PLUGIN_LIST_H_ | 6 #define CONTENT_COMMON_PLUGIN_LIST_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // and checking to see if they are valid NPAPI libraries. On the Mac, it walks | 33 // and checking to see if they are valid NPAPI libraries. On the Mac, it walks |
| 34 // the machine-wide and user plugin directories and loads anything that has | 34 // the machine-wide and user plugin directories and loads anything that has |
| 35 // the correct types. On Linux, it walks the plugin directories as well | 35 // the correct types. On Linux, it walks the plugin directories as well |
| 36 // (e.g. /usr/lib/browser-plugins/). | 36 // (e.g. /usr/lib/browser-plugins/). |
| 37 // This object is thread safe. | 37 // This object is thread safe. |
| 38 class CONTENT_EXPORT PluginList { | 38 class CONTENT_EXPORT PluginList { |
| 39 public: | 39 public: |
| 40 // Gets the one instance of the PluginList. | 40 // Gets the one instance of the PluginList. |
| 41 static PluginList* Singleton(); | 41 static PluginList* Singleton(); |
| 42 | 42 |
| 43 // Returns true if we're in debug-plugin-loading mode. This is controlled | |
| 44 // by a command line switch. | |
| 45 static bool DebugPluginLoading(); | |
| 46 | |
| 47 // Returns true if the plugin supports |mime_type|. |mime_type| should be all | 43 // Returns true if the plugin supports |mime_type|. |mime_type| should be all |
| 48 // lower case. | 44 // lower case. |
| 49 static bool SupportsType(const WebPluginInfo& plugin, | 45 static bool SupportsType(const WebPluginInfo& plugin, |
| 50 const std::string& mime_type, | 46 const std::string& mime_type, |
| 51 bool allow_wildcard); | 47 bool allow_wildcard); |
| 52 | 48 |
| 53 // Disables discovery of third_party plugins in standard places next time | |
| 54 // plugins are loaded. | |
| 55 void DisablePluginsDiscovery(); | |
| 56 | |
| 57 // Cause the plugin list to refresh next time they are accessed, regardless | 49 // Cause the plugin list to refresh next time they are accessed, regardless |
| 58 // of whether they are already loaded. | 50 // of whether they are already loaded. |
| 59 void RefreshPlugins(); | 51 void RefreshPlugins(); |
| 60 | 52 |
| 61 // Add/Remove an extra plugin to load when we actually do the loading. Must | |
| 62 // be called before the plugins have been loaded. | |
| 63 void AddExtraPluginPath(const base::FilePath& plugin_path); | |
| 64 void RemoveExtraPluginPath(const base::FilePath& plugin_path); | |
| 65 | |
| 66 // Same as above, but specifies a directory in which to search for plugins. | |
| 67 void AddExtraPluginDir(const base::FilePath& plugin_dir); | |
| 68 | |
| 69 // Get the ordered list of directories from which to load plugins | |
| 70 void GetPluginDirectories(std::vector<base::FilePath>* plugin_dirs); | |
| 71 | |
| 72 // Register an internal plugin with the specified plugin information. | 53 // Register an internal plugin with the specified plugin information. |
| 73 // An internal plugin must be registered before it can | 54 // An internal plugin must be registered before it can |
| 74 // be loaded using PluginList::LoadPlugin(). | 55 // be loaded using PluginList::LoadPlugin(). |
| 75 // If |add_at_beginning| is true the plugin will be added earlier in | 56 // If |add_at_beginning| is true the plugin will be added earlier in |
| 76 // the list so that it can override the MIME types of older registrations. | 57 // the list so that it can override the MIME types of older registrations. |
| 77 void RegisterInternalPlugin(const WebPluginInfo& info, | 58 void RegisterInternalPlugin(const WebPluginInfo& info, |
| 78 bool add_at_beginning); | 59 bool add_at_beginning); |
| 79 | 60 |
| 80 // Removes a specified internal plugin from the list. The search will match | 61 // Removes a specified internal plugin from the list. The search will match |
| 81 // on the path from the version info previously registered. | 62 // on the path from the version info previously registered. |
| 82 void UnregisterInternalPlugin(const base::FilePath& path); | 63 void UnregisterInternalPlugin(const base::FilePath& path); |
| 83 | 64 |
| 84 // Gets a list of all the registered internal plugins. | 65 // Gets a list of all the registered internal plugins. |
| 85 void GetInternalPlugins(std::vector<WebPluginInfo>* plugins); | 66 void GetInternalPlugins(std::vector<WebPluginInfo>* plugins); |
| 86 | 67 |
| 87 // Creates a WebPluginInfo structure given a plugin's path. On success | 68 // Creates a WebPluginInfo structure given a plugin's path. On success |
| 88 // returns true, with the information being put into "info". | 69 // returns true, with the information being put into "info". |
| 89 // Returns false if the library couldn't be found, or if it's not a plugin. | 70 // Returns false if the library couldn't be found, or if it's not a plugin. |
| 90 bool ReadPluginInfo(const base::FilePath& filename, | 71 bool ReadPluginInfo(const base::FilePath& filename, |
| 91 WebPluginInfo* info); | 72 WebPluginInfo* info); |
| 92 | 73 |
| 93 // In Windows plugins, the mime types are passed as a specially formatted list | |
| 94 // of strings. This function parses those strings into a WebPluginMimeType | |
| 95 // vector. | |
| 96 // TODO(evan): move this code into plugin_list_win. | |
| 97 static bool ParseMimeTypes( | |
| 98 const std::string& mime_types, | |
| 99 const std::string& file_extensions, | |
| 100 const base::string16& mime_type_descriptions, | |
| 101 std::vector<WebPluginMimeType>* parsed_mime_types); | |
| 102 | |
| 103 // Get all the plugins synchronously, loading them if necessary. | 74 // Get all the plugins synchronously, loading them if necessary. |
| 104 void GetPlugins(std::vector<WebPluginInfo>* plugins, | 75 void GetPlugins(std::vector<WebPluginInfo>* plugins); |
| 105 bool include_npapi); | |
| 106 | 76 |
| 107 // Copies the list of plugins into |plugins| without loading them. | 77 // Copies the list of plugins into |plugins| without loading them. |
| 108 // Returns true if the list of plugins is up-to-date. | 78 // Returns true if the list of plugins is up-to-date. |
| 109 bool GetPluginsNoRefresh(std::vector<WebPluginInfo>* plugins); | 79 bool GetPluginsNoRefresh(std::vector<WebPluginInfo>* plugins); |
| 110 | 80 |
| 111 // Returns a list in |info| containing plugins that are found for | 81 // Returns a list in |info| containing plugins that are found for |
| 112 // the given url and mime type (including disabled plugins, for | 82 // the given url and mime type (including disabled plugins, for |
| 113 // which |info->enabled| is false). The mime type which corresponds | 83 // which |info->enabled| is false). The mime type which corresponds |
| 114 // to the URL is optionally returned back in |actual_mime_types| (if | 84 // to the URL is optionally returned back in |actual_mime_types| (if |
| 115 // it is non-NULL), one for each of the plugin info objects found. | 85 // it is non-NULL), one for each of the plugin info objects found. |
| 116 // The |allow_wildcard| parameter controls whether this function | 86 // The |allow_wildcard| parameter controls whether this function |
| 117 // returns plugins which support wildcard mime types (* as the mime | 87 // returns plugins which support wildcard mime types (* as the mime |
| 118 // type). The |info| parameter is required to be non-NULL. The | 88 // type). The |info| parameter is required to be non-NULL. The |
| 119 // list is in order of "most desirable" to "least desirable". | 89 // list is in order of "most desirable" to "least desirable". |
| 120 // If |use_stale| is NULL, this will load the plugin list if necessary. | 90 // If |use_stale| is NULL, this will load the plugin list if necessary. |
| 121 // If it is not NULL, the plugin list will not be loaded, and |*use_stale| | 91 // If it is not NULL, the plugin list will not be loaded, and |*use_stale| |
| 122 // will be true iff the plugin list was stale. | 92 // will be true iff the plugin list was stale. |
| 123 void GetPluginInfoArray(const GURL& url, | 93 void GetPluginInfoArray(const GURL& url, |
| 124 const std::string& mime_type, | 94 const std::string& mime_type, |
| 125 bool allow_wildcard, | 95 bool allow_wildcard, |
| 126 bool* use_stale, | 96 bool* use_stale, |
| 127 bool include_npapi, | |
| 128 std::vector<WebPluginInfo>* info, | 97 std::vector<WebPluginInfo>* info, |
| 129 std::vector<std::string>* actual_mime_types); | 98 std::vector<std::string>* actual_mime_types); |
| 130 | 99 |
| 131 // Load a specific plugin with full path. Return true iff loading the plugin | 100 // Load a specific plugin with full path. Return true iff loading the plugin |
| 132 // was successful. | 101 // was successful. |
| 133 bool LoadPluginIntoPluginList(const base::FilePath& filename, | 102 bool LoadPluginIntoPluginList(const base::FilePath& filename, |
| 134 std::vector<WebPluginInfo>* plugins, | 103 std::vector<WebPluginInfo>* plugins, |
| 135 WebPluginInfo* plugin_info); | 104 WebPluginInfo* plugin_info); |
| 136 | 105 |
| 137 // The following functions are used to support probing for WebPluginInfo | 106 // The following functions are used to support probing for WebPluginInfo |
| 138 // using a different instance of this class. | 107 // using a different instance of this class. |
| 139 | 108 |
| 140 // Computes a list of all plugins to potentially load from all sources. | 109 // Computes a list of all plugins to potentially load from all sources. |
| 141 void GetPluginPathsToLoad(std::vector<base::FilePath>* plugin_paths, | 110 void GetPluginPathsToLoad(std::vector<base::FilePath>* plugin_paths); |
| 142 bool include_npapi); | |
| 143 | 111 |
| 144 // Signals that plugin loading will start. This method should be called before | 112 // Signals that plugin loading will start. This method should be called before |
| 145 // loading plugins with a different instance of this class. Returns false if | 113 // loading plugins with a different instance of this class. Returns false if |
| 146 // the plugin list is up to date. | 114 // the plugin list is up to date. |
| 147 // When loading has finished, SetPlugins() should be called with the list of | 115 // When loading has finished, SetPlugins() should be called with the list of |
| 148 // plugins. | 116 // plugins. |
| 149 bool PrepareForPluginLoading(); | 117 bool PrepareForPluginLoading(); |
| 150 | 118 |
| 151 // Clears the internal list of Plugins and copies them from the vector. | 119 // Clears the internal list of Plugins and copies them from the vector. |
| 152 void SetPlugins(const std::vector<WebPluginInfo>& plugins); | 120 void SetPlugins(const std::vector<WebPluginInfo>& plugins); |
| 153 | 121 |
| 154 void set_will_load_plugins_callback(const base::Closure& callback); | 122 void set_will_load_plugins_callback(const base::Closure& callback); |
| 155 | 123 |
| 156 virtual ~PluginList(); | 124 virtual ~PluginList(); |
| 157 | 125 |
| 158 // Creates a WebPluginInfo structure given a plugin's path. On success | |
| 159 // returns true, with the information being put into "info". | |
| 160 // Returns false if the library couldn't be found, or if it's not a plugin. | |
| 161 static bool ReadWebPluginInfo(const base::FilePath& filename, | |
| 162 WebPluginInfo* info); | |
| 163 | |
| 164 private: | 126 private: |
| 165 enum LoadingState { | 127 enum LoadingState { |
| 166 LOADING_STATE_NEEDS_REFRESH, | 128 LOADING_STATE_NEEDS_REFRESH, |
| 167 LOADING_STATE_REFRESHING, | 129 LOADING_STATE_REFRESHING, |
| 168 LOADING_STATE_UP_TO_DATE, | 130 LOADING_STATE_UP_TO_DATE, |
| 169 }; | 131 }; |
| 170 | 132 |
| 171 friend class PluginListTest; | 133 friend class PluginListTest; |
| 172 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 134 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
| 173 | 135 |
| 174 PluginList(); | 136 PluginList(); |
| 175 | 137 |
| 176 // Load all plugins from the default plugins directory. | 138 // Load all plugins from the default plugins directory. |
| 177 void LoadPlugins(bool include_npapi); | 139 void LoadPlugins(); |
| 178 | |
| 179 // Walks a directory and produces a list of all the plugins to potentially | |
| 180 // load in that directory. | |
| 181 void GetPluginsInDir(const base::FilePath& path, | |
| 182 std::vector<base::FilePath>* plugins); | |
| 183 | |
| 184 // Returns true if we should load the given plugin, or false otherwise. | |
| 185 // |plugins| is the list of plugins we have crawled in the current plugin | |
| 186 // loading run. | |
| 187 bool ShouldLoadPluginUsingPluginList(const WebPluginInfo& info, | |
| 188 std::vector<WebPluginInfo>* plugins); | |
| 189 | 140 |
| 190 // Returns true if the given plugin supports a given file extension. | 141 // Returns true if the given plugin supports a given file extension. |
| 191 // |extension| should be all lower case. If |mime_type| is not NULL, it will | 142 // |extension| should be all lower case. If |mime_type| is not NULL, it will |
| 192 // be set to the MIME type if found. The MIME type which corresponds to the | 143 // be set to the MIME type if found. The MIME type which corresponds to the |
| 193 // extension is optionally returned back. | 144 // extension is optionally returned back. |
| 194 bool SupportsExtension(const WebPluginInfo& plugin, | 145 bool SupportsExtension(const WebPluginInfo& plugin, |
| 195 const std::string& extension, | 146 const std::string& extension, |
| 196 std::string* actual_mime_type); | 147 std::string* actual_mime_type); |
| 197 | 148 |
| 198 // Removes |plugin_path| from the list of extra plugin paths. Should only be | 149 // Removes |plugin_path| from the list of extra plugin paths. Should only be |
| 199 // called while holding |lock_|. | 150 // called while holding |lock_|. |
| 200 void RemoveExtraPluginPathLocked(const base::FilePath& plugin_path); | 151 void RemoveExtraPluginPathLocked(const base::FilePath& plugin_path); |
| 201 | 152 |
| 202 // | 153 // |
| 203 // Command-line switches | |
| 204 // | |
| 205 | |
| 206 #if defined(OS_WIN) | |
| 207 // Gets plugin paths registered under HKCU\Software\MozillaPlugins and | |
| 208 // HKLM\Software\MozillaPlugins. | |
| 209 void GetPluginPathsFromRegistry(std::vector<base::FilePath>* plugins); | |
| 210 #endif | |
| 211 | |
| 212 // | |
| 213 // Internals | 154 // Internals |
| 214 // | 155 // |
| 215 | 156 |
| 216 // States whether we will load the plugin list the next time we try to access | 157 // States whether we will load the plugin list the next time we try to access |
| 217 // it, whether we are currently in the process of loading it, or whether we | 158 // it, whether we are currently in the process of loading it, or whether we |
| 218 // consider it up-to-date. | 159 // consider it up-to-date. |
| 219 LoadingState loading_state_; | 160 LoadingState loading_state_; |
| 220 | 161 |
| 221 // Extra plugin paths that we want to search when loading. | 162 // Extra plugin paths that we want to search when loading. |
| 222 std::vector<base::FilePath> extra_plugin_paths_; | 163 std::vector<base::FilePath> extra_plugin_paths_; |
| 223 | 164 |
| 224 // Extra plugin directories that we want to search when loading. | |
| 225 std::vector<base::FilePath> extra_plugin_dirs_; | |
| 226 | |
| 227 // Holds information about internal plugins. | 165 // Holds information about internal plugins. |
| 228 std::vector<WebPluginInfo> internal_plugins_; | 166 std::vector<WebPluginInfo> internal_plugins_; |
| 229 | 167 |
| 230 // A list holding all plugins. | 168 // A list holding all plugins. |
| 231 std::vector<WebPluginInfo> plugins_list_; | 169 std::vector<WebPluginInfo> plugins_list_; |
| 232 | 170 |
| 233 // Callback that is invoked whenever the PluginList will reload the plugins. | 171 // Callback that is invoked whenever the PluginList will reload the plugins. |
| 234 base::Closure will_load_plugins_callback_; | 172 base::Closure will_load_plugins_callback_; |
| 235 | 173 |
| 236 // Need synchronization for the above members since this object can be | 174 // Need synchronization for the above members since this object can be |
| 237 // accessed on multiple threads. | 175 // accessed on multiple threads. |
| 238 base::Lock lock_; | 176 base::Lock lock_; |
| 239 | 177 |
| 240 // Flag indicating whether third_party plugins will be searched for | |
| 241 // in common places. | |
| 242 bool plugins_discovery_disabled_; | |
| 243 | |
| 244 DISALLOW_COPY_AND_ASSIGN(PluginList); | 178 DISALLOW_COPY_AND_ASSIGN(PluginList); |
| 245 }; | 179 }; |
| 246 | 180 |
| 247 } // namespace content | 181 } // namespace content |
| 248 | 182 |
| 249 #endif // CONTENT_COMMON_PLUGIN_LIST_H_ | 183 #endif // CONTENT_COMMON_PLUGIN_LIST_H_ |
| OLD | NEW |