Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsIDOMClassInfo_h___ |
michael@0 | 7 | #define nsIDOMClassInfo_h___ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsIClassInfoImpl.h" |
michael@0 | 10 | #include "nsDOMClassInfoID.h" |
michael@0 | 11 | #include "nsIXPCScriptable.h" |
michael@0 | 12 | #include "nsIServiceManager.h" |
michael@0 | 13 | #include "nsIDOMScriptObjectFactory.h" |
michael@0 | 14 | #include "nsDOMCID.h" |
michael@0 | 15 | |
michael@0 | 16 | #define DOM_BASE_SCRIPTABLE_FLAGS \ |
michael@0 | 17 | (nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY | \ |
michael@0 | 18 | nsIXPCScriptable::USE_JSSTUB_FOR_DELPROPERTY | \ |
michael@0 | 19 | nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY | \ |
michael@0 | 20 | nsIXPCScriptable::ALLOW_PROP_MODS_TO_PROTOTYPE | \ |
michael@0 | 21 | nsIXPCScriptable::DONT_ASK_INSTANCE_FOR_SCRIPTABLE | \ |
michael@0 | 22 | nsIXPCScriptable::DONT_REFLECT_INTERFACE_NAMES) |
michael@0 | 23 | |
michael@0 | 24 | #define DEFAULT_SCRIPTABLE_FLAGS \ |
michael@0 | 25 | (DOM_BASE_SCRIPTABLE_FLAGS | \ |
michael@0 | 26 | nsIXPCScriptable::WANT_NEWRESOLVE | \ |
michael@0 | 27 | nsIXPCScriptable::WANT_PRECREATE) |
michael@0 | 28 | |
michael@0 | 29 | #define DOM_DEFAULT_SCRIPTABLE_FLAGS \ |
michael@0 | 30 | (DEFAULT_SCRIPTABLE_FLAGS | \ |
michael@0 | 31 | nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE | \ |
michael@0 | 32 | nsIXPCScriptable::CLASSINFO_INTERFACES_ONLY) |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | #ifdef MOZILLA_INTERNAL_API |
michael@0 | 36 | |
michael@0 | 37 | // See nsDOMClassInfoID.h |
michael@0 | 38 | |
michael@0 | 39 | #else |
michael@0 | 40 | |
michael@0 | 41 | #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \ |
michael@0 | 42 | if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ |
michael@0 | 43 | aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ |
michael@0 | 44 | static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \ |
michael@0 | 45 | \ |
michael@0 | 46 | nsresult rv; \ |
michael@0 | 47 | nsCOMPtr<nsIDOMScriptObjectFactory> sof(do_GetService(kDOMSOF_CID, \ |
michael@0 | 48 | &rv)); \ |
michael@0 | 49 | if (NS_FAILED(rv)) { \ |
michael@0 | 50 | *aInstancePtr = nullptr; \ |
michael@0 | 51 | return rv; \ |
michael@0 | 52 | } \ |
michael@0 | 53 | \ |
michael@0 | 54 | foundInterface = \ |
michael@0 | 55 | sof->GetClassInfoInstance(eDOMClassInfo_##_class##_id); \ |
michael@0 | 56 | } else |
michael@0 | 57 | |
michael@0 | 58 | #endif /* MOZILLA_INTERNAL_API */ |
michael@0 | 59 | |
michael@0 | 60 | // Looks up the nsIClassInfo for a class name registered with the |
michael@0 | 61 | // nsScriptNamespaceManager. Remember to release NS_CLASSINFO_NAME(_class) |
michael@0 | 62 | // (eg. when your module unloads). |
michael@0 | 63 | #define NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(_class) \ |
michael@0 | 64 | if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ |
michael@0 | 65 | aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ |
michael@0 | 66 | extern nsISupports *NS_CLASSINFO_NAME(_class); \ |
michael@0 | 67 | if (NS_CLASSINFO_NAME(_class)) { \ |
michael@0 | 68 | foundInterface = NS_CLASSINFO_NAME(_class); \ |
michael@0 | 69 | } else { \ |
michael@0 | 70 | static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \ |
michael@0 | 71 | \ |
michael@0 | 72 | nsresult rv; \ |
michael@0 | 73 | nsCOMPtr<nsIDOMScriptObjectFactory> sof(do_GetService(kDOMSOF_CID, \ |
michael@0 | 74 | &rv)); \ |
michael@0 | 75 | if (NS_FAILED(rv)) { \ |
michael@0 | 76 | *aInstancePtr = nullptr; \ |
michael@0 | 77 | return rv; \ |
michael@0 | 78 | } \ |
michael@0 | 79 | \ |
michael@0 | 80 | foundInterface = \ |
michael@0 | 81 | sof->GetExternalClassInfoInstance(NS_LITERAL_STRING(#_class)); \ |
michael@0 | 82 | \ |
michael@0 | 83 | if (foundInterface) { \ |
michael@0 | 84 | NS_CLASSINFO_NAME(_class) = foundInterface; \ |
michael@0 | 85 | NS_CLASSINFO_NAME(_class)->AddRef(); \ |
michael@0 | 86 | } \ |
michael@0 | 87 | } \ |
michael@0 | 88 | } else |
michael@0 | 89 | |
michael@0 | 90 | |
michael@0 | 91 | #define NS_DECL_DOM_CLASSINFO(_class) \ |
michael@0 | 92 | nsISupports *NS_CLASSINFO_NAME(_class) = nullptr; |
michael@0 | 93 | |
michael@0 | 94 | // {891a7b01-1b61-11d6-a7f2-f690b638899c} |
michael@0 | 95 | #define NS_IDOMCI_EXTENSION_IID \ |
michael@0 | 96 | { 0x891a7b01, 0x1b61, 0x11d6, \ |
michael@0 | 97 | { 0xa7, 0xf2, 0xf6, 0x90, 0xb6, 0x38, 0x89, 0x9c } } |
michael@0 | 98 | |
michael@0 | 99 | class nsIDOMScriptObjectFactory; |
michael@0 | 100 | |
michael@0 | 101 | class nsIDOMCIExtension : public nsISupports { |
michael@0 | 102 | public: |
michael@0 | 103 | NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOMCI_EXTENSION_IID) |
michael@0 | 104 | |
michael@0 | 105 | NS_IMETHOD RegisterDOMCI(const char* aName, |
michael@0 | 106 | nsIDOMScriptObjectFactory* aDOMSOFactory) = 0; |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMCIExtension, NS_IDOMCI_EXTENSION_IID) |
michael@0 | 110 | |
michael@0 | 111 | #define NS_DOMCI_EXTENSION_NAME(_module) ns##_module##DOMCIExtension |
michael@0 | 112 | #define NS_DOMCI_EXTENSION_CONSTRUCTOR(_module) \ |
michael@0 | 113 | ns##_module##DOMCIExtensionConstructor |
michael@0 | 114 | #define NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(_extension) \ |
michael@0 | 115 | NS_GENERIC_FACTORY_CONSTRUCTOR(_extension) |
michael@0 | 116 | |
michael@0 | 117 | #define NS_DOMCI_EXTENSION(_module) \ |
michael@0 | 118 | class NS_DOMCI_EXTENSION_NAME(_module) : public nsIDOMCIExtension \ |
michael@0 | 119 | { \ |
michael@0 | 120 | public: \ |
michael@0 | 121 | NS_DOMCI_EXTENSION_NAME(_module)(); \ |
michael@0 | 122 | virtual ~NS_DOMCI_EXTENSION_NAME(_module)(); \ |
michael@0 | 123 | \ |
michael@0 | 124 | NS_DECL_ISUPPORTS \ |
michael@0 | 125 | \ |
michael@0 | 126 | NS_IMETHOD RegisterDOMCI(const char* aName, \ |
michael@0 | 127 | nsIDOMScriptObjectFactory* aDOMSOFactory); \ |
michael@0 | 128 | }; \ |
michael@0 | 129 | \ |
michael@0 | 130 | NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(NS_DOMCI_EXTENSION_NAME(_module)) \ |
michael@0 | 131 | \ |
michael@0 | 132 | NS_DOMCI_EXTENSION_NAME(_module)::NS_DOMCI_EXTENSION_NAME(_module)() \ |
michael@0 | 133 | { \ |
michael@0 | 134 | } \ |
michael@0 | 135 | \ |
michael@0 | 136 | NS_DOMCI_EXTENSION_NAME(_module)::~NS_DOMCI_EXTENSION_NAME(_module)() \ |
michael@0 | 137 | { \ |
michael@0 | 138 | } \ |
michael@0 | 139 | \ |
michael@0 | 140 | NS_IMPL_ISUPPORTS(NS_DOMCI_EXTENSION_NAME(_module), nsIDOMCIExtension) \ |
michael@0 | 141 | \ |
michael@0 | 142 | NS_IMETHODIMP \ |
michael@0 | 143 | NS_DOMCI_EXTENSION_NAME(_module)::RegisterDOMCI(const char* aName, \ |
michael@0 | 144 | nsIDOMScriptObjectFactory* aDOMSOFactory) \ |
michael@0 | 145 | { |
michael@0 | 146 | |
michael@0 | 147 | #define NS_DOMCI_EXTENSION_ENTRY_BEGIN(_class) \ |
michael@0 | 148 | if (nsCRT::strcmp(aName, #_class) == 0) { \ |
michael@0 | 149 | static const nsIID* interfaces[] = { |
michael@0 | 150 | |
michael@0 | 151 | #define NS_DOMCI_EXTENSION_ENTRY_INTERFACE(_interface) \ |
michael@0 | 152 | &NS_GET_IID(_interface), |
michael@0 | 153 | |
michael@0 | 154 | // Don't forget to register the primary interface (_proto) in the |
michael@0 | 155 | // JAVASCRIPT_DOM_INTERFACE category, or prototypes for this class |
michael@0 | 156 | // won't work (except if the interface name starts with nsIDOM). |
michael@0 | 157 | #define NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, _proto, _hasclassif, \ |
michael@0 | 158 | _constructorcid) \ |
michael@0 | 159 | nullptr \ |
michael@0 | 160 | }; \ |
michael@0 | 161 | aDOMSOFactory->RegisterDOMClassInfo(#_class, nullptr, _proto, \ |
michael@0 | 162 | interfaces, \ |
michael@0 | 163 | DOM_DEFAULT_SCRIPTABLE_FLAGS, \ |
michael@0 | 164 | _hasclassif, _constructorcid); \ |
michael@0 | 165 | return NS_OK; \ |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | #define NS_DOMCI_EXTENSION_ENTRY_END(_class, _proto, _hasclassif, \ |
michael@0 | 169 | _constructorcid) \ |
michael@0 | 170 | NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, &NS_GET_IID(_proto), \ |
michael@0 | 171 | _hasclassif, _constructorcid) |
michael@0 | 172 | |
michael@0 | 173 | #define NS_DOMCI_EXTENSION_ENTRY_END_NO_PRIMARY_IF(_class, _hasclassif, \ |
michael@0 | 174 | _constructorcid) \ |
michael@0 | 175 | NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, nullptr, _hasclassif, \ |
michael@0 | 176 | _constructorcid) |
michael@0 | 177 | |
michael@0 | 178 | #define NS_DOMCI_EXTENSION_END \ |
michael@0 | 179 | return NS_ERROR_FAILURE; \ |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | |
michael@0 | 183 | #endif /* nsIDOMClassInfo_h___ */ |