Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/plugins/base/nsNPAPIPlugin.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef nsNPAPIPlugin_h_
7
#define nsNPAPIPlugin_h_
8
9
#include "prlink.h"
10
#include "npfunctions.h"
11
#include "nsPluginHost.h"
12
13
#include "mozilla/dom/ScriptSettings.h"
14
#include "mozilla/PluginLibrary.h"
15
#include "mozilla/RefCounted.h"
16
17
// nsNPAPIPlugin is held alive both by active nsPluginTag instances and
18
// by active nsNPAPIPluginInstance.
19
class nsNPAPIPlugin final
20
{
21
private:
22
  typedef mozilla::PluginLibrary PluginLibrary;
23
24
public:
25
  nsNPAPIPlugin();
26
27
  NS_INLINE_DECL_REFCOUNTING(nsNPAPIPlugin)
28
29
  // Constructs and initializes an nsNPAPIPlugin object. A nullptr file path
30
  // will prevent this from calling NP_Initialize.
31
  static nsresult CreatePlugin(nsPluginTag *aPluginTag, nsNPAPIPlugin** aResult);
32
33
  PluginLibrary* GetLibrary();
34
  // PluginFuncs() can't fail but results are only valid if GetLibrary() succeeds
35
  NPPluginFuncs* PluginFuncs();
36
37
#if defined(XP_MACOSX) && !defined(__LP64__)
38
  void SetPluginRefNum(short aRefNum);
39
#endif
40
41
  // The IPC mechanism notifies the nsNPAPIPlugin if the plugin
42
  // crashes and is no longer usable. pluginDumpID/browserDumpID are
43
  // the IDs of respective minidumps that were written, or empty if no
44
  // minidump was written.
45
  void PluginCrashed(const nsAString& pluginDumpID,
46
                     const nsAString& browserDumpID);
47
48
  nsresult Shutdown();
49
50
  static nsresult RetainStream(NPStream *pstream, nsISupports **aRetainedPeer);
51
52
private:
53
  ~nsNPAPIPlugin();
54
55
  NPPluginFuncs mPluginFuncs;
56
  PluginLibrary* mLibrary;
57
};
58
59
namespace mozilla {
60
namespace plugins {
61
namespace parent {
62
63
static_assert(sizeof(NPIdentifier) == sizeof(jsid),
64
              "NPIdentifier must be binary compatible with jsid.");
65
66
inline jsid
67
NPIdentifierToJSId(NPIdentifier id)
68
0
{
69
0
    jsid tmp;
70
0
    JSID_BITS(tmp) = (size_t)id;
71
0
    return tmp;
72
0
}
73
74
inline NPIdentifier
75
JSIdToNPIdentifier(jsid id)
76
0
{
77
0
    return (NPIdentifier)JSID_BITS(id);
78
0
}
79
80
inline bool
81
NPIdentifierIsString(NPIdentifier id)
82
0
{
83
0
    return JSID_IS_STRING(NPIdentifierToJSId(id));
84
0
}
85
86
inline JSString *
87
NPIdentifierToString(NPIdentifier id)
88
0
{
89
0
    return JSID_TO_STRING(NPIdentifierToJSId(id));
90
0
}
91
92
inline NPIdentifier
93
StringToNPIdentifier(JSContext *cx, JSString *str)
94
0
{
95
0
    return JSIdToNPIdentifier(INTERNED_STRING_TO_JSID(cx, str));
96
0
}
97
98
inline bool
99
NPIdentifierIsInt(NPIdentifier id)
100
0
{
101
0
    return JSID_IS_INT(NPIdentifierToJSId(id));
102
0
}
103
104
inline int
105
NPIdentifierToInt(NPIdentifier id)
106
0
{
107
0
    return JSID_TO_INT(NPIdentifierToJSId(id));
108
0
}
109
110
inline NPIdentifier
111
IntToNPIdentifier(int i)
112
0
{
113
0
    return JSIdToNPIdentifier(INT_TO_JSID(i));
114
0
}
115
116
JSContext* GetJSContext(NPP npp);
117
118
inline bool
119
NPStringIdentifierIsPermanent(NPIdentifier id)
120
0
{
121
0
  AutoSafeJSContext cx;
122
0
  return JS_StringHasBeenPinned(cx, NPIdentifierToString(id));
123
0
}
124
125
0
#define NPIdentifier_VOID (JSIdToNPIdentifier(JSID_VOID))
126
127
NPObject*
128
_getwindowobject(NPP npp);
129
130
NPObject*
131
_getpluginelement(NPP npp);
132
133
NPIdentifier
134
_getstringidentifier(const NPUTF8* name);
135
136
void
137
_getstringidentifiers(const NPUTF8** names, int32_t nameCount,
138
                      NPIdentifier *identifiers);
139
140
bool
141
_identifierisstring(NPIdentifier identifiers);
142
143
NPIdentifier
144
_getintidentifier(int32_t intid);
145
146
NPUTF8*
147
_utf8fromidentifier(NPIdentifier identifier);
148
149
int32_t
150
_intfromidentifier(NPIdentifier identifier);
151
152
NPObject*
153
_createobject(NPP npp, NPClass* aClass);
154
155
NPObject*
156
_retainobject(NPObject* npobj);
157
158
void
159
_releaseobject(NPObject* npobj);
160
161
bool
162
_invoke(NPP npp, NPObject* npobj, NPIdentifier method, const NPVariant *args,
163
        uint32_t argCount, NPVariant *result);
164
165
bool
166
_invokeDefault(NPP npp, NPObject* npobj, const NPVariant *args,
167
               uint32_t argCount, NPVariant *result);
168
169
bool
170
_evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result);
171
172
bool
173
_getproperty(NPP npp, NPObject* npobj, NPIdentifier property,
174
             NPVariant *result);
175
176
bool
177
_setproperty(NPP npp, NPObject* npobj, NPIdentifier property,
178
             const NPVariant *value);
179
180
bool
181
_removeproperty(NPP npp, NPObject* npobj, NPIdentifier property);
182
183
bool
184
_hasproperty(NPP npp, NPObject* npobj, NPIdentifier propertyName);
185
186
bool
187
_hasmethod(NPP npp, NPObject* npobj, NPIdentifier methodName);
188
189
bool
190
_enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
191
           uint32_t *count);
192
193
bool
194
_construct(NPP npp, NPObject* npobj, const NPVariant *args,
195
           uint32_t argCount, NPVariant *result);
196
197
void
198
_releasevariantvalue(NPVariant *variant);
199
200
void
201
_setexception(NPObject* npobj, const NPUTF8 *message);
202
203
void
204
_pushpopupsenabledstate(NPP npp, NPBool enabled);
205
206
void
207
_poppopupsenabledstate(NPP npp);
208
209
NPError
210
_getvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
211
                char **value, uint32_t *len);
