1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/nsIDOMClassInfo.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,183 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsIDOMClassInfo_h___ 1.10 +#define nsIDOMClassInfo_h___ 1.11 + 1.12 +#include "nsIClassInfoImpl.h" 1.13 +#include "nsDOMClassInfoID.h" 1.14 +#include "nsIXPCScriptable.h" 1.15 +#include "nsIServiceManager.h" 1.16 +#include "nsIDOMScriptObjectFactory.h" 1.17 +#include "nsDOMCID.h" 1.18 + 1.19 +#define DOM_BASE_SCRIPTABLE_FLAGS \ 1.20 + (nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY | \ 1.21 + nsIXPCScriptable::USE_JSSTUB_FOR_DELPROPERTY | \ 1.22 + nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY | \ 1.23 + nsIXPCScriptable::ALLOW_PROP_MODS_TO_PROTOTYPE | \ 1.24 + nsIXPCScriptable::DONT_ASK_INSTANCE_FOR_SCRIPTABLE | \ 1.25 + nsIXPCScriptable::DONT_REFLECT_INTERFACE_NAMES) 1.26 + 1.27 +#define DEFAULT_SCRIPTABLE_FLAGS \ 1.28 + (DOM_BASE_SCRIPTABLE_FLAGS | \ 1.29 + nsIXPCScriptable::WANT_NEWRESOLVE | \ 1.30 + nsIXPCScriptable::WANT_PRECREATE) 1.31 + 1.32 +#define DOM_DEFAULT_SCRIPTABLE_FLAGS \ 1.33 + (DEFAULT_SCRIPTABLE_FLAGS | \ 1.34 + nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE | \ 1.35 + nsIXPCScriptable::CLASSINFO_INTERFACES_ONLY) 1.36 + 1.37 + 1.38 +#ifdef MOZILLA_INTERNAL_API 1.39 + 1.40 +// See nsDOMClassInfoID.h 1.41 + 1.42 +#else 1.43 + 1.44 +#define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \ 1.45 + if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ 1.46 + aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ 1.47 + static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \ 1.48 + \ 1.49 + nsresult rv; \ 1.50 + nsCOMPtr<nsIDOMScriptObjectFactory> sof(do_GetService(kDOMSOF_CID, \ 1.51 + &rv)); \ 1.52 + if (NS_FAILED(rv)) { \ 1.53 + *aInstancePtr = nullptr; \ 1.54 + return rv; \ 1.55 + } \ 1.56 + \ 1.57 + foundInterface = \ 1.58 + sof->GetClassInfoInstance(eDOMClassInfo_##_class##_id); \ 1.59 + } else 1.60 + 1.61 +#endif /* MOZILLA_INTERNAL_API */ 1.62 + 1.63 +// Looks up the nsIClassInfo for a class name registered with the 1.64 +// nsScriptNamespaceManager. Remember to release NS_CLASSINFO_NAME(_class) 1.65 +// (eg. when your module unloads). 1.66 +#define NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(_class) \ 1.67 + if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ 1.68 + aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ 1.69 + extern nsISupports *NS_CLASSINFO_NAME(_class); \ 1.70 + if (NS_CLASSINFO_NAME(_class)) { \ 1.71 + foundInterface = NS_CLASSINFO_NAME(_class); \ 1.72 + } else { \ 1.73 + static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \ 1.74 + \ 1.75 + nsresult rv; \ 1.76 + nsCOMPtr<nsIDOMScriptObjectFactory> sof(do_GetService(kDOMSOF_CID, \ 1.77 + &rv)); \ 1.78 + if (NS_FAILED(rv)) { \ 1.79 + *aInstancePtr = nullptr; \ 1.80 + return rv; \ 1.81 + } \ 1.82 + \ 1.83 + foundInterface = \ 1.84 + sof->GetExternalClassInfoInstance(NS_LITERAL_STRING(#_class)); \ 1.85 + \ 1.86 + if (foundInterface) { \ 1.87 + NS_CLASSINFO_NAME(_class) = foundInterface; \ 1.88 + NS_CLASSINFO_NAME(_class)->AddRef(); \ 1.89 + } \ 1.90 + } \ 1.91 + } else 1.92 + 1.93 + 1.94 +#define NS_DECL_DOM_CLASSINFO(_class) \ 1.95 + nsISupports *NS_CLASSINFO_NAME(_class) = nullptr; 1.96 + 1.97 +// {891a7b01-1b61-11d6-a7f2-f690b638899c} 1.98 +#define NS_IDOMCI_EXTENSION_IID \ 1.99 +{ 0x891a7b01, 0x1b61, 0x11d6, \ 1.100 +{ 0xa7, 0xf2, 0xf6, 0x90, 0xb6, 0x38, 0x89, 0x9c } } 1.101 + 1.102 +class nsIDOMScriptObjectFactory; 1.103 + 1.104 +class nsIDOMCIExtension : public nsISupports { 1.105 +public: 1.106 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOMCI_EXTENSION_IID) 1.107 + 1.108 + NS_IMETHOD RegisterDOMCI(const char* aName, 1.109 + nsIDOMScriptObjectFactory* aDOMSOFactory) = 0; 1.110 +}; 1.111 + 1.112 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMCIExtension, NS_IDOMCI_EXTENSION_IID) 1.113 + 1.114 +#define NS_DOMCI_EXTENSION_NAME(_module) ns##_module##DOMCIExtension 1.115 +#define NS_DOMCI_EXTENSION_CONSTRUCTOR(_module) \ 1.116 + ns##_module##DOMCIExtensionConstructor 1.117 +#define NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(_extension) \ 1.118 + NS_GENERIC_FACTORY_CONSTRUCTOR(_extension) 1.119 + 1.120 +#define NS_DOMCI_EXTENSION(_module) \ 1.121 +class NS_DOMCI_EXTENSION_NAME(_module) : public nsIDOMCIExtension \ 1.122 +{ \ 1.123 +public: \ 1.124 + NS_DOMCI_EXTENSION_NAME(_module)(); \ 1.125 + virtual ~NS_DOMCI_EXTENSION_NAME(_module)(); \ 1.126 + \ 1.127 + NS_DECL_ISUPPORTS \ 1.128 + \ 1.129 + NS_IMETHOD RegisterDOMCI(const char* aName, \ 1.130 + nsIDOMScriptObjectFactory* aDOMSOFactory); \ 1.131 +}; \ 1.132 + \ 1.133 +NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(NS_DOMCI_EXTENSION_NAME(_module)) \ 1.134 + \ 1.135 +NS_DOMCI_EXTENSION_NAME(_module)::NS_DOMCI_EXTENSION_NAME(_module)() \ 1.136 +{ \ 1.137 +} \ 1.138 + \ 1.139 +NS_DOMCI_EXTENSION_NAME(_module)::~NS_DOMCI_EXTENSION_NAME(_module)() \ 1.140 +{ \ 1.141 +} \ 1.142 + \ 1.143 +NS_IMPL_ISUPPORTS(NS_DOMCI_EXTENSION_NAME(_module), nsIDOMCIExtension) \ 1.144 + \ 1.145 +NS_IMETHODIMP \ 1.146 +NS_DOMCI_EXTENSION_NAME(_module)::RegisterDOMCI(const char* aName, \ 1.147 + nsIDOMScriptObjectFactory* aDOMSOFactory) \ 1.148 +{ 1.149 + 1.150 +#define NS_DOMCI_EXTENSION_ENTRY_BEGIN(_class) \ 1.151 + if (nsCRT::strcmp(aName, #_class) == 0) { \ 1.152 + static const nsIID* interfaces[] = { 1.153 + 1.154 +#define NS_DOMCI_EXTENSION_ENTRY_INTERFACE(_interface) \ 1.155 + &NS_GET_IID(_interface), 1.156 + 1.157 +// Don't forget to register the primary interface (_proto) in the 1.158 +// JAVASCRIPT_DOM_INTERFACE category, or prototypes for this class 1.159 +// won't work (except if the interface name starts with nsIDOM). 1.160 +#define NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, _proto, _hasclassif, \ 1.161 + _constructorcid) \ 1.162 + nullptr \ 1.163 + }; \ 1.164 + aDOMSOFactory->RegisterDOMClassInfo(#_class, nullptr, _proto, \ 1.165 + interfaces, \ 1.166 + DOM_DEFAULT_SCRIPTABLE_FLAGS, \ 1.167 + _hasclassif, _constructorcid); \ 1.168 + return NS_OK; \ 1.169 + } 1.170 + 1.171 +#define NS_DOMCI_EXTENSION_ENTRY_END(_class, _proto, _hasclassif, \ 1.172 + _constructorcid) \ 1.173 + NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, &NS_GET_IID(_proto), \ 1.174 + _hasclassif, _constructorcid) 1.175 + 1.176 +#define NS_DOMCI_EXTENSION_ENTRY_END_NO_PRIMARY_IF(_class, _hasclassif, \ 1.177 + _constructorcid) \ 1.178 + NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, nullptr, _hasclassif, \ 1.179 + _constructorcid) 1.180 + 1.181 +#define NS_DOMCI_EXTENSION_END \ 1.182 + return NS_ERROR_FAILURE; \ 1.183 +} 1.184 + 1.185 + 1.186 +#endif /* nsIDOMClassInfo_h___ */