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 #include "mozilla/ModuleUtils.h"
8 #include "mozilla/GenericFactory.h"
10 #include "nsICategoryManager.h"
11 #include "nsIComponentManager.h"
12 #include "nsIComponentRegistrar.h"
13 #include "nsServiceManagerUtils.h"
14 #include "nsXPCOMCID.h"
15 #include "nsStringAPI.h"
19 NS_IMPL_ISUPPORTS(GenericModule
, nsIModule
)
22 GenericModule::GetClassObject(nsIComponentManager
* aCompMgr
,
27 for (const Module::CIDEntry
* e
= mData
->mCIDs
; e
->cid
; ++e
) {
28 if (e
->cid
->Equals(aCID
)) {
29 nsCOMPtr
<nsIFactory
> f
;
30 if (e
->getFactoryProc
) {
31 f
= e
->getFactoryProc(*mData
, *e
);
33 NS_ASSERTION(e
->constructorProc
, "No constructor proc?");
34 f
= new GenericFactory(e
->constructorProc
);
37 return NS_ERROR_FAILURE
;
40 return f
->QueryInterface(aIID
, aResult
);
43 NS_ERROR("Asking a module for a CID it doesn't implement.");
44 return NS_ERROR_NOT_IMPLEMENTED
;
48 GenericModule::RegisterSelf(nsIComponentManager
* aCompMgr
,
50 const char* aLoaderStr
,
53 nsCOMPtr
<nsIComponentRegistrar
> r
= do_QueryInterface(aCompMgr
);
54 for (const Module::CIDEntry
* e
= mData
->mCIDs
; e
->cid
; ++e
) {
55 r
->RegisterFactoryLocation(*e
->cid
, "", nullptr, aLocation
,
59 for (const Module::ContractIDEntry
* e
= mData
->mContractIDs
;
62 r
->RegisterFactoryLocation(*e
->cid
, "", e
->contractid
, aLocation
,
66 nsCOMPtr
<nsICategoryManager
> catman
;
67 for (const Module::CategoryEntry
* e
= mData
->mCategoryEntries
;
71 catman
= do_GetService(NS_CATEGORYMANAGER_CONTRACTID
);
75 catman
->AddCategoryEntry(e
->category
, e
->entry
, e
->value
, true, true,
82 GenericModule::UnregisterSelf(nsIComponentManager
* aCompMgr
,
84 const char* aLoaderStr
)
86 NS_ERROR("Nobody should ever call UnregisterSelf!");
87 return NS_ERROR_NOT_IMPLEMENTED
;
91 GenericModule::CanUnload(nsIComponentManager
* aCompMgr
, bool* aResult
)
93 NS_ERROR("Nobody should ever call CanUnload!");
98 } // namespace mozilla