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