2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-02-25 07:41:02 +03:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-02-25 07:41:02 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-02-25 07:41:02 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
1999-12-01 02:36:32 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-25 07:41:02 +03:00
|
|
|
|
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
// DO NOT COPY THIS CODE INTO YOUR SOURCE! USE NS_IMPL_NSGETMODULE()
|
|
|
|
|
|
|
|
#include "nsGenericFactory.h"
|
2002-03-06 07:22:27 +03:00
|
|
|
#include "nsMemory.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2006-03-15 07:59:42 +03:00
|
|
|
#include "nsIProgrammingLanguage.h"
|
2002-01-30 07:05:47 +03:00
|
|
|
|
2002-09-27 17:07:01 +04:00
|
|
|
#ifdef XPCOM_GLUE
|
|
|
|
#include "nsXPCOMGlue.h"
|
2004-02-19 05:44:03 +03:00
|
|
|
#include "nsXPCOMPrivate.h"
|
2002-09-27 17:07:01 +04:00
|
|
|
#endif
|
|
|
|
|
2002-01-30 07:05:47 +03:00
|
|
|
nsGenericFactory::nsGenericFactory(const nsModuleComponentInfo *info)
|
2001-03-12 23:43:02 +03:00
|
|
|
: mInfo(info)
|
1999-02-25 07:41:02 +03:00
|
|
|
{
|
2001-03-12 23:43:02 +03:00
|
|
|
if (mInfo && mInfo->mClassInfoGlobal)
|
2007-07-08 11:08:04 +04:00
|
|
|
*mInfo->mClassInfoGlobal = static_cast<nsIClassInfo *>(this);
|
1999-02-25 07:41:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-28 22:04:47 +03:00
|
|
|
nsGenericFactory::~nsGenericFactory()
|
|
|
|
{
|
2001-03-12 23:43:02 +03:00
|
|
|
if (mInfo) {
|
|
|
|
if (mInfo->mFactoryDestructor)
|
|
|
|
mInfo->mFactoryDestructor();
|
|
|
|
if (mInfo->mClassInfoGlobal)
|
|
|
|
*mInfo->mClassInfoGlobal = 0;
|
|
|
|
}
|
1999-02-28 22:04:47 +03:00
|
|
|
}
|
1999-02-25 07:41:02 +03:00
|
|
|
|
2001-03-12 23:43:02 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS3(nsGenericFactory,
|
2000-03-06 00:26:01 +03:00
|
|
|
nsIGenericFactory,
|
2001-03-12 23:43:02 +03:00
|
|
|
nsIFactory,
|
|
|
|
nsIClassInfo)
|
1999-02-25 07:41:02 +03:00
|
|
|
|
2001-03-12 23:43:02 +03:00
|
|
|
NS_IMETHODIMP nsGenericFactory::CreateInstance(nsISupports *aOuter,
|
|
|
|
REFNSIID aIID, void **aResult)
|
1999-02-25 07:41:02 +03:00
|
|
|
{
|
2002-09-14 04:18:33 +04:00
|
|
|
if (mInfo->mConstructor) {
|
|
|
|
return mInfo->mConstructor(aOuter, aIID, aResult);
|
2001-08-06 11:05:22 +04:00
|
|
|
}
|
2002-09-14 04:18:33 +04:00
|
|
|
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-02-25 07:41:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsGenericFactory::LockFactory(PRBool aLock)
|
|
|
|
{
|
2001-03-12 23:43:02 +03:00
|
|
|
// XXX do we care if (mInfo->mFlags & THREADSAFE)?
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsGenericFactory::GetInterfaces(PRUint32 *countp,
|
|
|
|
nsIID* **array)
|
|
|
|
{
|
2002-09-14 04:18:33 +04:00
|
|
|
if (!mInfo->mGetInterfacesProc) {
|
2001-03-12 23:43:02 +03:00
|
|
|
*countp = 0;
|
|
|
|
*array = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return mInfo->mGetInterfacesProc(countp, array);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsGenericFactory::GetHelperForLanguage(PRUint32 language,
|
|
|
|
nsISupports **helper)
|
|
|
|
{
|
2002-09-14 04:18:33 +04:00
|
|
|
if (mInfo->mGetLanguageHelperProc)
|
2001-03-12 23:43:02 +03:00
|
|
|
return mInfo->mGetLanguageHelperProc(language, helper);
|
|
|
|
*helper = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsGenericFactory::GetContractID(char **aContractID)
|
|
|
|
{
|
2002-09-14 04:18:33 +04:00
|
|
|
if (mInfo->mContractID) {
|
|
|
|
*aContractID = (char *)nsMemory::Alloc(strlen(mInfo->mContractID) + 1);
|
|
|
|
if (!*aContractID)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
strcpy(*aContractID, mInfo->mContractID);
|
|
|
|
} else {
|
|
|
|
*aContractID = nsnull;
|
|
|
|
}
|
2001-03-12 23:43:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_IMETHODIMP nsGenericFactory::GetClassDescription(char * *aClassDescription)
|
|
|
|
{
|
2002-09-14 04:18:33 +04:00
|
|
|
if (mInfo->mDescription) {
|
|
|
|
*aClassDescription = (char *)
|
|
|
|
nsMemory::Alloc(strlen(mInfo->mDescription) + 1);
|
|
|
|
if (!*aClassDescription)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
strcpy(*aClassDescription, mInfo->mDescription);
|
|
|
|
} else {
|
|
|
|
*aClassDescription = nsnull;
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-07 07:59:29 +04:00
|
|
|
NS_IMETHODIMP nsGenericFactory::GetClassID(nsCID * *aClassID)
|
|
|
|
{
|
2002-09-14 04:18:33 +04:00
|
|
|
*aClassID =
|
2007-07-08 11:08:04 +04:00
|
|
|
reinterpret_cast<nsCID*>
|
|
|
|
(nsMemory::Clone(&mInfo->mCID, sizeof mInfo->mCID));
|
2002-09-14 04:18:33 +04:00
|
|
|
if (! *aClassID)
|
2001-08-07 07:59:29 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-09-14 04:18:33 +04:00
|
|
|
return NS_OK;
|
2001-08-07 07:59:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsGenericFactory::GetClassIDNoAlloc(nsCID *aClassID)
|
2001-03-12 23:43:02 +03:00
|
|
|
{
|
2002-09-14 04:18:33 +04:00
|
|
|
*aClassID = mInfo->mCID;
|
2001-03-12 23:43:02 +03:00
|
|
|
return NS_OK;
|
1999-02-25 07:41:02 +03:00
|
|
|
}
|
1999-02-26 07:08:26 +03:00
|
|
|
|
2001-03-12 23:43:02 +03:00
|
|
|
NS_IMETHODIMP nsGenericFactory::GetImplementationLanguage(PRUint32 *langp)
|
1999-02-26 07:08:26 +03:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
*langp = nsIProgrammingLanguage::CPLUSPLUS;
|
2001-03-12 23:43:02 +03:00
|
|
|
return NS_OK;
|
1999-02-26 07:08:26 +03:00
|
|
|
}
|
|
|
|
|
2001-03-12 23:43:02 +03:00
|
|
|
NS_IMETHODIMP nsGenericFactory::GetFlags(PRUint32 *flagsp)
|
1999-02-28 22:04:47 +03:00
|
|
|
{
|
2001-03-12 23:43:02 +03:00
|
|
|
*flagsp = mInfo->mFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIGenericFactory: component-info accessors
|
2002-01-30 07:05:47 +03:00
|
|
|
NS_IMETHODIMP nsGenericFactory::SetComponentInfo(const nsModuleComponentInfo *info)
|
2001-03-12 23:43:02 +03:00
|
|
|
{
|
|
|
|
if (mInfo && mInfo->mClassInfoGlobal)
|
|
|
|
*mInfo->mClassInfoGlobal = 0;
|
|
|
|
mInfo = info;
|
|
|
|
if (mInfo && mInfo->mClassInfoGlobal)
|
2007-07-08 11:08:04 +04:00
|
|
|
*mInfo->mClassInfoGlobal = static_cast<nsIClassInfo *>(this);
|
2001-03-12 23:43:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-30 07:05:47 +03:00
|
|
|
NS_IMETHODIMP nsGenericFactory::GetComponentInfo(const nsModuleComponentInfo **infop)
|
2001-03-12 23:43:02 +03:00
|
|
|
{
|
|
|
|
*infop = mInfo;
|
|
|
|
return NS_OK;
|
1999-02-28 22:04:47 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 07:08:26 +03:00
|
|
|
NS_METHOD nsGenericFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
|
|
|
{
|
2001-03-12 23:43:02 +03:00
|
|
|
// sorry, aggregation not spoken here.
|
2002-09-14 04:18:33 +04:00
|
|
|
nsresult res = NS_ERROR_NO_AGGREGATION;
|
|
|
|
if (outer == NULL) {
|
|
|
|
nsGenericFactory* factory = new nsGenericFactory;
|
|
|
|
if (factory != NULL) {
|
|
|
|
res = factory->QueryInterface(aIID, aInstancePtr);
|
|
|
|
if (res != NS_OK)
|
|
|
|
delete factory;
|
|
|
|
} else {
|
|
|
|
res = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
1999-02-26 07:08:26 +03:00
|
|
|
}
|
1999-05-26 05:38:36 +04:00
|
|
|
|
2004-10-29 23:43:51 +04:00
|
|
|
NS_COM_GLUE nsresult
|
1999-05-26 05:38:36 +04:00
|
|
|
NS_NewGenericFactory(nsIGenericFactory* *result,
|
2002-01-30 07:05:47 +03:00
|
|
|
const nsModuleComponentInfo *info)
|
1999-05-26 05:38:36 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIGenericFactory* fact;
|
2002-09-14 04:18:33 +04:00
|
|
|
rv = nsGenericFactory::Create(NULL, NS_GET_IID(nsIGenericFactory), (void**)&fact);
|
1999-05-26 05:38:36 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-03-12 23:43:02 +03:00
|
|
|
rv = fact->SetComponentInfo(info);
|
1999-05-26 05:38:36 +04:00
|
|
|
if (NS_FAILED(rv)) goto error;
|
|
|
|
*result = fact;
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
error:
|
|
|
|
NS_RELEASE(fact);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-12 12:07:26 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsGenericModule::nsGenericModule(const char* moduleName, PRUint32 componentCount,
|
2002-01-30 07:05:47 +03:00
|
|
|
const nsModuleComponentInfo* components,
|
2001-08-07 06:55:54 +04:00
|
|
|
nsModuleConstructorProc ctor,
|
2005-07-14 22:42:59 +04:00
|
|
|
nsModuleDestructorProc dtor)
|
1999-11-12 12:07:26 +03:00
|
|
|
: mInitialized(PR_FALSE),
|
|
|
|
mModuleName(moduleName),
|
|
|
|
mComponentCount(componentCount),
|
|
|
|
mComponents(components),
|
2002-03-06 07:22:27 +03:00
|
|
|
mFactoriesNotToBeRegistered(nsnull),
|
2001-08-07 06:55:54 +04:00
|
|
|
mCtor(ctor),
|
2005-07-14 22:42:59 +04:00
|
|
|
mDtor(dtor)
|
1999-11-12 12:07:26 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericModule::~nsGenericModule()
|
|
|
|
{
|
|
|
|
Shutdown();
|
2002-09-27 17:07:01 +04:00
|
|
|
|
|
|
|
#ifdef XPCOM_GLUE
|
|
|
|
XPCOMGlueShutdown();
|
|
|
|
#endif
|
|
|
|
|
1999-11-12 12:07:26 +03:00
|
|
|
}
|
|
|
|
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsGenericModule, nsIModule)
|
1999-11-12 12:07:26 +03:00
|
|
|
|
2002-03-06 07:22:27 +03:00
|
|
|
nsresult
|
|
|
|
nsGenericModule::AddFactoryNode(nsIGenericFactory* fact)
|
|
|
|
{
|
|
|
|
if (!fact)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
FactoryNode *node = new FactoryNode(fact, mFactoriesNotToBeRegistered);
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
mFactoriesNotToBeRegistered = node;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-12 12:07:26 +03:00
|
|
|
// Perform our one-time intialization for this module
|
|
|
|
nsresult
|
2002-03-06 07:22:27 +03:00
|
|
|
nsGenericModule::Initialize(nsIComponentManager *compMgr)
|
1999-11-12 12:07:26 +03:00
|
|
|
{
|
2002-09-27 17:07:01 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-11-12 12:07:26 +03:00
|
|
|
if (mInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-08-06 11:05:22 +04:00
|
|
|
|
2001-08-07 06:55:54 +04:00
|
|
|
if (mCtor) {
|
2002-09-27 17:07:01 +04:00
|
|
|
rv = mCtor(this);
|
2001-08-07 06:55:54 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-09-27 17:07:01 +04:00
|
|
|
|
|
|
|
#ifdef XPCOM_GLUE
|
2004-02-19 05:44:03 +03:00
|
|
|
rv = XPCOMGlueStartup(".");
|
2002-09-27 17:07:01 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
#endif
|
|
|
|
|
2002-03-06 07:22:27 +03:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(compMgr, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-08-06 11:05:22 +04:00
|
|
|
// Eagerly populate factory/class object hash for entries
|
|
|
|
// without constructors. If we didn't, the class object would
|
2001-08-07 07:59:29 +04:00
|
|
|
// never get created. Also create the factory, which doubles
|
|
|
|
// as the class object, if the EAGER_CLASSINFO flag was given.
|
|
|
|
// This allows objects to be created (within their modules)
|
|
|
|
// via operator new rather than CreateInstance, yet still be
|
|
|
|
// QI'able to nsIClassInfo.
|
2002-01-30 07:05:47 +03:00
|
|
|
const nsModuleComponentInfo* desc = mComponents;
|
2001-08-06 11:05:22 +04:00
|
|
|
for (PRUint32 i = 0; i < mComponentCount; i++) {
|
2001-08-07 07:59:29 +04:00
|
|
|
if (!desc->mConstructor ||
|
|
|
|
(desc->mFlags & nsIClassInfo::EAGER_CLASSINFO)) {
|
2001-08-06 11:05:22 +04:00
|
|
|
nsCOMPtr<nsIGenericFactory> fact;
|
2009-06-14 12:37:38 +04:00
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(fact), desc);
|
2001-08-06 11:05:22 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-03-06 07:22:27 +03:00
|
|
|
|
|
|
|
// if we don't have a mConstructor, then we should not populate
|
|
|
|
// the component manager.
|
|
|
|
if (!desc->mConstructor) {
|
|
|
|
rv = AddFactoryNode(fact);
|
|
|
|
} else {
|
|
|
|
rv = registrar->RegisterFactory(desc->mCID,
|
|
|
|
desc->mDescription,
|
|
|
|
desc->mContractID,
|
|
|
|
fact);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-08-06 11:05:22 +04:00
|
|
|
}
|
|
|
|
desc++;
|
|
|
|
}
|
|
|
|
|
1999-11-12 12:07:26 +03:00
|
|
|
mInitialized = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown this module, releasing all of the module resources
|
|
|
|
void
|
|
|
|
nsGenericModule::Shutdown()
|
|
|
|
{
|
2002-03-06 07:22:27 +03:00
|
|
|
// Free cached factories that were not registered.
|
|
|
|
FactoryNode* node;
|
|
|
|
while (mFactoriesNotToBeRegistered)
|
|
|
|
{
|
|
|
|
node = mFactoriesNotToBeRegistered->mNext;
|
|
|
|
delete mFactoriesNotToBeRegistered;
|
|
|
|
mFactoriesNotToBeRegistered = node;
|
|
|
|
}
|
2002-02-06 23:47:37 +03:00
|
|
|
|
2001-08-21 04:55:20 +04:00
|
|
|
if (mInitialized) {
|
|
|
|
mInitialized = PR_FALSE;
|
|
|
|
|
|
|
|
if (mDtor)
|
|
|
|
mDtor(this);
|
|
|
|
}
|
1999-11-12 12:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a factory object for creating instances of aClass.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr,
|
|
|
|
const nsCID& aClass,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void** r_classObj)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Defensive programming: Initialize *r_classObj in case of error below
|
|
|
|
if (!r_classObj) {
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
}
|
2002-09-14 04:18:33 +04:00
|
|
|
*r_classObj = NULL;
|
1999-11-12 12:07:26 +03:00
|
|
|
|
|
|
|
// Do one-time-only initialization if necessary
|
|
|
|
if (!mInitialized) {
|
2002-03-06 07:22:27 +03:00
|
|
|
rv = Initialize(aCompMgr);
|
1999-11-12 12:07:26 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Initialization failed! yikes!
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Choose the appropriate factory, based on the desired instance
|
|
|
|
// class type (aClass).
|
2002-03-06 07:22:27 +03:00
|
|
|
const nsModuleComponentInfo* desc = mComponents;
|
|
|
|
for (PRUint32 i = 0; i < mComponentCount; i++) {
|
|
|
|
if (desc->mCID.Equals(aClass)) {
|
|
|
|
nsCOMPtr<nsIGenericFactory> fact;
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(fact), desc);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
return fact->QueryInterface(aIID, r_classObj);
|
1999-11-12 12:07:26 +03:00
|
|
|
}
|
2002-03-06 07:22:27 +03:00
|
|
|
desc++;
|
1999-11-12 12:07:26 +03:00
|
|
|
}
|
2002-03-06 07:22:27 +03:00
|
|
|
// not found in descriptions
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-11-12 12:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
2000-01-25 00:28:28 +03:00
|
|
|
nsIFile* aPath,
|
1999-11-12 12:07:26 +03:00
|
|
|
const char* registryLocation,
|
|
|
|
const char* componentType)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef DEBUG
|
2007-07-16 23:00:14 +04:00
|
|
|
printf_stderr("*** Registering components in: %s\n", mModuleName);
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif
|
1999-11-12 12:07:26 +03:00
|
|
|
|
2002-01-30 07:05:47 +03:00
|
|
|
const nsModuleComponentInfo* cp = mComponents;
|
1999-11-12 12:10:40 +03:00
|
|
|
for (PRUint32 i = 0; i < mComponentCount; i++) {
|
2001-08-06 11:05:22 +04:00
|
|
|
// Register the component only if it has a constructor
|
|
|
|
if (cp->mConstructor) {
|
2002-01-30 00:22:13 +03:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(aCompMgr, &rv);
|
|
|
|
if (registrar)
|
|
|
|
rv = registrar->RegisterFactoryLocation(cp->mCID,
|
|
|
|
cp->mDescription,
|
|
|
|
cp->mContractID,
|
|
|
|
aPath,
|
|
|
|
registryLocation,
|
|
|
|
componentType);
|
2001-08-06 11:05:22 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef DEBUG
|
2006-09-12 22:22:40 +04:00
|
|
|
printf_stderr("nsGenericModule %s: unable to register %s component => %x\n",
|
2001-08-06 11:05:22 +04:00
|
|
|
mModuleName?mModuleName:"(null)", cp->mDescription?cp->mDescription:"(null)", rv);
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif
|
2001-08-06 11:05:22 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-11-12 12:07:26 +03:00
|
|
|
}
|
2000-01-12 00:18:55 +03:00
|
|
|
// Call the registration hook of the component, if any
|
|
|
|
if (cp->mRegisterSelfProc)
|
|
|
|
{
|
2001-03-12 23:43:02 +03:00
|
|
|
rv = cp->mRegisterSelfProc(aCompMgr, aPath, registryLocation,
|
|
|
|
componentType, cp);
|
2000-01-12 00:18:55 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef DEBUG
|
2006-09-12 22:22:40 +04:00
|
|
|
printf_stderr("nsGenericModule %s: Register hook for %s component returned error => %x\n",
|
2000-01-12 00:18:55 +03:00
|
|
|
mModuleName?mModuleName:"(null)", cp->mDescription?cp->mDescription:"(null)", rv);
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif
|
2000-01-12 00:18:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-11-12 12:07:26 +03:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
2000-01-25 00:28:28 +03:00
|
|
|
nsIFile* aPath,
|
1999-11-12 12:07:26 +03:00
|
|
|
const char* registryLocation)
|
|
|
|
{
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef DEBUG
|
2007-07-16 23:00:14 +04:00
|
|
|
printf_stderr("*** Unregistering components in: %s\n", mModuleName);
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif
|
2002-01-30 07:05:47 +03:00
|
|
|
const nsModuleComponentInfo* cp = mComponents;
|
1999-11-12 12:10:40 +03:00
|
|
|
for (PRUint32 i = 0; i < mComponentCount; i++) {
|
2000-01-12 00:18:55 +03:00
|
|
|
// Call the unregistration hook of the component, if any
|
|
|
|
if (cp->mUnregisterSelfProc)
|
|
|
|
{
|
2001-03-12 23:43:02 +03:00
|
|
|
cp->mUnregisterSelfProc(aCompMgr, aPath, registryLocation, cp);
|
2000-01-12 00:18:55 +03:00
|
|
|
}
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2000-01-12 00:18:55 +03:00
|
|
|
// Unregister the component
|
2001-12-19 03:12:41 +03:00
|
|
|
nsresult rv;
|
2002-01-30 00:22:13 +03:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(aCompMgr, &rv);
|
|
|
|
if (registrar)
|
|
|
|
rv = registrar->UnregisterFactoryLocation(cp->mCID, aPath);
|
1999-11-12 12:07:26 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef DEBUG
|
2006-09-12 22:22:40 +04:00
|
|
|
printf_stderr("nsGenericModule %s: unable to unregister %s component => %x\n",
|
1999-11-12 12:07:26 +03:00
|
|
|
mModuleName, cp->mDescription, rv);
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif
|
1999-11-12 12:07:26 +03:00
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
|
|
|
{
|
|
|
|
if (!okToUnload) {
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
}
|
|
|
|
*okToUnload = PR_FALSE;
|
2008-12-11 23:13:52 +03:00
|
|
|
return NS_OK;
|
1999-11-12 12:07:26 +03:00
|
|
|
}
|
|
|
|
|
2004-10-29 23:43:51 +04:00
|
|
|
NS_COM_GLUE nsresult
|
2005-07-21 17:33:43 +04:00
|
|
|
NS_NewGenericModule2(nsModuleInfo const *info, nsIModule* *result)
|
1999-11-12 12:07:26 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Create and initialize the module instance
|
|
|
|
nsGenericModule *m =
|
2001-08-21 04:55:20 +04:00
|
|
|
new nsGenericModule(info->mModuleName, info->mCount, info->mComponents,
|
2005-07-14 22:42:59 +04:00
|
|
|
info->mCtor, info->mDtor);
|
2001-08-21 04:55:20 +04:00
|
|
|
|
|
|
|
if (!m)
|
1999-11-12 12:07:26 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2004-01-22 04:01:19 +03:00
|
|
|
// Increase refcnt and store away nsIModule interface to m in result
|
|
|
|
NS_ADDREF(*result = m);
|
1999-11-12 12:07:26 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-10-29 23:43:51 +04:00
|
|
|
NS_COM_GLUE nsresult
|
2001-08-30 01:59:43 +04:00
|
|
|
NS_NewGenericModule(const char* moduleName,
|
|
|
|
PRUint32 componentCount,
|
|
|
|
nsModuleComponentInfo* components,
|
|
|
|
nsModuleDestructorProc dtor,
|
|
|
|
nsIModule* *result)
|
|
|
|
{
|
|
|
|
nsModuleInfo info;
|
2002-02-05 04:41:13 +03:00
|
|
|
memset(&info, 0, sizeof(info));
|
2001-08-30 01:59:43 +04:00
|
|
|
|
|
|
|
info.mVersion = NS_MODULEINFO_VERSION;
|
|
|
|
info.mModuleName = moduleName;
|
|
|
|
info.mComponents = components;
|
|
|
|
info.mCount = componentCount;
|
|
|
|
info.mDtor = dtor;
|
|
|
|
|
|
|
|
return NS_NewGenericModule2(&info, result);
|
|
|
|
}
|
|
|
|
|
1999-11-12 12:07:26 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|