1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/glue/GenericModule.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/ModuleUtils.h" 1.10 +#include "mozilla/GenericFactory.h" 1.11 + 1.12 +#include "nsICategoryManager.h" 1.13 +#include "nsIComponentManager.h" 1.14 +#include "nsIComponentRegistrar.h" 1.15 +#include "nsServiceManagerUtils.h" 1.16 +#include "nsXPCOMCID.h" 1.17 +#include "nsStringAPI.h" 1.18 + 1.19 +namespace mozilla { 1.20 + 1.21 +NS_IMPL_ISUPPORTS(GenericModule, nsIModule) 1.22 + 1.23 +NS_IMETHODIMP 1.24 +GenericModule::GetClassObject(nsIComponentManager* aCompMgr, 1.25 + const nsCID& aCID, 1.26 + const nsIID& aIID, 1.27 + void** aResult) 1.28 +{ 1.29 + for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) { 1.30 + if (e->cid->Equals(aCID)) { 1.31 + nsCOMPtr<nsIFactory> f; 1.32 + if (e->getFactoryProc) { 1.33 + f = e->getFactoryProc(*mData, *e); 1.34 + } 1.35 + else { 1.36 + NS_ASSERTION(e->constructorProc, "No constructor proc?"); 1.37 + f = new GenericFactory(e->constructorProc); 1.38 + } 1.39 + if (!f) 1.40 + return NS_ERROR_FAILURE; 1.41 + 1.42 + return f->QueryInterface(aIID, aResult); 1.43 + } 1.44 + } 1.45 + NS_ERROR("Asking a module for a CID it doesn't implement."); 1.46 + return NS_ERROR_NOT_IMPLEMENTED; 1.47 +} 1.48 + 1.49 +NS_IMETHODIMP 1.50 +GenericModule::RegisterSelf(nsIComponentManager* aCompMgr, 1.51 + nsIFile* aLocation, 1.52 + const char* aLoaderStr, 1.53 + const char* aType) 1.54 +{ 1.55 + nsCOMPtr<nsIComponentRegistrar> r = do_QueryInterface(aCompMgr); 1.56 + for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) 1.57 + r->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation, aLoaderStr, aType); 1.58 + 1.59 + for (const Module::ContractIDEntry* e = mData->mContractIDs; 1.60 + e && e->contractid; 1.61 + ++e) 1.62 + r->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation, aLoaderStr, aType); 1.63 + 1.64 + nsCOMPtr<nsICategoryManager> catman; 1.65 + for (const Module::CategoryEntry* e = mData->mCategoryEntries; 1.66 + e && e->category; 1.67 + ++e) { 1.68 + if (!catman) 1.69 + catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID); 1.70 + 1.71 + nsAutoCString r; 1.72 + catman->AddCategoryEntry(e->category, e->entry, e->value, true, true, 1.73 + getter_Copies(r)); 1.74 + } 1.75 + return NS_OK; 1.76 +} 1.77 + 1.78 +NS_IMETHODIMP 1.79 +GenericModule::UnregisterSelf(nsIComponentManager* aCompMgr, 1.80 + nsIFile* aFile, 1.81 + const char* aLoaderStr) 1.82 +{ 1.83 + NS_ERROR("Nobody should ever call UnregisterSelf!"); 1.84 + return NS_ERROR_NOT_IMPLEMENTED; 1.85 +} 1.86 + 1.87 +NS_IMETHODIMP 1.88 +GenericModule::CanUnload(nsIComponentManager* aCompMgr, bool* aResult) 1.89 +{ 1.90 + NS_ERROR("Nobody should ever call CanUnload!"); 1.91 + *aResult = false; 1.92 + return NS_OK; 1.93 +} 1.94 + 1.95 +} // namespace mozilla