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 nsJSNPRuntime_h_ michael@0: #define nsJSNPRuntime_h_ michael@0: michael@0: #include "nscore.h" michael@0: #include "npapi.h" michael@0: #include "npruntime.h" michael@0: #include "pldhash.h" michael@0: michael@0: class nsJSNPRuntime michael@0: { michael@0: public: michael@0: static void OnPluginDestroy(NPP npp); michael@0: }; michael@0: michael@0: class nsJSObjWrapperKey michael@0: { michael@0: public: michael@0: nsJSObjWrapperKey(JSObject *obj, NPP npp) michael@0: : mJSObj(obj), mNpp(npp) michael@0: { michael@0: } michael@0: michael@0: bool operator==(const nsJSObjWrapperKey& other) const { michael@0: return mJSObj == other.mJSObj && mNpp == other.mNpp; michael@0: } michael@0: bool operator!=(const nsJSObjWrapperKey& other) const { michael@0: return !(*this == other); michael@0: } michael@0: michael@0: JSObject * mJSObj; michael@0: const NPP mNpp; michael@0: }; michael@0: michael@0: extern const JSClass sNPObjectJSWrapperClass; michael@0: michael@0: class nsJSObjWrapper : public NPObject michael@0: { michael@0: public: michael@0: JS::PersistentRooted mJSObj; michael@0: const NPP mNpp; michael@0: michael@0: static NPObject *GetNewOrUsed(NPP npp, JSContext *cx, michael@0: JS::Handle obj); michael@0: michael@0: protected: michael@0: nsJSObjWrapper(NPP npp); michael@0: ~nsJSObjWrapper(); michael@0: michael@0: static NPObject * NP_Allocate(NPP npp, NPClass *aClass); michael@0: static void NP_Deallocate(NPObject *obj); michael@0: static void NP_Invalidate(NPObject *obj); michael@0: static bool NP_HasMethod(NPObject *, NPIdentifier identifier); michael@0: static bool NP_Invoke(NPObject *obj, NPIdentifier method, michael@0: const NPVariant *args, uint32_t argCount, michael@0: NPVariant *result); michael@0: static bool NP_InvokeDefault(NPObject *obj, const NPVariant *args, michael@0: uint32_t argCount, NPVariant *result); michael@0: static bool NP_HasProperty(NPObject * obj, NPIdentifier property); michael@0: static bool NP_GetProperty(NPObject *obj, NPIdentifier property, michael@0: NPVariant *result); michael@0: static bool NP_SetProperty(NPObject *obj, NPIdentifier property, michael@0: const NPVariant *value); michael@0: static bool NP_RemoveProperty(NPObject *obj, NPIdentifier property); michael@0: static bool NP_Enumerate(NPObject *npobj, NPIdentifier **identifier, michael@0: uint32_t *count); michael@0: static bool NP_Construct(NPObject *obj, const NPVariant *args, michael@0: uint32_t argCount, NPVariant *result); michael@0: michael@0: public: michael@0: static NPClass sJSObjWrapperNPClass; michael@0: }; michael@0: michael@0: class nsNPObjWrapper michael@0: { michael@0: public: michael@0: static void OnDestroy(NPObject *npobj); michael@0: static JSObject *GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj); michael@0: }; michael@0: michael@0: bool michael@0: JSValToNPVariant(NPP npp, JSContext *cx, JS::Value val, NPVariant *variant); michael@0: michael@0: michael@0: #endif // nsJSNPRuntime_h_