michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/ModuleUtils.h" michael@0: #include "mozilla/GenericFactory.h" michael@0: michael@0: #include "nsICategoryManager.h" michael@0: #include "nsIComponentManager.h" michael@0: #include "nsIComponentRegistrar.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "nsXPCOMCID.h" michael@0: #include "nsStringAPI.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: NS_IMPL_ISUPPORTS(GenericModule, nsIModule) michael@0: michael@0: NS_IMETHODIMP michael@0: GenericModule::GetClassObject(nsIComponentManager* aCompMgr, michael@0: const nsCID& aCID, michael@0: const nsIID& aIID, michael@0: void** aResult) michael@0: { michael@0: for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) { michael@0: if (e->cid->Equals(aCID)) { michael@0: nsCOMPtr f; michael@0: if (e->getFactoryProc) { michael@0: f = e->getFactoryProc(*mData, *e); michael@0: } michael@0: else { michael@0: NS_ASSERTION(e->constructorProc, "No constructor proc?"); michael@0: f = new GenericFactory(e->constructorProc); michael@0: } michael@0: if (!f) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: return f->QueryInterface(aIID, aResult); michael@0: } michael@0: } michael@0: NS_ERROR("Asking a module for a CID it doesn't implement."); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: GenericModule::RegisterSelf(nsIComponentManager* aCompMgr, michael@0: nsIFile* aLocation, michael@0: const char* aLoaderStr, michael@0: const char* aType) michael@0: { michael@0: nsCOMPtr r = do_QueryInterface(aCompMgr); michael@0: for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) michael@0: r->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation, aLoaderStr, aType); michael@0: michael@0: for (const Module::ContractIDEntry* e = mData->mContractIDs; michael@0: e && e->contractid; michael@0: ++e) michael@0: r->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation, aLoaderStr, aType); michael@0: michael@0: nsCOMPtr catman; michael@0: for (const Module::CategoryEntry* e = mData->mCategoryEntries; michael@0: e && e->category; michael@0: ++e) { michael@0: if (!catman) michael@0: catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID); michael@0: michael@0: nsAutoCString r; michael@0: catman->AddCategoryEntry(e->category, e->entry, e->value, true, true, michael@0: getter_Copies(r)); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: GenericModule::UnregisterSelf(nsIComponentManager* aCompMgr, michael@0: nsIFile* aFile, michael@0: const char* aLoaderStr) michael@0: { michael@0: NS_ERROR("Nobody should ever call UnregisterSelf!"); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: GenericModule::CanUnload(nsIComponentManager* aCompMgr, bool* aResult) michael@0: { michael@0: NS_ERROR("Nobody should ever call CanUnload!"); michael@0: *aResult = false; michael@0: return NS_OK; michael@0: } michael@0: michael@0: } // namespace mozilla