OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "third_party/npapi/bindings/nphostapi.h" | 18 #include "third_party/npapi/bindings/nphostapi.h" |
19 #include "webkit/plugins/npapi/plugin_group.h" | 19 #include "webkit/plugins/npapi/plugin_group.h" |
20 #include "webkit/plugins/npapi/webplugininfo.h" | 20 #include "webkit/plugins/webplugininfo.h" |
21 | 21 |
22 class GURL; | 22 class GURL; |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 | 25 |
26 template <typename T> | 26 template <typename T> |
27 struct DefaultLazyInstanceTraits; | 27 struct DefaultLazyInstanceTraits; |
28 | 28 |
29 } // namespace base | 29 } // namespace base |
30 | 30 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 // Same as above, but specifies a directory in which to search for plugins. | 74 // Same as above, but specifies a directory in which to search for plugins. |
75 void AddExtraPluginDir(const FilePath& plugin_dir); | 75 void AddExtraPluginDir(const FilePath& plugin_dir); |
76 | 76 |
77 // Get the ordered list of directories from which to load plugins | 77 // Get the ordered list of directories from which to load plugins |
78 void GetPluginDirectories(std::vector<FilePath>* plugin_dirs); | 78 void GetPluginDirectories(std::vector<FilePath>* plugin_dirs); |
79 | 79 |
80 // Register an internal plugin with the specified plugin information. | 80 // Register an internal plugin with the specified plugin information. |
81 // An internal plugin must be registered before it can | 81 // An internal plugin must be registered before it can |
82 // be loaded using PluginList::LoadPlugin(). | 82 // be loaded using PluginList::LoadPlugin(). |
83 void RegisterInternalPlugin(const WebPluginInfo& info); | 83 void RegisterInternalPlugin(const webkit::WebPluginInfo& info); |
84 | 84 |
85 // This second version is for "plugins" that have been compiled | 85 // This second version is for "plugins" that have been compiled |
86 // directly into the binary -- callers must provide the metadata and | 86 // directly into the binary -- callers must provide the metadata and |
87 // the entry points. | 87 // the entry points. |
88 // TODO(evan): we use file names here, but they're not really files, they're | 88 // TODO(evan): we use file names here, but they're not really files, they're |
89 // actually a string that uniquely identifies the plugin. | 89 // actually a string that uniquely identifies the plugin. |
90 void RegisterInternalPlugin(const FilePath& filename, | 90 void RegisterInternalPlugin(const FilePath& filename, |
91 const std::string& name, | 91 const std::string& name, |
92 const std::string& description, | 92 const std::string& description, |
93 const std::string& mime_type, | 93 const std::string& mime_type, |
94 const PluginEntryPoints& entry_points); | 94 const PluginEntryPoints& entry_points); |
95 | 95 |
96 // Removes a specified internal plugin from the list. The search will match | 96 // Removes a specified internal plugin from the list. The search will match |
97 // on the path from the version info previously registered. | 97 // on the path from the version info previously registered. |
98 // | 98 // |
99 // This is generally only necessary for tests. | 99 // This is generally only necessary for tests. |
100 void UnregisterInternalPlugin(const FilePath& path); | 100 void UnregisterInternalPlugin(const FilePath& path); |
101 | 101 |
102 // Creates a WebPluginInfo structure given a plugin's path. On success | 102 // Creates a WebPluginInfo structure given a plugin's path. On success |
103 // returns true, with the information being put into "info". If it's an | 103 // returns true, with the information being put into "info". If it's an |
104 // internal plugin, "entry_points" is filled in as well with a | 104 // internal plugin, "entry_points" is filled in as well with a |
105 // internally-owned PluginEntryPoints pointer. | 105 // internally-owned PluginEntryPoints pointer. |
106 // Returns false if the library couldn't be found, or if it's not a plugin. | 106 // Returns false if the library couldn't be found, or if it's not a plugin. |
107 bool ReadPluginInfo(const FilePath& filename, | 107 bool ReadPluginInfo(const FilePath& filename, |
108 WebPluginInfo* info, | 108 webkit::WebPluginInfo* info, |
109 const PluginEntryPoints** entry_points); | 109 const PluginEntryPoints** entry_points); |
110 | 110 |
111 // In Windows plugins, the mime types are passed as a specially formatted list | 111 // In Windows plugins, the mime types are passed as a specially formatted list |
112 // of strings. This function parses those strings into a WebPluginMimeType | 112 // of strings. This function parses those strings into a WebPluginMimeType |
113 // vector. | 113 // vector. |
114 // TODO(evan): move this code into plugin_list_win. | 114 // TODO(evan): move this code into plugin_list_win. |
115 static bool ParseMimeTypes(const std::string& mime_types, | 115 static bool ParseMimeTypes( |
116 const std::string& file_extensions, | 116 const std::string& mime_types, |
117 const string16& mime_type_descriptions, | 117 const std::string& file_extensions, |
118 std::vector<WebPluginMimeType>* parsed_mime_types); | 118 const string16& mime_type_descriptions, |
| 119 std::vector<webkit::WebPluginMimeType>* parsed_mime_types); |
119 | 120 |
120 // Get all the plugins. | 121 // Get all the plugins. |
121 void GetPlugins(std::vector<WebPluginInfo>* plugins); | 122 void GetPlugins(std::vector<webkit::WebPluginInfo>* plugins); |
122 | 123 |
123 // Returns a list in |info| containing plugins that are found for | 124 // Returns a list in |info| containing plugins that are found for |
124 // the given url and mime type (including disabled plugins, for | 125 // the given url and mime type (including disabled plugins, for |
125 // which |info->enabled| is false). The mime type which corresponds | 126 // which |info->enabled| is false). The mime type which corresponds |
126 // to the URL is optionally returned back in |actual_mime_types| (if | 127 // to the URL is optionally returned back in |actual_mime_types| (if |
127 // it is non-NULL), one for each of the plugin info objects found. | 128 // it is non-NULL), one for each of the plugin info objects found. |
128 // The |allow_wildcard| parameter controls whether this function | 129 // The |allow_wildcard| parameter controls whether this function |
129 // returns plugins which support wildcard mime types (* as the mime | 130 // returns plugins which support wildcard mime types (* as the mime |
130 // type). The |info| parameter is required to be non-NULL. The | 131 // type). The |info| parameter is required to be non-NULL. The |
131 // list is in order of "most desirable" to "least desirable", | 132 // list is in order of "most desirable" to "least desirable", |
132 // meaning that the default plugin is at the end of the list. | 133 // meaning that the default plugin is at the end of the list. |
133 // If |use_stale| is NULL, this will load the plug-in list if necessary. | 134 // If |use_stale| is NULL, this will load the plug-in list if necessary. |
134 // If it is not NULL, the plug-in list will not be loaded, and |*use_stale| | 135 // If it is not NULL, the plug-in list will not be loaded, and |*use_stale| |
135 // will be true iff the plug-in list was stale. | 136 // will be true iff the plug-in list was stale. |
136 void GetPluginInfoArray(const GURL& url, | 137 void GetPluginInfoArray(const GURL& url, |
137 const std::string& mime_type, | 138 const std::string& mime_type, |
138 bool allow_wildcard, | 139 bool allow_wildcard, |
139 bool* use_stale, | 140 bool* use_stale, |
140 std::vector<WebPluginInfo>* info, | 141 std::vector<webkit::WebPluginInfo>* info, |
141 std::vector<std::string>* actual_mime_types); | 142 std::vector<std::string>* actual_mime_types); |
142 | 143 |
143 // Get plugin info by plugin path (including disabled plugins). Returns true | 144 // Get plugin info by plugin path (including disabled plugins). Returns true |
144 // if the plugin is found and WebPluginInfo has been filled in |info|. | 145 // if the plugin is found and WebPluginInfo has been filled in |info|. |
145 bool GetPluginInfoByPath(const FilePath& plugin_path, | 146 bool GetPluginInfoByPath(const FilePath& plugin_path, |
146 WebPluginInfo* info); | 147 webkit::WebPluginInfo* info); |
147 | 148 |
148 // Populates the given vector with all available plugin groups. | 149 // Populates the given vector with all available plugin groups. |
149 void GetPluginGroups(bool load_if_necessary, | 150 void GetPluginGroups(bool load_if_necessary, |
150 std::vector<PluginGroup>* plugin_groups); | 151 std::vector<PluginGroup>* plugin_groups); |
151 | 152 |
152 // Returns the PluginGroup corresponding to the given WebPluginInfo. If no | 153 // Returns the PluginGroup corresponding to the given WebPluginInfo. If no |
153 // such group exists, it is created and added to the cache. | 154 // such group exists, it is created and added to the cache. |
154 // Beware: when calling this from the Browser process, the group that the | 155 // Beware: when calling this from the Browser process, the group that the |
155 // returned pointer points to might disappear suddenly. This happens when | 156 // returned pointer points to might disappear suddenly. This happens when |
156 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a | 157 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a |
157 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, | 158 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, |
158 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's | 159 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's |
159 // responsibility to make sure this doesn't happen. | 160 // responsibility to make sure this doesn't happen. |
160 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info); | 161 const PluginGroup* GetPluginGroup( |
| 162 const webkit::WebPluginInfo& web_plugin_info); |
161 | 163 |
162 // Returns the name of the PluginGroup with the given identifier. | 164 // Returns the name of the PluginGroup with the given identifier. |
163 // If no such group exists, an empty string is returned. | 165 // If no such group exists, an empty string is returned. |
164 string16 GetPluginGroupName(const std::string& identifier); | 166 string16 GetPluginGroupName(const std::string& identifier); |
165 | 167 |
166 // Returns the identifier string of the PluginGroup corresponding to the given | 168 // Returns the identifier string of the PluginGroup corresponding to the given |
167 // WebPluginInfo. If no such group exists, it is created and added to the | 169 // WebPluginInfo. If no such group exists, it is created and added to the |
168 // cache. | 170 // cache. |
169 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); | 171 std::string GetPluginGroupIdentifier( |
| 172 const webkit::WebPluginInfo& web_plugin_info); |
170 | 173 |
171 // Load a specific plugin with full path. | 174 // Load a specific plugin with full path. |
172 void LoadPlugin(const FilePath& filename, | 175 void LoadPlugin(const FilePath& filename, |
173 ScopedVector<PluginGroup>* plugin_groups); | 176 ScopedVector<PluginGroup>* plugin_groups); |
174 | 177 |
175 // Enable a specific plugin, specified by path. Returns |true| iff a plugin | 178 // Enable a specific plugin, specified by path. Returns |true| iff a plugin |
176 // currently in the plugin list was actually enabled as a result; regardless | 179 // currently in the plugin list was actually enabled as a result; regardless |
177 // of return value, if a plugin is found in the future with the given name, it | 180 // of return value, if a plugin is found in the future with the given name, it |
178 // will be enabled. | 181 // will be enabled. |
179 bool EnablePlugin(const FilePath& filename); | 182 bool EnablePlugin(const FilePath& filename); |
(...skipping 19 matching lines...) Expand all Loading... |
199 virtual ~PluginList(); | 202 virtual ~PluginList(); |
200 | 203 |
201 protected: | 204 protected: |
202 // This constructor is used in unit tests to override the platform-dependent | 205 // This constructor is used in unit tests to override the platform-dependent |
203 // real-world plugin group definitions with custom ones. | 206 // real-world plugin group definitions with custom ones. |
204 PluginList(const PluginGroupDefinition* definitions, size_t num_definitions); | 207 PluginList(const PluginGroupDefinition* definitions, size_t num_definitions); |
205 | 208 |
206 // Adds the given WebPluginInfo to its corresponding group, creating it if | 209 // Adds the given WebPluginInfo to its corresponding group, creating it if |
207 // necessary, and returns the group. | 210 // necessary, and returns the group. |
208 // Callers need to protect calls to this method by a lock themselves. | 211 // Callers need to protect calls to this method by a lock themselves. |
209 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info, | 212 PluginGroup* AddToPluginGroups(const webkit::WebPluginInfo& web_plugin_info, |
210 ScopedVector<PluginGroup>* plugin_groups); | 213 ScopedVector<PluginGroup>* plugin_groups); |
211 | 214 |
212 private: | 215 private: |
213 friend class PluginListTest; | 216 friend class PluginListTest; |
214 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 217 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
215 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | 218 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); |
216 | 219 |
217 // Constructors are private for singletons | 220 // Constructors are private for singletons |
218 PluginList(); | 221 PluginList(); |
219 | 222 |
(...skipping 13 matching lines...) Expand all Loading... |
233 // |plugins| is updated with loaded plugin information. | 236 // |plugins| is updated with loaded plugin information. |
234 // |visited_plugins| is updated with paths to all plugins that were considered | 237 // |visited_plugins| is updated with paths to all plugins that were considered |
235 // (including those we didn't load) | 238 // (including those we didn't load) |
236 void LoadPluginsFromDir(const FilePath& path, | 239 void LoadPluginsFromDir(const FilePath& path, |
237 ScopedVector<PluginGroup>* plugin_groups, | 240 ScopedVector<PluginGroup>* plugin_groups, |
238 std::set<FilePath>* visited_plugins); | 241 std::set<FilePath>* visited_plugins); |
239 | 242 |
240 // Returns true if we should load the given plugin, or false otherwise. | 243 // Returns true if we should load the given plugin, or false otherwise. |
241 // plugins is the list of plugins we have crawled in the current plugin | 244 // plugins is the list of plugins we have crawled in the current plugin |
242 // loading run. | 245 // loading run. |
243 bool ShouldLoadPlugin(const WebPluginInfo& info, | 246 bool ShouldLoadPlugin(const webkit::WebPluginInfo& info, |
244 ScopedVector<PluginGroup>* plugins); | 247 ScopedVector<PluginGroup>* plugins); |
245 | 248 |
246 // Return whether a plug-in group with the given name should be disabled, | 249 // Return whether a plug-in group with the given name should be disabled, |
247 // either because it already is on the list of disabled groups, or because it | 250 // either because it already is on the list of disabled groups, or because it |
248 // is blacklisted by a policy. In the latter case, add the plugin group to the | 251 // is blacklisted by a policy. In the latter case, add the plugin group to the |
249 // list of disabled groups as well. | 252 // list of disabled groups as well. |
250 bool ShouldDisableGroup(const string16& group_name); | 253 bool ShouldDisableGroup(const string16& group_name); |
251 | 254 |
252 // Returns true if the plugin supports |mime_type|. |mime_type| should be all | 255 // Returns true if the plugin supports |mime_type|. |mime_type| should be all |
253 // lower case. | 256 // lower case. |
254 bool SupportsType(const WebPluginInfo& plugin, | 257 bool SupportsType(const webkit::WebPluginInfo& plugin, |
255 const std::string& mime_type, | 258 const std::string& mime_type, |
256 bool allow_wildcard); | 259 bool allow_wildcard); |
257 | 260 |
258 // Returns true if the given plugin supports a given file extension. | 261 // Returns true if the given plugin supports a given file extension. |
259 // |extension| should be all lower case. If |mime_type| is not NULL, it will | 262 // |extension| should be all lower case. If |mime_type| is not NULL, it will |
260 // be set to the MIME type if found. The MIME type which corresponds to the | 263 // be set to the MIME type if found. The MIME type which corresponds to the |
261 // extension is optionally returned back. | 264 // extension is optionally returned back. |
262 bool SupportsExtension(const WebPluginInfo& plugin, | 265 bool SupportsExtension(const webkit::WebPluginInfo& plugin, |
263 const std::string& extension, | 266 const std::string& extension, |
264 std::string* actual_mime_type); | 267 std::string* actual_mime_type); |
265 | 268 |
266 // | 269 // |
267 // Platform functions | 270 // Platform functions |
268 // | 271 // |
269 | 272 |
270 // Do any initialization. | 273 // Do any initialization. |
271 void PlatformInit(); | 274 void PlatformInit(); |
272 | 275 |
(...skipping 18 matching lines...) Expand all Loading... |
291 // If true, we reload plugins even if they've been loaded already. | 294 // If true, we reload plugins even if they've been loaded already. |
292 bool plugins_need_refresh_; | 295 bool plugins_need_refresh_; |
293 | 296 |
294 // Extra plugin paths that we want to search when loading. | 297 // Extra plugin paths that we want to search when loading. |
295 std::vector<FilePath> extra_plugin_paths_; | 298 std::vector<FilePath> extra_plugin_paths_; |
296 | 299 |
297 // Extra plugin directories that we want to search when loading. | 300 // Extra plugin directories that we want to search when loading. |
298 std::vector<FilePath> extra_plugin_dirs_; | 301 std::vector<FilePath> extra_plugin_dirs_; |
299 | 302 |
300 struct InternalPlugin { | 303 struct InternalPlugin { |
301 WebPluginInfo info; | 304 webkit::WebPluginInfo info; |
302 PluginEntryPoints entry_points; | 305 PluginEntryPoints entry_points; |
303 }; | 306 }; |
304 // Holds information about internal plugins. | 307 // Holds information about internal plugins. |
305 std::vector<InternalPlugin> internal_plugins_; | 308 std::vector<InternalPlugin> internal_plugins_; |
306 | 309 |
307 // If set to true outdated plugins are disabled in the end of LoadPlugins. | 310 // If set to true outdated plugins are disabled in the end of LoadPlugins. |
308 bool disable_outdated_plugins_; | 311 bool disable_outdated_plugins_; |
309 | 312 |
310 // Hardcoded plugin group definitions. | 313 // Hardcoded plugin group definitions. |
311 const PluginGroupDefinition* const group_definitions_; | 314 const PluginGroupDefinition* const group_definitions_; |
(...skipping 21 matching lines...) Expand all Loading... |
333 // Set to true if the default plugin is enabled. | 336 // Set to true if the default plugin is enabled. |
334 bool default_plugin_enabled_; | 337 bool default_plugin_enabled_; |
335 | 338 |
336 DISALLOW_COPY_AND_ASSIGN(PluginList); | 339 DISALLOW_COPY_AND_ASSIGN(PluginList); |
337 }; | 340 }; |
338 | 341 |
339 } // namespace npapi | 342 } // namespace npapi |
340 } // namespace webkit | 343 } // namespace webkit |
341 | 344 |
342 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 345 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
OLD | NEW |