Bug 1910362 - Create new Nimbus helper r=aaronmt,ohorvath
[gecko.git] / xpcom / components / nsComponentManagerUtils.cpp
blob569c97060c6689e3cae3540d260f50640223864d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsXPCOM_h__
8 # include "nsXPCOM.h"
9 #endif
11 #ifndef nsCOMPtr_h__
12 # include "nsCOMPtr.h"
13 #endif
15 #ifdef MOZILLA_INTERNAL_API
16 # include "nsComponentManager.h"
17 #endif
19 #include "nsComponentManagerUtils.h"
20 #include "nsServiceManagerUtils.h"
22 #include "nsIComponentManager.h"
24 #ifndef MOZILLA_INTERNAL_API
26 nsresult CallGetService(const nsCID& aCID, const nsIID& aIID, void** aResult) {
27 nsCOMPtr<nsIServiceManager> servMgr;
28 nsresult status = NS_GetServiceManager(getter_AddRefs(servMgr));
29 if (servMgr) {
30 status = servMgr->GetService(aCID, aIID, aResult);
32 return status;
35 nsresult CallGetService(const char* aContractID, const nsIID& aIID,
36 void** aResult) {
37 nsCOMPtr<nsIServiceManager> servMgr;
38 nsresult status = NS_GetServiceManager(getter_AddRefs(servMgr));
39 if (servMgr) {
40 status = servMgr->GetServiceByContractID(aContractID, aIID, aResult);
42 return status;
45 #else
47 nsresult CallGetService(const nsCID& aCID, const nsIID& aIID, void** aResult) {
48 nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager;
49 if (!compMgr) {
50 return NS_ERROR_NOT_INITIALIZED;
53 return compMgr->nsComponentManagerImpl::GetService(aCID, aIID, aResult);
56 nsresult CallGetService(const char* aContractID, const nsIID& aIID,
57 void** aResult) {
58 nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager;
59 if (!compMgr) {
60 return NS_ERROR_NOT_INITIALIZED;
63 return compMgr->nsComponentManagerImpl::GetServiceByContractID(aContractID,
64 aIID, aResult);
67 #endif
69 #ifndef MOZILLA_INTERNAL_API
71 nsresult CallCreateInstance(const nsCID& aCID, const nsIID& aIID,
72 void** aResult) {
73 nsCOMPtr<nsIComponentManager> compMgr;
74 nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
75 if (compMgr) {
76 status = compMgr->CreateInstance(aCID, aIID, aResult);
78 return status;
81 nsresult CallCreateInstance(const char* aContractID, const nsIID& aIID,
82 void** aResult) {
83 nsCOMPtr<nsIComponentManager> compMgr;
84 nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
85 if (compMgr)
86 status = compMgr->CreateInstanceByContractID(aContractID, aIID, aResult);
87 return status;
90 nsresult CallGetClassObject(const nsCID& aCID, const nsIID& aIID,
91 void** aResult) {
92 nsCOMPtr<nsIComponentManager> compMgr;
93 nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
94 if (compMgr) {
95 status = compMgr->GetClassObject(aCID, aIID, aResult);
97 return status;
100 nsresult CallGetClassObject(const char* aContractID, const nsIID& aIID,
101 void** aResult) {
102 nsCOMPtr<nsIComponentManager> compMgr;
103 nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
104 if (compMgr)
105 status = compMgr->GetClassObjectByContractID(aContractID, aIID, aResult);
106 return status;
109 #else
111 nsresult CallCreateInstance(const nsCID& aCID, const nsIID& aIID,
112 void** aResult) {
113 nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager;
114 if (NS_WARN_IF(!compMgr)) {
115 return NS_ERROR_NOT_INITIALIZED;
118 return compMgr->nsComponentManagerImpl::CreateInstance(aCID, aIID, aResult);
121 nsresult CallCreateInstance(const char* aContractID, const nsIID& aIID,
122 void** aResult) {
123 nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager;
124 if (NS_WARN_IF(!compMgr)) {
125 return NS_ERROR_NOT_INITIALIZED;
128 return compMgr->nsComponentManagerImpl::CreateInstanceByContractID(
129 aContractID, aIID, aResult);
132 nsresult CallGetClassObject(const nsCID& aCID, const nsIID& aIID,
133 void** aResult) {
134 nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager;
135 if (NS_WARN_IF(!compMgr)) {
136 return NS_ERROR_NOT_INITIALIZED;
139 return compMgr->nsComponentManagerImpl::GetClassObject(aCID, aIID, aResult);
142 nsresult CallGetClassObject(const char* aContractID, const nsIID& aIID,
143 void** aResult) {
144 nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager;
145 if (NS_WARN_IF(!compMgr)) {
146 return NS_ERROR_NOT_INITIALIZED;
149 return compMgr->nsComponentManagerImpl::GetClassObjectByContractID(
150 aContractID, aIID, aResult);
153 #endif
155 nsresult nsCreateInstanceByCID::operator()(const nsIID& aIID,
156 void** aInstancePtr) const {
157 nsresult status = CallCreateInstance(mCID, aIID, aInstancePtr);
158 if (NS_FAILED(status)) {
159 *aInstancePtr = 0;
161 if (mErrorPtr) {
162 *mErrorPtr = status;
164 return status;
167 nsresult nsCreateInstanceByContractID::operator()(const nsIID& aIID,
168 void** aInstancePtr) const {
169 nsresult status = CallCreateInstance(mContractID, aIID, aInstancePtr);
170 if (NS_FAILED(status)) {
171 *aInstancePtr = 0;
173 if (mErrorPtr) {
174 *mErrorPtr = status;
176 return status;
179 nsresult nsCreateInstanceFromFactory::operator()(const nsIID& aIID,
180 void** aInstancePtr) const {
181 nsresult status = mFactory->CreateInstance(aIID, aInstancePtr);
182 if (NS_FAILED(status)) {
183 *aInstancePtr = 0;
185 if (mErrorPtr) {
186 *mErrorPtr = status;
188 return status;
191 nsresult nsGetClassObjectByCID::operator()(const nsIID& aIID,
192 void** aInstancePtr) const {
193 nsresult status = CallGetClassObject(mCID, aIID, aInstancePtr);
194 if (NS_FAILED(status)) {
195 *aInstancePtr = 0;
197 if (mErrorPtr) {
198 *mErrorPtr = status;
200 return status;
203 nsresult nsGetClassObjectByContractID::operator()(const nsIID& aIID,
204 void** aInstancePtr) const {
205 nsresult status = CallGetClassObject(mContractID, aIID, aInstancePtr);
206 if (NS_FAILED(status)) {
207 *aInstancePtr = 0;
209 if (mErrorPtr) {
210 *mErrorPtr = status;
212 return status;
215 nsresult nsGetServiceByCID::operator()(const nsIID& aIID,
216 void** aInstancePtr) const {
217 nsresult status = CallGetService(mCID, aIID, aInstancePtr);
218 if (NS_FAILED(status)) {
219 *aInstancePtr = 0;
222 return status;
225 nsresult nsGetServiceByCIDWithError::operator()(const nsIID& aIID,
226 void** aInstancePtr) const {
227 nsresult status = CallGetService(mCID, aIID, aInstancePtr);
228 if (NS_FAILED(status)) {
229 *aInstancePtr = 0;
232 if (mErrorPtr) {
233 *mErrorPtr = status;
235 return status;
238 nsresult nsGetServiceByContractID::operator()(const nsIID& aIID,
239 void** aInstancePtr) const {
240 nsresult status = CallGetService(mContractID, aIID, aInstancePtr);
241 if (NS_FAILED(status)) {
242 *aInstancePtr = 0;
245 return status;
248 nsresult nsGetServiceByContractIDWithError::operator()(
249 const nsIID& aIID, void** aInstancePtr) const {
250 nsresult status = CallGetService(mContractID, aIID, aInstancePtr);
251 if (NS_FAILED(status)) {
252 *aInstancePtr = 0;
255 if (mErrorPtr) {
256 *mErrorPtr = status;
258 return status;