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.

     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/. */
     6 #ifndef nsNPAPIPlugin_h_
     7 #define nsNPAPIPlugin_h_
     9 #include "prlink.h"
    10 #include "npfunctions.h"
    11 #include "nsPluginHost.h"
    13 #include "nsCxPusher.h"
    15 #include "mozilla/PluginLibrary.h"
    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
    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) ();
    28 class nsNPAPIPlugin : public nsISupports
    29 {
    30 private:
    31   typedef mozilla::PluginLibrary PluginLibrary;
    33 public:
    34   nsNPAPIPlugin();
    35   virtual ~nsNPAPIPlugin();
    37   NS_DECL_ISUPPORTS
    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);
    43   PluginLibrary* GetLibrary();
    44   // PluginFuncs() can't fail but results are only valid if GetLibrary() succeeds
    45   NPPluginFuncs* PluginFuncs();
    47 #if defined(XP_MACOSX) && !defined(__LP64__)
    48   void SetPluginRefNum(short aRefNum);
    49 #endif
    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);
    58   static bool RunPluginOOP(const nsPluginTag *aPluginTag);
    60   nsresult Shutdown();
    62   static nsresult RetainStream(NPStream *pstream, nsISupports **aRetainedPeer);
    64 protected:
    65   NPPluginFuncs mPluginFuncs;
    66   PluginLibrary* mLibrary;
    67 };
    69 namespace mozilla {
    70 namespace plugins {
    71 namespace parent {
    73 static_assert(sizeof(NPIdentifier) == sizeof(jsid),
    74               "NPIdentifier must be binary compatible with jsid.");
    76 inline jsid
    77 NPIdentifierToJSId(NPIdentifier id)
    78 {
    79     jsid tmp;
    80     JSID_BITS(tmp) = (size_t)id;
    81     return tmp;
    82 }
    84 inline NPIdentifier
    85 JSIdToNPIdentifier(jsid id)
    86 {
    87     return (NPIdentifier)JSID_BITS(id);
    88 }
    90 inline bool
    91 NPIdentifierIsString(NPIdentifier id)
    92 {
    93     return JSID_IS_STRING(NPIdentifierToJSId(id));
    94 }
    96 inline JSString *
    97 NPIdentifierToString(NPIdentifier id)
    98 {
    99     return JSID_TO_STRING(NPIdentifierToJSId(id));
   100 }
   102 inline NPIdentifier
   103 StringToNPIdentifier(JSContext *cx, JSString *str)
   104 {
   105     return JSIdToNPIdentifier(INTERNED_STRING_TO_JSID(cx, str));
   106 }
   108 inline bool
   109 NPIdentifierIsInt(NPIdentifier id)
   110 {
   111     return JSID_IS_INT(NPIdentifierToJSId(id));
   112 }
   114 inline int
   115 NPIdentifierToInt(NPIdentifier id)
   116 {
   117     return JSID_TO_INT(NPIdentifierToJSId(id));
   118 }
   120 inline NPIdentifier
   121 IntToNPIdentifier(int i)
   122 {
   123     return JSIdToNPIdentifier(INT_TO_JSID(i));
   124 }
   126 JSContext* GetJSContext(NPP npp);
   128 inline bool
   129 NPStringIdentifierIsPermanent(NPP npp, NPIdentifier id)
   130 {
   131   AutoSafeJSContext cx;
   132   return JS_StringHasBeenInterned(cx, NPIdentifierToString(id));
   133 }
   135 #define NPIdentifier_VOID (JSIdToNPIdentifier(JSID_VOID))
   137 NPObject*
   138 _getwindowobject(NPP npp);
   140 NPObject*
   141 _getpluginelement(NPP npp);
   143 NPIdentifier
   144 _getstringidentifier(const NPUTF8* name);
   146 void
   147 _getstringidentifiers(const NPUTF8** names, int32_t nameCount,
   148                       NPIdentifier *identifiers);
   150 bool
   151 _identifierisstring(NPIdentifier identifiers);
   153 NPIdentifier
   154 _getintidentifier(int32_t intid);
   156 NPUTF8*
   157 _utf8fromidentifier(NPIdentifier identifier);
   159 int32_t
   160 _intfromidentifier(NPIdentifier identifier);
   162 NPObject*
   163 _createobject(NPP npp, NPClass* aClass);
   165 NPObject*
   166 _retainobject(NPObject* npobj);
   168 void
   169 _releaseobject(NPObject* npobj);
   171 bool
   172 _invoke(NPP npp, NPObject* npobj, NPIdentifier method, const NPVariant *args,
   173         uint32_t argCount, NPVariant *result);
   175 bool
   176 _invokeDefault(NPP npp, NPObject* npobj, const NPVariant *args,
   177                uint32_t argCount, NPVariant *result);
   179 bool
   180 _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result);
   182 bool
   183 _getproperty(NPP npp, NPObject* npobj, NPIdentifier property,
   184              NPVariant *result);
   186 bool
   187 _setproperty(NPP npp, NPObject* npobj, NPIdentifier property,
   188              const NPVariant *value);
   190 bool
   191 _removeproperty(NPP npp, NPObject* npobj, NPIdentifier property);
   193 bool
   194 _hasproperty(NPP npp, NPObject* npobj, NPIdentifier propertyName);
   196 bool
   197 _hasmethod(NPP npp, NPObject* npobj, NPIdentifier methodName);
   199 bool
   200 _enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
   201            uint32_t *count);
   203 bool
   204 _construct(NPP npp, NPObject* npobj, const NPVariant *args,
   205            uint32_t argCount, NPVariant *result);
   207 void
   208 _releasevariantvalue(NPVariant *variant);
   210 void
   211 _setexception(NPObject* npobj, const NPUTF8 *message);
   213 void
   214 _pushpopupsenabledstate(NPP npp, NPBool enabled);
   216 void
   217 _poppopupsenabledstate(NPP npp);
   219 typedef void(*PluginThreadCallback)(void *);
   221 void
   222 _pluginthreadasynccall(NPP instance, PluginThreadCallback func,
   223                        void *userData);
   225 NPError
   226 _getvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
   227                 char **value, uint32_t *len);
   229 NPError
   230 _setvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
   231                 const char *value, uint32_t len);
   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);
   239 typedef void(*PluginTimerFunc)(NPP npp, uint32_t timerID);
   241 uint32_t
   242 _scheduletimer(NPP instance, uint32_t interval, NPBool repeat, PluginTimerFunc timerFunc);
   244 void
   245 _unscheduletimer(NPP instance, uint32_t timerID);
   247 NPError
   248 _popupcontextmenu(NPP instance, NPMenu* menu);
   250 NPError
   251 _initasyncsurface(NPP instance, NPSize *size, NPImageFormat format, void *initData, NPAsyncSurface *surface);
   253 NPError
   254 _finalizeasyncsurface(NPP instance, NPAsyncSurface *surface);
   256 void
   257 _setcurrentasyncsurface(NPP instance, NPAsyncSurface *surface, NPRect *changed);
   259 NPBool
   260 _convertpoint(NPP instance, double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double *destX, double *destY, NPCoordinateSpace destSpace);
   262 NPError
   263 _requestread(NPStream *pstream, NPByteRange *rangeList);
   265 NPError
   266 _geturlnotify(NPP npp, const char* relativeURL, const char* target,
   267               void* notifyData);
   269 NPError
   270 _getvalue(NPP npp, NPNVariable variable, void *r_value);
   272 NPError
   273 _setvalue(NPP npp, NPPVariable variable, void *r_value);
   275 NPError
   276 _geturl(NPP npp, const char* relativeURL, const char* target);
   278 NPError
   279 _posturlnotify(NPP npp, const char* relativeURL, const char *target,
   280                uint32_t len, const char *buf, NPBool file, void* notifyData);
   282 NPError
   283 _posturl(NPP npp, const char* relativeURL, const char *target, uint32_t len,
   284             const char *buf, NPBool file);
   286 NPError
   287 _newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream);
   289 int32_t
   290 _write(NPP npp, NPStream *pstream, int32_t len, void *buffer);
   292 NPError
   293 _destroystream(NPP npp, NPStream *pstream, NPError reason);
   295 void
   296 _status(NPP npp, const char *message);
   298 void
   299 _memfree (void *ptr);
   301 uint32_t
   302 _memflush(uint32_t size);
   304 void
   305 _reloadplugins(NPBool reloadPages);
   307 void
   308 _invalidaterect(NPP npp, NPRect *invalidRect);
   310 void
   311 _invalidateregion(NPP npp, NPRegion invalidRegion);
   313 void
   314 _forceredraw(NPP npp);
   316 const char*
   317 _useragent(NPP npp);
   319 void*
   320 _memalloc (uint32_t size);
   322 // Deprecated entry points for the old Java plugin.
   323 void* /* OJI type: JRIEnv* */
   324 _getJavaEnv();
   326 void* /* OJI type: jref */
   327 _getJavaPeer(NPP npp);
   329 void
   330 _urlredirectresponse(NPP instance, void* notifyData, NPBool allow);
   332 } /* namespace parent */
   333 } /* namespace plugins */
   334 } /* namespace mozilla */
   336 const char *
   337 PeekException();
   339 void
   340 PopException();
   342 void
   343 OnPluginDestroy(NPP instance);
   345 void
   346 OnShutdown();
   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 };
   358 class NPPStack
   359 {
   360 public:
   361   static NPP Peek()
   362   {
   363     return sCurrentNPP;
   364   }
   366 protected:
   367   static NPP sCurrentNPP;
   368 };
   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.
   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!");
   389     sCurrentNPP = npp;
   390   }
   392   ~NPPAutoPusher()
   393   {
   394     sCurrentNPP = mOldNPP;
   395   }
   397 private:
   398   NPP mOldNPP;
   399 };
   401 class NPPExceptionAutoHolder
   402 {
   403 public:
   404   NPPExceptionAutoHolder();
   405   ~NPPExceptionAutoHolder();
   407 protected:
   408   char *mOldException;
   409 };
   411 #endif // nsNPAPIPlugin_h_

mercurial