dom/plugins/base/nsNPAPIPlugin.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial