1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Benjamin Smedberg <benjamin@smedbergs.us>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "mozilla/ModuleUtils.h"
40 #include "mozilla/GenericFactory.h"
42 #include "nsICategoryManager.h"
43 #include "nsIComponentManager.h"
44 #include "nsIComponentRegistrar.h"
45 #include "nsServiceManagerUtils.h"
46 #include "nsXPCOMCID.h"
47 #include "nsStringAPI.h"
51 NS_IMPL_THREADSAFE_ISUPPORTS1(GenericModule
, nsIModule
)
54 GenericModule::GetClassObject(nsIComponentManager
* aCompMgr
,
59 for (const Module::CIDEntry
* e
= mData
->mCIDs
; e
->cid
; ++e
) {
60 if (e
->cid
->Equals(aCID
)) {
61 nsCOMPtr
<nsIFactory
> f
;
62 if (e
->getFactoryProc
) {
63 f
= e
->getFactoryProc(*mData
, *e
);
66 NS_ASSERTION(e
->constructorProc
, "No constructor proc?");
67 f
= new GenericFactory(e
->constructorProc
);
70 return NS_ERROR_FAILURE
;
72 return f
->QueryInterface(aIID
, aResult
);
75 NS_ERROR("Asking a module for a CID it doesn't implement.");
76 return NS_ERROR_NOT_IMPLEMENTED
;
80 GenericModule::RegisterSelf(nsIComponentManager
* aCompMgr
,
82 const char* aLoaderStr
,
85 nsCOMPtr
<nsIComponentRegistrar
> r
= do_QueryInterface(aCompMgr
);
86 for (const Module::CIDEntry
* e
= mData
->mCIDs
; e
->cid
; ++e
)
87 r
->RegisterFactoryLocation(*e
->cid
, "", NULL
, aLocation
, aLoaderStr
, aType
);
89 for (const Module::ContractIDEntry
* e
= mData
->mContractIDs
;
92 r
->RegisterFactoryLocation(*e
->cid
, "", e
->contractid
, aLocation
, aLoaderStr
, aType
);
94 nsCOMPtr
<nsICategoryManager
> catman
;
95 for (const Module::CategoryEntry
* e
= mData
->mCategoryEntries
;
99 catman
= do_GetService(NS_CATEGORYMANAGER_CONTRACTID
);
102 catman
->AddCategoryEntry(e
->category
, e
->entry
, e
->value
, true, true,
109 GenericModule::UnregisterSelf(nsIComponentManager
* aCompMgr
,
111 const char* aLoaderStr
)
113 NS_ERROR("Nobody should ever call UnregisterSelf!");
114 return NS_ERROR_NOT_IMPLEMENTED
;
118 GenericModule::CanUnload(nsIComponentManager
* aCompMgr
, PRBool
* aResult
)
120 NS_ERROR("Nobody should ever call CanUnload!");
125 } // namespace mozilla