Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / dom / plugins / PluginScriptableObjectParent.h
blobbd89436e8c4ca4b2d0368c35151d2a6f3ddb3415
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
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/
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.
16 * The Original Code is Mozilla Plugin App.
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.
23 * Contributor(s):
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.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef dom_plugins_PluginScriptableObjectParent_h
40 #define dom_plugins_PluginScriptableObjectParent_h 1
42 #include "mozilla/plugins/PPluginScriptableObjectParent.h"
44 #include "jsapi.h"
45 #include "npfunctions.h"
46 #include "npruntime.h"
48 namespace mozilla {
49 namespace plugins {
51 class PluginInstanceParent;
52 class PluginScriptableObjectParent;
53 class PPluginIdentifierParent;
55 struct ParentNPObject : NPObject
57 ParentNPObject()
58 : NPObject(), parent(NULL), invalidated(false) { }
60 // |parent| is always valid as long as the actor is alive. Once the actor is
61 // destroyed this will be set to null.
62 PluginScriptableObjectParent* parent;
63 bool invalidated;
66 class PluginScriptableObjectParent : public PPluginScriptableObjectParent
68 friend class PluginInstanceParent;
70 public:
71 PluginScriptableObjectParent(ScriptableObjectType aType);
72 virtual ~PluginScriptableObjectParent();
74 void
75 InitializeProxy();
77 void
78 InitializeLocal(NPObject* aObject);
80 virtual bool
81 AnswerHasMethod(PPluginIdentifierParent* aId,
82 bool* aHasMethod);
84 virtual bool
85 AnswerInvoke(PPluginIdentifierParent* aId,
86 const InfallibleTArray<Variant>& aArgs,
87 Variant* aResult,
88 bool* aSuccess);
90 virtual bool
91 AnswerInvokeDefault(const InfallibleTArray<Variant>& aArgs,
92 Variant* aResult,
93 bool* aSuccess);
95 virtual bool
96 AnswerHasProperty(PPluginIdentifierParent* aId,
97 bool* aHasProperty);
99 virtual bool
100 AnswerGetParentProperty(PPluginIdentifierParent* aId,
101 Variant* aResult,
102 bool* aSuccess);
104 virtual bool
105 AnswerSetProperty(PPluginIdentifierParent* aId,
106 const Variant& aValue,
107 bool* aSuccess);
109 virtual bool
110 AnswerRemoveProperty(PPluginIdentifierParent* aId,
111 bool* aSuccess);
113 virtual bool
114 AnswerEnumerate(InfallibleTArray<PPluginIdentifierParent*>* aProperties,
115 bool* aSuccess);
117 virtual bool
118 AnswerConstruct(const InfallibleTArray<Variant>& aArgs,
119 Variant* aResult,
120 bool* aSuccess);
122 virtual bool
123 AnswerNPN_Evaluate(const nsCString& aScript,
124 Variant* aResult,
125 bool* aSuccess);
127 virtual bool
128 RecvProtect();
130 virtual bool
131 RecvUnprotect();
133 static const NPClass*
134 GetClass()
136 return &sNPClass;
139 PluginInstanceParent*
140 GetInstance() const
142 return mInstance;
145 NPObject*
146 GetObject(bool aCanResurrect);
148 // Protect only affects LocalObject actors. It is called by the
149 // ProtectedVariant/Actor helper classes before the actor is used as an
150 // argument to an IPC call and when the child process resurrects a
151 // proxy object to the NPObject associated with this actor.
152 void Protect();
154 // Unprotect only affects LocalObject actors. It is called by the
155 // ProtectedVariant/Actor helper classes after the actor is used as an
156 // argument to an IPC call and when the child process is no longer using this
157 // actor.
158 void Unprotect();
160 // DropNPObject is only used for Proxy actors and is called when the parent
161 // process is no longer using the NPObject associated with this actor. The
162 // child process may subsequently use this actor again in which case a new
163 // NPObject will be created and associated with this actor (see
164 // ResurrectProxyObject).
165 void DropNPObject();
167 ScriptableObjectType
168 Type() const {
169 return mType;
172 JSBool GetPropertyHelper(NPIdentifier aName,
173 PRBool* aHasProperty,
174 PRBool* aHasMethod,
175 NPVariant* aResult);
177 private:
178 static NPObject*
179 ScriptableAllocate(NPP aInstance,
180 NPClass* aClass);
182 static void
183 ScriptableInvalidate(NPObject* aObject);
185 static void
186 ScriptableDeallocate(NPObject* aObject);
188 static bool
189 ScriptableHasMethod(NPObject* aObject,
190 NPIdentifier aName);
192 static bool
193 ScriptableInvoke(NPObject* aObject,
194 NPIdentifier aName,
195 const NPVariant* aArgs,
196 uint32_t aArgCount,
197 NPVariant* aResult);
199 static bool
200 ScriptableInvokeDefault(NPObject* aObject,
201 const NPVariant* aArgs,
202 uint32_t aArgCount,
203 NPVariant* aResult);
205 static bool
206 ScriptableHasProperty(NPObject* aObject,
207 NPIdentifier aName);
209 static bool
210 ScriptableGetProperty(NPObject* aObject,
211 NPIdentifier aName,
212 NPVariant* aResult);
214 static bool
215 ScriptableSetProperty(NPObject* aObject,
216 NPIdentifier aName,
217 const NPVariant* aValue);
219 static bool
220 ScriptableRemoveProperty(NPObject* aObject,
221 NPIdentifier aName);
223 static bool
224 ScriptableEnumerate(NPObject* aObject,
225 NPIdentifier** aIdentifiers,
226 uint32_t* aCount);
228 static bool
229 ScriptableConstruct(NPObject* aObject,
230 const NPVariant* aArgs,
231 uint32_t aArgCount,
232 NPVariant* aResult);
234 NPObject*
235 CreateProxyObject();
237 // ResurrectProxyObject is only used with Proxy actors. It is called when the
238 // child process uses an actor whose NPObject was deleted by the parent
239 // process.
240 bool ResurrectProxyObject();
242 private:
243 PluginInstanceParent* mInstance;
245 // This may be a ParentNPObject or some other kind depending on who created
246 // it. Have to check its class to find out.
247 NPObject* mObject;
248 int mProtectCount;
250 ScriptableObjectType mType;
252 static const NPClass sNPClass;
255 } /* namespace plugins */
256 } /* namespace mozilla */
258 #endif /* dom_plugins_PluginScriptableObjectParent_h */