dom/plugins/base/nsNPAPIPlugin.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/base/nsNPAPIPlugin.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,411 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsNPAPIPlugin_h_
    1.10 +#define nsNPAPIPlugin_h_
    1.11 +
    1.12 +#include "prlink.h"
    1.13 +#include "npfunctions.h"
    1.14 +#include "nsPluginHost.h"
    1.15 +
    1.16 +#include "nsCxPusher.h"
    1.17 +
    1.18 +#include "mozilla/PluginLibrary.h"
    1.19 +
    1.20 +#if defined(XP_WIN)
    1.21 +#define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (__stdcall * _name)
    1.22 +#else
    1.23 +#define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (* _name)
    1.24 +#endif
    1.25 +
    1.26 +typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_GETENTRYPOINTS) (NPPluginFuncs* pCallbacks);
    1.27 +typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGININIT) (const NPNetscapeFuncs* pCallbacks);
    1.28 +typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINUNIXINIT) (const NPNetscapeFuncs* pCallbacks, NPPluginFuncs* fCallbacks);
    1.29 +typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINSHUTDOWN) ();
    1.30 +
    1.31 +class nsNPAPIPlugin : public nsISupports
    1.32 +{
    1.33 +private:
    1.34 +  typedef mozilla::PluginLibrary PluginLibrary;
    1.35 +
    1.36 +public:
    1.37 +  nsNPAPIPlugin();
    1.38 +  virtual ~nsNPAPIPlugin();
    1.39 +
    1.40 +  NS_DECL_ISUPPORTS
    1.41 +
    1.42 +  // Constructs and initializes an nsNPAPIPlugin object. A nullptr file path
    1.43 +  // will prevent this from calling NP_Initialize.
    1.44 +  static nsresult CreatePlugin(nsPluginTag *aPluginTag, nsNPAPIPlugin** aResult);
    1.45 +
    1.46 +  PluginLibrary* GetLibrary();
    1.47 +  // PluginFuncs() can't fail but results are only valid if GetLibrary() succeeds
    1.48 +  NPPluginFuncs* PluginFuncs();
    1.49 +
    1.50 +#if defined(XP_MACOSX) && !defined(__LP64__)
    1.51 +  void SetPluginRefNum(short aRefNum);
    1.52 +#endif
    1.53 +
    1.54 +  // The IPC mechanism notifies the nsNPAPIPlugin if the plugin
    1.55 +  // crashes and is no longer usable. pluginDumpID/browserDumpID are
    1.56 +  // the IDs of respective minidumps that were written, or empty if no
    1.57 +  // minidump was written.
    1.58 +  void PluginCrashed(const nsAString& pluginDumpID,
    1.59 +                     const nsAString& browserDumpID);
    1.60 +  
    1.61 +  static bool RunPluginOOP(const nsPluginTag *aPluginTag);
    1.62 +
    1.63 +  nsresult Shutdown();
    1.64 +
    1.65 +  static nsresult RetainStream(NPStream *pstream, nsISupports **aRetainedPeer);
    1.66 +
    1.67 +protected:
    1.68 +  NPPluginFuncs mPluginFuncs;
    1.69 +  PluginLibrary* mLibrary;
    1.70 +};
    1.71 +
    1.72 +namespace mozilla {
    1.73 +namespace plugins {
    1.74 +namespace parent {
    1.75 +
    1.76 +static_assert(sizeof(NPIdentifier) == sizeof(jsid),
    1.77 +              "NPIdentifier must be binary compatible with jsid.");
    1.78 +
    1.79 +inline jsid
    1.80 +NPIdentifierToJSId(NPIdentifier id)
    1.81 +{
    1.82 +    jsid tmp;
    1.83 +    JSID_BITS(tmp) = (size_t)id;
    1.84 +    return tmp;
    1.85 +}
    1.86 +
    1.87 +inline NPIdentifier
    1.88 +JSIdToNPIdentifier(jsid id)
    1.89 +{
    1.90 +    return (NPIdentifier)JSID_BITS(id);
    1.91 +}
    1.92 +
    1.93 +inline bool
    1.94 +NPIdentifierIsString(NPIdentifier id)
    1.95 +{
    1.96 +    return JSID_IS_STRING(NPIdentifierToJSId(id));
    1.97 +}
    1.98 +
    1.99 +inline JSString *
   1.100 +NPIdentifierToString(NPIdentifier id)
   1.101 +{
   1.102 +    return JSID_TO_STRING(NPIdentifierToJSId(id));
   1.103 +}
   1.104 +
   1.105 +inline NPIdentifier
   1.106 +StringToNPIdentifier(JSContext *cx, JSString *str)
   1.107 +{
   1.108 +    return JSIdToNPIdentifier(INTERNED_STRING_TO_JSID(cx, str));
   1.109 +}
   1.110 +
   1.111 +inline bool
   1.112 +NPIdentifierIsInt(NPIdentifier id)
   1.113 +{
   1.114 +    return JSID_IS_INT(NPIdentifierToJSId(id));
   1.115 +}
   1.116 +
   1.117 +inline int
   1.118 +NPIdentifierToInt(NPIdentifier id)
   1.119 +{
   1.120 +    return JSID_TO_INT(NPIdentifierToJSId(id));
   1.121 +}
   1.122 +
   1.123 +inline NPIdentifier
   1.124 +IntToNPIdentifier(int i)
   1.125 +{
   1.126 +    return JSIdToNPIdentifier(INT_TO_JSID(i));
   1.127 +}
   1.128 +
   1.129 +JSContext* GetJSContext(NPP npp);
   1.130 +
   1.131 +inline bool
   1.132 +NPStringIdentifierIsPermanent(NPP npp, NPIdentifier id)
   1.133 +{
   1.134 +  AutoSafeJSContext cx;
   1.135 +  return JS_StringHasBeenInterned(cx, NPIdentifierToString(id));
   1.136 +}
   1.137 +
   1.138 +#define NPIdentifier_VOID (JSIdToNPIdentifier(JSID_VOID))
   1.139 +
   1.140 +NPObject*
   1.141 +_getwindowobject(NPP npp);
   1.142 +
   1.143 +NPObject*
   1.144 +_getpluginelement(NPP npp);
   1.145 +
   1.146 +NPIdentifier
   1.147 +_getstringidentifier(const NPUTF8* name);
   1.148 +
   1.149 +void
   1.150 +_getstringidentifiers(const NPUTF8** names, int32_t nameCount,
   1.151 +                      NPIdentifier *identifiers);
   1.152 +
   1.153 +bool
   1.154 +_identifierisstring(NPIdentifier identifiers);
   1.155 +
   1.156 +NPIdentifier
   1.157 +_getintidentifier(int32_t intid);
   1.158 +
   1.159 +NPUTF8*
   1.160 +_utf8fromidentifier(NPIdentifier identifier);
   1.161 +
   1.162 +int32_t
   1.163 +_intfromidentifier(NPIdentifier identifier);
   1.164 +
   1.165 +NPObject*
   1.166 +_createobject(NPP npp, NPClass* aClass);
   1.167 +
   1.168 +NPObject*
   1.169 +_retainobject(NPObject* npobj);
   1.170 +
   1.171 +void
   1.172 +_releaseobject(NPObject* npobj);
   1.173 +
   1.174 +bool
   1.175 +_invoke(NPP npp, NPObject* npobj, NPIdentifier method, const NPVariant *args,
   1.176 +        uint32_t argCount, NPVariant *result);
   1.177 +
   1.178 +bool
   1.179 +_invokeDefault(NPP npp, NPObject* npobj, const NPVariant *args,
   1.180 +               uint32_t argCount, NPVariant *result);
   1.181 +
   1.182 +bool
   1.183 +_evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result);
   1.184 +
   1.185 +bool
   1.186 +_getproperty(NPP npp, NPObject* npobj, NPIdentifier property,
   1.187 +             NPVariant *result);
   1.188 +
   1.189 +bool
   1.190 +_setproperty(NPP npp, NPObject* npobj, NPIdentifier property,
   1.191 +             const NPVariant *value);
   1.192 +
   1.193 +bool
   1.194 +_removeproperty(NPP npp, NPObject* npobj, NPIdentifier property);
   1.195 +
   1.196 +bool
   1.197 +_hasproperty(NPP npp, NPObject* npobj, NPIdentifier propertyName);
   1.198 +
   1.199 +bool
   1.200 +_hasmethod(NPP npp, NPObject* npobj, NPIdentifier methodName);
   1.201 +
   1.202 +bool
   1.203 +_enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
   1.204 +           uint32_t *count);
   1.205 +
   1.206 +bool
   1.207 +_construct(NPP npp, NPObject* npobj, const NPVariant *args,
   1.208 +           uint32_t argCount, NPVariant *result);
   1.209 +
   1.210 +void
   1.211 +_releasevariantvalue(NPVariant *variant);
   1.212 +
   1.213 +void
   1.214 +_setexception(NPObject* npobj, const NPUTF8 *message);
   1.215 +
   1.216 +void
   1.217 +_pushpopupsenabledstate(NPP npp, NPBool enabled);
   1.218 +
   1.219 +void
   1.220 +_poppopupsenabledstate(NPP npp);
   1.221 +
   1.222 +typedef void(*PluginThreadCallback)(void *);
   1.223 +
   1.224 +void
   1.225 +_pluginthreadasynccall(NPP instance, PluginThreadCallback func,
   1.226 +                       void *userData);
   1.227 +
   1.228 +NPError
   1.229 +_getvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
   1.230 +                char **value, uint32_t *len);
   1.231 +
   1.232 +NPError
   1.233 +_setvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
   1.234 +                const char *value, uint32_t len);
   1.235 +
   1.236 +NPError
   1.237 +_getauthenticationinfo(NPP instance, const char *protocol, const char *host,
   1.238 +                       int32_t port, const char *scheme, const char *realm,
   1.239 +                       char **username, uint32_t *ulen, char **password,
   1.240 +                       uint32_t *plen);
   1.241 +
   1.242 +typedef void(*PluginTimerFunc)(NPP npp, uint32_t timerID);
   1.243 +
   1.244 +uint32_t
   1.245 +_scheduletimer(NPP instance, uint32_t interval, NPBool repeat, PluginTimerFunc timerFunc);
   1.246 +
   1.247 +void
   1.248 +_unscheduletimer(NPP instance, uint32_t timerID);
   1.249 +
   1.250 +NPError
   1.251 +_popupcontextmenu(NPP instance, NPMenu* menu);
   1.252 +
   1.253 +NPError
   1.254 +_initasyncsurface(NPP instance, NPSize *size, NPImageFormat format, void *initData, NPAsyncSurface *surface);
   1.255 +
   1.256 +NPError
   1.257 +_finalizeasyncsurface(NPP instance, NPAsyncSurface *surface);
   1.258 +
   1.259 +void
   1.260 +_setcurrentasyncsurface(NPP instance, NPAsyncSurface *surface, NPRect *changed);
   1.261 +
   1.262 +NPBool
   1.263 +_convertpoint(NPP instance, double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double *destX, double *destY, NPCoordinateSpace destSpace);
   1.264 +
   1.265 +NPError
   1.266 +_requestread(NPStream *pstream, NPByteRange *rangeList);
   1.267 +
   1.268 +NPError
   1.269 +_geturlnotify(NPP npp, const char* relativeURL, const char* target,
   1.270 +              void* notifyData);
   1.271 +
   1.272 +NPError
   1.273 +_getvalue(NPP npp, NPNVariable variable, void *r_value);
   1.274 +
   1.275 +NPError
   1.276 +_setvalue(NPP npp, NPPVariable variable, void *r_value);
   1.277 +
   1.278 +NPError
   1.279 +_geturl(NPP npp, const char* relativeURL, const char* target);
   1.280 +
   1.281 +NPError
   1.282 +_posturlnotify(NPP npp, const char* relativeURL, const char *target,
   1.283 +               uint32_t len, const char *buf, NPBool file, void* notifyData);
   1.284 +
   1.285 +NPError
   1.286 +_posturl(NPP npp, const char* relativeURL, const char *target, uint32_t len,
   1.287 +            const char *buf, NPBool file);
   1.288 +
   1.289 +NPError
   1.290 +_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream);
   1.291 +
   1.292 +int32_t
   1.293 +_write(NPP npp, NPStream *pstream, int32_t len, void *buffer);
   1.294 +
   1.295 +NPError
   1.296 +_destroystream(NPP npp, NPStream *pstream, NPError reason);
   1.297 +
   1.298 +void
   1.299 +_status(NPP npp, const char *message);
   1.300 +
   1.301 +void
   1.302 +_memfree (void *ptr);
   1.303 +
   1.304 +uint32_t
   1.305 +_memflush(uint32_t size);
   1.306 +
   1.307 +void
   1.308 +_reloadplugins(NPBool reloadPages);
   1.309 +
   1.310 +void
   1.311 +_invalidaterect(NPP npp, NPRect *invalidRect);
   1.312 +
   1.313 +void
   1.314 +_invalidateregion(NPP npp, NPRegion invalidRegion);
   1.315 +
   1.316 +void
   1.317 +_forceredraw(NPP npp);
   1.318 +
   1.319 +const char*
   1.320 +_useragent(NPP npp);
   1.321 +
   1.322 +void*
   1.323 +_memalloc (uint32_t size);
   1.324 +
   1.325 +// Deprecated entry points for the old Java plugin.
   1.326 +void* /* OJI type: JRIEnv* */
   1.327 +_getJavaEnv();
   1.328 +
   1.329 +void* /* OJI type: jref */
   1.330 +_getJavaPeer(NPP npp);
   1.331 +
   1.332 +void
   1.333 +_urlredirectresponse(NPP instance, void* notifyData, NPBool allow);
   1.334 +
   1.335 +} /* namespace parent */
   1.336 +} /* namespace plugins */
   1.337 +} /* namespace mozilla */
   1.338 +
   1.339 +const char *
   1.340 +PeekException();
   1.341 +
   1.342 +void
   1.343 +PopException();
   1.344 +
   1.345 +void
   1.346 +OnPluginDestroy(NPP instance);
   1.347 +
   1.348 +void
   1.349 +OnShutdown();
   1.350 +
   1.351 +/**
   1.352 + * within a lexical scope, locks and unlocks the mutex used to
   1.353 + * serialize modifications to plugin async callback state.
   1.354 + */
   1.355 +struct MOZ_STACK_CLASS AsyncCallbackAutoLock
   1.356 +{
   1.357 +  AsyncCallbackAutoLock();
   1.358 +  ~AsyncCallbackAutoLock();
   1.359 +};
   1.360 +
   1.361 +class NPPStack
   1.362 +{
   1.363 +public:
   1.364 +  static NPP Peek()
   1.365 +  {
   1.366 +    return sCurrentNPP;
   1.367 +  }
   1.368 +
   1.369 +protected:
   1.370 +  static NPP sCurrentNPP;
   1.371 +};
   1.372 +
   1.373 +// XXXjst: The NPPAutoPusher stack is a bit redundant now that
   1.374 +// PluginDestructionGuard exists, and could thus be replaced by code
   1.375 +// that uses the PluginDestructionGuard list of plugins on the
   1.376 +// stack. But they're not identical, and to minimize code changes
   1.377 +// we're keeping both for the moment, and making NPPAutoPusher inherit
   1.378 +// the PluginDestructionGuard class to avoid having to keep two
   1.379 +// separate objects on the stack since we always want a
   1.380 +// PluginDestructionGuard where we use an NPPAutoPusher.
   1.381 +
   1.382 +class MOZ_STACK_CLASS NPPAutoPusher : public NPPStack,
   1.383 +                                      protected PluginDestructionGuard
   1.384 +{
   1.385 +public:
   1.386 +  NPPAutoPusher(NPP npp)
   1.387 +    : PluginDestructionGuard(npp),
   1.388 +      mOldNPP(sCurrentNPP)
   1.389 +  {
   1.390 +    NS_ASSERTION(npp, "Uh, null npp passed to NPPAutoPusher!");
   1.391 +
   1.392 +    sCurrentNPP = npp;
   1.393 +  }
   1.394 +
   1.395 +  ~NPPAutoPusher()
   1.396 +  {
   1.397 +    sCurrentNPP = mOldNPP;
   1.398 +  }
   1.399 +
   1.400 +private:
   1.401 +  NPP mOldNPP;
   1.402 +};
   1.403 +
   1.404 +class NPPExceptionAutoHolder
   1.405 +{
   1.406 +public:
   1.407 +  NPPExceptionAutoHolder();
   1.408 +  ~NPPExceptionAutoHolder();
   1.409 +
   1.410 +protected:
   1.411 +  char *mOldException;
   1.412 +};
   1.413 +
   1.414 +#endif // nsNPAPIPlugin_h_

mercurial