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

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

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made *_to_disable_ sets and extracted some functionality from LoadPlugins for better testability. Created 9 years, 11 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) 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/synchronization/lock.h" 16 #include "base/synchronization/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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
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 // Retrieves the list of currently present plugins and transfers their enabled
223 // status to the newly loaded ones. After that it checks if the
224 // |plugins_to_disable_| have entries to be disabled. Then it purges empty
225 // groups and enforces all policies active on the groups and disables outdated
226 // plugins if the user has opted for that.
227 // This function doesn't lock and depends on the caller to aquire the lock.
228 void UpdatePluginsEnabledFlags(ScopedVector<PluginGroup>* plugin_groups);
229
230 // Adds the given WebPluginInfo to its corresponding group, creating it if
231 // necessary, and returns the group.
232 // Callers need to protect calls to this method by a lock themselves.
233 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info,
234 ScopedVector<PluginGroup>* plugin_groups);
235
236 bool plugins_loaded_;
237
238 // Holds the currently available plugin groups.
239 ScopedVector<PluginGroup> plugin_groups_;
240
241 // The set of plugins that have been scheduled for disabling once they get
242 // loaded. This list is used in LoadPlugins and pruned after it. Contains
243 // plugins that were either disabled by the user (prefs are loaded before
244 // plugins) or disabled by a policy.
245 std::set<FilePath> plugins_to_disable_;
246 // Equivalent to the |prematurely_disabled_plugins_| this is the set of groups
247 // scheduled for disabling once they appear. This list is never completely
248 // pruned but all groups that do get created are removed from it. New groups
249 // might get added if they should be pruned because of plugins getting removed
250 // for example.
251 std::set<string16> groups_to_disable_;
217 252
218 private: 253 private:
219 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); 254 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition);
220 255
221 // Constructors are private for singletons
222 PluginList();
223
224 // Creates PluginGroups for the static group definitions, and adds them to 256 // Creates PluginGroups for the static group definitions, and adds them to
225 // the PluginGroup cache of this PluginList. 257 // the PluginGroup cache of this PluginList.
226 void AddHardcodedPluginGroups(); 258 void AddHardcodedPluginGroups();
227 259
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. 260 // Load all plugins from a specific directory.
237 // |plugins| is updated with loaded plugin information. 261 // |plugins| is updated with loaded plugin information.
238 // |visited_plugins| is updated with paths to all plugins that were considered 262 // |visited_plugins| is updated with paths to all plugins that were considered
239 // (including those we didn't load) 263 // (including those we didn't load)
240 void LoadPluginsFromDir(const FilePath& path, 264 void LoadPluginsFromDir(const FilePath& path,
241 std::vector<WebPluginInfo>* plugins, 265 ScopedVector<PluginGroup>* plugin_groups,
242 std::set<FilePath>* visited_plugins); 266 std::set<FilePath>* visited_plugins);
243 267
244 // Returns true if we should load the given plugin, or false otherwise. 268 // 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 269 // plugins is the list of plugins we have crawled in the current plugin
246 // loading run. 270 // loading run.
247 bool ShouldLoadPlugin(const WebPluginInfo& info, 271 bool ShouldLoadPlugin(const WebPluginInfo& info,
248 std::vector<WebPluginInfo>* plugins); 272 ScopedVector<PluginGroup>* plugins);
249 273
250 // Return whether a plug-in group with the given name should be disabled, 274 // 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 275 // 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 276 // is blacklisted by a policy. In the latter case, add the plugin group to the
253 // list of disabled groups as well. 277 // list of disabled groups as well.
254 bool ShouldDisableGroup(const string16& group_name); 278 bool ShouldDisableGroup(const string16& group_name);
255 279
256 // Returns true if the given WebPluginInfo supports "mime-type". 280 // Returns true if the plugin supports |mime_type|. |mime_type| should be all
257 // mime_type should be all lower case. 281 // lower case.
258 static bool SupportsType(const WebPluginInfo& info, 282 bool SupportsType(const WebPluginInfo& plugin,
259 const std::string &mime_type, 283 const std::string& mime_type,
260 bool allow_wildcard); 284 bool allow_wildcard);
261 285
262 // Returns true if the given WebPluginInfo supports a given file extension. 286 // Returns true if the given plugin supports a given file extension.
263 // extension should be all lower case. 287 // |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. 288 // 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 289 // extension is optionally returned back.
266 // back. 290 bool SupportsExtension(const WebPluginInfo& plugin,
267 static bool SupportsExtension(const WebPluginInfo& info, 291 const std::string& extension,
268 const std::string &extension, 292 std::string* actual_mime_type);
269 std::string* actual_mime_type);
270 293
271 // 294 //
272 // Platform functions 295 // Platform functions
273 // 296 //
274 297
275 // Do any initialization. 298 // Do any initialization.
276 void PlatformInit(); 299 void PlatformInit();
277 300
278 // 301 //
279 // Command-line switches 302 // Command-line switches
280 // 303 //
281 304
282 #if defined(OS_WIN) 305 #if defined(OS_WIN)
283 // true if we shouldn't load the new WMP plugin. 306 // true if we shouldn't load the new WMP plugin.
284 bool dont_load_new_wmp_; 307 bool dont_load_new_wmp_;
285 308
286 // Loads plugins registered under HKCU\Software\MozillaPlugins and 309 // Loads plugins registered under HKCU\Software\MozillaPlugins and
287 // HKLM\Software\MozillaPlugins. 310 // HKLM\Software\MozillaPlugins.
288 void LoadPluginsFromRegistry(std::vector<WebPluginInfo>* plugins, 311 void LoadPluginsFromRegistry(ScopedVector<PluginGroup>* plugins,
289 std::set<FilePath>* visited_plugins); 312 std::set<FilePath>* visited_plugins);
290 #endif 313 #endif
291 314
292 // 315 //
293 // Internals 316 // Internals
294 // 317 //
295 318
296 bool plugins_loaded_;
297
298 // If true, we reload plugins even if they've been loaded already. 319 // If true, we reload plugins even if they've been loaded already.
299 bool plugins_need_refresh_; 320 bool plugins_need_refresh_;
300 321
301 // Contains information about the available plugins.
302 std::vector<WebPluginInfo> plugins_;
303
304 // Extra plugin paths that we want to search when loading. 322 // Extra plugin paths that we want to search when loading.
305 std::vector<FilePath> extra_plugin_paths_; 323 std::vector<FilePath> extra_plugin_paths_;
306 324
307 // Extra plugin directories that we want to search when loading. 325 // Extra plugin directories that we want to search when loading.
308 std::vector<FilePath> extra_plugin_dirs_; 326 std::vector<FilePath> extra_plugin_dirs_;
309 327
310 struct InternalPlugin { 328 struct InternalPlugin {
311 WebPluginInfo info; 329 WebPluginInfo info;
312 PluginEntryPoints entry_points; 330 PluginEntryPoints entry_points;
313 }; 331 };
314 // Holds information about internal plugins. 332 // Holds information about internal plugins.
315 std::vector<InternalPlugin> internal_plugins_; 333 std::vector<InternalPlugin> internal_plugins_;
316 334
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_; 335 bool disable_outdated_plugins_;
324 336
325 // Holds the currently available plugin groups.
326 PluginGroup::PluginMap plugin_groups_;
327
328 int next_priority_;
329
330 // Need synchronization for the above members since this object can be 337 // Need synchronization for the above members since this object can be
331 // accessed on multiple threads. 338 // accessed on multiple threads.
332 base::Lock lock_; 339 base::Lock lock_;
333 340
334 friend struct base::DefaultLazyInstanceTraits<PluginList>; 341 friend struct base::DefaultLazyInstanceTraits<PluginList>;
335 342
336 DISALLOW_COPY_AND_ASSIGN(PluginList); 343 DISALLOW_COPY_AND_ASSIGN(PluginList);
337 }; 344 };
338 345
339 } // namespace npapi 346 } // namespace npapi
340 } // namespace webkit 347 } // namespace webkit
341 348
342 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ 349 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698