1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
7 #ifndef dom_plugins_PluginScriptableObjectChild_h
8 #define dom_plugins_PluginScriptableObjectChild_h 1
10 #include "mozilla/plugins/PPluginScriptableObjectChild.h"
11 #include "mozilla/plugins/PluginMessageUtils.h"
12 #include "mozilla/plugins/PluginTypes.h"
14 #include "npruntime.h"
15 #include "nsDataHashtable.h"
20 class PluginInstanceChild
;
21 class PluginScriptableObjectChild
;
23 struct ChildNPObject
: NPObject
26 : NPObject(), parent(nullptr), invalidated(false)
28 MOZ_COUNT_CTOR(ChildNPObject
);
33 MOZ_COUNT_DTOR(ChildNPObject
);
36 // |parent| is always valid as long as the actor is alive. Once the actor is
37 // destroyed this will be set to null.
38 PluginScriptableObjectChild
* parent
;
42 class PluginScriptableObjectChild
: public PPluginScriptableObjectChild
44 friend class PluginInstanceChild
;
47 explicit PluginScriptableObjectChild(ScriptableObjectType aType
);
48 virtual ~PluginScriptableObjectChild();
54 InitializeLocal(NPObject
* aObject
);
58 AnswerInvalidate() MOZ_OVERRIDE
;
61 AnswerHasMethod(const PluginIdentifier
& aId
,
62 bool* aHasMethod
) MOZ_OVERRIDE
;
65 AnswerInvoke(const PluginIdentifier
& aId
,
66 const InfallibleTArray
<Variant
>& aArgs
,
68 bool* aSuccess
) MOZ_OVERRIDE
;
71 AnswerInvokeDefault(const InfallibleTArray
<Variant
>& aArgs
,
73 bool* aSuccess
) MOZ_OVERRIDE
;
76 AnswerHasProperty(const PluginIdentifier
& aId
,
77 bool* aHasProperty
) MOZ_OVERRIDE
;
80 AnswerGetChildProperty(const PluginIdentifier
& aId
,
84 bool* aSuccess
) MOZ_OVERRIDE
;
87 AnswerSetProperty(const PluginIdentifier
& aId
,
88 const Variant
& aValue
,
89 bool* aSuccess
) MOZ_OVERRIDE
;
92 AnswerRemoveProperty(const PluginIdentifier
& aId
,
93 bool* aSuccess
) MOZ_OVERRIDE
;
96 AnswerEnumerate(InfallibleTArray
<PluginIdentifier
>* aProperties
,
97 bool* aSuccess
) MOZ_OVERRIDE
;
100 AnswerConstruct(const InfallibleTArray
<Variant
>& aArgs
,
102 bool* aSuccess
) MOZ_OVERRIDE
;
105 RecvProtect() MOZ_OVERRIDE
;
108 RecvUnprotect() MOZ_OVERRIDE
;
111 GetObject(bool aCanResurrect
);
113 static const NPClass
*
125 // Protect only affects LocalObject actors. It is called by the
126 // ProtectedVariant/Actor helper classes before the actor is used as an
127 // argument to an IPC call and when the parent process resurrects a
128 // proxy object to the NPObject associated with this actor.
131 // Unprotect only affects LocalObject actors. It is called by the
132 // ProtectedVariant/Actor helper classes after the actor is used as an
133 // argument to an IPC call and when the parent process is no longer using
137 // DropNPObject is only used for Proxy actors and is called when the child
138 // process is no longer using the NPObject associated with this actor. The
139 // parent process may subsequently use this actor again in which case a new
140 // NPObject will be created and associated with this actor (see
141 // ResurrectProxyObject).
145 * After NPP_Destroy, all NPObjects associated with an instance are
146 * destroyed. We are informed of this destruction. This should only be called
149 void NPObjectDestroyed();
152 Evaluate(NPString
* aScript
,
161 struct StoredIdentifier
163 nsCString mIdentifier
;
164 nsAutoRefCnt mRefCnt
;
181 explicit StoredIdentifier(const nsCString
& aIdentifier
)
182 : mIdentifier(aIdentifier
), mRefCnt(), mPermanent(false)
183 { MOZ_COUNT_CTOR(StoredIdentifier
); }
185 ~StoredIdentifier() { MOZ_COUNT_DTOR(StoredIdentifier
); }
189 class MOZ_STACK_CLASS StackIdentifier
192 explicit StackIdentifier(const PluginIdentifier
& aIdentifier
);
193 explicit StackIdentifier(NPIdentifier aIdentifier
);
199 mStored
->mPermanent
= true;
202 NPIdentifier
ToNPIdentifier() const;
204 bool IsString() const { return mIdentifier
.type() == PluginIdentifier::TnsCString
; }
205 const nsCString
& GetString() const { return mIdentifier
.get_nsCString(); }
207 int32_t GetInt() const { return mIdentifier
.get_int32_t(); }
209 PluginIdentifier
GetIdentifier() const { return mIdentifier
; }
212 DISALLOW_COPY_AND_ASSIGN(StackIdentifier
);
214 PluginIdentifier mIdentifier
;
215 nsRefPtr
<StoredIdentifier
> mStored
;
218 static void ClearIdentifiers();
220 bool RegisterActor(NPObject
* aObject
);
221 void UnregisterActor(NPObject
* aObject
);
223 static PluginScriptableObjectChild
* GetActorForNPObject(NPObject
* aObject
);
225 static void RegisterObject(NPObject
* aObject
, PluginInstanceChild
* aInstance
);
226 static void UnregisterObject(NPObject
* aObject
);
228 static PluginInstanceChild
* GetInstanceForNPObject(NPObject
* aObject
);
231 * Fill PluginInstanceChild.mDeletingHash with all the remaining NPObjects
232 * associated with that instance.
234 static void NotifyOfInstanceShutdown(PluginInstanceChild
* aInstance
);
238 ScriptableAllocate(NPP aInstance
,
242 ScriptableInvalidate(NPObject
* aObject
);
245 ScriptableDeallocate(NPObject
* aObject
);
248 ScriptableHasMethod(NPObject
* aObject
,
252 ScriptableInvoke(NPObject
* aObject
,
254 const NPVariant
* aArgs
,
259 ScriptableInvokeDefault(NPObject
* aObject
,
260 const NPVariant
* aArgs
,
265 ScriptableHasProperty(NPObject
* aObject
,
269 ScriptableGetProperty(NPObject
* aObject
,
274 ScriptableSetProperty(NPObject
* aObject
,
276 const NPVariant
* aValue
);
279 ScriptableRemoveProperty(NPObject
* aObject
,
283 ScriptableEnumerate(NPObject
* aObject
,
284 NPIdentifier
** aIdentifiers
,
288 ScriptableConstruct(NPObject
* aObject
,
289 const NPVariant
* aArgs
,
296 // ResurrectProxyObject is only used with Proxy actors. It is called when the
297 // parent process uses an actor whose NPObject was deleted by the child
299 bool ResurrectProxyObject();
302 PluginInstanceChild
* mInstance
;
307 ScriptableObjectType mType
;
309 static const NPClass sNPClass
;
311 static StoredIdentifier
* HashIdentifier(const nsCString
& aIdentifier
);
312 static void UnhashIdentifier(StoredIdentifier
* aIdentifier
);
314 typedef nsDataHashtable
<nsCStringHashKey
, nsRefPtr
<StoredIdentifier
>> IdentifierTable
;
315 static IdentifierTable sIdentifiers
;
317 struct NPObjectData
: public nsPtrHashKey
<NPObject
>
319 explicit NPObjectData(const NPObject
* key
)
320 : nsPtrHashKey
<NPObject
>(key
),
326 PluginInstanceChild
* instance
;
328 // sometimes nullptr (no actor associated with an NPObject)
329 PluginScriptableObjectChild
* actor
;
332 static PLDHashOperator
CollectForInstance(NPObjectData
* d
, void* userArg
);
335 * mObjectMap contains all the currently active NPObjects (from NPN_CreateObject until the
336 * final release/dealloc, whether or not an actor is currently associated with the object.
338 static nsTHashtable
<NPObjectData
>* sObjectMap
;
341 } /* namespace plugins */
342 } /* namespace mozilla */
344 #endif /* dom_plugins_PluginScriptableObjectChild_h */