Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
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"
13 #include "npruntime.h"
15 namespace mozilla {
16 namespace plugins {
18 class PluginInstanceChild;
19 class PluginScriptableObjectChild;
20 class PPluginIdentifierChild;
22 struct ChildNPObject : NPObject
23 {
24 ChildNPObject()
25 : NPObject(), parent(nullptr), invalidated(false)
26 {
27 MOZ_COUNT_CTOR(ChildNPObject);
28 }
30 ~ChildNPObject()
31 {
32 MOZ_COUNT_DTOR(ChildNPObject);
33 }
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 };
41 class PluginScriptableObjectChild : public PPluginScriptableObjectChild
42 {
43 friend class PluginInstanceChild;
45 public:
46 PluginScriptableObjectChild(ScriptableObjectType aType);
47 virtual ~PluginScriptableObjectChild();
49 void
50 InitializeProxy();
52 void
53 InitializeLocal(NPObject* aObject);
56 virtual bool
57 AnswerInvalidate() MOZ_OVERRIDE;
59 virtual bool
60 AnswerHasMethod(PPluginIdentifierChild* aId,
61 bool* aHasMethod) MOZ_OVERRIDE;
63 virtual bool
64 AnswerInvoke(PPluginIdentifierChild* aId,
65 const InfallibleTArray<Variant>& aArgs,
66 Variant* aResult,
67 bool* aSuccess) MOZ_OVERRIDE;
69 virtual bool
70 AnswerInvokeDefault(const InfallibleTArray<Variant>& aArgs,
71 Variant* aResult,
72 bool* aSuccess) MOZ_OVERRIDE;
74 virtual bool
75 AnswerHasProperty(PPluginIdentifierChild* aId,
76 bool* aHasProperty) MOZ_OVERRIDE;
78 virtual bool
79 AnswerGetChildProperty(PPluginIdentifierChild* aId,
80 bool* aHasProperty,
81 bool* aHasMethod,
82 Variant* aResult,
83 bool* aSuccess) MOZ_OVERRIDE;
85 virtual bool
86 AnswerSetProperty(PPluginIdentifierChild* aId,
87 const Variant& aValue,
88 bool* aSuccess) MOZ_OVERRIDE;
90 virtual bool
91 AnswerRemoveProperty(PPluginIdentifierChild* aId,
92 bool* aSuccess) MOZ_OVERRIDE;
94 virtual bool
95 AnswerEnumerate(InfallibleTArray<PPluginIdentifierChild*>* aProperties,
96 bool* aSuccess) MOZ_OVERRIDE;
98 virtual bool
99 AnswerConstruct(const InfallibleTArray<Variant>& aArgs,
100 Variant* aResult,
101 bool* aSuccess) MOZ_OVERRIDE;
103 virtual bool
104 RecvProtect() MOZ_OVERRIDE;
106 virtual bool
107 RecvUnprotect() MOZ_OVERRIDE;
109 NPObject*
110 GetObject(bool aCanResurrect);
112 static const NPClass*
113 GetClass()
114 {
115 return &sNPClass;
116 }
118 PluginInstanceChild*
119 GetInstance() const
120 {
121 return mInstance;
122 }
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();
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();
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();
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();
150 bool
151 Evaluate(NPString* aScript,
152 NPVariant* aResult);
154 ScriptableObjectType
155 Type() const {
156 return mType;
157 }
159 private:
160 static NPObject*
161 ScriptableAllocate(NPP aInstance,
162 NPClass* aClass);
164 static void
165 ScriptableInvalidate(NPObject* aObject);
167 static void
168 ScriptableDeallocate(NPObject* aObject);
170 static bool
171 ScriptableHasMethod(NPObject* aObject,
172 NPIdentifier aName);
174 static bool
175 ScriptableInvoke(NPObject* aObject,
176 NPIdentifier aName,
177 const NPVariant* aArgs,
178 uint32_t aArgCount,
179 NPVariant* aResult);
181 static bool
182 ScriptableInvokeDefault(NPObject* aObject,
183 const NPVariant* aArgs,
184 uint32_t aArgCount,
185 NPVariant* aResult);
187 static bool
188 ScriptableHasProperty(NPObject* aObject,
189 NPIdentifier aName);
191 static bool
192 ScriptableGetProperty(NPObject* aObject,
193 NPIdentifier aName,
194 NPVariant* aResult);
196 static bool
197 ScriptableSetProperty(NPObject* aObject,
198 NPIdentifier aName,
199 const NPVariant* aValue);
201 static bool
202 ScriptableRemoveProperty(NPObject* aObject,
203 NPIdentifier aName);
205 static bool
206 ScriptableEnumerate(NPObject* aObject,
207 NPIdentifier** aIdentifiers,
208 uint32_t* aCount);
210 static bool
211 ScriptableConstruct(NPObject* aObject,
212 const NPVariant* aArgs,
213 uint32_t aArgCount,
214 NPVariant* aResult);
216 NPObject*
217 CreateProxyObject();
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();
224 private:
225 PluginInstanceChild* mInstance;
226 NPObject* mObject;
227 bool mInvalidated;
228 int mProtectCount;
230 ScriptableObjectType mType;
232 static const NPClass sNPClass;
233 };
235 } /* namespace plugins */
236 } /* namespace mozilla */
238 #endif /* dom_plugins_PluginScriptableObjectChild_h */