212
213
NPError
214
_setvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
215
                const char *value, uint32_t len);
216
217
typedef void(*PluginTimerFunc)(NPP npp, uint32_t timerID);
218
219
uint32_t
220
_scheduletimer(NPP instance, uint32_t interval, NPBool repeat, PluginTimerFunc timerFunc);
221
222
void
223
_unscheduletimer(NPP instance, uint32_t timerID);
224
225
NPError
226
_popupcontextmenu(NPP instance, NPMenu* menu);
227
228
NPBool
229
_convertpoint(NPP instance, double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double *destX, double *destY, NPCoordinateSpace destSpace);
230
231
NPError
232
_requestread(NPStream *pstream, NPByteRange *rangeList);
233
234
NPError
235
_geturlnotify(NPP npp, const char* relativeURL, const char* target,
236
              void* notifyData);
237
238
NPError
239
_getvalue(NPP npp, NPNVariable variable, void *r_value);
240
241
NPError
242
_setvalue(NPP npp, NPPVariable variable, void *r_value);
243
244
NPError
245
_geturl(NPP npp, const char* relativeURL, const char* target);
246
247
NPError
248
_posturlnotify(NPP npp, const char* relativeURL, const char *target,
249
               uint32_t len, const char *buf, NPBool file, void* notifyData);
250
251
NPError
252
_posturl(NPP npp, const char* relativeURL, const char *target, uint32_t len,
253
            const char *buf, NPBool file);
254
255
void
256
_status(NPP npp, const char *message);
257
258
void
259
_memfree (void *ptr);
260
261
uint32_t
262
_memflush(uint32_t size);
263
264
void
265
_reloadplugins(NPBool reloadPages);
266
267
void
268
_invalidaterect(NPP npp, NPRect *invalidRect);
269
270
void
271
_invalidateregion(NPP npp, NPRegion invalidRegion);
272
273
void
274
_forceredraw(NPP npp);
275
276
const char*
277
_useragent(NPP npp);
278
279
void*
280
_memalloc (uint32_t size);
281
282
// Deprecated entry points for the old Java plugin.
283
void* /* OJI type: JRIEnv* */
284
_getJavaEnv();
285
286
void* /* OJI type: jref */
287
_getJavaPeer(NPP npp);
288
289
void
290
_urlredirectresponse(NPP instance, void* notifyData, NPBool allow);
291
292
NPError
293
_initasyncsurface(NPP instance, NPSize *size, NPImageFormat format, void *initData, NPAsyncSurface *surface);
294
295
NPError
296
_finalizeasyncsurface(NPP instance, NPAsyncSurface *surface);
297
298
void
299
_setcurrentasyncsurface(NPP instance, NPAsyncSurface *surface, NPRect *changed);
300
301
} /* namespace parent */
302
} /* namespace plugins */
303
} /* namespace mozilla */
304
305
const char *
306
PeekException();
307
308
void
309
PopException();
310
311
class NPPStack
312
{
313
public:
314
  static NPP Peek()
315
0
  {
316
0
    return sCurrentNPP;
317
0
  }
318
319
protected:
320
  static NPP sCurrentNPP;
321
};
322
323
// XXXjst: The NPPAutoPusher stack is a bit redundant now that
324
// PluginDestructionGuard exists, and could thus be replaced by code
325
// that uses the PluginDestructionGuard list of plugins on the
326
// stack. But they're not identical, and to minimize code changes
327
// we're keeping both for the moment, and making NPPAutoPusher inherit
328
// the PluginDestructionGuard class to avoid having to keep two
329
// separate objects on the stack since we always want a
330
// PluginDestructionGuard where we use an NPPAutoPusher.
331
332
class MOZ_STACK_CLASS NPPAutoPusher : public NPPStack,
333
                                      protected PluginDestructionGuard
334
{
335
public:
336
  explicit NPPAutoPusher(NPP aNpp)
337
    : PluginDestructionGuard(aNpp),
338
      mOldNPP(sCurrentNPP)
339
0
  {
340
0
    NS_ASSERTION(aNpp, "Uh, null aNpp passed to NPPAutoPusher!");
341
0
342
0
    sCurrentNPP = aNpp;
343
0
  }
344
345
  ~NPPAutoPusher()
346
0
  {
347
0
    sCurrentNPP = mOldNPP;
348
0
  }
349
350
private:
351
  NPP mOldNPP;
352
};
353
354
class NPPExceptionAutoHolder
355
{
356
public:
357
  NPPExceptionAutoHolder();
358
  ~NPPExceptionAutoHolder();
359
360
protected:
361
  char *mOldException;
362
};
363
364
#endif // nsNPAPIPlugin_h_