OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ | |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/native_library.h" | |
13 #include "base/process.h" | |
14 #include "base/ref_counted.h" | |
15 #include "base/scoped_ptr.h" | |
16 #include "base/weak_ptr.h" | |
17 #include "ppapi/c/pp_module.h" | |
18 #include "ppapi/c/ppb.h" | |
19 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | |
20 | |
21 class FilePath; | |
22 class MessageLoop; | |
23 typedef struct NPObject NPObject; | |
24 struct PPB_Core; | |
25 typedef void* NPIdentifier; | |
26 | |
27 namespace base { | |
28 class WaitableEvent; | |
29 } | |
30 | |
31 namespace pp { | |
32 namespace proxy { | |
33 class HostDispatcher; | |
34 } // proxy | |
35 } // pp | |
36 | |
37 namespace IPC { | |
38 struct ChannelHandle; | |
39 } | |
40 | |
41 namespace pepper { | |
42 | |
43 class ObjectVar; | |
44 class PluginDelegate; | |
45 class PluginInstance; | |
46 class PluginObject; | |
47 | |
48 // Represents one plugin library loaded into one renderer. This library may | |
49 // have multiple instances. | |
50 // | |
51 // Note: to get from a PP_Instance to a PluginInstance*, use the | |
52 // ResourceTracker. | |
53 class PluginModule : public base::RefCounted<PluginModule>, | |
54 public base::SupportsWeakPtr<PluginModule> { | |
55 public: | |
56 typedef const void* (*GetInterfaceFunc)(const char*); | |
57 typedef int (*PPP_InitializeModuleFunc)(PP_Module, PPB_GetInterface); | |
58 typedef void (*PPP_ShutdownModuleFunc)(); | |
59 | |
60 struct EntryPoints { | |
61 // This structure is POD, with the constructor initializing to NULL. | |
62 EntryPoints(); | |
63 | |
64 GetInterfaceFunc get_interface; | |
65 PPP_InitializeModuleFunc initialize_module; | |
66 PPP_ShutdownModuleFunc shutdown_module; // Optional, may be NULL. | |
67 }; | |
68 | |
69 // You must call one of the Init functions to create a module of the type | |
70 // you desire. | |
71 PluginModule(); | |
72 | |
73 ~PluginModule(); | |
74 | |
75 // Initializes this module as an internal plugin with the given entrypoints. | |
76 // This is used for "plugins" compiled into Chrome. Returns true on success. | |
77 // False means that the plugin can not be used. | |
78 bool InitAsInternalPlugin(const EntryPoints& entry_points); | |
79 | |
80 // Initializes this module using the given library path as the plugin. | |
81 // Returns true on success. False means that the plugin can not be used. | |
82 bool InitAsLibrary(const FilePath& path); | |
83 | |
84 // Initializes this module for the given out of process proxy. This takes | |
85 // ownership of the given pointer, even in the failure case. | |
86 void InitAsProxied(PluginDelegate::OutOfProcessProxy* out_of_process_proxy); | |
87 | |
88 static const PPB_Core* GetCore(); | |
89 | |
90 // Returns a pointer to the local GetInterface function for retrieving | |
91 // PPB interfaces. | |
92 static GetInterfaceFunc GetLocalGetInterfaceFunc(); | |
93 | |
94 // Returns the module handle. This may be used before Init() is called (the | |
95 // proxy needs this information to set itself up properly). | |
96 PP_Module pp_module() const { return pp_module_; } | |
97 | |
98 void set_name(const std::string& name) { name_ = name; } | |
99 const std::string& name() const { return name_; } | |
100 | |
101 PluginInstance* CreateInstance(PluginDelegate* delegate); | |
102 | |
103 // Returns "some" plugin instance associated with this module. This is not | |
104 // guaranteed to be any one in particular. This is normally used to execute | |
105 // callbacks up to the browser layer that are not inherently per-instance, | |
106 // but the delegate lives only on the plugin instance so we need one of them. | |
107 PluginInstance* GetSomeInstance() const; | |
108 | |
109 // Calls the plugin's GetInterface and returns the given interface pointer, | |
110 // which could be NULL. | |
111 const void* GetPluginInterface(const char* name) const; | |
112 | |
113 // This module is associated with a set of instances. The PluginInstance | |
114 // object declares its association with this module in its destructor and | |
115 // releases us in its destructor. | |
116 void InstanceCreated(PluginInstance* instance); | |
117 void InstanceDeleted(PluginInstance* instance); | |
118 | |
119 // Tracks all live ObjectVar. This is so we can map between PluginModule + | |
120 // NPObject and get the ObjectVar corresponding to it. This Add/Remove | |
121 // function should be called by the ObjectVar when it is created and | |
122 // destroyed. | |
123 void AddNPObjectVar(ObjectVar* object_var); | |
124 void RemoveNPObjectVar(ObjectVar* object_var); | |
125 | |
126 // Looks up a previously registered ObjectVar for the given NPObject and | |
127 // module. Returns NULL if there is no ObjectVar corresponding to the given | |
128 // NPObject for the given module. See AddNPObjectVar above. | |
129 ObjectVar* ObjectVarForNPObject(NPObject* np_object) const; | |
130 | |
131 // Tracks all live PluginObjects. | |
132 void AddPluginObject(PluginObject* plugin_object); | |
133 void RemovePluginObject(PluginObject* plugin_object); | |
134 | |
135 private: | |
136 // Calls the InitializeModule entrypoint. The entrypoint must have been | |
137 // set and the plugin must not be out of process (we don't maintain | |
138 // entrypoints in that case). | |
139 bool InitializeModule(); | |
140 | |
141 PP_Module pp_module_; | |
142 | |
143 // Manages the out of process proxy interface. The presence of this | |
144 // pointer indicates that the plugin is running out of process and that the | |
145 // entry_points_ aren't valid. | |
146 scoped_ptr<PluginDelegate::OutOfProcessProxy> out_of_process_proxy_; | |
147 | |
148 // Holds a reference to the base::NativeLibrary handle if this PluginModule | |
149 // instance wraps functions loaded from a library. Can be NULL. If | |
150 // |library_| is non-NULL, PluginModule will attempt to unload the library | |
151 // during destruction. | |
152 base::NativeLibrary library_; | |
153 | |
154 // Contains pointers to the entry points of the actual plugin implementation. | |
155 // These will be NULL for out-of-process plugins, which is indicated by the | |
156 // presence of the out_of_process_proxy_ value. | |
157 EntryPoints entry_points_; | |
158 | |
159 // The name of the module. | |
160 std::string name_; | |
161 | |
162 // Non-owning pointers to all instances associated with this module. When | |
163 // there are no more instances, this object should be deleted. | |
164 typedef std::set<PluginInstance*> PluginInstanceSet; | |
165 PluginInstanceSet instances_; | |
166 | |
167 // Tracks all live ObjectVars used by this module so we can map NPObjects to | |
168 // the corresponding object. These are non-owning references. | |
169 typedef std::map<NPObject*, ObjectVar*> NPObjectToObjectVarMap;; | |
170 NPObjectToObjectVarMap np_object_to_object_var_; | |
171 | |
172 typedef std::set<PluginObject*> PluginObjectSet; | |
173 PluginObjectSet live_plugin_objects_; | |
174 | |
175 DISALLOW_COPY_AND_ASSIGN(PluginModule); | |
176 }; | |
177 | |
178 } // namespace pepper | |
179 | |
180 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ | |
OLD | NEW |