OLD | NEW |
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 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> |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // If |use_stale| is NULL, this will load the plug-in list if necessary. | 141 // If |use_stale| is NULL, this will load the plug-in list if necessary. |
142 // If it is not NULL, the plug-in list will not be loaded, and |*use_stale| | 142 // If it is not NULL, the plug-in list will not be loaded, and |*use_stale| |
143 // will be true iff the plug-in list was stale. | 143 // will be true iff the plug-in list was stale. |
144 void GetPluginInfoArray(const GURL& url, | 144 void GetPluginInfoArray(const GURL& url, |
145 const std::string& mime_type, | 145 const std::string& mime_type, |
146 bool allow_wildcard, | 146 bool allow_wildcard, |
147 bool* use_stale, | 147 bool* use_stale, |
148 std::vector<webkit::WebPluginInfo>* info, | 148 std::vector<webkit::WebPluginInfo>* info, |
149 std::vector<std::string>* actual_mime_types); | 149 std::vector<std::string>* actual_mime_types); |
150 | 150 |
| 151 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
151 // Populates the given vector with all available plugin groups. If | 152 // Populates the given vector with all available plugin groups. If |
152 // |load_if_necessary| is true, this will potentially load the plugin list | 153 // |load_if_necessary| is true, this will potentially load the plugin list |
153 // synchronously. | 154 // synchronously. |
154 void GetPluginGroups(bool load_if_necessary, | 155 void GetPluginGroups(bool load_if_necessary, |
155 std::vector<PluginGroup>* plugin_groups); | 156 std::vector<PluginGroup>* plugin_groups); |
156 | 157 |
| 158 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
157 // Returns a copy of the PluginGroup corresponding to the given WebPluginInfo. | 159 // Returns a copy of the PluginGroup corresponding to the given WebPluginInfo. |
158 // The caller takes ownership of the returned PluginGroup. | 160 // The caller takes ownership of the returned PluginGroup. |
159 PluginGroup* GetPluginGroup(const webkit::WebPluginInfo& web_plugin_info); | 161 PluginGroup* GetPluginGroup(const webkit::WebPluginInfo& web_plugin_info); |
160 | 162 |
| 163 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
161 // Returns the name of the PluginGroup with the given identifier. | 164 // Returns the name of the PluginGroup with the given identifier. |
162 // If no such group exists, an empty string is returned. | 165 // If no such group exists, an empty string is returned. |
163 string16 GetPluginGroupName(const std::string& identifier); | 166 string16 GetPluginGroupName(const std::string& identifier); |
164 | 167 |
| 168 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
165 // Load a specific plugin with full path. Return true iff loading the plug-in | 169 // Load a specific plugin with full path. Return true iff loading the plug-in |
166 // was successful. | 170 // was successful. |
167 bool LoadPlugin(const FilePath& filename, | 171 bool LoadPlugin(const FilePath& filename, |
168 ScopedVector<PluginGroup>* plugin_groups, | 172 ScopedVector<PluginGroup>* plugin_groups, |
169 webkit::WebPluginInfo* plugin_info); | 173 webkit::WebPluginInfo* plugin_info); |
170 | 174 |
| 175 // Load a specific plugin with full path. Return true iff loading the plug-in |
| 176 // was successful. |
| 177 bool LoadPluginIntoPluginList(const FilePath& filename, |
| 178 std::vector<webkit::WebPluginInfo>* plugins, |
| 179 webkit::WebPluginInfo* plugin_info); |
| 180 |
171 // The following functions are used to support probing for WebPluginInfo | 181 // The following functions are used to support probing for WebPluginInfo |
172 // using a different instance of this class. | 182 // using a different instance of this class. |
173 | 183 |
174 // Computes a list of all plugins to potentially load from all sources. | 184 // Computes a list of all plugins to potentially load from all sources. |
175 void GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths); | 185 void GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths); |
176 | 186 |
| 187 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
177 // Returns the list of hardcoded plug-in groups for testing. | 188 // Returns the list of hardcoded plug-in groups for testing. |
178 const std::vector<PluginGroup*>& GetHardcodedPluginGroups() const; | 189 const std::vector<PluginGroup*>& GetHardcodedPluginGroups() const; |
179 | 190 |
180 // Clears the internal list of PluginGroups and copies them from the vector. | 191 // Clears the internal list of PluginGroups and copies them from the vector. |
181 void SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins); | 192 void SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins); |
182 | 193 |
183 void set_will_load_plugins_callback(const base::Closure& callback); | 194 void set_will_load_plugins_callback(const base::Closure& callback); |
184 | 195 |
185 virtual ~PluginList(); | 196 virtual ~PluginList(); |
186 | 197 |
187 protected: | 198 protected: |
| 199 // TODO(ibraaaa): DELETE and add a different one. http://crbug.com/124396 |
188 // This constructor is used in unit tests to override the platform-dependent | 200 // This constructor is used in unit tests to override the platform-dependent |
189 // real-world plugin group definitions with custom ones. | 201 // real-world plugin group definitions with custom ones. |
190 PluginList(const PluginGroupDefinition* definitions, size_t num_definitions); | 202 PluginList(const PluginGroupDefinition* definitions, size_t num_definitions); |
191 | 203 |
| 204 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
192 // Adds the given WebPluginInfo to its corresponding group, creating it if | 205 // Adds the given WebPluginInfo to its corresponding group, creating it if |
193 // necessary, and returns the group. | 206 // necessary, and returns the group. |
194 PluginGroup* AddToPluginGroups(const webkit::WebPluginInfo& web_plugin_info, | 207 PluginGroup* AddToPluginGroups(const webkit::WebPluginInfo& web_plugin_info, |
195 ScopedVector<PluginGroup>* plugin_groups); | 208 ScopedVector<PluginGroup>* plugin_groups); |
196 | 209 |
197 private: | 210 private: |
198 enum LoadingState { | 211 enum LoadingState { |
199 LOADING_STATE_NEEDS_REFRESH, | 212 LOADING_STATE_NEEDS_REFRESH, |
200 LOADING_STATE_REFRESHING, | 213 LOADING_STATE_REFRESHING, |
201 LOADING_STATE_UP_TO_DATE, | 214 LOADING_STATE_UP_TO_DATE, |
202 }; | 215 }; |
203 | 216 |
204 struct InternalPlugin { | 217 struct InternalPlugin { |
205 webkit::WebPluginInfo info; | 218 webkit::WebPluginInfo info; |
206 PluginEntryPoints entry_points; | 219 PluginEntryPoints entry_points; |
207 }; | 220 }; |
208 | 221 |
209 friend class PluginListTest; | 222 friend class PluginListTest; |
210 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 223 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
211 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | 224 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); |
212 | 225 |
213 // Constructors are private for singletons. | 226 // Constructors are private for singletons. |
214 PluginList(); | 227 PluginList(); |
215 | 228 |
| 229 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
216 // Creates PluginGroups for the hardcoded group definitions, and stores them | 230 // Creates PluginGroups for the hardcoded group definitions, and stores them |
217 // in |hardcoded_plugin_groups_|. | 231 // in |hardcoded_plugin_groups_|. |
218 void AddHardcodedPluginGroups(const PluginGroupDefinition* group_definitions, | 232 void AddHardcodedPluginGroups(const PluginGroupDefinition* group_definitions, |
219 size_t num_group_definitions); | 233 size_t num_group_definitions); |
220 | 234 |
| 235 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
221 // Creates a new PluginGroup either from a hardcoded group definition, or from | 236 // Creates a new PluginGroup either from a hardcoded group definition, or from |
222 // the plug-in information. | 237 // the plug-in information. |
223 // Caller takes ownership of the returned PluginGroup. | 238 // Caller takes ownership of the returned PluginGroup. |
224 PluginGroup* CreatePluginGroup( | 239 PluginGroup* CreatePluginGroup( |
225 const webkit::WebPluginInfo& web_plugin_info) const; | 240 const webkit::WebPluginInfo& web_plugin_info) const; |
226 | 241 |
227 // Implements all IO dependent operations of the LoadPlugins method so that | 242 // Implements all IO dependent operations of the LoadPlugins method so that |
228 // test classes can mock these out. | 243 // test classes can mock these out. |
229 virtual void LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups); | 244 virtual void LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups); |
230 | 245 |
| 246 // Implements all IO dependent operations of the LoadPlugins method so that |
| 247 // test classes can mock these out. |
| 248 virtual void LoadPluginsIntoPluginListInternal( |
| 249 std::vector<webkit::WebPluginInfo>* plugins); |
| 250 |
231 // Load all plugins from the default plugins directory. | 251 // Load all plugins from the default plugins directory. |
232 void LoadPlugins(); | 252 void LoadPlugins(); |
233 | 253 |
234 // Walks a directory and produces a list of all the plugins to potentially | 254 // Walks a directory and produces a list of all the plugins to potentially |
235 // load in that directory. | 255 // load in that directory. |
236 void GetPluginsInDir(const FilePath& path, std::vector<FilePath>* plugins); | 256 void GetPluginsInDir(const FilePath& path, std::vector<FilePath>* plugins); |
237 | 257 |
| 258 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
238 // Returns true if we should load the given plugin, or false otherwise. | 259 // Returns true if we should load the given plugin, or false otherwise. |
239 // |plugins| is the list of plugins we have crawled in the current plugin | 260 // |plugins| is the list of plugins we have crawled in the current plugin |
240 // loading run. | 261 // loading run. |
241 bool ShouldLoadPlugin(const webkit::WebPluginInfo& info, | 262 bool ShouldLoadPlugin(const webkit::WebPluginInfo& info, |
242 ScopedVector<PluginGroup>* plugins); | 263 ScopedVector<PluginGroup>* plugins); |
243 | 264 |
| 265 // Returns true if we should load the given plugin, or false otherwise. |
| 266 // |plugins| is the list of plugins we have crawled in the current plugin |
| 267 // loading run. |
| 268 bool ShouldLoadPluginUsingPluginList( |
| 269 const webkit::WebPluginInfo& info, |
| 270 std::vector<webkit::WebPluginInfo>* plugins); |
| 271 |
244 // Returns true if the plugin supports |mime_type|. |mime_type| should be all | 272 // Returns true if the plugin supports |mime_type|. |mime_type| should be all |
245 // lower case. | 273 // lower case. |
246 bool SupportsType(const webkit::WebPluginInfo& plugin, | 274 bool SupportsType(const webkit::WebPluginInfo& plugin, |
247 const std::string& mime_type, | 275 const std::string& mime_type, |
248 bool allow_wildcard); | 276 bool allow_wildcard); |
249 | 277 |
250 // Returns true if the given plugin supports a given file extension. | 278 // Returns true if the given plugin supports a given file extension. |
251 // |extension| should be all lower case. If |mime_type| is not NULL, it will | 279 // |extension| should be all lower case. If |mime_type| is not NULL, it will |
252 // be set to the MIME type if found. The MIME type which corresponds to the | 280 // be set to the MIME type if found. The MIME type which corresponds to the |
253 // extension is optionally returned back. | 281 // extension is optionally returned back. |
254 bool SupportsExtension(const webkit::WebPluginInfo& plugin, | 282 bool SupportsExtension(const webkit::WebPluginInfo& plugin, |
255 const std::string& extension, | 283 const std::string& extension, |
256 std::string* actual_mime_type); | 284 std::string* actual_mime_type); |
257 | 285 |
| 286 // Removes a plug-in from |plugins_list_| by its path. |
| 287 static bool RemovePlugin(const FilePath& filename, |
| 288 std::vector<webkit::WebPluginInfo>* plugins); |
| 289 |
258 // | 290 // |
259 // Platform functions | 291 // Platform functions |
260 // | 292 // |
261 | 293 |
262 // Do any initialization. | 294 // Do any initialization. |
263 void PlatformInit(); | 295 void PlatformInit(); |
264 | 296 |
265 // | 297 // |
266 // Command-line switches | 298 // Command-line switches |
267 // | 299 // |
(...skipping 18 matching lines...) Expand all Loading... |
286 | 318 |
287 // Extra plugin paths that we want to search when loading. | 319 // Extra plugin paths that we want to search when loading. |
288 std::vector<FilePath> extra_plugin_paths_; | 320 std::vector<FilePath> extra_plugin_paths_; |
289 | 321 |
290 // Extra plugin directories that we want to search when loading. | 322 // Extra plugin directories that we want to search when loading. |
291 std::vector<FilePath> extra_plugin_dirs_; | 323 std::vector<FilePath> extra_plugin_dirs_; |
292 | 324 |
293 // Holds information about internal plugins. | 325 // Holds information about internal plugins. |
294 std::vector<InternalPlugin> internal_plugins_; | 326 std::vector<InternalPlugin> internal_plugins_; |
295 | 327 |
| 328 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
296 // Holds the currently available plugin groups. | 329 // Holds the currently available plugin groups. |
297 ScopedVector<PluginGroup> plugin_groups_; | 330 ScopedVector<PluginGroup> plugin_groups_; |
298 | 331 |
299 // Holds the hardcoded definitions of well-known plug-ins. | 332 // Holds the hardcoded definitions of well-known plug-ins. |
300 // This should only be modified during construction of the PluginList. | 333 // This should only be modified during construction of the PluginList. |
301 ScopedVector<PluginGroup> hardcoded_plugin_groups_; | 334 ScopedVector<PluginGroup> hardcoded_plugin_groups_; |
302 | 335 |
| 336 // A list holding all plug-ins. |
| 337 std::vector<webkit::WebPluginInfo> plugins_list_; |
| 338 |
303 // Callback that is invoked whenever the PluginList will reload the plugins. | 339 // Callback that is invoked whenever the PluginList will reload the plugins. |
304 base::Closure will_load_plugins_callback_; | 340 base::Closure will_load_plugins_callback_; |
305 | 341 |
306 // Need synchronization for the above members since this object can be | 342 // Need synchronization for the above members since this object can be |
307 // accessed on multiple threads. | 343 // accessed on multiple threads. |
308 base::Lock lock_; | 344 base::Lock lock_; |
309 | 345 |
310 DISALLOW_COPY_AND_ASSIGN(PluginList); | 346 DISALLOW_COPY_AND_ASSIGN(PluginList); |
311 }; | 347 }; |
312 | 348 |
313 } // namespace npapi | 349 } // namespace npapi |
314 } // namespace webkit | 350 } // namespace webkit |
315 | 351 |
316 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 352 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
OLD | NEW |