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

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

Issue 10918174: Remove PluginGroup (Closed) Base URL: http://git.chromium.org/chromium/src.git@remove_async_plugin_finder
Patch Set: bauerb@ +1 Created 8 years, 3 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
« no previous file with comments | « webkit/plugins/npapi/plugin_group.cc ('k') | webkit/plugins/npapi/plugin_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/lazy_instance.h"
16 #include "base/memory/linked_ptr.h" 17 #include "base/memory/linked_ptr.h"
17 #include "base/memory/scoped_vector.h" 18 #include "base/memory/scoped_vector.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "third_party/npapi/bindings/nphostapi.h" 20 #include "third_party/npapi/bindings/nphostapi.h"
20 #include "webkit/plugins/npapi/plugin_group.h"
21 #include "webkit/plugins/webkit_plugins_export.h" 21 #include "webkit/plugins/webkit_plugins_export.h"
22 #include "webkit/plugins/webplugininfo.h" 22 #include "webkit/plugins/webplugininfo.h"
23 23
24 class GURL; 24 class GURL;
25 25
26 namespace base {
27
28 template <typename T>
29 struct DefaultLazyInstanceTraits;
30
31 } // namespace base
32
33 namespace webkit { 26 namespace webkit {
34 namespace npapi { 27 namespace npapi {
35 28
36 // This struct holds entry points into a plugin. The entry points are 29 // This struct holds entry points into a plugin. The entry points are
37 // slightly different between Win/Mac and Unixes. Note that the interface for 30 // slightly different between Win/Mac and Unixes. Note that the interface for
38 // querying plugins is synchronous and it is preferable to use a higher-level 31 // querying plugins is synchronous and it is preferable to use a higher-level
39 // asynchronous information to query information. 32 // asynchronous information to query information.
40 struct PluginEntryPoints { 33 struct PluginEntryPoints {
41 #if !defined(OS_POSIX) || defined(OS_MACOSX) 34 #if !defined(OS_POSIX) || defined(OS_MACOSX)
42 NP_GetEntryPointsFunc np_getentrypoints; 35 NP_GetEntryPointsFunc np_getentrypoints;
43 #endif 36 #endif
44 NP_InitializeFunc np_initialize; 37 NP_InitializeFunc np_initialize;
45 NP_ShutdownFunc np_shutdown; 38 NP_ShutdownFunc np_shutdown;
46 }; 39 };
47 40
48 // The PluginList is responsible for loading our NPAPI based plugins. It does 41 // The PluginList is responsible for loading our NPAPI based plugins. It does
49 // so in whatever manner is appropriate for the platform. On Windows, it loads 42 // so in whatever manner is appropriate for the platform. On Windows, it loads
50 // plugins from a known directory by looking for DLLs which start with "NP", 43 // plugins from a known directory by looking for DLLs which start with "NP",
51 // and checking to see if they are valid NPAPI libraries. On the Mac, it walks 44 // and checking to see if they are valid NPAPI libraries. On the Mac, it walks
52 // the machine-wide and user plugin directories and loads anything that has 45 // the machine-wide and user plugin directories and loads anything that has
53 // the correct types. On Linux, it walks the plugin directories as well 46 // the correct types. On Linux, it walks the plugin directories as well
54 // (e.g. /usr/lib/browser-plugins/). 47 // (e.g. /usr/lib/browser-plugins/).
55 // This object is thread safe. 48 // This object is thread safe.
56 class WEBKIT_PLUGINS_EXPORT PluginList { 49 class WEBKIT_PLUGINS_EXPORT PluginList {
57 public: 50 public:
51 // Custom traits that performs platform-dependent initialization
52 // when the instance is created.
53 struct CustomLazyInstanceTraits
Bernhard Bauer 2012/09/20 17:03:00 I think you could forward-declare the struct, move
ibraaaa 2012/09/21 09:24:57 If I understand correctly, then you mean: .h file
Bernhard Bauer 2012/09/21 09:33:52 Yes, it will only be forward-declared for other cl
ibraaaa 2012/09/21 09:37:56 yes but the LazyInstance in the .cc file is declar
Bernhard Bauer 2012/09/21 09:53:28 Ah, you meant visible in the 'public'/'private' se
54 : base::DefaultLazyInstanceTraits<PluginList> {
55 static PluginList* New(void* instance);
56 };
57
58 // Gets the one instance of the PluginList. 58 // Gets the one instance of the PluginList.
59 static PluginList* Singleton(); 59 static PluginList* Singleton();
60 60
61 // Returns true if we're in debug-plugin-loading mode. This is controlled 61 // Returns true if we're in debug-plugin-loading mode. This is controlled
62 // by a command line switch. 62 // by a command line switch.
63 static bool DebugPluginLoading(); 63 static bool DebugPluginLoading();
64 64
65 // Cause the plugin list to refresh next time they are accessed, regardless 65 // Cause the plugin list to refresh next time they are accessed, regardless
66 // of whether they are already loaded. 66 // of whether they are already loaded.
67 void RefreshPlugins(); 67 void RefreshPlugins();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
152 // Populates the given vector with all available plugin groups. If
153 // |load_if_necessary| is true, this will potentially load the plugin list
154 // synchronously.
155 void GetPluginGroups(bool load_if_necessary,
156 std::vector<PluginGroup>* plugin_groups);
157
158 // TODO(ibraaaa): DELETE. http://crbug.com/124396
159 // Returns a copy of the PluginGroup corresponding to the given WebPluginInfo.
160 // The caller takes ownership of the returned PluginGroup.
161 PluginGroup* GetPluginGroup(const webkit::WebPluginInfo& web_plugin_info);
162
163 // TODO(ibraaaa): DELETE. http://crbug.com/124396
164 // Returns the name of the PluginGroup with the given identifier.
165 // If no such group exists, an empty string is returned.
166 string16 GetPluginGroupName(const std::string& identifier);
167
168 // TODO(ibraaaa): DELETE. http://crbug.com/124396
169 // Load a specific plugin with full path. Return true iff loading the plug-in
170 // was successful.
171 bool LoadPlugin(const FilePath& filename,
172 ScopedVector<PluginGroup>* plugin_groups,
173 webkit::WebPluginInfo* plugin_info);
174
175 // Load a specific plugin with full path. Return true iff loading the plug-in 151 // Load a specific plugin with full path. Return true iff loading the plug-in
176 // was successful. 152 // was successful.
177 bool LoadPluginIntoPluginList(const FilePath& filename, 153 bool LoadPluginIntoPluginList(const FilePath& filename,
178 std::vector<webkit::WebPluginInfo>* plugins, 154 std::vector<webkit::WebPluginInfo>* plugins,
179 webkit::WebPluginInfo* plugin_info); 155 webkit::WebPluginInfo* plugin_info);
180 156
181 // The following functions are used to support probing for WebPluginInfo 157 // The following functions are used to support probing for WebPluginInfo
182 // using a different instance of this class. 158 // using a different instance of this class.
183 159
184 // Computes a list of all plugins to potentially load from all sources. 160 // Computes a list of all plugins to potentially load from all sources.
185 void GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths); 161 void GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths);
186 162
187 // TODO(ibraaaa): DELETE. http://crbug.com/124396 163 // Clears the internal list of Plugins and copies them from the vector.
188 // Returns the list of hardcoded plug-in groups for testing.
189 const std::vector<PluginGroup*>& GetHardcodedPluginGroups() const;
190
191 // Clears the internal list of PluginGroups and copies them from the vector.
192 void SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins); 164 void SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins);
193 165
194 void set_will_load_plugins_callback(const base::Closure& callback); 166 void set_will_load_plugins_callback(const base::Closure& callback);
195 167
196 virtual ~PluginList(); 168 virtual ~PluginList();
197 169
198 protected: 170 protected:
199 // TODO(ibraaaa): DELETE and add a different one. http://crbug.com/124396 171 // Constructors are private for singletons but we expose this one
200 // This constructor is used in unit tests to override the platform-dependent 172 // for subclasses for test purposes.
201 // real-world plugin group definitions with custom ones. 173 PluginList();
202 PluginList(const PluginGroupDefinition* definitions, size_t num_definitions);
203
204 // TODO(ibraaaa): DELETE. http://crbug.com/124396
205 // Adds the given WebPluginInfo to its corresponding group, creating it if
206 // necessary, and returns the group.
207 PluginGroup* AddToPluginGroups(const webkit::WebPluginInfo& web_plugin_info,
208 ScopedVector<PluginGroup>* plugin_groups);
209 174
210 private: 175 private:
211 enum LoadingState { 176 enum LoadingState {
212 LOADING_STATE_NEEDS_REFRESH, 177 LOADING_STATE_NEEDS_REFRESH,
213 LOADING_STATE_REFRESHING, 178 LOADING_STATE_REFRESHING,
214 LOADING_STATE_UP_TO_DATE, 179 LOADING_STATE_UP_TO_DATE,
215 }; 180 };
216 181
217 struct InternalPlugin { 182 struct InternalPlugin {
218 webkit::WebPluginInfo info; 183 webkit::WebPluginInfo info;
219 PluginEntryPoints entry_points; 184 PluginEntryPoints entry_points;
220 }; 185 };
221 186
222 friend class PluginListTest; 187 friend class PluginListTest;
223 friend struct base::DefaultLazyInstanceTraits<PluginList>; 188 friend struct base::DefaultLazyInstanceTraits<PluginList>;
224 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition);
225
226 // Constructors are private for singletons.
227 PluginList();
228
229 // TODO(ibraaaa): DELETE. http://crbug.com/124396
230 // Creates PluginGroups for the hardcoded group definitions, and stores them
231 // in |hardcoded_plugin_groups_|.
232 void AddHardcodedPluginGroups(const PluginGroupDefinition* group_definitions,
233 size_t num_group_definitions);
234
235 // TODO(ibraaaa): DELETE. http://crbug.com/124396
236 // Creates a new PluginGroup either from a hardcoded group definition, or from
237 // the plug-in information.
238 // Caller takes ownership of the returned PluginGroup.
239 PluginGroup* CreatePluginGroup(
240 const webkit::WebPluginInfo& web_plugin_info) const;
241 189
242 // Implements all IO dependent operations of the LoadPlugins method so that 190 // Implements all IO dependent operations of the LoadPlugins method so that
243 // test classes can mock these out. 191 // test classes can mock these out.
244 virtual void LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups);
245
246 // Implements all IO dependent operations of the LoadPlugins method so that
247 // test classes can mock these out.
248 virtual void LoadPluginsIntoPluginListInternal( 192 virtual void LoadPluginsIntoPluginListInternal(
249 std::vector<webkit::WebPluginInfo>* plugins); 193 std::vector<webkit::WebPluginInfo>* plugins);
250 194
251 // Load all plugins from the default plugins directory. 195 // Load all plugins from the default plugins directory.
252 void LoadPlugins(); 196 void LoadPlugins();
253 197
254 // Walks a directory and produces a list of all the plugins to potentially 198 // Walks a directory and produces a list of all the plugins to potentially
255 // load in that directory. 199 // load in that directory.
256 void GetPluginsInDir(const FilePath& path, std::vector<FilePath>* plugins); 200 void GetPluginsInDir(const FilePath& path, std::vector<FilePath>* plugins);
257 201
258 // TODO(ibraaaa): DELETE. http://crbug.com/124396
259 // Returns true if we should load the given plugin, or false otherwise.
260 // |plugins| is the list of plugins we have crawled in the current plugin
261 // loading run.
262 bool ShouldLoadPlugin(const webkit::WebPluginInfo& info,
263 ScopedVector<PluginGroup>* plugins);
264
265 // Returns true if we should load the given plugin, or false otherwise. 202 // 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 203 // |plugins| is the list of plugins we have crawled in the current plugin
267 // loading run. 204 // loading run.
268 bool ShouldLoadPluginUsingPluginList( 205 bool ShouldLoadPluginUsingPluginList(
269 const webkit::WebPluginInfo& info, 206 const webkit::WebPluginInfo& info,
270 std::vector<webkit::WebPluginInfo>* plugins); 207 std::vector<webkit::WebPluginInfo>* plugins);
271 208
272 // Returns true if the plugin supports |mime_type|. |mime_type| should be all 209 // Returns true if the plugin supports |mime_type|. |mime_type| should be all
273 // lower case. 210 // lower case.
274 bool SupportsType(const webkit::WebPluginInfo& plugin, 211 bool SupportsType(const webkit::WebPluginInfo& plugin,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 255
319 // Extra plugin paths that we want to search when loading. 256 // Extra plugin paths that we want to search when loading.
320 std::vector<FilePath> extra_plugin_paths_; 257 std::vector<FilePath> extra_plugin_paths_;
321 258
322 // Extra plugin directories that we want to search when loading. 259 // Extra plugin directories that we want to search when loading.
323 std::vector<FilePath> extra_plugin_dirs_; 260 std::vector<FilePath> extra_plugin_dirs_;
324 261
325 // Holds information about internal plugins. 262 // Holds information about internal plugins.
326 std::vector<InternalPlugin> internal_plugins_; 263 std::vector<InternalPlugin> internal_plugins_;
327 264
328 // TODO(ibraaaa): DELETE. http://crbug.com/124396
329 // Holds the currently available plugin groups.
330 ScopedVector<PluginGroup> plugin_groups_;
331
332 // Holds the hardcoded definitions of well-known plug-ins.
333 // This should only be modified during construction of the PluginList.
334 ScopedVector<PluginGroup> hardcoded_plugin_groups_;
335
336 // A list holding all plug-ins. 265 // A list holding all plug-ins.
337 std::vector<webkit::WebPluginInfo> plugins_list_; 266 std::vector<webkit::WebPluginInfo> plugins_list_;
338 267
339 // Callback that is invoked whenever the PluginList will reload the plugins. 268 // Callback that is invoked whenever the PluginList will reload the plugins.
340 base::Closure will_load_plugins_callback_; 269 base::Closure will_load_plugins_callback_;
341 270
342 // Need synchronization for the above members since this object can be 271 // Need synchronization for the above members since this object can be
343 // accessed on multiple threads. 272 // accessed on multiple threads.
344 base::Lock lock_; 273 base::Lock lock_;
345 274
346 DISALLOW_COPY_AND_ASSIGN(PluginList); 275 DISALLOW_COPY_AND_ASSIGN(PluginList);
347 }; 276 };
348 277
349 } // namespace npapi 278 } // namespace npapi
350 } // namespace webkit 279 } // namespace webkit
351 280
352 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ 281 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_group.cc ('k') | webkit/plugins/npapi/plugin_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698