Coverage Report

Created: 2018-09-25 14:53

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