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 nsIDOMClassInfo_h___ michael@0: #define nsIDOMClassInfo_h___ michael@0: michael@0: #include "nsIClassInfoImpl.h" michael@0: #include "nsDOMClassInfoID.h" michael@0: #include "nsIXPCScriptable.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsIDOMScriptObjectFactory.h" michael@0: #include "nsDOMCID.h" michael@0: michael@0: #define DOM_BASE_SCRIPTABLE_FLAGS \ michael@0: (nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY | \ michael@0: nsIXPCScriptable::USE_JSSTUB_FOR_DELPROPERTY | \ michael@0: nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY | \ michael@0: nsIXPCScriptable::ALLOW_PROP_MODS_TO_PROTOTYPE | \ michael@0: nsIXPCScriptable::DONT_ASK_INSTANCE_FOR_SCRIPTABLE | \ michael@0: nsIXPCScriptable::DONT_REFLECT_INTERFACE_NAMES) michael@0: michael@0: #define DEFAULT_SCRIPTABLE_FLAGS \ michael@0: (DOM_BASE_SCRIPTABLE_FLAGS | \ michael@0: nsIXPCScriptable::WANT_NEWRESOLVE | \ michael@0: nsIXPCScriptable::WANT_PRECREATE) michael@0: michael@0: #define DOM_DEFAULT_SCRIPTABLE_FLAGS \ michael@0: (DEFAULT_SCRIPTABLE_FLAGS | \ michael@0: nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE | \ michael@0: nsIXPCScriptable::CLASSINFO_INTERFACES_ONLY) michael@0: michael@0: michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: michael@0: // See nsDOMClassInfoID.h michael@0: michael@0: #else michael@0: michael@0: #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \ michael@0: if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ michael@0: aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ michael@0: static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \ michael@0: \ michael@0: nsresult rv; \ michael@0: nsCOMPtr sof(do_GetService(kDOMSOF_CID, \ michael@0: &rv)); \ michael@0: if (NS_FAILED(rv)) { \ michael@0: *aInstancePtr = nullptr; \ michael@0: return rv; \ michael@0: } \ michael@0: \ michael@0: foundInterface = \ michael@0: sof->GetClassInfoInstance(eDOMClassInfo_##_class##_id); \ michael@0: } else michael@0: michael@0: #endif /* MOZILLA_INTERNAL_API */ michael@0: michael@0: // Looks up the nsIClassInfo for a class name registered with the michael@0: // nsScriptNamespaceManager. Remember to release NS_CLASSINFO_NAME(_class) michael@0: // (eg. when your module unloads). michael@0: #define NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(_class) \ michael@0: if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ michael@0: aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ michael@0: extern nsISupports *NS_CLASSINFO_NAME(_class); \ michael@0: if (NS_CLASSINFO_NAME(_class)) { \ michael@0: foundInterface = NS_CLASSINFO_NAME(_class); \ michael@0: } else { \ michael@0: static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \ michael@0: \ michael@0: nsresult rv; \ michael@0: nsCOMPtr sof(do_GetService(kDOMSOF_CID, \ michael@0: &rv)); \ michael@0: if (NS_FAILED(rv)) { \ michael@0: *aInstancePtr = nullptr; \ michael@0: return rv; \ michael@0: } \ michael@0: \ michael@0: foundInterface = \ michael@0: sof->GetExternalClassInfoInstance(NS_LITERAL_STRING(#_class)); \ michael@0: \ michael@0: if (foundInterface) { \ michael@0: NS_CLASSINFO_NAME(_class) = foundInterface; \ michael@0: NS_CLASSINFO_NAME(_class)->AddRef(); \ michael@0: } \ michael@0: } \ michael@0: } else michael@0: michael@0: michael@0: #define NS_DECL_DOM_CLASSINFO(_class) \ michael@0: nsISupports *NS_CLASSINFO_NAME(_class) = nullptr; michael@0: michael@0: // {891a7b01-1b61-11d6-a7f2-f690b638899c} michael@0: #define NS_IDOMCI_EXTENSION_IID \ michael@0: { 0x891a7b01, 0x1b61, 0x11d6, \ michael@0: { 0xa7, 0xf2, 0xf6, 0x90, 0xb6, 0x38, 0x89, 0x9c } } michael@0: michael@0: class nsIDOMScriptObjectFactory; michael@0: michael@0: class nsIDOMCIExtension : public nsISupports { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOMCI_EXTENSION_IID) michael@0: michael@0: NS_IMETHOD RegisterDOMCI(const char* aName, michael@0: nsIDOMScriptObjectFactory* aDOMSOFactory) = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMCIExtension, NS_IDOMCI_EXTENSION_IID) michael@0: michael@0: #define NS_DOMCI_EXTENSION_NAME(_module) ns##_module##DOMCIExtension michael@0: #define NS_DOMCI_EXTENSION_CONSTRUCTOR(_module) \ michael@0: ns##_module##DOMCIExtensionConstructor michael@0: #define NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(_extension) \ michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(_extension) michael@0: michael@0: #define NS_DOMCI_EXTENSION(_module) \ michael@0: class NS_DOMCI_EXTENSION_NAME(_module) : public nsIDOMCIExtension \ michael@0: { \ michael@0: public: \ michael@0: NS_DOMCI_EXTENSION_NAME(_module)(); \ michael@0: virtual ~NS_DOMCI_EXTENSION_NAME(_module)(); \ michael@0: \ michael@0: NS_DECL_ISUPPORTS \ michael@0: \ michael@0: NS_IMETHOD RegisterDOMCI(const char* aName, \ michael@0: nsIDOMScriptObjectFactory* aDOMSOFactory); \ michael@0: }; \ michael@0: \ michael@0: NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(NS_DOMCI_EXTENSION_NAME(_module)) \ michael@0: \ michael@0: NS_DOMCI_EXTENSION_NAME(_module)::NS_DOMCI_EXTENSION_NAME(_module)() \ michael@0: { \ michael@0: } \ michael@0: \ michael@0: NS_DOMCI_EXTENSION_NAME(_module)::~NS_DOMCI_EXTENSION_NAME(_module)() \ michael@0: { \ michael@0: } \ michael@0: \ michael@0: NS_IMPL_ISUPPORTS(NS_DOMCI_EXTENSION_NAME(_module), nsIDOMCIExtension) \ michael@0: \ michael@0: NS_IMETHODIMP \ michael@0: NS_DOMCI_EXTENSION_NAME(_module)::RegisterDOMCI(const char* aName, \ michael@0: nsIDOMScriptObjectFactory* aDOMSOFactory) \ michael@0: { michael@0: michael@0: #define NS_DOMCI_EXTENSION_ENTRY_BEGIN(_class) \ michael@0: if (nsCRT::strcmp(aName, #_class) == 0) { \ michael@0: static const nsIID* interfaces[] = { michael@0: michael@0: #define NS_DOMCI_EXTENSION_ENTRY_INTERFACE(_interface) \ michael@0: &NS_GET_IID(_interface), michael@0: michael@0: // Don't forget to register the primary interface (_proto) in the michael@0: // JAVASCRIPT_DOM_INTERFACE category, or prototypes for this class michael@0: // won't work (except if the interface name starts with nsIDOM). michael@0: #define NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, _proto, _hasclassif, \ michael@0: _constructorcid) \ michael@0: nullptr \ michael@0: }; \ michael@0: aDOMSOFactory->RegisterDOMClassInfo(#_class, nullptr, _proto, \ michael@0: interfaces, \ michael@0: DOM_DEFAULT_SCRIPTABLE_FLAGS, \ michael@0: _hasclassif, _constructorcid); \ michael@0: return NS_OK; \ michael@0: } michael@0: michael@0: #define NS_DOMCI_EXTENSION_ENTRY_END(_class, _proto, _hasclassif, \ michael@0: _constructorcid) \ michael@0: NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, &NS_GET_IID(_proto), \ michael@0: _hasclassif, _constructorcid) michael@0: michael@0: #define NS_DOMCI_EXTENSION_ENTRY_END_NO_PRIMARY_IF(_class, _hasclassif, \ michael@0: _constructorcid) \ michael@0: NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, nullptr, _hasclassif, \ michael@0: _constructorcid) michael@0: michael@0: #define NS_DOMCI_EXTENSION_END \ michael@0: return NS_ERROR_FAILURE; \ michael@0: } michael@0: michael@0: michael@0: #endif /* nsIDOMClassInfo_h___ */