Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: content/common/plugin_list.h

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

Powered by Google App Engine
This is Rietveld 408576698