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 CHROME_COMMON_PEPPER_PLUGIN_REGISTRY_H_ | 5 #ifndef CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ |
6 #define CHROME_COMMON_PEPPER_PLUGIN_REGISTRY_H_ | 6 #define CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "ppapi/proxy/dispatcher.h" | 15 #include "ppapi/proxy/dispatcher.h" |
16 #include "webkit/plugins/npapi/webplugininfo.h" | 16 #include "webkit/plugins/npapi/webplugininfo.h" |
17 #include "webkit/plugins/ppapi/plugin_delegate.h" | 17 #include "webkit/plugins/ppapi/plugin_delegate.h" |
18 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
19 | 19 |
20 struct PepperPluginInfo { | 20 struct PepperPluginInfo { |
21 PepperPluginInfo(); | 21 PepperPluginInfo(); |
22 ~PepperPluginInfo(); | 22 ~PepperPluginInfo(); |
23 | 23 |
24 webkit::npapi::WebPluginInfo ToWebPluginInfo() const; | 24 webkit::npapi::WebPluginInfo ToWebPluginInfo() const; |
25 | 25 |
26 // Indicates internal plugins for which there's not actually a library. | 26 // Indicates internal plugins for which there's not actually a library. |
27 // These plugins are implemented in the Chrome binary using a separate set | 27 // These plugins are implemented in the Chrome binary using a separate set |
28 // of entry points (see internal_entry_points below). | 28 // of entry points (see internal_entry_points below). |
29 // Defaults to false. | 29 // Defaults to false. |
30 bool is_internal; | 30 bool is_internal; |
31 | 31 |
32 // True when this plugin should be run out of process. Defaults to false. | 32 // True when this plugin should be run out of process. Defaults to false. |
33 bool is_out_of_process; | 33 bool is_out_of_process; |
34 | 34 |
| 35 // Whether the plugin is enabled. Defaults to true. |
| 36 bool enabled; |
| 37 |
35 FilePath path; // Internal plugins have "internal-[name]" as path. | 38 FilePath path; // Internal plugins have "internal-[name]" as path. |
36 std::string name; | 39 std::string name; |
37 std::string description; | 40 std::string description; |
38 std::string version; | 41 std::string version; |
39 std::vector<webkit::npapi::WebPluginMimeType> mime_types; | 42 std::vector<webkit::npapi::WebPluginMimeType> mime_types; |
40 | 43 |
41 // When is_internal is set, this contains the function pointers to the | 44 // When is_internal is set, this contains the function pointers to the |
42 // entry points for the internal plugins. | 45 // entry points for the internal plugins. |
43 webkit::ppapi::PluginModule::EntryPoints internal_entry_points; | 46 webkit::ppapi::PluginModule::EntryPoints internal_entry_points; |
44 }; | 47 }; |
45 | 48 |
46 struct NaClModuleInfo { | |
47 NaClModuleInfo(); | |
48 ~NaClModuleInfo(); | |
49 | |
50 GURL url; | |
51 std::string mime_type; | |
52 }; | |
53 | |
54 // This class holds references to all of the known pepper plugin modules. | 49 // This class holds references to all of the known pepper plugin modules. |
55 // | 50 // |
56 // It keeps two lists. One list of preloaded in-process modules, and one list | 51 // It keeps two lists. One list of preloaded in-process modules, and one list |
57 // is a list of all live modules (some of which may be out-of-process and hence | 52 // is a list of all live modules (some of which may be out-of-process and hence |
58 // not preloaded). | 53 // not preloaded). |
59 class PepperPluginRegistry | 54 class PepperPluginRegistry |
60 : public webkit::ppapi::PluginDelegate::ModuleLifetime, | 55 : public webkit::ppapi::PluginDelegate::ModuleLifetime, |
61 public pp::proxy::Dispatcher::Delegate { | 56 public pp::proxy::Dispatcher::Delegate { |
62 public: | 57 public: |
63 ~PepperPluginRegistry(); | 58 ~PepperPluginRegistry(); |
64 | 59 |
65 static const char* kPDFPluginName; | |
66 | |
67 static PepperPluginRegistry* GetInstance(); | 60 static PepperPluginRegistry* GetInstance(); |
68 | 61 |
69 // Computes the list of known pepper plugins. | 62 // Computes the list of known pepper plugins. |
70 // | 63 // |
71 // This method is static so that it can be used by the browser process, which | 64 // This method is static so that it can be used by the browser process, which |
72 // has no need to load the pepper plugin modules. It will re-compute the | 65 // has no need to load the pepper plugin modules. It will re-compute the |
73 // plugin list every time it is called. Generally, code in the registry should | 66 // plugin list every time it is called. Generally, code in the registry should |
74 // be using the cached plugin_list_ instead. | 67 // be using the cached plugin_list_ instead. |
75 static void ComputeList(std::vector<PepperPluginInfo>* plugins); | 68 static void ComputeList(std::vector<PepperPluginInfo>* plugins); |
76 | 69 |
(...skipping 16 matching lines...) Expand all Loading... |
93 | 86 |
94 // Notifies the registry that a new non-preloaded module has been created. | 87 // Notifies the registry that a new non-preloaded module has been created. |
95 // This is normally called for out-of-process plugins. Once this is called, | 88 // This is normally called for out-of-process plugins. Once this is called, |
96 // the module is available to be returned by GetModule(). The module will | 89 // the module is available to be returned by GetModule(). The module will |
97 // automatically unregister itself by calling PluginModuleDestroyed(). | 90 // automatically unregister itself by calling PluginModuleDestroyed(). |
98 void AddLiveModule(const FilePath& path, webkit::ppapi::PluginModule* module); | 91 void AddLiveModule(const FilePath& path, webkit::ppapi::PluginModule* module); |
99 | 92 |
100 // ModuleLifetime implementation. | 93 // ModuleLifetime implementation. |
101 virtual void PluginModuleDead(webkit::ppapi::PluginModule* dead_module); | 94 virtual void PluginModuleDead(webkit::ppapi::PluginModule* dead_module); |
102 | 95 |
103 // We implement some Pepper plug-ins using NaCl to take advantage of NaCl's | |
104 // strong sandbox. Typically, these NaCl modules are stored in extensions | |
105 // and registered here. Not all NaCl modules need to register for a MIME | |
106 // type, just the ones that are responsible for rendering a particular MIME | |
107 // type, like application/pdf. Note: We only register NaCl modules in the | |
108 // browser process. | |
109 void RegisterNaClModule(const GURL& url, const std::string& mime_type); | |
110 void UnregisterNaClModule(const GURL& url); | |
111 | |
112 // Call UpdatePluginListWithNaClModules() after registering or unregistering | |
113 // a NaCl module to see those changes reflected in the PluginList. | |
114 void UpdatePluginListWithNaClModules(); | |
115 | |
116 private: | 96 private: |
117 typedef std::list<NaClModuleInfo> NaClModuleInfoList; | |
118 | |
119 PepperPluginRegistry(); | 97 PepperPluginRegistry(); |
120 | 98 |
121 // Dispatcher::Delegate implementation. | 99 // Dispatcher::Delegate implementation. |
122 virtual MessageLoop* GetIPCMessageLoop(); | 100 virtual MessageLoop* GetIPCMessageLoop(); |
123 virtual base::WaitableEvent* GetShutdownEvent(); | 101 virtual base::WaitableEvent* GetShutdownEvent(); |
124 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet(); | 102 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet(); |
125 | 103 |
126 NaClModuleInfoList::iterator FindNaClModule(const GURL& url); | |
127 | |
128 // All known pepper plugins. | 104 // All known pepper plugins. |
129 std::vector<PepperPluginInfo> plugin_list_; | 105 std::vector<PepperPluginInfo> plugin_list_; |
130 | 106 |
131 // Plugins that have been preloaded so they can be executed in-process in | 107 // Plugins that have been preloaded so they can be executed in-process in |
132 // the renderer (the sandbox prevents on-demand loading). | 108 // the renderer (the sandbox prevents on-demand loading). |
133 typedef std::map<FilePath, scoped_refptr<webkit::ppapi::PluginModule> > | 109 typedef std::map<FilePath, scoped_refptr<webkit::ppapi::PluginModule> > |
134 OwningModuleMap; | 110 OwningModuleMap; |
135 OwningModuleMap preloaded_modules_; | 111 OwningModuleMap preloaded_modules_; |
136 | 112 |
137 // A list of non-owning pointers to all currently-live plugin modules. This | 113 // A list of non-owning pointers to all currently-live plugin modules. This |
138 // includes both preloaded ones in preloaded_modules_, and out-of-process | 114 // includes both preloaded ones in preloaded_modules_, and out-of-process |
139 // modules whose lifetime is managed externally. This will contain only | 115 // modules whose lifetime is managed externally. This will contain only |
140 // non-crashed modules. If an out-of-process module crashes, it may | 116 // non-crashed modules. If an out-of-process module crashes, it may |
141 // continue as long as there are WebKit references to it, but it will not | 117 // continue as long as there are WebKit references to it, but it will not |
142 // appear in this list. | 118 // appear in this list. |
143 typedef std::map<FilePath, webkit::ppapi::PluginModule*> NonOwningModuleMap; | 119 typedef std::map<FilePath, webkit::ppapi::PluginModule*> NonOwningModuleMap; |
144 NonOwningModuleMap live_modules_; | 120 NonOwningModuleMap live_modules_; |
145 | 121 |
146 NaClModuleInfoList nacl_module_list_; | |
147 | |
148 DISALLOW_COPY_AND_ASSIGN(PepperPluginRegistry); | 122 DISALLOW_COPY_AND_ASSIGN(PepperPluginRegistry); |
149 }; | 123 }; |
150 | 124 |
151 #endif // CHROME_COMMON_PEPPER_PLUGIN_REGISTRY_H_ | 125 #endif // CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ |
OLD | NEW |