Bumping manifests a=b2g-bump
[gecko.git] / xpcom / glue / GenericModule.cpp
blobf2260a13f71f96842a17459b158570b868c45873
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"
17 namespace mozilla {
19 NS_IMPL_ISUPPORTS(GenericModule, nsIModule)
21 NS_IMETHODIMP
22 GenericModule::GetClassObject(nsIComponentManager* aCompMgr,
23 const nsCID& aCID,
24 const nsIID& aIID,
25 void** aResult)
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);
32 } else {
33 NS_ASSERTION(e->constructorProc, "No constructor proc?");
34 f = new GenericFactory(e->constructorProc);
36 if (!f) {
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;
47 NS_IMETHODIMP
48 GenericModule::RegisterSelf(nsIComponentManager* aCompMgr,
49 nsIFile* aLocation,
50 const char* aLoaderStr,
51 const char* aType)
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,
56 aLoaderStr, aType);
59 for (const Module::ContractIDEntry* e = mData->mContractIDs;
60 e && e->contractid;
61 ++e) {
62 r->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation,
63 aLoaderStr, aType);
66 nsCOMPtr<nsICategoryManager> catman;
67 for (const Module::CategoryEntry* e = mData->mCategoryEntries;
68 e && e->category;
69 ++e) {
70 if (!catman) {
71 catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
74 nsAutoCString r;
75 catman->AddCategoryEntry(e->category, e->entry, e->value, true, true,
76 getter_Copies(r));
78 return NS_OK;
81 NS_IMETHODIMP
82 GenericModule::UnregisterSelf(nsIComponentManager* aCompMgr,
83 nsIFile* aFile,
84 const char* aLoaderStr)
86 NS_ERROR("Nobody should ever call UnregisterSelf!");
87 return NS_ERROR_NOT_IMPLEMENTED;
90 NS_IMETHODIMP
91 GenericModule::CanUnload(nsIComponentManager* aCompMgr, bool* aResult)
93 NS_ERROR("Nobody should ever call CanUnload!");
94 *aResult = false;
95 return NS_OK;
98 } // namespace mozilla