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

Side by Side Diff: webkit/plugins/npapi/plugin_list.h

Issue 5998002: Revert "Move the NPAPI files from webkit/glue/plugins to webkit/plugins/npapi" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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
« no previous file with comments | « webkit/plugins/npapi/plugin_constants_win.cc ('k') | webkit/plugins/plugin_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_
6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/file_path.h"
14 #include "base/linked_ptr.h"
15 #include "base/lock.h"
16 #include "third_party/npapi/bindings/nphostapi.h"
17 #include "webkit/plugins/npapi/plugin_group.h"
18 #include "webkit/plugins/npapi/webplugininfo.h"
19
20 class GURL;
21
22 namespace base {
23
24 template <typename T>
25 struct DefaultLazyInstanceTraits;
26
27 } // namespace base
28
29 namespace webkit {
30 namespace npapi {
31
32 extern FilePath::CharType kDefaultPluginLibraryName[];
33
34 class PluginInstance;
35
36 // This struct holds entry points into a plugin. The entry points are
37 // slightly different between Win/Mac and Unixes.
38 struct PluginEntryPoints {
39 #if !defined(OS_POSIX) || defined(OS_MACOSX)
40 NP_GetEntryPointsFunc np_getentrypoints;
41 #endif
42 NP_InitializeFunc np_initialize;
43 NP_ShutdownFunc np_shutdown;
44 };
45
46 // This struct fully describes a plugin. For external plugins, it's read in from
47 // the version info of the dll; For internal plugins, it's predefined and
48 // includes addresses of entry functions. (Yes, it's Win32 NPAPI-centric, but
49 // it'll do for holding descriptions of internal plugins cross-platform.)
50 struct PluginVersionInfo {
51 FilePath path;
52 // Info about the plugin itself.
53 std::wstring product_name;
54 std::wstring file_description;
55 std::wstring file_version;
56 // Info about the data types that the plugin supports.
57 std::wstring mime_types;
58 std::wstring file_extensions;
59 std::wstring type_descriptions;
60 // Entry points for internal plugins. Pointers are NULL for external plugins.
61 PluginEntryPoints entry_points;
62 };
63
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
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
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
70 // (e.g. /usr/lib/browser-plugins/).
71 // This object is thread safe.
72 class PluginList {
73 public:
74 // Gets the one instance of the PluginList.
75 static PluginList* Singleton();
76
77 // Returns true if we're in debug-plugin-loading mode. This is controlled
78 // by a command line switch.
79 static bool DebugPluginLoading();
80
81 static const PluginGroupDefinition* GetPluginGroupDefinitions();
82 static size_t GetPluginGroupDefinitionsSize();
83
84 // Returns true iff the plugin list has been loaded already.
85 bool PluginsLoaded();
86
87 // Cause the plugin list to refresh next time they are accessed, regardless
88 // of whether they are already loaded.
89 void RefreshPlugins();
90
91 // Add/Remove an extra plugin to load when we actually do the loading. Must
92 // be called before the plugins have been loaded.
93 void AddExtraPluginPath(const FilePath& plugin_path);
94 void RemoveExtraPluginPath(const FilePath& plugin_path);
95
96 // Same as above, but specifies a directory in which to search for plugins.
97 void AddExtraPluginDir(const FilePath& plugin_dir);
98
99 // Register an internal plugin with the specified plugin information and
100 // function pointers. An internal plugin must be registered before it can
101 // be loaded using PluginList::LoadPlugin().
102 void RegisterInternalPlugin(const PluginVersionInfo& info);
103
104 // Removes a specified internal plugin from the list. The search will match
105 // on the path from the version info previously registered.
106 //
107 // This is generally only necessary for tests.
108 void UnregisterInternalPlugin(const FilePath& path);
109
110 // Creates a WebPluginInfo structure given a plugin's path. On success
111 // returns true, with the information being put into "info". If it's an
112 // internal plugin, "entry_points" is filled in as well with a
113 // internally-owned PluginEntryPoints pointer.
114 // Returns false if the library couldn't be found, or if it's not a plugin.
115 bool ReadPluginInfo(const FilePath& filename,
116 WebPluginInfo* info,
117 const PluginEntryPoints** entry_points);
118
119 // Populate a WebPluginInfo from a PluginVersionInfo.
120 static bool CreateWebPluginInfo(const PluginVersionInfo& pvi,
121 WebPluginInfo* info);
122
123 // Shutdown all plugins. Should be called at process teardown.
124 void Shutdown();
125
126 // Get all the plugins.
127 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins);
128
129 // Get all the enabled plugins.
130 void GetEnabledPlugins(bool refresh, std::vector<WebPluginInfo>* plugins);
131
132 // Returns a list in |info| containing plugins that are found for
133 // the given url and mime type (including disabled plugins, for
134 // which |info->enabled| is false). The mime type which corresponds
135 // to the URL is optionally returned back in |actual_mime_types| (if
136 // it is non-NULL), one for each of the plugin info objects found.
137 // The |allow_wildcard| parameter controls whether this function
138 // returns plugins which support wildcard mime types (* as the mime
139 // type). The |info| parameter is required to be non-NULL. The
140 // list is in order of "most desirable" to "least desirable",
141 // meaning that the default plugin is at the end of the list.
142 void GetPluginInfoArray(const GURL& url,
143 const std::string& mime_type,
144 bool allow_wildcard,
145 std::vector<WebPluginInfo>* info,
146 std::vector<std::string>* actual_mime_types);
147
148 // Returns the first item from the list returned in GetPluginInfo in |info|.
149 // Returns true if it found a match. |actual_mime_type| may be NULL.
150 bool GetPluginInfo(const GURL& url,
151 const std::string& mime_type,
152 bool allow_wildcard,
153 WebPluginInfo* info,
154 std::string* actual_mime_type);
155
156 // Get plugin info by plugin path (including disabled plugins). Returns true
157 // if the plugin is found and WebPluginInfo has been filled in |info|.
158 bool GetPluginInfoByPath(const FilePath& plugin_path,
159 WebPluginInfo* info);
160
161 // Populates the given vector with all available plugin groups.
162 void GetPluginGroups(bool load_if_necessary,
163 std::vector<PluginGroup>* plugin_groups);
164
165 // Returns the PluginGroup corresponding to the given WebPluginInfo. If no
166 // such group exists, it is created and added to the cache.
167 // Beware: when calling this from the Browser process, the group that the
168 // returned pointer points to might disappear suddenly. This happens when
169 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a
170 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|,
171 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's
172 // responsibility to make sure this doesn't happen.
173 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info);
174
175 // Returns the name of the PluginGroup with the given identifier.
176 // If no such group exists, an empty string is returned.
177 string16 GetPluginGroupName(std::string identifier);
178
179 // 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
181 // cache.
182 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info);
183
184 // Load a specific plugin with full path.
185 void LoadPlugin(const FilePath& filename,
186 std::vector<WebPluginInfo>* plugins);
187
188 // 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
190 // 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
192 // |PluginList| is concerned.
193 bool EnablePlugin(const FilePath& filename);
194
195 // 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
197 // of return value, if a plugin is found in the future with the given name, it
198 // will be disabled.
199 bool DisablePlugin(const FilePath& filename);
200
201 // 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
203 // 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
205 // by default as far as |PluginList| is concerned.
206 bool EnableGroup(bool enable, const string16& name);
207
208 // 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
210 // be loaded on a web page and instead show a UI to update to the latest
211 // version.
212 void DisableOutdatedPluginGroups();
213
214 ~PluginList();
215
216 private:
217 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition);
218
219 // Constructors are private for singletons
220 PluginList();
221
222 // Creates PluginGroups for the static group definitions, and adds them to
223 // the PluginGroup cache of this PluginList.
224 void AddHardcodedPluginGroups();
225
226 // Adds the given WebPluginInfo to its corresponding group, creating it if
227 // necessary, and returns the group.
228 // Callers need to protect calls to this method by a lock themselves.
229 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info);
230
231 // Load all plugins from the default plugins directory
232 void LoadPlugins(bool refresh);
233
234 // Load all plugins from a specific directory.
235 // |plugins| is updated with loaded plugin information.
236 // |visited_plugins| is updated with paths to all plugins that were considered
237 // (including those we didn't load)
238 void LoadPluginsFromDir(const FilePath& path,
239 std::vector<WebPluginInfo>* plugins,
240 std::set<FilePath>* visited_plugins);
241
242 // 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
244 // loading run.
245 bool ShouldLoadPlugin(const WebPluginInfo& info,
246 std::vector<WebPluginInfo>* plugins);
247
248 // 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
250 // is blacklisted by a policy. In the latter case, add the plugin group to the
251 // list of disabled groups as well.
252 bool ShouldDisableGroup(const string16& group_name);
253
254 // Returns true if the given WebPluginInfo supports "mime-type".
255 // mime_type should be all lower case.
256 static bool SupportsType(const WebPluginInfo& info,
257 const std::string &mime_type,
258 bool allow_wildcard);
259
260 // Returns true if the given WebPluginInfo supports a given file extension.
261 // extension should be all lower case.
262 // If mime_type is not NULL, it will be set to the mime type if found.
263 // The mime type which corresponds to the extension is optionally returned
264 // back.
265 static bool SupportsExtension(const WebPluginInfo& info,
266 const std::string &extension,
267 std::string* actual_mime_type);
268
269 //
270 // Platform functions
271 //
272
273 // Do any initialization.
274 void PlatformInit();
275
276 // Get the ordered list of directories from which to load plugins
277 void GetPluginDirectories(std::vector<FilePath>* plugin_dirs);
278
279 //
280 // Command-line switches
281 //
282
283 #if defined(OS_WIN)
284 // true if we shouldn't load the new WMP plugin.
285 bool dont_load_new_wmp_;
286
287 // Loads plugins registered under HKCU\Software\MozillaPlugins and
288 // HKLM\Software\MozillaPlugins.
289 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins,
290 std::set<FilePath>* visited_plugins);
291 #endif
292
293 //
294 // Internals
295 //
296
297 bool plugins_loaded_;
298
299 // If true, we reload plugins even if they've been loaded already.
300 bool plugins_need_refresh_;
301
302 // Contains information about the available plugins.
303 std::vector<WebPluginInfo> plugins_;
304
305 // Extra plugin paths that we want to search when loading.
306 std::vector<FilePath> extra_plugin_paths_;
307
308 // Extra plugin directories that we want to search when loading.
309 std::vector<FilePath> extra_plugin_dirs_;
310
311 // Holds information about internal plugins.
312 std::vector<PluginVersionInfo> internal_plugins_;
313
314 // Path names of plugins to disable (the default is to enable them all).
315 std::set<FilePath> disabled_plugins_;
316
317 // Group names to disable (the default is to enable them all).
318 std::set<string16> disabled_groups_;
319
320 bool disable_outdated_plugins_;
321
322 // Holds the currently available plugin groups.
323 PluginGroup::PluginMap plugin_groups_;
324
325 int next_priority_;
326
327 // Need synchronization for the above members since this object can be
328 // accessed on multiple threads.
329 Lock lock_;
330
331 friend struct base::DefaultLazyInstanceTraits<PluginList>;
332
333 DISALLOW_COPY_AND_ASSIGN(PluginList);
334 };
335
336 } // namespace npapi
337 } // namespace webkit
338
339 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_constants_win.cc ('k') | webkit/plugins/plugin_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698