|
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_PluginScriptableObjectParent_h |
|
8 #define dom_plugins_PluginScriptableObjectParent_h 1 |
|
9 |
|
10 #include "mozilla/plugins/PPluginScriptableObjectParent.h" |
|
11 #include "mozilla/plugins/PluginMessageUtils.h" |
|
12 |
|
13 #include "npfunctions.h" |
|
14 #include "npruntime.h" |
|
15 |
|
16 namespace mozilla { |
|
17 namespace plugins { |
|
18 |
|
19 class PluginInstanceParent; |
|
20 class PluginScriptableObjectParent; |
|
21 class PPluginIdentifierParent; |
|
22 |
|
23 struct ParentNPObject : NPObject |
|
24 { |
|
25 ParentNPObject() |
|
26 : NPObject(), parent(nullptr), invalidated(false) { } |
|
27 |
|
28 // |parent| is always valid as long as the actor is alive. Once the actor is |
|
29 // destroyed this will be set to null. |
|
30 PluginScriptableObjectParent* parent; |
|
31 bool invalidated; |
|
32 }; |
|
33 |
|
34 class PluginScriptableObjectParent : public PPluginScriptableObjectParent |
|
35 { |
|
36 friend class PluginInstanceParent; |
|
37 |
|
38 public: |
|
39 PluginScriptableObjectParent(ScriptableObjectType aType); |
|
40 virtual ~PluginScriptableObjectParent(); |
|
41 |
|
42 void |
|
43 InitializeProxy(); |
|
44 |
|
45 void |
|
46 InitializeLocal(NPObject* aObject); |
|
47 |
|
48 virtual bool |
|
49 AnswerHasMethod(PPluginIdentifierParent* aId, |
|
50 bool* aHasMethod) MOZ_OVERRIDE; |
|
51 |
|
52 virtual bool |
|
53 AnswerInvoke(PPluginIdentifierParent* aId, |
|
54 const InfallibleTArray<Variant>& aArgs, |
|
55 Variant* aResult, |
|
56 bool* aSuccess) MOZ_OVERRIDE; |
|
57 |
|
58 virtual bool |
|
59 AnswerInvokeDefault(const InfallibleTArray<Variant>& aArgs, |
|
60 Variant* aResult, |
|
61 bool* aSuccess) MOZ_OVERRIDE; |
|
62 |
|
63 virtual bool |
|
64 AnswerHasProperty(PPluginIdentifierParent* aId, |
|
65 bool* aHasProperty) MOZ_OVERRIDE; |
|
66 |
|
67 virtual bool |
|
68 AnswerGetParentProperty(PPluginIdentifierParent* aId, |
|
69 Variant* aResult, |
|
70 bool* aSuccess) MOZ_OVERRIDE; |
|
71 |
|
72 virtual bool |
|
73 AnswerSetProperty(PPluginIdentifierParent* aId, |
|
74 const Variant& aValue, |
|
75 bool* aSuccess) MOZ_OVERRIDE; |
|
76 |
|
77 virtual bool |
|
78 AnswerRemoveProperty(PPluginIdentifierParent* aId, |
|
79 bool* aSuccess) MOZ_OVERRIDE; |
|
80 |
|
81 virtual bool |
|
82 AnswerEnumerate(InfallibleTArray<PPluginIdentifierParent*>* aProperties, |
|
83 bool* aSuccess) MOZ_OVERRIDE; |
|
84 |
|
85 virtual bool |
|
86 AnswerConstruct(const InfallibleTArray<Variant>& aArgs, |
|
87 Variant* aResult, |
|
88 bool* aSuccess) MOZ_OVERRIDE; |
|
89 |
|
90 virtual bool |
|
91 AnswerNPN_Evaluate(const nsCString& aScript, |
|
92 Variant* aResult, |
|
93 bool* aSuccess) MOZ_OVERRIDE; |
|
94 |
|
95 virtual bool |
|
96 RecvProtect() MOZ_OVERRIDE; |
|
97 |
|
98 virtual bool |
|
99 RecvUnprotect() MOZ_OVERRIDE; |
|
100 |
|
101 static const NPClass* |
|
102 GetClass() |
|
103 { |
|
104 return &sNPClass; |
|
105 } |
|
106 |
|
107 PluginInstanceParent* |
|
108 GetInstance() const |
|
109 { |
|
110 return mInstance; |
|
111 } |
|
112 |
|
113 NPObject* |
|
114 GetObject(bool aCanResurrect); |
|
115 |
|
116 // Protect only affects LocalObject actors. It is called by the |
|
117 // ProtectedVariant/Actor helper classes before the actor is used as an |
|
118 // argument to an IPC call and when the child process resurrects a |
|
119 // proxy object to the NPObject associated with this actor. |
|
120 void Protect(); |
|
121 |
|
122 // Unprotect only affects LocalObject actors. It is called by the |
|
123 // ProtectedVariant/Actor helper classes after the actor is used as an |
|
124 // argument to an IPC call and when the child process is no longer using this |
|
125 // actor. |
|
126 void Unprotect(); |
|
127 |
|
128 // DropNPObject is only used for Proxy actors and is called when the parent |
|
129 // process is no longer using the NPObject associated with this actor. The |
|
130 // child process may subsequently use this actor again in which case a new |
|
131 // NPObject will be created and associated with this actor (see |
|
132 // ResurrectProxyObject). |
|
133 void DropNPObject(); |
|
134 |
|
135 ScriptableObjectType |
|
136 Type() const { |
|
137 return mType; |
|
138 } |
|
139 |
|
140 bool GetPropertyHelper(NPIdentifier aName, |
|
141 bool* aHasProperty, |
|
142 bool* aHasMethod, |
|
143 NPVariant* aResult); |
|
144 |
|
145 private: |
|
146 static NPObject* |
|
147 ScriptableAllocate(NPP aInstance, |
|
148 NPClass* aClass); |
|
149 |
|
150 static void |
|
151 ScriptableInvalidate(NPObject* aObject); |
|
152 |
|
153 static void |
|
154 ScriptableDeallocate(NPObject* aObject); |
|
155 |
|
156 static bool |
|
157 ScriptableHasMethod(NPObject* aObject, |
|
158 NPIdentifier aName); |
|
159 |
|
160 static bool |
|
161 ScriptableInvoke(NPObject* aObject, |
|
162 NPIdentifier aName, |
|
163 const NPVariant* aArgs, |
|
164 uint32_t aArgCount, |
|
165 NPVariant* aResult); |
|
166 |
|
167 static bool |
|
168 ScriptableInvokeDefault(NPObject* aObject, |
|
169 const NPVariant* aArgs, |
|
170 uint32_t aArgCount, |
|
171 NPVariant* aResult); |
|
172 |
|
173 static bool |
|
174 ScriptableHasProperty(NPObject* aObject, |
|
175 NPIdentifier aName); |
|
176 |
|
177 static bool |
|
178 ScriptableGetProperty(NPObject* aObject, |
|
179 NPIdentifier aName, |
|
180 NPVariant* aResult); |
|
181 |
|
182 static bool |
|
183 ScriptableSetProperty(NPObject* aObject, |
|
184 NPIdentifier aName, |
|
185 const NPVariant* aValue); |
|
186 |
|
187 static bool |
|
188 ScriptableRemoveProperty(NPObject* aObject, |
|
189 NPIdentifier aName); |
|
190 |
|
191 static bool |
|
192 ScriptableEnumerate(NPObject* aObject, |
|
193 NPIdentifier** aIdentifiers, |
|
194 uint32_t* aCount); |
|
195 |
|
196 static bool |
|
197 ScriptableConstruct(NPObject* aObject, |
|
198 const NPVariant* aArgs, |
|
199 uint32_t aArgCount, |
|
200 NPVariant* aResult); |
|
201 |
|
202 NPObject* |
|
203 CreateProxyObject(); |
|
204 |
|
205 // ResurrectProxyObject is only used with Proxy actors. It is called when the |
|
206 // child process uses an actor whose NPObject was deleted by the parent |
|
207 // process. |
|
208 bool ResurrectProxyObject(); |
|
209 |
|
210 private: |
|
211 PluginInstanceParent* mInstance; |
|
212 |
|
213 // This may be a ParentNPObject or some other kind depending on who created |
|
214 // it. Have to check its class to find out. |
|
215 NPObject* mObject; |
|
216 int mProtectCount; |
|
217 |
|
218 ScriptableObjectType mType; |
|
219 |
|
220 static const NPClass sNPClass; |
|
221 }; |
|
222 |
|
223 } /* namespace plugins */ |
|
224 } /* namespace mozilla */ |
|
225 |
|
226 #endif /* dom_plugins_PluginScriptableObjectParent_h */ |