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