dom/plugins/ipc/PluginScriptableObjectChild.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:16560ad08500
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef dom_plugins_PluginScriptableObjectChild_h
8 #define dom_plugins_PluginScriptableObjectChild_h 1
9
10 #include "mozilla/plugins/PPluginScriptableObjectChild.h"
11 #include "mozilla/plugins/PluginMessageUtils.h"
12
13 #include "npruntime.h"
14
15 namespace mozilla {
16 namespace plugins {
17
18 class PluginInstanceChild;
19 class PluginScriptableObjectChild;
20 class PPluginIdentifierChild;
21
22 struct ChildNPObject : NPObject
23 {
24 ChildNPObject()
25 : NPObject(), parent(nullptr), invalidated(false)
26 {
27 MOZ_COUNT_CTOR(ChildNPObject);
28 }
29
30 ~ChildNPObject()
31 {
32 MOZ_COUNT_DTOR(ChildNPObject);
33 }
34
35 // |parent| is always valid as long as the actor is alive. Once the actor is
36 // destroyed this will be set to null.
37 PluginScriptableObjectChild* parent;
38 bool invalidated;
39 };
40
41 class PluginScriptableObjectChild : public PPluginScriptableObjectChild
42 {
43 friend class PluginInstanceChild;
44
45 public:
46 PluginScriptableObjectChild(ScriptableObjectType aType);
47 virtual ~PluginScriptableObjectChild();
48
49 void
50 InitializeProxy();
51
52 void
53 InitializeLocal(NPObject* aObject);
54
55
56 virtual bool
57 AnswerInvalidate() MOZ_OVERRIDE;
58
59 virtual bool
60 AnswerHasMethod(PPluginIdentifierChild* aId,
61 bool* aHasMethod) MOZ_OVERRIDE;
62
63 virtual bool
64 AnswerInvoke(PPluginIdentifierChild* aId,
65 const InfallibleTArray<Variant>& aArgs,
66 Variant* aResult,
67 bool* aSuccess) MOZ_OVERRIDE;
68
69 virtual bool
70 AnswerInvokeDefault(const InfallibleTArray<Variant>& aArgs,
71 Variant* aResult,
72 bool* aSuccess) MOZ_OVERRIDE;
73
74 virtual bool
75 AnswerHasProperty(PPluginIdentifierChild* aId,
76 bool* aHasProperty) MOZ_OVERRIDE;
77
78 virtual bool
79 AnswerGetChildProperty(PPluginIdentifierChild* aId,
80 bool* aHasProperty,
81 bool* aHasMethod,
82 Variant* aResult,
83 bool* aSuccess) MOZ_OVERRIDE;
84
85 virtual bool
86 AnswerSetProperty(PPluginIdentifierChild* aId,
87 const Variant& aValue,
88 bool* aSuccess) MOZ_OVERRIDE;
89
90 virtual bool
91 AnswerRemoveProperty(PPluginIdentifierChild* aId,
92 bool* aSuccess) MOZ_OVERRIDE;
93
94 virtual bool
95 AnswerEnumerate(InfallibleTArray<PPluginIdentifierChild*>* aProperties,
96 bool* aSuccess) MOZ_OVERRIDE;
97
98 virtual bool
99 AnswerConstruct(const InfallibleTArray<Variant>& aArgs,
100 Variant* aResult,
101 bool* aSuccess) MOZ_OVERRIDE;
102
103 virtual bool
104 RecvProtect() MOZ_OVERRIDE;
105
106 virtual bool
107 RecvUnprotect() MOZ_OVERRIDE;
108
109 NPObject*
110 GetObject(bool aCanResurrect);
111
112 static const NPClass*
113 GetClass()
114 {
115 return &sNPClass;
116 }
117
118 PluginInstanceChild*
119 GetInstance() const
120 {
121 return mInstance;
122 }
123
124 // Protect only affects LocalObject actors. It is called by the
125 // ProtectedVariant/Actor helper classes before the actor is used as an
126 // argument to an IPC call and when the parent process resurrects a
127 // proxy object to the NPObject associated with this actor.
128 void Protect();
129
130 // Unprotect only affects LocalObject actors. It is called by the
131 // ProtectedVariant/Actor helper classes after the actor is used as an
132 // argument to an IPC call and when the parent process is no longer using
133 // this actor.
134 void Unprotect();
135
136 // DropNPObject is only used for Proxy actors and is called when the child
137 // process is no longer using the NPObject associated with this actor. The
138 // parent process may subsequently use this actor again in which case a new
139 // NPObject will be created and associated with this actor (see
140 // ResurrectProxyObject).
141 void DropNPObject();
142
143 /**
144 * After NPP_Destroy, all NPObjects associated with an instance are
145 * destroyed. We are informed of this destruction. This should only be called
146 * on Local actors.
147 */
148 void NPObjectDestroyed();
149
150 bool
151 Evaluate(NPString* aScript,
152 NPVariant* aResult);
153
154 ScriptableObjectType
155 Type() const {
156 return mType;
157 }
158
159 private:
160 static NPObject*
161 ScriptableAllocate(NPP aInstance,
162 NPClass* aClass);
163
164 static void
165 ScriptableInvalidate(NPObject* aObject);
166
167 static void
168 ScriptableDeallocate(NPObject* aObject);
169
170 static bool
171 ScriptableHasMethod(NPObject* aObject,
172 NPIdentifier aName);
173
174 static bool
175 ScriptableInvoke(NPObject* aObject,
176 NPIdentifier aName,
177 const NPVariant* aArgs,
178 uint32_t aArgCount,
179 NPVariant* aResult);
180
181 static bool
182 ScriptableInvokeDefault(NPObject* aObject,
183 const NPVariant* aArgs,
184 uint32_t aArgCount,
185 NPVariant* aResult);
186
187 static bool
188 ScriptableHasProperty(NPObject* aObject,
189 NPIdentifier aName);
190
191 static bool
192 ScriptableGetProperty(NPObject* aObject,
193 NPIdentifier aName,
194 NPVariant* aResult);
195
196 static bool
197 ScriptableSetProperty(NPObject* aObject,
198 NPIdentifier aName,
199 const NPVariant* aValue);
200
201 static bool
202 ScriptableRemoveProperty(NPObject* aObject,
203 NPIdentifier aName);
204
205 static bool
206 ScriptableEnumerate(NPObject* aObject,
207 NPIdentifier** aIdentifiers,
208 uint32_t* aCount);
209
210 static bool
211 ScriptableConstruct(NPObject* aObject,
212 const NPVariant* aArgs,
213 uint32_t aArgCount,
214 NPVariant* aResult);
215
216 NPObject*
217 CreateProxyObject();
218
219 // ResurrectProxyObject is only used with Proxy actors. It is called when the
220 // parent process uses an actor whose NPObject was deleted by the child
221 // process.
222 bool ResurrectProxyObject();
223
224 private:
225 PluginInstanceChild* mInstance;
226 NPObject* mObject;
227 bool mInvalidated;
228 int mProtectCount;
229
230 ScriptableObjectType mType;
231
232 static const NPClass sNPClass;
233 };
234
235 } /* namespace plugins */
236 } /* namespace mozilla */
237
238 #endif /* dom_plugins_PluginScriptableObjectChild_h */

mercurial