michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsNPAPIPlugin_h_ michael@0: #define nsNPAPIPlugin_h_ michael@0: michael@0: #include "prlink.h" michael@0: #include "npfunctions.h" michael@0: #include "nsPluginHost.h" michael@0: michael@0: #include "nsCxPusher.h" michael@0: michael@0: #include "mozilla/PluginLibrary.h" michael@0: michael@0: #if defined(XP_WIN) michael@0: #define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (__stdcall * _name) michael@0: #else michael@0: #define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (* _name) michael@0: #endif michael@0: michael@0: typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_GETENTRYPOINTS) (NPPluginFuncs* pCallbacks); michael@0: typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGININIT) (const NPNetscapeFuncs* pCallbacks); michael@0: typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINUNIXINIT) (const NPNetscapeFuncs* pCallbacks, NPPluginFuncs* fCallbacks); michael@0: typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINSHUTDOWN) (); michael@0: michael@0: class nsNPAPIPlugin : public nsISupports michael@0: { michael@0: private: michael@0: typedef mozilla::PluginLibrary PluginLibrary; michael@0: michael@0: public: michael@0: nsNPAPIPlugin(); michael@0: virtual ~nsNPAPIPlugin(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // Constructs and initializes an nsNPAPIPlugin object. A nullptr file path michael@0: // will prevent this from calling NP_Initialize. michael@0: static nsresult CreatePlugin(nsPluginTag *aPluginTag, nsNPAPIPlugin** aResult); michael@0: michael@0: PluginLibrary* GetLibrary(); michael@0: // PluginFuncs() can't fail but results are only valid if GetLibrary() succeeds michael@0: NPPluginFuncs* PluginFuncs(); michael@0: michael@0: #if defined(XP_MACOSX) && !defined(__LP64__) michael@0: void SetPluginRefNum(short aRefNum); michael@0: #endif michael@0: michael@0: // The IPC mechanism notifies the nsNPAPIPlugin if the plugin michael@0: // crashes and is no longer usable. pluginDumpID/browserDumpID are michael@0: // the IDs of respective minidumps that were written, or empty if no michael@0: // minidump was written. michael@0: void PluginCrashed(const nsAString& pluginDumpID, michael@0: const nsAString& browserDumpID); michael@0: michael@0: static bool RunPluginOOP(const nsPluginTag *aPluginTag); michael@0: michael@0: nsresult Shutdown(); michael@0: michael@0: static nsresult RetainStream(NPStream *pstream, nsISupports **aRetainedPeer); michael@0: michael@0: protected: michael@0: NPPluginFuncs mPluginFuncs; michael@0: PluginLibrary* mLibrary; michael@0: }; michael@0: michael@0: namespace mozilla { michael@0: namespace plugins { michael@0: namespace parent { michael@0: michael@0: static_assert(sizeof(NPIdentifier) == sizeof(jsid), michael@0: "NPIdentifier must be binary compatible with jsid."); michael@0: michael@0: inline jsid michael@0: NPIdentifierToJSId(NPIdentifier id) michael@0: { michael@0: jsid tmp; michael@0: JSID_BITS(tmp) = (size_t)id; michael@0: return tmp; michael@0: } michael@0: michael@0: inline NPIdentifier michael@0: JSIdToNPIdentifier(jsid id) michael@0: { michael@0: return (NPIdentifier)JSID_BITS(id); michael@0: } michael@0: michael@0: inline bool michael@0: NPIdentifierIsString(NPIdentifier id) michael@0: { michael@0: return JSID_IS_STRING(NPIdentifierToJSId(id)); michael@0: } michael@0: michael@0: inline JSString * michael@0: NPIdentifierToString(NPIdentifier id) michael@0: { michael@0: return JSID_TO_STRING(NPIdentifierToJSId(id)); michael@0: } michael@0: michael@0: inline NPIdentifier michael@0: StringToNPIdentifier(JSContext *cx, JSString *str) michael@0: { michael@0: return JSIdToNPIdentifier(INTERNED_STRING_TO_JSID(cx, str)); michael@0: } michael@0: michael@0: inline bool michael@0: NPIdentifierIsInt(NPIdentifier id) michael@0: { michael@0: return JSID_IS_INT(NPIdentifierToJSId(id)); michael@0: } michael@0: michael@0: inline int michael@0: NPIdentifierToInt(NPIdentifier id) michael@0: { michael@0: return JSID_TO_INT(NPIdentifierToJSId(id)); michael@0: } michael@0: michael@0: inline NPIdentifier michael@0: IntToNPIdentifier(int i) michael@0: { michael@0: return JSIdToNPIdentifier(INT_TO_JSID(i)); michael@0: } michael@0: michael@0: JSContext* GetJSContext(NPP npp); michael@0: michael@0: inline bool michael@0: NPStringIdentifierIsPermanent(NPP npp, NPIdentifier id) michael@0: { michael@0: AutoSafeJSContext cx; michael@0: return JS_StringHasBeenInterned(cx, NPIdentifierToString(id)); michael@0: } michael@0: michael@0: #define NPIdentifier_VOID (JSIdToNPIdentifier(JSID_VOID)) michael@0: michael@0: NPObject* michael@0: _getwindowobject(NPP npp); michael@0: michael@0: NPObject* michael@0: _getpluginelement(NPP npp); michael@0: michael@0: NPIdentifier michael@0: _getstringidentifier(const NPUTF8* name); michael@0: michael@0: void michael@0: _getstringidentifiers(const NPUTF8** names, int32_t nameCount, michael@0: NPIdentifier *identifiers); michael@0: michael@0: bool michael@0: _identifierisstring(NPIdentifier identifiers); michael@0: michael@0: NPIdentifier michael@0: _getintidentifier(int32_t intid); michael@0: michael@0: NPUTF8* michael@0: _utf8fromidentifier(NPIdentifier identifier); michael@0: michael@0: int32_t michael@0: _intfromidentifier(NPIdentifier identifier); michael@0: michael@0: NPObject* michael@0: _createobject(NPP npp, NPClass* aClass); michael@0: michael@0: NPObject* michael@0: _retainobject(NPObject* npobj); michael@0: michael@0: void michael@0: _releaseobject(NPObject* npobj); michael@0: michael@0: bool michael@0: _invoke(NPP npp, NPObject* npobj, NPIdentifier method, const NPVariant *args, michael@0: uint32_t argCount, NPVariant *result); michael@0: michael@0: bool michael@0: _invokeDefault(NPP npp, NPObject* npobj, const NPVariant *args, michael@0: uint32_t argCount, NPVariant *result); michael@0: michael@0: bool michael@0: _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result); michael@0: michael@0: bool michael@0: _getproperty(NPP npp, NPObject* npobj, NPIdentifier property, michael@0: NPVariant *result); michael@0: michael@0: bool michael@0: _setproperty(NPP npp, NPObject* npobj, NPIdentifier property, michael@0: const NPVariant *value); michael@0: michael@0: bool michael@0: _removeproperty(NPP npp, NPObject* npobj, NPIdentifier property); michael@0: michael@0: bool michael@0: _hasproperty(NPP npp, NPObject* npobj, NPIdentifier propertyName); michael@0: michael@0: bool michael@0: _hasmethod(NPP npp, NPObject* npobj, NPIdentifier methodName); michael@0: michael@0: bool michael@0: _enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier, michael@0: uint32_t *count); michael@0: michael@0: bool michael@0: _construct(NPP npp, NPObject* npobj, const NPVariant *args, michael@0: uint32_t argCount, NPVariant *result); michael@0: michael@0: void michael@0: _releasevariantvalue(NPVariant *variant); michael@0: michael@0: void michael@0: _setexception(NPObject* npobj, const NPUTF8 *message); michael@0: michael@0: void michael@0: _pushpopupsenabledstate(NPP npp, NPBool enabled); michael@0: michael@0: void michael@0: _poppopupsenabledstate(NPP npp); michael@0: michael@0: typedef void(*PluginThreadCallback)(void *); michael@0: michael@0: void michael@0: _pluginthreadasynccall(NPP instance, PluginThreadCallback func, michael@0: void *userData); michael@0: michael@0: NPError michael@0: _getvalueforurl(NPP instance, NPNURLVariable variable, const char *url, michael@0: char **value, uint32_t *len); michael@0: michael@0: NPError michael@0: _setvalueforurl(NPP instance, NPNURLVariable variable, const char *url, michael@0: const char *value, uint32_t len); michael@0: michael@0: NPError michael@0: _getauthenticationinfo(NPP instance, const char *protocol, const char *host, michael@0: int32_t port, const char *scheme, const char *realm, michael@0: char **username, uint32_t *ulen, char **password, michael@0: uint32_t *plen); michael@0: michael@0: typedef void(*PluginTimerFunc)(NPP npp, uint32_t timerID); michael@0: michael@0: uint32_t michael@0: _scheduletimer(NPP instance, uint32_t interval, NPBool repeat, PluginTimerFunc timerFunc); michael@0: michael@0: void michael@0: _unscheduletimer(NPP instance, uint32_t timerID); michael@0: michael@0: NPError michael@0: _popupcontextmenu(NPP instance, NPMenu* menu); michael@0: michael@0: NPError michael@0: _initasyncsurface(NPP instance, NPSize *size, NPImageFormat format, void *initData, NPAsyncSurface *surface); michael@0: michael@0: NPError michael@0: _finalizeasyncsurface(NPP instance, NPAsyncSurface *surface); michael@0: michael@0: void michael@0: _setcurrentasyncsurface(NPP instance, NPAsyncSurface *surface, NPRect *changed); michael@0: michael@0: NPBool michael@0: _convertpoint(NPP instance, double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double *destX, double *destY, NPCoordinateSpace destSpace); michael@0: michael@0: NPError michael@0: _requestread(NPStream *pstream, NPByteRange *rangeList); michael@0: michael@0: NPError michael@0: _geturlnotify(NPP npp, const char* relativeURL, const char* target, michael@0: void* notifyData); michael@0: michael@0: NPError michael@0: _getvalue(NPP npp, NPNVariable variable, void *r_value); michael@0: michael@0: NPError michael@0: _setvalue(NPP npp, NPPVariable variable, void *r_value); michael@0: michael@0: NPError michael@0: _geturl(NPP npp, const char* relativeURL, const char* target); michael@0: michael@0: NPError michael@0: _posturlnotify(NPP npp, const char* relativeURL, const char *target, michael@0: uint32_t len, const char *buf, NPBool file, void* notifyData); michael@0: michael@0: NPError michael@0: _posturl(NPP npp, const char* relativeURL, const char *target, uint32_t len, michael@0: const char *buf, NPBool file); michael@0: michael@0: NPError michael@0: _newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream); michael@0: michael@0: int32_t michael@0: _write(NPP npp, NPStream *pstream, int32_t len, void *buffer); michael@0: michael@0: NPError michael@0: _destroystream(NPP npp, NPStream *pstream, NPError reason); michael@0: michael@0: void michael@0: _status(NPP npp, const char *message); michael@0: michael@0: void michael@0: _memfree (void *ptr); michael@0: michael@0: uint32_t michael@0: _memflush(uint32_t size); michael@0: michael@0: void michael@0: _reloadplugins(NPBool reloadPages); michael@0: michael@0: void michael@0: _invalidaterect(NPP npp, NPRect *invalidRect); michael@0: michael@0: void michael@0: _invalidateregion(NPP npp, NPRegion invalidRegion); michael@0: michael@0: void michael@0: _forceredraw(NPP npp); michael@0: michael@0: const char* michael@0: _useragent(NPP npp); michael@0: michael@0: void* michael@0: _memalloc (uint32_t size); michael@0: michael@0: // Deprecated entry points for the old Java plugin. michael@0: void* /* OJI type: JRIEnv* */ michael@0: _getJavaEnv(); michael@0: michael@0: void* /* OJI type: jref */ michael@0: _getJavaPeer(NPP npp); michael@0: michael@0: void michael@0: _urlredirectresponse(NPP instance, void* notifyData, NPBool allow); michael@0: michael@0: } /* namespace parent */ michael@0: } /* namespace plugins */ michael@0: } /* namespace mozilla */ michael@0: michael@0: const char * michael@0: PeekException(); michael@0: michael@0: void michael@0: PopException(); michael@0: michael@0: void michael@0: OnPluginDestroy(NPP instance); michael@0: michael@0: void michael@0: OnShutdown(); michael@0: michael@0: /** michael@0: * within a lexical scope, locks and unlocks the mutex used to michael@0: * serialize modifications to plugin async callback state. michael@0: */ michael@0: struct MOZ_STACK_CLASS AsyncCallbackAutoLock michael@0: { michael@0: AsyncCallbackAutoLock(); michael@0: ~AsyncCallbackAutoLock(); michael@0: }; michael@0: michael@0: class NPPStack michael@0: { michael@0: public: michael@0: static NPP Peek() michael@0: { michael@0: return sCurrentNPP; michael@0: } michael@0: michael@0: protected: michael@0: static NPP sCurrentNPP; michael@0: }; michael@0: michael@0: // XXXjst: The NPPAutoPusher stack is a bit redundant now that michael@0: // PluginDestructionGuard exists, and could thus be replaced by code michael@0: // that uses the PluginDestructionGuard list of plugins on the michael@0: // stack. But they're not identical, and to minimize code changes michael@0: // we're keeping both for the moment, and making NPPAutoPusher inherit michael@0: // the PluginDestructionGuard class to avoid having to keep two michael@0: // separate objects on the stack since we always want a michael@0: // PluginDestructionGuard where we use an NPPAutoPusher. michael@0: michael@0: class MOZ_STACK_CLASS NPPAutoPusher : public NPPStack, michael@0: protected PluginDestructionGuard michael@0: { michael@0: public: michael@0: NPPAutoPusher(NPP npp) michael@0: : PluginDestructionGuard(npp), michael@0: mOldNPP(sCurrentNPP) michael@0: { michael@0: NS_ASSERTION(npp, "Uh, null npp passed to NPPAutoPusher!"); michael@0: michael@0: sCurrentNPP = npp; michael@0: } michael@0: michael@0: ~NPPAutoPusher() michael@0: { michael@0: sCurrentNPP = mOldNPP; michael@0: } michael@0: michael@0: private: michael@0: NPP mOldNPP; michael@0: }; michael@0: michael@0: class NPPExceptionAutoHolder michael@0: { michael@0: public: michael@0: NPPExceptionAutoHolder(); michael@0: ~NPPExceptionAutoHolder(); michael@0: michael@0: protected: michael@0: char *mOldException; michael@0: }; michael@0: michael@0: #endif // nsNPAPIPlugin_h_