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_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 5 #ifndef WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
14 #include "base/linked_ptr.h" | 15 #include "base/linked_ptr.h" |
15 #include "base/lock.h" | 16 #include "base/lock.h" |
17 #include "base/scoped_vector.h" | |
16 #include "third_party/npapi/bindings/nphostapi.h" | 18 #include "third_party/npapi/bindings/nphostapi.h" |
17 #include "webkit/plugins/npapi/plugin_group.h" | 19 #include "webkit/plugins/npapi/plugin_group.h" |
18 #include "webkit/plugins/npapi/webplugininfo.h" | 20 #include "webkit/plugins/npapi/webplugininfo.h" |
19 | 21 |
20 class GURL; | 22 class GURL; |
21 | 23 |
22 namespace base { | 24 namespace base { |
23 | 25 |
24 template <typename T> | 26 template <typename T> |
25 struct DefaultLazyInstanceTraits; | 27 struct DefaultLazyInstanceTraits; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 // In Windows and Pepper plugins, the mime types are passed as a specially | 117 // In Windows and Pepper plugins, the mime types are passed as a specially |
116 // formatted list of strings. This function parses those strings into | 118 // formatted list of strings. This function parses those strings into |
117 // a WebPluginMimeType vector. | 119 // a WebPluginMimeType vector. |
118 // TODO(evan): make Pepper pass around formatted data and move this code | 120 // TODO(evan): make Pepper pass around formatted data and move this code |
119 // into plugin_list_win. | 121 // into plugin_list_win. |
120 static bool ParseMimeTypes(const std::string& mime_types, | 122 static bool ParseMimeTypes(const std::string& mime_types, |
121 const std::string& file_extensions, | 123 const std::string& file_extensions, |
122 const string16& mime_type_descriptions, | 124 const string16& mime_type_descriptions, |
123 std::vector<WebPluginMimeType>* parsed_mime_types); | 125 std::vector<WebPluginMimeType>* parsed_mime_types); |
124 | 126 |
125 // Shutdown all plugins. Should be called at process teardown. | |
126 void Shutdown(); | |
127 | |
128 // Get all the plugins. | 127 // Get all the plugins. |
129 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); | 128 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); |
130 | 129 |
131 // Get all the enabled plugins. | 130 // Get all the enabled plugins. |
132 void GetEnabledPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); | 131 void GetEnabledPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); |
133 | 132 |
134 // Returns a list in |info| containing plugins that are found for | 133 // Returns a list in |info| containing plugins that are found for |
135 // the given url and mime type (including disabled plugins, for | 134 // the given url and mime type (including disabled plugins, for |
136 // which |info->enabled| is false). The mime type which corresponds | 135 // which |info->enabled| is false). The mime type which corresponds |
137 // to the URL is optionally returned back in |actual_mime_types| (if | 136 // to the URL is optionally returned back in |actual_mime_types| (if |
(...skipping 27 matching lines...) Expand all Loading... | |
165 std::vector<PluginGroup>* plugin_groups); | 164 std::vector<PluginGroup>* plugin_groups); |
166 | 165 |
167 // Returns the PluginGroup corresponding to the given WebPluginInfo. If no | 166 // Returns the PluginGroup corresponding to the given WebPluginInfo. If no |
168 // such group exists, it is created and added to the cache. | 167 // such group exists, it is created and added to the cache. |
169 // Beware: when calling this from the Browser process, the group that the | 168 // Beware: when calling this from the Browser process, the group that the |
170 // returned pointer points to might disappear suddenly. This happens when | 169 // returned pointer points to might disappear suddenly. This happens when |
171 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a | 170 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a |
172 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, | 171 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, |
173 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's | 172 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's |
174 // responsibility to make sure this doesn't happen. | 173 // responsibility to make sure this doesn't happen. |
175 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info); | 174 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info); |
jam
2011/01/20 18:22:34
this function is now only called from test code.
pastarmovj
2011/01/20 22:59:49
I wish I can but it is also used from RenderView::
| |
176 | 175 |
177 // Returns the name of the PluginGroup with the given identifier. | 176 // Returns the name of the PluginGroup with the given identifier. |
178 // If no such group exists, an empty string is returned. | 177 // If no such group exists, an empty string is returned. |
179 string16 GetPluginGroupName(std::string identifier); | 178 string16 GetPluginGroupName(const std::string& identifier); |
180 | 179 |
181 // Returns the identifier string of the PluginGroup corresponding to the given | 180 // Returns the identifier string of the PluginGroup corresponding to the given |
182 // WebPluginInfo. If no such group exists, it is created and added to the | 181 // WebPluginInfo. If no such group exists, it is created and added to the |
183 // cache. | 182 // cache. |
184 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); | 183 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); |
185 | 184 |
186 // Load a specific plugin with full path. | 185 // Load a specific plugin with full path. |
187 void LoadPlugin(const FilePath& filename, | 186 void LoadPlugin(const FilePath& filename, |
188 std::vector<WebPluginInfo>* plugins); | 187 ScopedVector<PluginGroup>* plugin_groups); |
189 | 188 |
190 // Enable a specific plugin, specified by path. Returns |true| iff a plugin | 189 // Enable a specific plugin, specified by path. Returns |true| iff a plugin |
191 // currently in the plugin list was actually enabled as a result; regardless | 190 // currently in the plugin list was actually enabled as a result; regardless |
192 // of return value, if a plugin is found in the future with the given name, it | 191 // of return value, if a plugin is found in the future with the given name, it |
193 // will be enabled. Note that plugins are enabled by default as far as | 192 // will be enabled. |
194 // |PluginList| is concerned. | |
195 bool EnablePlugin(const FilePath& filename); | 193 bool EnablePlugin(const FilePath& filename); |
196 | 194 |
197 // Disable a specific plugin, specified by path. Returns |true| iff a plugin | 195 // Disable a specific plugin, specified by path. Returns |true| iff a plugin |
198 // currently in the plugin list was actually disabled as a result; regardless | 196 // currently in the plugin list was actually disabled as a result; regardless |
199 // of return value, if a plugin is found in the future with the given name, it | 197 // of return value, if a plugin is found in the future with the given name, it |
200 // will be disabled. | 198 // will be disabled. |
201 bool DisablePlugin(const FilePath& filename); | 199 bool DisablePlugin(const FilePath& filename); |
202 | 200 |
203 // Enable/disable a plugin group, specified by group_name. Returns |true| iff | 201 // Enable/disable a plugin group, specified by group_name. Returns |true| iff |
204 // a plugin currently in the plugin list was actually enabled/disabled as a | 202 // a plugin currently in the plugin list was actually enabled/disabled as a |
205 // result; regardless of return value, if a plugin is found in the future with | 203 // result; regardless of return value, if a plugin is found in the future with |
206 // the given name, it will be enabled/disabled. Note that plugins are enabled | 204 // the given name, it will be enabled/disabled. |
207 // by default as far as |PluginList| is concerned. | |
208 bool EnableGroup(bool enable, const string16& name); | 205 bool EnableGroup(bool enable, const string16& name); |
209 | 206 |
210 // Disable all plugins groups that are known to be outdated, according to | 207 // Disable all plugins groups that are known to be outdated, according to |
211 // the information hardcoded in PluginGroup, to make sure that they can't | 208 // the information hardcoded in PluginGroup, to make sure that they can't |
212 // be loaded on a web page and instead show a UI to update to the latest | 209 // be loaded on a web page and instead show a UI to update to the latest |
213 // version. | 210 // version. |
214 void DisableOutdatedPluginGroups(); | 211 void DisableOutdatedPluginGroups(); |
215 | 212 |
216 ~PluginList(); | 213 virtual ~PluginList(); |
214 | |
215 protected: | |
216 // Constructors are private for singletons | |
217 PluginList(); | |
218 | |
219 // Load all plugins from the default plugins directory | |
220 virtual void LoadPlugins(bool refresh); | |
221 | |
222 // Allows tests to perform custom post-initialization tasks on newly created | |
223 // PluginGroups. | |
224 virtual void ProcessGroupAfterInitialize(PluginGroup* group) { } | |
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 ScopedVector<PluginGroup>* plugin_groups); | |
231 | |
232 bool plugins_loaded_; | |
233 | |
234 // Holds the currently available plugin groups. | |
235 ScopedVector<PluginGroup> plugin_groups_; | |
217 | 236 |
218 private: | 237 private: |
219 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | 238 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); |
220 | 239 |
221 // Constructors are private for singletons | |
222 PluginList(); | |
223 | |
224 // Creates PluginGroups for the static group definitions, and adds them to | 240 // Creates PluginGroups for the static group definitions, and adds them to |
225 // the PluginGroup cache of this PluginList. | 241 // the PluginGroup cache of this PluginList. |
226 void AddHardcodedPluginGroups(); | 242 void AddHardcodedPluginGroups(); |
227 | 243 |
228 // Adds the given WebPluginInfo to its corresponding group, creating it if | |
229 // necessary, and returns the group. | |
230 // Callers need to protect calls to this method by a lock themselves. | |
231 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info); | |
232 | |
233 // Load all plugins from the default plugins directory | |
234 void LoadPlugins(bool refresh); | |
235 | |
236 // Load all plugins from a specific directory. | 244 // Load all plugins from a specific directory. |
237 // |plugins| is updated with loaded plugin information. | 245 // |plugins| is updated with loaded plugin information. |
238 // |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 |
239 // (including those we didn't load) | 247 // (including those we didn't load) |
240 void LoadPluginsFromDir(const FilePath& path, | 248 void LoadPluginsFromDir(const FilePath& path, |
241 std::vector<WebPluginInfo>* plugins, | 249 ScopedVector<PluginGroup>* plugin_groups, |
242 std::set<FilePath>* visited_plugins); | 250 std::set<FilePath>* visited_plugins); |
243 | 251 |
244 // Returns true if we should load the given plugin, or false otherwise. | 252 // Returns true if we should load the given plugin, or false otherwise. |
245 // plugins is the list of plugins we have crawled in the current plugin | 253 // plugins is the list of plugins we have crawled in the current plugin |
246 // loading run. | 254 // loading run. |
247 bool ShouldLoadPlugin(const WebPluginInfo& info, | 255 bool ShouldLoadPlugin(const WebPluginInfo& info, |
248 std::vector<WebPluginInfo>* plugins); | 256 ScopedVector<PluginGroup>* plugins); |
249 | 257 |
250 // Return whether a plug-in group with the given name should be disabled, | 258 // Return whether a plug-in group with the given name should be disabled, |
251 // either because it already is on the list of disabled groups, or because it | 259 // either because it already is on the list of disabled groups, or because it |
252 // is blacklisted by a policy. In the latter case, add the plugin group to the | 260 // is blacklisted by a policy. In the latter case, add the plugin group to the |
253 // list of disabled groups as well. | 261 // list of disabled groups as well. |
254 bool ShouldDisableGroup(const string16& group_name); | 262 bool ShouldDisableGroup(const string16& group_name); |
255 | 263 |
256 // Returns true if the given WebPluginInfo supports "mime-type". | 264 // Returns true if the plugin supports |mime_type|. |mime_type| should be all |
257 // mime_type should be all lower case. | 265 // lower case. |
258 static bool SupportsType(const WebPluginInfo& info, | 266 bool SupportsType(const WebPluginInfo& plugin, |
259 const std::string &mime_type, | 267 const std::string& mime_type, |
260 bool allow_wildcard); | 268 bool allow_wildcard); |
261 | 269 |
262 // Returns true if the given WebPluginInfo supports a given file extension. | 270 // Returns true if the given plugin supports a given file extension. |
263 // extension should be all lower case. | 271 // |extension| should be all lower case. If |mime_type| is not NULL, it will |
264 // If mime_type is not NULL, it will be set to the mime type if found. | 272 // be set to the MIME type if found. The MIME type which corresponds to the |
265 // The mime type which corresponds to the extension is optionally returned | 273 // extension is optionally returned back. |
266 // back. | 274 bool SupportsExtension(const WebPluginInfo& plugin, |
267 static bool SupportsExtension(const WebPluginInfo& info, | 275 const std::string& extension, |
268 const std::string &extension, | 276 std::string* actual_mime_type); |
269 std::string* actual_mime_type); | |
270 | |
271 // | 277 // |
272 // Platform functions | 278 // Platform functions |
273 // | 279 // |
274 | 280 |
275 // Do any initialization. | 281 // Do any initialization. |
276 void PlatformInit(); | 282 void PlatformInit(); |
277 | 283 |
278 // | 284 // |
279 // Command-line switches | 285 // Command-line switches |
280 // | 286 // |
281 | 287 |
282 #if defined(OS_WIN) | 288 #if defined(OS_WIN) |
283 // true if we shouldn't load the new WMP plugin. | 289 // true if we shouldn't load the new WMP plugin. |
284 bool dont_load_new_wmp_; | 290 bool dont_load_new_wmp_; |
285 | 291 |
286 // Loads plugins registered under HKCU\Software\MozillaPlugins and | 292 // Loads plugins registered under HKCU\Software\MozillaPlugins and |
287 // HKLM\Software\MozillaPlugins. | 293 // HKLM\Software\MozillaPlugins. |
288 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins, | 294 void LoadPluginsFromRegistry(ScopedVector<PluginGroup>* plugins, |
289 std::set<FilePath>* visited_plugins); | 295 std::set<FilePath>* visited_plugins); |
290 #endif | 296 #endif |
291 | 297 |
292 // | 298 // |
293 // Internals | 299 // Internals |
294 // | 300 // |
295 | 301 |
296 bool plugins_loaded_; | |
297 | |
298 // If true, we reload plugins even if they've been loaded already. | 302 // If true, we reload plugins even if they've been loaded already. |
299 bool plugins_need_refresh_; | 303 bool plugins_need_refresh_; |
300 | 304 |
301 // Contains information about the available plugins. | |
302 std::vector<WebPluginInfo> plugins_; | |
303 | |
304 // Extra plugin paths that we want to search when loading. | 305 // Extra plugin paths that we want to search when loading. |
305 std::vector<FilePath> extra_plugin_paths_; | 306 std::vector<FilePath> extra_plugin_paths_; |
306 | 307 |
307 // Extra plugin directories that we want to search when loading. | 308 // Extra plugin directories that we want to search when loading. |
308 std::vector<FilePath> extra_plugin_dirs_; | 309 std::vector<FilePath> extra_plugin_dirs_; |
309 | 310 |
310 struct InternalPlugin { | 311 struct InternalPlugin { |
311 WebPluginInfo info; | 312 WebPluginInfo info; |
312 PluginEntryPoints entry_points; | 313 PluginEntryPoints entry_points; |
313 }; | 314 }; |
314 // Holds information about internal plugins. | 315 // Holds information about internal plugins. |
315 std::vector<InternalPlugin> internal_plugins_; | 316 std::vector<InternalPlugin> internal_plugins_; |
316 | 317 |
317 // Path names of plugins to disable (the default is to enable them all). | |
318 std::set<FilePath> disabled_plugins_; | |
319 | |
320 // Group names to disable (the default is to enable them all). | |
321 std::set<string16> disabled_groups_; | |
322 | |
323 bool disable_outdated_plugins_; | 318 bool disable_outdated_plugins_; |
324 | 319 |
325 // Holds the currently available plugin groups. | 320 // The set of plugins that have been scheduled for disabled once they get |
326 PluginGroup::PluginMap plugin_groups_; | 321 // loaded. This list is used in LoadPlugins and pruned after it. Contains |
327 | 322 // plugins that were either disabled by the user (prefs are loaded before |
328 int next_priority_; | 323 // plugins) or disabled by a policy. |
324 std::vector<FilePath> prematurely_disabled_plugins_; | |
325 // Equivalent to the |prematurely_disabled_plugins_| this is the set of groups | |
326 // scheduled for disabling once they appear. This list is never completely | |
327 // pruned but all groups that do get created are removed from it. New groups | |
328 // might get added if they should be pruned because of plugins getting removed | |
329 // for example. | |
330 std::vector<string16> prematurely_disabled_groups_; | |
329 | 331 |
330 // Need synchronization for the above members since this object can be | 332 // Need synchronization for the above members since this object can be |
331 // accessed on multiple threads. | 333 // accessed on multiple threads. |
332 Lock lock_; | 334 Lock lock_; |
333 | 335 |
334 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 336 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
335 | 337 |
336 DISALLOW_COPY_AND_ASSIGN(PluginList); | 338 DISALLOW_COPY_AND_ASSIGN(PluginList); |
337 }; | 339 }; |
338 | 340 |
339 } // namespace npapi | 341 } // namespace npapi |
340 } // namespace webkit | 342 } // namespace webkit |
341 | 343 |
342 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 344 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
OLD | NEW |