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 CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ | 5 #ifndef CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ |
6 #define CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ | 6 #define CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "content/public/common/pepper_plugin_info.h" | 11 #include "content/public/common/pepper_plugin_info.h" |
12 #include "webkit/plugins/ppapi/plugin_delegate.h" | 12 #include "webkit/plugins/ppapi/plugin_delegate.h" |
13 | 13 |
| 14 namespace content { |
| 15 |
14 // Constructs a PepperPluginInfo from a WebPluginInfo. Returns false if | 16 // Constructs a PepperPluginInfo from a WebPluginInfo. Returns false if |
15 // the operation is not possible, in particular the WebPluginInfo::type | 17 // the operation is not possible, in particular the WebPluginInfo::type |
16 // must be one of the pepper types. | 18 // must be one of the pepper types. |
17 bool MakePepperPluginInfo(const webkit::WebPluginInfo& webplugin_info, | 19 bool MakePepperPluginInfo(const webkit::WebPluginInfo& webplugin_info, |
18 content::PepperPluginInfo* pepper_info); | 20 PepperPluginInfo* pepper_info); |
19 | 21 |
20 // This class holds references to all of the known pepper plugin modules. | 22 // This class holds references to all of the known pepper plugin modules. |
21 // | 23 // |
22 // It keeps two lists. One list of preloaded in-process modules, and one list | 24 // It keeps two lists. One list of preloaded in-process modules, and one list |
23 // is a list of all live modules (some of which may be out-of-process and hence | 25 // is a list of all live modules (some of which may be out-of-process and hence |
24 // not preloaded). | 26 // not preloaded). |
25 class PepperPluginRegistry | 27 class PepperPluginRegistry |
26 : public webkit::ppapi::PluginDelegate::ModuleLifetime { | 28 : public webkit::ppapi::PluginDelegate::ModuleLifetime { |
27 public: | 29 public: |
28 ~PepperPluginRegistry(); | 30 ~PepperPluginRegistry(); |
29 | 31 |
30 static PepperPluginRegistry* GetInstance(); | 32 static PepperPluginRegistry* GetInstance(); |
31 | 33 |
32 // Computes the list of known pepper plugins. | 34 // Computes the list of known pepper plugins. |
33 // | 35 // |
34 // This method is static so that it can be used by the browser process, which | 36 // This method is static so that it can be used by the browser process, which |
35 // has no need to load the pepper plugin modules. It will re-compute the | 37 // has no need to load the pepper plugin modules. It will re-compute the |
36 // plugin list every time it is called. Generally, code in the registry should | 38 // plugin list every time it is called. Generally, code in the registry should |
37 // be using the cached plugin_list_ instead. | 39 // be using the cached plugin_list_ instead. |
38 CONTENT_EXPORT static void ComputeList( | 40 CONTENT_EXPORT static void ComputeList( |
39 std::vector<content::PepperPluginInfo>* plugins); | 41 std::vector<PepperPluginInfo>* plugins); |
40 | 42 |
41 // Loads the (native) libraries but does not initialize them (i.e., does not | 43 // Loads the (native) libraries but does not initialize them (i.e., does not |
42 // call PPP_InitializeModule). This is needed by the zygote on Linux to get | 44 // call PPP_InitializeModule). This is needed by the zygote on Linux to get |
43 // access to the plugins before entering the sandbox. | 45 // access to the plugins before entering the sandbox. |
44 static void PreloadModules(); | 46 static void PreloadModules(); |
45 | 47 |
46 // Retrieves the information associated with the given plugin info. The | 48 // Retrieves the information associated with the given plugin info. The |
47 // return value will be NULL if there is no such plugin. | 49 // return value will be NULL if there is no such plugin. |
48 // | 50 // |
49 // The returned pointer is owned by the PluginRegistry. | 51 // The returned pointer is owned by the PluginRegistry. |
50 const content::PepperPluginInfo* GetInfoForPlugin( | 52 const PepperPluginInfo* GetInfoForPlugin(const webkit::WebPluginInfo& info); |
51 const webkit::WebPluginInfo& info); | |
52 | 53 |
53 // Returns an existing loaded module for the given path. It will search for | 54 // Returns an existing loaded module for the given path. It will search for |
54 // both preloaded in-process or currently active (non crashed) out-of-process | 55 // both preloaded in-process or currently active (non crashed) out-of-process |
55 // plugins matching the given name. Returns NULL if the plugin hasn't been | 56 // plugins matching the given name. Returns NULL if the plugin hasn't been |
56 // loaded. | 57 // loaded. |
57 webkit::ppapi::PluginModule* GetLiveModule(const FilePath& path); | 58 webkit::ppapi::PluginModule* GetLiveModule(const FilePath& path); |
58 | 59 |
59 // Notifies the registry that a new non-preloaded module has been created. | 60 // Notifies the registry that a new non-preloaded module has been created. |
60 // This is normally called for out-of-process plugins. Once this is called, | 61 // This is normally called for out-of-process plugins. Once this is called, |
61 // the module is available to be returned by GetModule(). The module will | 62 // the module is available to be returned by GetModule(). The module will |
62 // automatically unregister itself by calling PluginModuleDestroyed(). | 63 // automatically unregister itself by calling PluginModuleDestroyed(). |
63 void AddLiveModule(const FilePath& path, webkit::ppapi::PluginModule* module); | 64 void AddLiveModule(const FilePath& path, webkit::ppapi::PluginModule* module); |
64 | 65 |
65 // ModuleLifetime implementation. | 66 // ModuleLifetime implementation. |
66 virtual void PluginModuleDead( | 67 virtual void PluginModuleDead( |
67 webkit::ppapi::PluginModule* dead_module) OVERRIDE; | 68 webkit::ppapi::PluginModule* dead_module) OVERRIDE; |
68 | 69 |
69 private: | 70 private: |
70 PepperPluginRegistry(); | 71 PepperPluginRegistry(); |
71 | 72 |
72 // All known pepper plugins. | 73 // All known pepper plugins. |
73 std::vector<content::PepperPluginInfo> plugin_list_; | 74 std::vector<PepperPluginInfo> plugin_list_; |
74 | 75 |
75 // Plugins that have been preloaded so they can be executed in-process in | 76 // Plugins that have been preloaded so they can be executed in-process in |
76 // the renderer (the sandbox prevents on-demand loading). | 77 // the renderer (the sandbox prevents on-demand loading). |
77 typedef std::map<FilePath, scoped_refptr<webkit::ppapi::PluginModule> > | 78 typedef std::map<FilePath, scoped_refptr<webkit::ppapi::PluginModule> > |
78 OwningModuleMap; | 79 OwningModuleMap; |
79 OwningModuleMap preloaded_modules_; | 80 OwningModuleMap preloaded_modules_; |
80 | 81 |
81 // A list of non-owning pointers to all currently-live plugin modules. This | 82 // A list of non-owning pointers to all currently-live plugin modules. This |
82 // includes both preloaded ones in preloaded_modules_, and out-of-process | 83 // includes both preloaded ones in preloaded_modules_, and out-of-process |
83 // modules whose lifetime is managed externally. This will contain only | 84 // modules whose lifetime is managed externally. This will contain only |
84 // non-crashed modules. If an out-of-process module crashes, it may | 85 // non-crashed modules. If an out-of-process module crashes, it may |
85 // continue as long as there are WebKit references to it, but it will not | 86 // continue as long as there are WebKit references to it, but it will not |
86 // appear in this list. | 87 // appear in this list. |
87 typedef std::map<FilePath, webkit::ppapi::PluginModule*> NonOwningModuleMap; | 88 typedef std::map<FilePath, webkit::ppapi::PluginModule*> NonOwningModuleMap; |
88 NonOwningModuleMap live_modules_; | 89 NonOwningModuleMap live_modules_; |
89 | 90 |
90 DISALLOW_COPY_AND_ASSIGN(PepperPluginRegistry); | 91 DISALLOW_COPY_AND_ASSIGN(PepperPluginRegistry); |
91 }; | 92 }; |
92 | 93 |
| 94 } // namespace content |
| 95 |
93 #endif // CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ | 96 #endif // CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ |
OLD | NEW |