LCOV - code coverage report
Current view: top level - dom/plugins/base - nsNPAPIPlugin.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 31 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13