|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "mozilla/ModuleUtils.h" |
|
7 #include "mozilla/GenericFactory.h" |
|
8 |
|
9 #include "nsICategoryManager.h" |
|
10 #include "nsIComponentManager.h" |
|
11 #include "nsIComponentRegistrar.h" |
|
12 #include "nsServiceManagerUtils.h" |
|
13 #include "nsXPCOMCID.h" |
|
14 #include "nsStringAPI.h" |
|
15 |
|
16 namespace mozilla { |
|
17 |
|
18 NS_IMPL_ISUPPORTS(GenericModule, nsIModule) |
|
19 |
|
20 NS_IMETHODIMP |
|
21 GenericModule::GetClassObject(nsIComponentManager* aCompMgr, |
|
22 const nsCID& aCID, |
|
23 const nsIID& aIID, |
|
24 void** aResult) |
|
25 { |
|
26 for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) { |
|
27 if (e->cid->Equals(aCID)) { |
|
28 nsCOMPtr<nsIFactory> f; |
|
29 if (e->getFactoryProc) { |
|
30 f = e->getFactoryProc(*mData, *e); |
|
31 } |
|
32 else { |
|
33 NS_ASSERTION(e->constructorProc, "No constructor proc?"); |
|
34 f = new GenericFactory(e->constructorProc); |
|
35 } |
|
36 if (!f) |
|
37 return NS_ERROR_FAILURE; |
|
38 |
|
39 return f->QueryInterface(aIID, aResult); |
|
40 } |
|
41 } |
|
42 NS_ERROR("Asking a module for a CID it doesn't implement."); |
|
43 return NS_ERROR_NOT_IMPLEMENTED; |
|
44 } |
|
45 |
|
46 NS_IMETHODIMP |
|
47 GenericModule::RegisterSelf(nsIComponentManager* aCompMgr, |
|
48 nsIFile* aLocation, |
|
49 const char* aLoaderStr, |
|
50 const char* aType) |
|
51 { |
|
52 nsCOMPtr<nsIComponentRegistrar> r = do_QueryInterface(aCompMgr); |
|
53 for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) |
|
54 r->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation, aLoaderStr, aType); |
|
55 |
|
56 for (const Module::ContractIDEntry* e = mData->mContractIDs; |
|
57 e && e->contractid; |
|
58 ++e) |
|
59 r->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation, aLoaderStr, aType); |
|
60 |
|
61 nsCOMPtr<nsICategoryManager> catman; |
|
62 for (const Module::CategoryEntry* e = mData->mCategoryEntries; |
|
63 e && e->category; |
|
64 ++e) { |
|
65 if (!catman) |
|
66 catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID); |
|
67 |
|
68 nsAutoCString r; |
|
69 catman->AddCategoryEntry(e->category, e->entry, e->value, true, true, |
|
70 getter_Copies(r)); |
|
71 } |
|
72 return NS_OK; |
|
73 } |
|
74 |
|
75 NS_IMETHODIMP |
|
76 GenericModule::UnregisterSelf(nsIComponentManager* aCompMgr, |
|
77 nsIFile* aFile, |
|
78 const char* aLoaderStr) |
|
79 { |
|
80 NS_ERROR("Nobody should ever call UnregisterSelf!"); |
|
81 return NS_ERROR_NOT_IMPLEMENTED; |
|
82 } |
|
83 |
|
84 NS_IMETHODIMP |
|
85 GenericModule::CanUnload(nsIComponentManager* aCompMgr, bool* aResult) |
|
86 { |
|
87 NS_ERROR("Nobody should ever call CanUnload!"); |
|
88 *aResult = false; |
|
89 return NS_OK; |
|
90 } |
|
91 |
|
92 } // namespace mozilla |