1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * vim: sw=2 ts=2 et :
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Plugin App.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Ben Turner <bent.mozilla@gmail.com>
20 : * Portions created by the Initial Developer are Copyright (C) 2009
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef dom_plugins_PluginScriptableObjectChild_h
40 : #define dom_plugins_PluginScriptableObjectChild_h 1
41 :
42 : #include "mozilla/plugins/PPluginScriptableObjectChild.h"
43 :
44 : #include "npruntime.h"
45 :
46 : namespace mozilla {
47 : namespace plugins {
48 :
49 : class PluginInstanceChild;
50 : class PluginScriptableObjectChild;
51 : class PPluginIdentifierChild;
52 :
53 : struct ChildNPObject : NPObject
54 : {
55 0 : ChildNPObject()
56 0 : : NPObject(), parent(NULL), invalidated(false)
57 : {
58 0 : MOZ_COUNT_CTOR(ChildNPObject);
59 0 : }
60 :
61 0 : ~ChildNPObject()
62 : {
63 0 : MOZ_COUNT_DTOR(ChildNPObject);
64 0 : }
65 :
66 : // |parent| is always valid as long as the actor is alive. Once the actor is
67 : // destroyed this will be set to null.
68 : PluginScriptableObjectChild* parent;
69 : bool invalidated;
70 : };
71 :
72 : class PluginScriptableObjectChild : public PPluginScriptableObjectChild
73 : {
74 : friend class PluginInstanceChild;
75 :
76 : public:
77 : PluginScriptableObjectChild(ScriptableObjectType aType);
78 : virtual ~PluginScriptableObjectChild();
79 :
80 : void
81 : InitializeProxy();
82 :
83 : void
84 : InitializeLocal(NPObject* aObject);
85 :
86 :
87 : virtual bool
88 : AnswerInvalidate();
89 :
90 : virtual bool
91 : AnswerHasMethod(PPluginIdentifierChild* aId,
92 : bool* aHasMethod);
93 :
94 : virtual bool
95 : AnswerInvoke(PPluginIdentifierChild* aId,
96 : const InfallibleTArray<Variant>& aArgs,
97 : Variant* aResult,
98 : bool* aSuccess);
99 :
100 : virtual bool
101 : AnswerInvokeDefault(const InfallibleTArray<Variant>& aArgs,
102 : Variant* aResult,
103 : bool* aSuccess);
104 :
105 : virtual bool
106 : AnswerHasProperty(PPluginIdentifierChild* aId,
107 : bool* aHasProperty);
108 :
109 : virtual bool
110 : AnswerGetChildProperty(PPluginIdentifierChild* aId,
111 : bool* aHasProperty,
112 : bool* aHasMethod,
113 : Variant* aResult,
114 : bool* aSuccess);
115 :
116 : virtual bool
117 : AnswerSetProperty(PPluginIdentifierChild* aId,
118 : const Variant& aValue,
119 : bool* aSuccess);
120 :
121 : virtual bool
122 : AnswerRemoveProperty(PPluginIdentifierChild* aId,
123 : bool* aSuccess);
124 :
125 : virtual bool
126 : AnswerEnumerate(InfallibleTArray<PPluginIdentifierChild*>* aProperties,
127 : bool* aSuccess);
128 :
129 : virtual bool
130 : AnswerConstruct(const InfallibleTArray<Variant>& aArgs,
131 : Variant* aResult,
132 : bool* aSuccess);
133 :
134 : virtual bool
135 : RecvProtect();
136 :
137 : virtual bool
138 : RecvUnprotect();
139 :
140 : NPObject*
141 : GetObject(bool aCanResurrect);
142 :
143 : static const NPClass*
144 0 : GetClass()
145 : {
146 0 : return &sNPClass;
147 : }
148 :
149 : PluginInstanceChild*
150 0 : GetInstance() const
151 : {
152 0 : return mInstance;
153 : }
154 :
155 : // Protect only affects LocalObject actors. It is called by the
156 : // ProtectedVariant/Actor helper classes before the actor is used as an
157 : // argument to an IPC call and when the parent process resurrects a
158 : // proxy object to the NPObject associated with this actor.
159 : void Protect();
160 :
161 : // Unprotect only affects LocalObject actors. It is called by the
162 : // ProtectedVariant/Actor helper classes after the actor is used as an
163 : // argument to an IPC call and when the parent process is no longer using
164 : // this actor.
165 : void Unprotect();
166 :
167 : // DropNPObject is only used for Proxy actors and is called when the child
168 : // process is no longer using the NPObject associated with this actor. The
169 : // parent process may subsequently use this actor again in which case a new
170 : // NPObject will be created and associated with this actor (see
171 : // ResurrectProxyObject).
172 : void DropNPObject();
173 :
174 : /**
175 : * After NPP_Destroy, all NPObjects associated with an instance are
176 : * destroyed. We are informed of this destruction. This should only be called
177 : * on Local actors.
178 : */
179 : void NPObjectDestroyed();
180 :
181 : bool
182 : Evaluate(NPString* aScript,
183 : NPVariant* aResult);
184 :
185 : ScriptableObjectType
186 0 : Type() const {
187 0 : return mType;
188 : }
189 :
190 : private:
191 : static NPObject*
192 : ScriptableAllocate(NPP aInstance,
193 : NPClass* aClass);
194 :
195 : static void
196 : ScriptableInvalidate(NPObject* aObject);
197 :
198 : static void
199 : ScriptableDeallocate(NPObject* aObject);
200 :
201 : static bool
202 : ScriptableHasMethod(NPObject* aObject,
203 : NPIdentifier aName);
204 :
205 : static bool
206 : ScriptableInvoke(NPObject* aObject,
207 : NPIdentifier aName,
208 : const NPVariant* aArgs,
209 : uint32_t aArgCount,
210 : NPVariant* aResult);
211 :
212 : static bool
213 : ScriptableInvokeDefault(NPObject* aObject,
214 : const NPVariant* aArgs,
215 : uint32_t aArgCount,
216 : NPVariant* aResult);
217 :
218 : static bool
219 : ScriptableHasProperty(NPObject* aObject,
220 : NPIdentifier aName);
221 :
222 : static bool
223 : ScriptableGetProperty(NPObject* aObject,
224 : NPIdentifier aName,
225 : NPVariant* aResult);
226 :
227 : static bool
228 : ScriptableSetProperty(NPObject* aObject,
229 : NPIdentifier aName,
230 : const NPVariant* aValue);
231 :
232 : static bool
233 : ScriptableRemoveProperty(NPObject* aObject,
234 : NPIdentifier aName);
235 :
236 : static bool
237 : ScriptableEnumerate(NPObject* aObject,
238 : NPIdentifier** aIdentifiers,
239 : uint32_t* aCount);
240 :
241 : static bool
242 : ScriptableConstruct(NPObject* aObject,
243 : const NPVariant* aArgs,
244 : uint32_t aArgCount,
245 : NPVariant* aResult);
246 :
247 : NPObject*
248 : CreateProxyObject();
249 :
250 : // ResurrectProxyObject is only used with Proxy actors. It is called when the
251 : // parent process uses an actor whose NPObject was deleted by the child
252 : // process.
253 : bool ResurrectProxyObject();
254 :
255 : private:
256 : PluginInstanceChild* mInstance;
257 : NPObject* mObject;
258 : bool mInvalidated;
259 : int mProtectCount;
260 :
261 : ScriptableObjectType mType;
262 :
263 : static const NPClass sNPClass;
264 : };
265 :
266 : } /* namespace plugins */
267 : } /* namespace mozilla */
268 :
269 : #endif /* dom_plugins_PluginScriptableObjectChild_h */
|