2014-06-30 15:39:45 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-03-09 09:44:27 +00:00
|
|
|
|
1999-09-05 06:27:42 +00:00
|
|
|
#ifndef nsComponentManagerUtils_h__
|
|
|
|
#define nsComponentManagerUtils_h__
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2004-11-23 20:53:38 +00:00
|
|
|
#include "nscore.h"
|
1999-11-10 00:14:54 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2004-11-23 22:19:13 +00:00
|
|
|
#include "nsIFactory.h"
|
2004-11-23 20:53:38 +00:00
|
|
|
|
2014-08-27 22:47:27 +00:00
|
|
|
nsresult CallCreateInstance(const nsCID& aClass, nsISupports* aDelegate,
|
|
|
|
const nsIID& aIID, void** aResult);
|
2004-11-23 20:53:38 +00:00
|
|
|
|
2014-08-27 22:47:27 +00:00
|
|
|
nsresult CallCreateInstance(const char* aContractID, nsISupports* aDelegate,
|
|
|
|
const nsIID& aIID, void** aResult);
|
2004-11-23 20:53:38 +00:00
|
|
|
|
2014-08-27 22:47:27 +00:00
|
|
|
nsresult CallGetClassObject(const nsCID& aClass, const nsIID& aIID,
|
|
|
|
void** aResult);
|
2004-11-23 20:53:38 +00:00
|
|
|
|
2014-08-27 22:47:27 +00:00
|
|
|
nsresult CallGetClassObject(const char* aContractID, const nsIID& aIID,
|
|
|
|
void** aResult);
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2015-04-20 20:58:15 +00:00
|
|
|
class MOZ_STACK_CLASS nsCreateInstanceByCID final : public nsCOMPtr_helper {
|
1999-03-09 09:44:27 +00:00
|
|
|
public:
|
2016-04-14 15:30:59 +00:00
|
|
|
nsCreateInstanceByCID(const nsCID& aCID, nsresult* aErrorPtr)
|
2014-06-27 01:35:39 +00:00
|
|
|
: mCID(aCID), mErrorPtr(aErrorPtr) {}
|
|
|
|
|
2015-01-15 16:36:10 +00:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const override;
|
2014-06-27 01:35:39 +00:00
|
|
|
|
2001-12-19 00:12:41 +00:00
|
|
|
private:
|
2014-06-27 01:35:39 +00:00
|
|
|
const nsCID& mCID;
|
|
|
|
nsresult* mErrorPtr;
|
1999-03-09 09:44:27 +00:00
|
|
|
};
|
|
|
|
|
2015-04-20 20:58:15 +00:00
|
|
|
class MOZ_STACK_CLASS nsCreateInstanceByContractID final
|
|
|
|
: public nsCOMPtr_helper {
|
2001-12-19 00:12:41 +00:00
|
|
|
public:
|
2016-04-14 15:30:59 +00:00
|
|
|
nsCreateInstanceByContractID(const char* aContractID, nsresult* aErrorPtr)
|
2014-06-27 01:35:39 +00:00
|
|
|
: mContractID(aContractID), mErrorPtr(aErrorPtr) {}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const override;
|
2014-06-27 01:35:39 +00:00
|
|
|
|
2001-12-19 00:12:41 +00:00
|
|
|
private:
|
2014-06-27 01:35:39 +00:00
|
|
|
const char* mContractID;
|
|
|
|
nsresult* mErrorPtr;
|
2001-12-19 00:12:41 +00:00
|
|
|
};
|
1999-11-10 00:14:54 +00:00
|
|
|
|
2015-04-20 20:58:15 +00:00
|
|
|
class MOZ_STACK_CLASS nsCreateInstanceFromFactory final
|
|
|
|
: public nsCOMPtr_helper {
|
2004-10-02 00:44:13 +00:00
|
|
|
public:
|
2016-04-14 15:30:59 +00:00
|
|
|
nsCreateInstanceFromFactory(nsIFactory* aFactory, nsresult* aErrorPtr)
|
2014-06-27 01:35:39 +00:00
|
|
|
: mFactory(aFactory), mErrorPtr(aErrorPtr) {}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const override;
|
2014-06-27 01:35:39 +00:00
|
|
|
|
2004-10-02 00:44:13 +00:00
|
|
|
private:
|
2014-12-24 02:17:50 +00:00
|
|
|
nsIFactory* MOZ_NON_OWNING_REF mFactory;
|
2014-06-27 01:35:39 +00:00
|
|
|
nsresult* mErrorPtr;
|
2004-10-02 00:44:13 +00:00
|
|
|
};
|
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
inline const nsCreateInstanceByCID do_CreateInstance(const nsCID& aCID,
|
|
|
|
nsresult* aError = 0) {
|
2016-04-14 15:30:59 +00:00
|
|
|
return nsCreateInstanceByCID(aCID, aError);
|
2001-12-19 00:12:41 +00:00
|
|
|
}
|
1999-11-10 00:14:54 +00:00
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
inline const nsCreateInstanceByContractID do_CreateInstance(
|
|
|
|
const char* aContractID, nsresult* aError = 0) {
|
2016-04-14 15:30:59 +00:00
|
|
|
return nsCreateInstanceByContractID(aContractID, aError);
|
2001-12-19 00:12:41 +00:00
|
|
|
}
|
1999-11-10 00:14:54 +00:00
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
inline const nsCreateInstanceFromFactory do_CreateInstance(
|
|
|
|
nsIFactory* aFactory, nsresult* aError = 0) {
|
2016-04-14 15:30:59 +00:00
|
|
|
return nsCreateInstanceFromFactory(aFactory, aError);
|
2004-10-02 00:44:13 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 20:58:15 +00:00
|
|
|
class MOZ_STACK_CLASS nsGetClassObjectByCID final : public nsCOMPtr_helper {
|
2004-10-02 00:44:13 +00:00
|
|
|
public:
|
2014-06-27 01:35:39 +00:00
|
|
|
nsGetClassObjectByCID(const nsCID& aCID, nsresult* aErrorPtr)
|
|
|
|
: mCID(aCID), mErrorPtr(aErrorPtr) {}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const override;
|
2014-06-27 01:35:39 +00:00
|
|
|
|
2004-10-02 00:44:13 +00:00
|
|
|
private:
|
2014-06-27 01:35:39 +00:00
|
|
|
const nsCID& mCID;
|
|
|
|
nsresult* mErrorPtr;
|
2004-10-02 00:44:13 +00:00
|
|
|
};
|
|
|
|
|
2015-04-20 20:58:15 +00:00
|
|
|
class MOZ_STACK_CLASS nsGetClassObjectByContractID final
|
|
|
|
: public nsCOMPtr_helper {
|
2004-10-02 00:44:13 +00:00
|
|
|
public:
|
2014-06-27 01:35:39 +00:00
|
|
|
nsGetClassObjectByContractID(const char* aContractID, nsresult* aErrorPtr)
|
|
|
|
: mContractID(aContractID), mErrorPtr(aErrorPtr) {}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const override;
|
2014-06-27 01:35:39 +00:00
|
|
|
|
2004-10-02 00:44:13 +00:00
|
|
|
private:
|
2014-06-27 01:35:39 +00:00
|
|
|
const char* mContractID;
|
|
|
|
nsresult* mErrorPtr;
|
2004-10-02 00:44:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-06-27 01:35:39 +00:00
|
|
|
* do_GetClassObject can be used to improve performance of callers
|
2004-10-02 00:44:13 +00:00
|
|
|
* that call |CreateInstance| many times. They can cache the factory
|
|
|
|
* and call do_CreateInstance or CallCreateInstance with the cached
|
|
|
|
* factory rather than having the component manager retrieve it every
|
|
|
|
* time.
|
|
|
|
*/
|
2014-06-27 01:35:39 +00:00
|
|
|
inline const nsGetClassObjectByCID do_GetClassObject(const nsCID& aCID,
|
|
|
|
nsresult* aError = 0) {
|
|
|
|
return nsGetClassObjectByCID(aCID, aError);
|
2004-10-02 00:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const nsGetClassObjectByContractID do_GetClassObject(
|
2014-06-27 01:35:39 +00:00
|
|
|
const char* aContractID, nsresult* aError = 0) {
|
|
|
|
return nsGetClassObjectByContractID(aContractID, aError);
|
2004-10-02 00:44:13 +00:00
|
|
|
}
|
|
|
|
|
2001-07-04 18:55:14 +00:00
|
|
|
// type-safe shortcuts for calling |CreateInstance|
|
2014-06-27 01:35:39 +00:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallCreateInstance(const nsCID& aClass, nsISupports* aDelegate,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 01:35:39 +00:00
|
|
|
|
|
|
|
return CallCreateInstance(aClass, aDelegate,
|
|
|
|
NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2001-12-19 00:12:41 +00:00
|
|
|
}
|
2001-07-04 18:55:14 +00:00
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallCreateInstance(const nsCID& aClass,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 01:35:39 +00:00
|
|
|
|
|
|
|
return CallCreateInstance(aClass, nullptr,
|
|
|
|
NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2001-12-19 00:12:41 +00:00
|
|
|
}
|
2001-07-04 18:55:14 +00:00
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallCreateInstance(const char* aContractID,
|
|
|
|
nsISupports* aDelegate,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aContractID, "null parameter");
|
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 01:35:39 +00:00
|
|
|
|
|
|
|
return CallCreateInstance(aContractID, aDelegate,
|
|
|
|
NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2001-12-19 00:12:41 +00:00
|
|
|
}
|
2001-07-04 18:55:14 +00:00
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallCreateInstance(const char* aContractID,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aContractID, "null parameter");
|
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 01:35:39 +00:00
|
|
|
|
|
|
|
return CallCreateInstance(aContractID, nullptr,
|
|
|
|
NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2001-12-19 00:12:41 +00:00
|
|
|
}
|
2001-07-04 18:55:14 +00:00
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallCreateInstance(nsIFactory* aFactory, nsISupports* aDelegate,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aFactory, "null parameter");
|
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 01:35:39 +00:00
|
|
|
|
|
|
|
return aFactory->CreateInstance(aDelegate,
|
|
|
|
NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2004-10-02 00:44:13 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallCreateInstance(nsIFactory* aFactory,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aFactory, "null parameter");
|
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 01:35:39 +00:00
|
|
|
|
|
|
|
return aFactory->CreateInstance(nullptr, NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2004-10-02 00:44:13 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallGetClassObject(const nsCID& aClass,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 01:35:39 +00:00
|
|
|
|
|
|
|
return CallGetClassObject(aClass, NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2004-10-02 00:44:13 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 01:35:39 +00:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallGetClassObject(const char* aContractID,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 01:35:39 +00:00
|
|
|
|
|
|
|
return CallGetClassObject(aContractID, NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2004-10-02 00:44:13 +00:00
|
|
|
}
|
|
|
|
|
1999-09-05 06:27:42 +00:00
|
|
|
#endif /* nsComponentManagerUtils_h__ */
|