michael@0: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * 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: #include "nsISupports.idl" michael@0: #include "nsIClassInfo.idl" michael@0: michael@0: %{C++ michael@0: #ifdef XP_WIN michael@0: #undef GetClassName michael@0: #endif michael@0: michael@0: #include "js/TypeDecls.h" michael@0: michael@0: struct JSFreeOp; michael@0: %} michael@0: michael@0: interface nsIXPConnectWrappedNative; michael@0: michael@0: [ptr] native JSContextPtr(JSContext); michael@0: [ptr] native JSObjectPtr(JSObject); michael@0: [ptr] native JSValPtr(JS::Value); michael@0: [ptr] native JSFreeOpPtr(JSFreeOp); michael@0: [ref] native JSCallArgsRef(const JS::CallArgs); michael@0: michael@0: /** michael@0: * Note: This is not really an XPCOM interface. For example, callers must michael@0: * guarantee that they set the *_retval of the various methods that return a michael@0: * boolean to PR_TRUE before making the call. Implementations may skip writing michael@0: * to *_retval unless they want to return PR_FALSE. michael@0: */ michael@0: [uuid(9bae4ff5-5618-4ccd-b106-8e21e3fb64d3)] michael@0: interface nsIXPCScriptable : nsISupports michael@0: { michael@0: /* bitflags used for 'flags' (only 32 bits available!) */ michael@0: michael@0: const uint32_t WANT_PRECREATE = 1 << 0; michael@0: const uint32_t WANT_CREATE = 1 << 1; michael@0: const uint32_t WANT_POSTCREATE = 1 << 2; michael@0: const uint32_t WANT_ADDPROPERTY = 1 << 3; michael@0: const uint32_t WANT_DELPROPERTY = 1 << 4; michael@0: const uint32_t WANT_GETPROPERTY = 1 << 5; michael@0: const uint32_t WANT_SETPROPERTY = 1 << 6; michael@0: const uint32_t WANT_ENUMERATE = 1 << 7; michael@0: const uint32_t WANT_NEWENUMERATE = 1 << 8; michael@0: const uint32_t WANT_NEWRESOLVE = 1 << 9; michael@0: const uint32_t WANT_CONVERT = 1 << 10; michael@0: const uint32_t WANT_FINALIZE = 1 << 11; michael@0: // unused bit here! michael@0: const uint32_t WANT_CALL = 1 << 13; michael@0: const uint32_t WANT_CONSTRUCT = 1 << 14; michael@0: const uint32_t WANT_HASINSTANCE = 1 << 15; michael@0: // Unused bit here! michael@0: const uint32_t USE_JSSTUB_FOR_ADDPROPERTY = 1 << 17; michael@0: const uint32_t USE_JSSTUB_FOR_DELPROPERTY = 1 << 18; michael@0: const uint32_t USE_JSSTUB_FOR_SETPROPERTY = 1 << 19; michael@0: const uint32_t DONT_ENUM_STATIC_PROPS = 1 << 20; michael@0: const uint32_t DONT_ENUM_QUERY_INTERFACE = 1 << 21; michael@0: const uint32_t DONT_ASK_INSTANCE_FOR_SCRIPTABLE = 1 << 22; michael@0: const uint32_t CLASSINFO_INTERFACES_ONLY = 1 << 23; michael@0: const uint32_t ALLOW_PROP_MODS_DURING_RESOLVE = 1 << 24; michael@0: const uint32_t ALLOW_PROP_MODS_TO_PROTOTYPE = 1 << 25; michael@0: const uint32_t IS_GLOBAL_OBJECT = 1 << 26; michael@0: const uint32_t DONT_REFLECT_INTERFACE_NAMES = 1 << 27; michael@0: // Unused bit here! michael@0: const uint32_t WANT_OUTER_OBJECT = 1 << 29; michael@0: michael@0: // The high order bit is RESERVED for consumers of these flags. michael@0: // No implementor of this interface should ever return flags michael@0: // with this bit set. michael@0: const uint32_t RESERVED = 1 << 31; michael@0: michael@0: readonly attribute string className; michael@0: [notxpcom,nostdcall] uint32_t getScriptableFlags(); michael@0: michael@0: void preCreate(in nsISupports nativeObj, in JSContextPtr cx, michael@0: in JSObjectPtr globalObj, out JSObjectPtr parentObj); michael@0: michael@0: void create(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj); michael@0: michael@0: // Both methods here are protected by WANT_POSTCREATE. If you want to do michael@0: // something after a wrapper is created, there's a good chance you also michael@0: // want to do something when the wrapper is transplanted to a new michael@0: // compartment. michael@0: void postCreate(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj); michael@0: michael@0: void postTransplant(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj); michael@0: michael@0: boolean addProperty(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, in jsid id, michael@0: in JSValPtr vp); michael@0: michael@0: boolean delProperty(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, in jsid id); michael@0: michael@0: // The returnCode should be set to NS_SUCCESS_I_DID_SOMETHING if michael@0: // this method does something. michael@0: boolean getProperty(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, in jsid id, michael@0: in JSValPtr vp); michael@0: michael@0: // The returnCode should be set to NS_SUCCESS_I_DID_SOMETHING if michael@0: // this method does something. michael@0: boolean setProperty(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, in jsid id, michael@0: in JSValPtr vp); michael@0: michael@0: boolean enumerate(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj); michael@0: michael@0: boolean newEnumerate(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, michael@0: in uint32_t enum_op, in JSValPtr statep, out jsid idp); michael@0: michael@0: boolean newResolve(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, in jsid id, michael@0: out JSObjectPtr objp); michael@0: michael@0: boolean convert(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, michael@0: in uint32_t type, in JSValPtr vp); michael@0: michael@0: void finalize(in nsIXPConnectWrappedNative wrapper, michael@0: in JSFreeOpPtr fop, in JSObjectPtr obj); michael@0: michael@0: boolean call(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, michael@0: in JSCallArgsRef args); michael@0: michael@0: boolean construct(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, michael@0: in JSCallArgsRef args); michael@0: michael@0: boolean hasInstance(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj, michael@0: in jsval val, out boolean bp); michael@0: michael@0: JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, michael@0: in JSContextPtr cx, in JSObjectPtr obj); michael@0: michael@0: void postCreatePrototype(in JSContextPtr cx, in JSObjectPtr proto); michael@0: }; michael@0: michael@0: %{ C++ michael@0: michael@0: #include "nsAutoPtr.h" michael@0: michael@0: #define NS_XPCCLASSINFO_IID \ michael@0: { 0x9a5b0342, 0x0f70, 0x4d31, \ michael@0: { 0xb7, 0xd7, 0x29, 0x68, 0xa5, 0x70, 0x4b, 0xd8 } } michael@0: michael@0: class NS_NO_VTABLE nsXPCClassInfo : public nsIClassInfo, michael@0: public nsIXPCScriptable michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_XPCCLASSINFO_IID) michael@0: michael@0: NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0; michael@0: NS_IMETHOD_(MozExternalRefCountType) Release() = 0; michael@0: michael@0: virtual void PreserveWrapper(nsISupports *aNative) = 0; michael@0: michael@0: virtual uint32_t GetInterfacesBitmap() = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsXPCClassInfo, NS_XPCCLASSINFO_IID) michael@0: michael@0: inline michael@0: nsresult michael@0: CallQueryInterface(nsISupports* aSourcePtr, michael@0: nsRefPtrGetterAddRefs aDestPtr) michael@0: { michael@0: return CallQueryInterface(aSourcePtr, michael@0: static_cast(aDestPtr)); michael@0: } michael@0: michael@0: %}