CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / xpcom / glue / GenericModule.cpp
blob6be00bc310599665df5b255fcc945f5bc6c98b58
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
13 * License.
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.
22 * Contributor(s):
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"
49 namespace mozilla {
51 NS_IMPL_THREADSAFE_ISUPPORTS1(GenericModule, nsIModule)
53 NS_IMETHODIMP
54 GenericModule::GetClassObject(nsIComponentManager* aCompMgr,
55 const nsCID& aCID,
56 const nsIID& aIID,
57 void** aResult)
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);
65 else {
66 NS_ASSERTION(e->constructorProc, "No constructor proc?");
67 f = new GenericFactory(e->constructorProc);
69 if (!f)
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;
79 NS_IMETHODIMP
80 GenericModule::RegisterSelf(nsIComponentManager* aCompMgr,
81 nsIFile* aLocation,
82 const char* aLoaderStr,
83 const char* aType)
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;
90 e && e->contractid;
91 ++e)
92 r->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation, aLoaderStr, aType);
94 nsCOMPtr<nsICategoryManager> catman;
95 for (const Module::CategoryEntry* e = mData->mCategoryEntries;
96 e && e->category;
97 ++e) {
98 if (!catman)
99 catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
101 nsCAutoString r;
102 catman->AddCategoryEntry(e->category, e->entry, e->value, true, true,
103 getter_Copies(r));
105 return NS_OK;
108 NS_IMETHODIMP
109 GenericModule::UnregisterSelf(nsIComponentManager* aCompMgr,
110 nsIFile* aFile,
111 const char* aLoaderStr)
113 NS_ERROR("Nobody should ever call UnregisterSelf!");
114 return NS_ERROR_NOT_IMPLEMENTED;
117 NS_IMETHODIMP
118 GenericModule::CanUnload(nsIComponentManager* aCompMgr, PRBool* aResult)
120 NS_ERROR("Nobody should ever call CanUnload!");
121 *aResult = false;
122 return NS_OK;
125 } // namespace mozilla