1999-03-10 12:53:25 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
1999-03-09 12:44:27 +03:00
|
|
|
/*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03: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-03-09 12:44:27 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-03-09 12:44:27 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-12-01 02:36:32 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2000-05-03 02:38:04 +04:00
|
|
|
*
|
|
|
|
* This Original Code has been modified by IBM Corporation.
|
|
|
|
* Modifications made by IBM described herein are
|
|
|
|
* Copyright (c) International Business Machines
|
|
|
|
* Corporation, 2000
|
|
|
|
*
|
|
|
|
* Modifications to Mozilla code or documentation
|
|
|
|
* identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 04/20/2000 IBM Corp. Added PR_CALLBACK for Optlink use in OS2
|
1999-03-09 12:44:27 +03:00
|
|
|
*/
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
#include <stdlib.h>
|
2000-04-25 09:11:30 +04:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
// this after nsISupports, to pick up IID
|
|
|
|
// so that xpt stuff doesn't try to define it itself...
|
|
|
|
#include "xptinfo.h"
|
|
|
|
#include "nsIInterfaceInfoManager.h"
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2000-05-26 08:56:23 +04:00
|
|
|
#include "nsICategoryManager.h"
|
1999-07-02 07:35:09 +04:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIEnumerator.h"
|
1999-08-09 09:40:51 +04:00
|
|
|
#include "nsIModule.h"
|
1999-08-09 09:02:25 +04:00
|
|
|
#include "nsHashtableEnumerator.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
1999-09-01 01:40:21 +04:00
|
|
|
#include "nsIComponentLoader.h"
|
|
|
|
#include "nsNativeComponentLoader.h"
|
1999-11-10 03:28:34 +03:00
|
|
|
#include "nsXPIDLString.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2000-05-15 23:28:12 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
#include "nsILocalFile.h"
|
|
|
|
#include "nsLocalFile.h"
|
|
|
|
#include "nsDirectoryService.h"
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "plstr.h"
|
|
|
|
#include "prlink.h"
|
|
|
|
#include "prsystem.h"
|
|
|
|
#include "prprf.h"
|
1999-03-12 14:25:17 +03:00
|
|
|
#include "xcDll.h"
|
1999-03-11 01:07:34 +03:00
|
|
|
#include "prerror.h"
|
1999-03-31 11:04:12 +04:00
|
|
|
#include "prmem.h"
|
2000-02-15 04:32:12 +03:00
|
|
|
#include "nsIFile.h"
|
|
|
|
//#include "mozreg.h"
|
1999-09-27 01:20:21 +04:00
|
|
|
#include "NSReg.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#include "prcmon.h"
|
|
|
|
#include "prthread.h" /* XXX: only used for the NSPR initialization hack (rick) */
|
|
|
|
|
1999-06-29 14:27:58 +04:00
|
|
|
#ifdef XP_BEOS
|
|
|
|
#include <FindDirectory.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#endif
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
// Logging of debug output
|
1999-06-29 01:51:46 +04:00
|
|
|
#define FORCE_PR_LOG /* Allow logging in the release build */
|
|
|
|
#include "prlog.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
PRLogModuleInfo* nsComponentManagerLog = NULL;
|
1999-06-14 06:07:03 +04:00
|
|
|
|
|
|
|
// Enable printing of critical errors on screen even for release builds
|
|
|
|
#define PRINT_CRITICAL_ERROR_TO_SCREEN
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-04-05 04:07:18 +04:00
|
|
|
// Common Key Names
|
2000-02-16 10:45:20 +03:00
|
|
|
const char xpcomKeyName[]="software/mozilla/XPCOM";
|
2000-02-20 06:12:59 +03:00
|
|
|
const char classesKeyName[]="progID";
|
|
|
|
const char classIDKeyName[]="classID";
|
2000-02-16 10:45:20 +03:00
|
|
|
const char componentsKeyName[]="components";
|
|
|
|
const char componentLoadersKeyName[]="componentLoaders";
|
|
|
|
const char xpcomComponentsKeyName[]="software/mozilla/XPCOM/components";
|
1999-04-05 04:07:18 +04:00
|
|
|
|
|
|
|
// Common Value Names
|
2000-02-20 06:12:59 +03:00
|
|
|
const char classIDValueName[]="ClassID";
|
1999-04-05 04:07:18 +04:00
|
|
|
const char versionValueName[]="VersionString";
|
|
|
|
const char lastModValueName[]="LastModTimeStamp";
|
|
|
|
const char fileSizeValueName[]="FileSize";
|
|
|
|
const char componentCountValueName[]="ComponentsCount";
|
|
|
|
const char progIDValueName[]="ProgID";
|
|
|
|
const char classNameValueName[]="ClassName";
|
|
|
|
const char inprocServerValueName[]="InprocServer";
|
1999-09-01 01:40:21 +04:00
|
|
|
const char componentTypeValueName[]="ComponentType";
|
1999-09-02 11:00:29 +04:00
|
|
|
const char nativeComponentType[]="application/x-mozilla-native";
|
1999-04-05 04:07:18 +04:00
|
|
|
|
1999-09-07 09:06:37 +04:00
|
|
|
const static char XPCOM_ABSCOMPONENT_PREFIX[] = "abs:";
|
|
|
|
const static char XPCOM_RELCOMPONENT_PREFIX[] = "rel:";
|
|
|
|
const char XPCOM_LIB_PREFIX[] = "lib:";
|
|
|
|
|
1999-04-12 16:32:24 +04:00
|
|
|
// We define a CID that is used to indicate the non-existence of a
|
|
|
|
// progid in the hash table.
|
|
|
|
#define NS_NO_CID { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
1999-09-06 20:43:09 +04:00
|
|
|
static NS_DEFINE_CID(kNoCID, NS_NO_CID);
|
1999-04-12 16:32:24 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
// Build is using USE_NSREG to turn off xpcom using registry
|
|
|
|
// but internally we use USE_REGISTRY. Map them propertly.
|
|
|
|
#ifdef USE_NSREG
|
|
|
|
#define USE_REGISTRY
|
|
|
|
#endif /* USE_NSREG */
|
1999-04-12 16:32:24 +04:00
|
|
|
|
1999-10-31 03:35:48 +03:00
|
|
|
|
2000-05-05 03:11:30 +04:00
|
|
|
extern PRBool gShuttingDown;
|
1999-10-31 03:35:48 +03:00
|
|
|
nsresult
|
2000-05-05 03:11:30 +04:00
|
|
|
|
1999-11-10 03:14:54 +03:00
|
|
|
nsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
2000-05-12 05:24:36 +04:00
|
|
|
{
|
|
|
|
nsresult status = nsComponentManager::CreateInstance(mCID, mOuter, aIID, aInstancePtr);
|
|
|
|
if ( !NS_SUCCEEDED(status) )
|
|
|
|
*aInstancePtr = 0;
|
1999-11-10 03:14:54 +03:00
|
|
|
|
2000-05-12 05:24:36 +04:00
|
|
|
if ( mErrorPtr )
|
|
|
|
*mErrorPtr = status;
|
|
|
|
return status;
|
|
|
|
}
|
1999-11-10 03:14:54 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCreateInstanceByProgID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
2000-05-12 05:24:36 +04:00
|
|
|
{
|
|
|
|
nsresult status;
|
|
|
|
if ( mProgID )
|
|
|
|
{
|
|
|
|
if ( !NS_SUCCEEDED(status = nsComponentManager::CreateInstance(mProgID, mOuter, aIID, aInstancePtr)) )
|
|
|
|
*aInstancePtr = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if ( mErrorPtr )
|
|
|
|
*mErrorPtr = status;
|
|
|
|
return status;
|
|
|
|
}
|
1999-10-31 03:35:48 +03:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
nsresult
|
|
|
|
nsCreateInstanceFromCategory::operator()( const nsIID& aIID,
|
|
|
|
void** aInstancePtr ) const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If I were a real man, I would consolidate this with
|
|
|
|
* nsGetServiceFromProgID::operator().
|
|
|
|
*/
|
|
|
|
nsresult status;
|
|
|
|
nsXPIDLCString value;
|
|
|
|
nsCOMPtr<nsICategoryManager> catman =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_PROGID, &status);
|
|
|
|
|
|
|
|
if (NS_FAILED(status)) goto error;
|
|
|
|
|
|
|
|
if (!mCategory || !mEntry) {
|
|
|
|
// when categories have defaults, use that for null mEntry
|
|
|
|
status = NS_ERROR_NULL_POINTER;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the progID for category.entry */
|
|
|
|
status = catman->GetCategoryEntry(mCategory, mEntry,
|
|
|
|
getter_Copies(value));
|
|
|
|
if (NS_FAILED(status)) goto error;
|
|
|
|
if (!value) {
|
|
|
|
status = NS_ERROR_SERVICE_NOT_FOUND;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = nsComponentManager::CreateInstance(value, mOuter, aIID,
|
|
|
|
aInstancePtr);
|
|
|
|
error:
|
|
|
|
if (NS_FAILED(status)) {
|
|
|
|
*aInstancePtr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*mErrorPtr = status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
/* prototypes for the Mac */
|
2000-05-03 02:38:04 +04:00
|
|
|
PRBool PR_CALLBACK
|
1999-09-01 01:40:21 +04:00
|
|
|
nsFactoryEntry_Destroy(nsHashKey *aKey, void *aData, void* closure);
|
1999-04-12 16:32:24 +04:00
|
|
|
|
2000-05-03 02:38:04 +04:00
|
|
|
PRBool PR_CALLBACK
|
1999-09-01 01:40:21 +04:00
|
|
|
nsCID_Destroy(nsHashKey *aKey, void *aData, void* closure);
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFactoryEntry
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-06-15 06:20:30 +04:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsFactoryEntry);
|
2000-05-15 17:10:18 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID &aClass,
|
1999-11-10 03:28:34 +03:00
|
|
|
const char *aLocation,
|
|
|
|
const char *aType,
|
1999-09-01 01:40:21 +04:00
|
|
|
nsIComponentLoader *aLoader)
|
|
|
|
: cid(aClass), factory(nsnull), loader(aLoader)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2000-05-15 17:10:18 +04:00
|
|
|
MOZ_COUNT_CTOR(nsFactoryEntry);
|
1999-09-01 01:40:21 +04:00
|
|
|
loader = aLoader;
|
1999-09-09 04:48:30 +04:00
|
|
|
type = aType;
|
|
|
|
location = aLocation;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, nsIFactory *aFactory)
|
1999-11-10 03:28:34 +03:00
|
|
|
: cid(aClass), loader(nsnull)
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
{
|
2000-05-15 17:10:18 +04:00
|
|
|
MOZ_COUNT_CTOR(nsFactoryEntry);
|
1999-09-01 01:40:21 +04:00
|
|
|
factory = aFactory;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFactoryEntry::~nsFactoryEntry(void)
|
|
|
|
{
|
2000-05-15 17:10:18 +04:00
|
|
|
MOZ_COUNT_DTOR(nsFactoryEntry);
|
1999-09-01 01:40:21 +04:00
|
|
|
factory = 0;
|
|
|
|
loader = 0;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsComponentManagerImpl
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManagerImpl::nsComponentManagerImpl()
|
1999-09-01 01:40:21 +04:00
|
|
|
: mFactories(NULL), mProgIDs(NULL), mLoaders(0), mMon(NULL),
|
|
|
|
mRegistry(NULL), mPrePopulationDone(PR_FALSE),
|
1999-10-22 01:34:39 +04:00
|
|
|
mNativeComponentLoader(0), mShuttingDown(NS_SHUTDOWN_NEVERHAPPENED)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
1999-07-28 12:01:03 +04:00
|
|
|
PRBool
|
|
|
|
nsFactoryEntry_Destroy(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
|
|
|
nsFactoryEntry* entry = NS_STATIC_CAST(nsFactoryEntry*, aData);
|
|
|
|
delete entry;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCID_Destroy(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
|
|
|
nsCID* entry = NS_STATIC_CAST(nsCID*, aData);
|
1999-08-14 03:26:47 +04:00
|
|
|
// nasty hack. We "know" that kNoCID was entered into the hash table.
|
|
|
|
if (entry != &kNoCID)
|
2000-05-12 05:24:36 +04:00
|
|
|
delete entry;
|
1999-07-28 12:01:03 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsresult nsComponentManagerImpl::Init(void)
|
|
|
|
{
|
1999-10-22 01:34:39 +04:00
|
|
|
PR_ASSERT(mShuttingDown != NS_SHUTDOWN_INPROGRESS);
|
|
|
|
if (mShuttingDown == NS_SHUTDOWN_INPROGRESS)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mShuttingDown = NS_SHUTDOWN_NEVERHAPPENED;
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
if (nsComponentManagerLog == NULL)
|
|
|
|
{
|
|
|
|
nsComponentManagerLog = PR_NewLogModule("nsComponentManager");
|
2000-03-12 01:44:51 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("xpcom-log-version : " NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING));
|
1999-06-14 06:07:03 +04:00
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
if (mFactories == NULL) {
|
1999-07-28 12:01:03 +04:00
|
|
|
mFactories = new nsObjectHashtable(nsnull, nsnull, // should never be copied
|
|
|
|
nsFactoryEntry_Destroy, nsnull,
|
|
|
|
256, /* Thread Safe */ PR_TRUE);
|
1999-03-09 12:44:27 +03:00
|
|
|
if (mFactories == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if (mProgIDs == NULL) {
|
1999-07-28 12:01:03 +04:00
|
|
|
mProgIDs = new nsObjectHashtable(nsnull, nsnull, // should never be copied
|
|
|
|
nsCID_Destroy, nsnull,
|
|
|
|
256, /* Thread Safe */ PR_TRUE);
|
1999-03-09 12:44:27 +03:00
|
|
|
if (mProgIDs == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
|
1999-03-09 13:15:54 +03:00
|
|
|
if (mMon == NULL) {
|
|
|
|
mMon = PR_NewMonitor();
|
|
|
|
if (mMon == NULL)
|
1999-03-09 12:44:27 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
if (mNativeComponentLoader == nsnull) {
|
|
|
|
/* Create the NativeComponentLoader */
|
|
|
|
mNativeComponentLoader = new nsNativeComponentLoader();
|
|
|
|
if (!mNativeComponentLoader)
|
1999-03-09 12:44:27 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-09-01 01:40:21 +04:00
|
|
|
NS_ADDREF(mNativeComponentLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLoaders == nsnull) {
|
2000-05-12 05:24:36 +04:00
|
|
|
mLoaders = new nsSupportsHashtable(16, /* Thread safe */ PR_TRUE);
|
|
|
|
if (mLoaders == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
nsStringKey loaderKey(nativeComponentType);
|
|
|
|
mLoaders->Put(&loaderKey, mNativeComponentLoader);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
#ifdef USE_REGISTRY
|
2000-01-25 00:28:28 +03:00
|
|
|
NR_StartupRegistry();
|
|
|
|
PlatformInit();
|
1999-06-14 06:07:03 +04:00
|
|
|
#endif
|
1999-03-31 11:04:12 +04:00
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Initialized."));
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-10-22 01:34:39 +04:00
|
|
|
nsresult nsComponentManagerImpl::Shutdown(void)
|
1999-06-14 06:07:03 +04:00
|
|
|
{
|
1999-10-22 01:34:39 +04:00
|
|
|
PR_ASSERT(mShuttingDown == NS_SHUTDOWN_NEVERHAPPENED);
|
|
|
|
if (mShuttingDown != NS_SHUTDOWN_NEVERHAPPENED)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mShuttingDown = NS_SHUTDOWN_INPROGRESS;
|
|
|
|
|
|
|
|
// Shutdown the component manager
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Beginning Shutdown."));
|
1999-07-31 09:55:04 +04:00
|
|
|
|
|
|
|
// Release all cached factories
|
1999-06-14 06:07:03 +04:00
|
|
|
if (mFactories)
|
|
|
|
delete mFactories;
|
1999-07-31 09:55:04 +04:00
|
|
|
|
|
|
|
// Unload libraries
|
1999-09-26 22:04:27 +04:00
|
|
|
UnloadLibraries(NULL, NS_Shutdown);
|
1999-07-31 09:55:04 +04:00
|
|
|
|
|
|
|
// Release Progid hash tables
|
1999-06-14 06:07:03 +04:00
|
|
|
if (mProgIDs)
|
|
|
|
delete mProgIDs;
|
1999-07-31 09:55:04 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
#ifdef USE_REGISTRY
|
1999-07-31 09:55:04 +04:00
|
|
|
// Release registry
|
1999-09-01 01:40:21 +04:00
|
|
|
NS_IF_RELEASE(mRegistry);
|
1999-06-14 06:07:03 +04:00
|
|
|
#endif /* USE_REGISTRY */
|
1999-09-01 01:40:21 +04:00
|
|
|
|
2000-01-29 02:37:27 +03:00
|
|
|
// This is were the nsFileSpec was deleted, so I am
|
2000-05-12 05:24:36 +04:00
|
|
|
// going to assign zero to
|
|
|
|
mComponentsDir = 0;
|
1999-09-21 00:53:57 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
// Release all the component loaders
|
|
|
|
if (mLoaders)
|
2000-05-12 05:24:36 +04:00
|
|
|
delete mLoaders;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
// we have an extra reference on this one, which is probably a good thing
|
|
|
|
NS_IF_RELEASE(mNativeComponentLoader);
|
1999-07-31 09:55:04 +04:00
|
|
|
|
|
|
|
// Destroy the Lock
|
|
|
|
if (mMon)
|
|
|
|
PR_DestroyMonitor(mMon);
|
|
|
|
|
1999-09-27 01:20:21 +04:00
|
|
|
#ifdef USE_REGISTRY
|
|
|
|
NR_ShutdownRegistry();
|
|
|
|
#endif /* USE_REGISTRY */
|
|
|
|
|
1999-10-22 01:34:39 +04:00
|
|
|
mShuttingDown = NS_SHUTDOWN_COMPLETE;
|
1999-07-31 09:55:04 +04:00
|
|
|
|
1999-10-22 01:34:39 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Shutdown complete."));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsComponentManagerImpl::~nsComponentManagerImpl()
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Beginning destruction."));
|
|
|
|
|
|
|
|
if (mShuttingDown != NS_SHUTDOWN_COMPLETE)
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Destroyed."));
|
1999-06-14 06:07:03 +04:00
|
|
|
}
|
|
|
|
|
2000-01-12 01:54:46 +03:00
|
|
|
NS_IMPL_ISUPPORTS3(nsComponentManagerImpl, nsIComponentManager,
|
|
|
|
nsISupportsWeakReference, nsIInterfaceRequestor)
|
1999-06-14 06:07:03 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsComponentManagerImpl: Platform methods
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformInit(void)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
// We need to create our registry. Since we are in the constructor
|
1999-06-14 06:07:03 +04:00
|
|
|
// we haven't gone as far as registering the registry factory.
|
|
|
|
// Hence, we hand create a registry.
|
2000-05-12 05:24:36 +04:00
|
|
|
if (mRegistry == NULL) {
|
1999-06-14 06:07:03 +04:00
|
|
|
nsIFactory *registryFactory = NULL;
|
|
|
|
rv = NS_RegistryGetFactory(®istryFactory);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
1999-12-01 02:36:32 +03:00
|
|
|
rv = registryFactory->CreateInstance(NULL, NS_GET_IID(nsIRegistry),(void **)&mRegistry);
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-31 11:04:12 +04:00
|
|
|
NS_RELEASE(registryFactory);
|
|
|
|
}
|
|
|
|
}
|
1999-03-11 10:44:23 +03:00
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
// Create ~/.mozilla as that is the default place for the registry file
|
|
|
|
|
|
|
|
/* The default registry on the unix system is $HOME/.mozilla/registry per
|
|
|
|
* vr_findGlobalRegName(). vr_findRegFile() will create the registry file
|
|
|
|
* if it doesn't exist. But it wont create directories.
|
|
|
|
*
|
|
|
|
* Hence we need to create the directory if it doesn't exist already.
|
|
|
|
*
|
|
|
|
* Why create it here as opposed to the app ?
|
|
|
|
* ------------------------------------------
|
|
|
|
* The app cannot create the directory in main() as most of the registry
|
|
|
|
* and initialization happens due to use of static variables.
|
|
|
|
* And we dont want to be dependent on the order in which
|
|
|
|
* these static stuff happen.
|
|
|
|
*
|
|
|
|
* Permission for the $HOME/.mozilla will be Read,Write,Execute
|
|
|
|
* for user only. Nothing to group and others.
|
|
|
|
*/
|
|
|
|
char *home = getenv("HOME");
|
|
|
|
if (home != NULL)
|
|
|
|
{
|
|
|
|
char dotMozillaDir[1024];
|
|
|
|
PR_snprintf(dotMozillaDir, sizeof(dotMozillaDir),
|
|
|
|
"%s/" NS_MOZILLA_DIR_NAME, home);
|
|
|
|
if (PR_Access(dotMozillaDir, PR_ACCESS_EXISTS) != PR_SUCCESS)
|
|
|
|
{
|
|
|
|
PR_MkDir(dotMozillaDir, NS_MOZILLA_DIR_PERMISSION);
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-03-31 11:04:12 +04:00
|
|
|
("nsComponentManager: Creating Directory %s", dotMozillaDir));
|
1999-03-11 10:44:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* XP_UNIX */
|
1999-06-29 14:27:58 +04:00
|
|
|
|
|
|
|
#ifdef XP_BEOS
|
|
|
|
BPath p;
|
|
|
|
const char *settings = "/boot/home/config/settings";
|
|
|
|
if(find_directory(B_USER_SETTINGS_DIRECTORY, &p) == B_OK)
|
|
|
|
settings = p.Path();
|
|
|
|
char settingsMozillaDir[1024];
|
|
|
|
PR_snprintf(settingsMozillaDir, sizeof(settingsMozillaDir),
|
|
|
|
"%s/" NS_MOZILLA_DIR_NAME, settings);
|
|
|
|
if (PR_Access(settingsMozillaDir, PR_ACCESS_EXISTS) != PR_SUCCESS) {
|
|
|
|
PR_MkDir(settingsMozillaDir, NS_MOZILLA_DIR_PERMISSION);
|
|
|
|
printf("nsComponentManager: Creating Directory %s\n", settingsMozillaDir);
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Creating Directory %s", settingsMozillaDir));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-06-09 23:18:24 +04:00
|
|
|
// Open the App Components registry. We will keep it open forever!
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
// Check the version of registry. Nuke old versions.
|
2000-02-16 10:45:20 +03:00
|
|
|
nsRegistryKey xpcomRoot;
|
|
|
|
rv = PlatformVersionCheck(&xpcomRoot);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-06 12:26:38 +04:00
|
|
|
|
1999-05-06 17:29:37 +04:00
|
|
|
// Open common registry keys here to speed access
|
|
|
|
// Do this after PlatformVersionCheck as it may re-create our keys
|
2000-02-16 10:45:20 +03:00
|
|
|
rv = mRegistry->AddSubtree(xpcomRoot, componentsKeyName, &mXPCOMKey);
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-06 12:26:38 +04:00
|
|
|
|
2000-02-16 10:45:20 +03:00
|
|
|
rv = mRegistry->AddSubtree(xpcomRoot, classesKeyName, &mClassesKey);
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-06 12:26:38 +04:00
|
|
|
|
2000-02-16 10:45:20 +03:00
|
|
|
rv = mRegistry->AddSubtree(xpcomRoot, classIDKeyName, &mCLSIDKey);
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-25 00:28:28 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProperties> directoryService;
|
|
|
|
rv = nsDirectoryService::Create(nsnull,
|
|
|
|
NS_GET_IID(nsIProperties),
|
|
|
|
getter_AddRefs(directoryService));
|
|
|
|
|
2000-01-29 02:37:27 +03:00
|
|
|
directoryService->Get("xpcom.currentProcess.componentDirectory", NS_GET_IID(nsIFile), getter_AddRefs(mComponentsDir));
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-09-07 09:06:37 +04:00
|
|
|
if (!mComponentsDir)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-01-25 00:28:28 +03:00
|
|
|
|
2000-05-12 05:24:36 +04:00
|
|
|
char* componentDescriptor;
|
|
|
|
mComponentsDir->GetPath(&componentDescriptor);
|
|
|
|
if (!componentDescriptor)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-02-01 10:54:46 +03:00
|
|
|
|
2000-05-12 05:24:36 +04:00
|
|
|
mComponentsOffset = strlen(componentDescriptor);
|
|
|
|
|
|
|
|
if (componentDescriptor)
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(componentDescriptor);
|
2000-02-01 10:54:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
if (mNativeComponentLoader) {
|
|
|
|
/* now that we have the registry, Init the native loader */
|
|
|
|
rv = mNativeComponentLoader->Init(this, mRegistry);
|
|
|
|
} else {
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("no native component loader available for init"));
|
|
|
|
}
|
1999-06-14 06:07:03 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PlatformVersionCheck()
|
|
|
|
*
|
|
|
|
* Checks to see if the XPCOM hierarchy in the registry is the same as that of
|
|
|
|
* the software as defined by NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING
|
|
|
|
*/
|
|
|
|
nsresult
|
2000-02-16 10:45:20 +03:00
|
|
|
nsComponentManagerImpl::PlatformVersionCheck(nsRegistryKey *aXPCOMRootKey)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey xpcomKey;
|
1999-06-14 06:07:03 +04:00
|
|
|
nsresult rv;
|
|
|
|
rv = mRegistry->AddSubtree(nsIRegistry::Common, xpcomKeyName, &xpcomKey);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-10 03:28:34 +03:00
|
|
|
nsXPIDLCString buf;
|
2000-02-15 04:32:12 +03:00
|
|
|
nsresult err = mRegistry->GetStringUTF8(xpcomKey, versionValueName,
|
1999-11-10 03:28:34 +03:00
|
|
|
getter_Copies(buf));
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// If there is a version mismatch or no version string, we got an old registry.
|
|
|
|
// Delete the old repository hierarchies and recreate version string
|
1999-05-06 17:29:37 +04:00
|
|
|
if (NS_FAILED(err) || PL_strcmp(buf, NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
2000-03-12 01:44:51 +03:00
|
|
|
("nsComponentManager: Registry version mismatch (old:%s vs new:%s)."
|
1999-11-10 03:28:34 +03:00
|
|
|
"Nuking xpcom registry hierarchy.", (const char *)buf,
|
|
|
|
NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING));
|
1999-03-10 12:53:25 +03:00
|
|
|
|
2000-02-16 10:45:20 +03:00
|
|
|
// Delete the XPCOM hierarchy
|
|
|
|
rv = mRegistry->RemoveSubtree(nsIRegistry::Common, xpcomKeyName);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
2000-02-16 10:45:20 +03:00
|
|
|
("nsComponentManager: Failed To Nuke Subtree (%s)",xpcomKeyName));
|
|
|
|
return rv;
|
1999-03-31 11:04:12 +04:00
|
|
|
}
|
|
|
|
|
2000-02-16 10:45:20 +03:00
|
|
|
// The top-level Classes and CLSID trees are from an early alpha version,
|
|
|
|
// we can probably remove these two deletions after the second beta or so.
|
2000-03-12 01:44:51 +03:00
|
|
|
(void) mRegistry->RemoveSubtree(nsIRegistry::Common, classIDKeyName);
|
|
|
|
(void) mRegistry->RemoveSubtree(nsIRegistry::Common, classesKeyName);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
2000-02-16 10:45:20 +03:00
|
|
|
// Recreate XPCOM key and version
|
|
|
|
rv = mRegistry->AddSubtree(nsIRegistry::Common,xpcomKeyName, &xpcomKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
2000-02-16 10:45:20 +03:00
|
|
|
("nsComponentManager: Failed To Add Subtree (%s)",xpcomKeyName));
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->SetStringUTF8(xpcomKey,versionValueName, NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-04-05 04:07:18 +04:00
|
|
|
("nsComponentManager: Failed To Set String (Version) Under (%s)",xpcomKeyName));
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
2000-02-16 10:45:20 +03:00
|
|
|
else
|
1999-03-31 11:04:12 +04:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: platformVersionCheck() passed."));
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2000-02-16 10:45:20 +03:00
|
|
|
|
2000-03-12 01:44:51 +03:00
|
|
|
// return the XPCOM key (null check deferred so cleanup always happens)
|
2000-02-16 10:45:20 +03:00
|
|
|
if (!aXPCOMRootKey)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
else
|
|
|
|
*aXPCOMRootKey = xpcomKey;
|
1999-09-02 11:00:29 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
#if 0
|
2000-05-12 05:24:36 +04:00
|
|
|
// If ever revived, this code is not fully updated to escape the dll location
|
1999-06-22 18:02:58 +04:00
|
|
|
void
|
1999-09-29 06:35:42 +04:00
|
|
|
nsComponentManagerImpl::PlatformSetFileInfo(nsRegistryKey key, PRUint32 lastModifiedTime, PRUint32 fileSize)
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
|
|
|
mRegistry->SetInt(key, lastModValueName, lastModifiedTime);
|
|
|
|
mRegistry->SetInt(key, fileSizeValueName, fileSize);
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/**
|
|
|
|
* PlatformMarkNoComponents(nsDll *dll)
|
|
|
|
*
|
|
|
|
* Stores the dll name, last modified time, size and 0 for number of
|
|
|
|
* components in dll in the registry at location
|
2000-05-12 05:24:36 +04:00
|
|
|
* ROOTKEY_COMMON/Software/Mozilla/XPCOM/Components/dllname
|
1999-03-09 12:44:27 +03:00
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformMarkNoComponents(nsDll *dll)
|
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry!=NULL);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey dllPathKey;
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mXPCOMKey, dll->GetPersistentDescriptorString(), &dllPathKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
PlatformSetFileInfo(dllPathKey, dll->GetLastModifiedTime(), dll->GetSize());
|
|
|
|
rv = mRegistry->SetInt(dllPathKey, componentCountValueName, 0);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-06-14 06:07:03 +04:00
|
|
|
nsComponentManagerImpl::PlatformRegister(const char *cidString,
|
|
|
|
const char *className,
|
|
|
|
const char * progID, nsDll *dll)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Preconditions
|
1999-06-14 06:07:03 +04:00
|
|
|
PR_ASSERT(cidString != NULL);
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ASSERT(dll != NULL);
|
1999-06-14 06:07:03 +04:00
|
|
|
PR_ASSERT(mRegistry !=NULL);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
1999-04-06 12:26:38 +04:00
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey IDkey;
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mCLSIDKey, cidString, &IDkey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv)) return (rv);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->SetStringUTF8(IDkey,classNameValueName, className);
|
1999-06-14 06:07:03 +04:00
|
|
|
if (progID)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->SetStringUTF8(IDkey,progIDValueName, progID);
|
1999-03-31 11:04:12 +04:00
|
|
|
}
|
2000-05-12 05:24:36 +04:00
|
|
|
rv = mRegistry->SetBytesUTF8(IDkey, inprocServerValueName,
|
|
|
|
strlen(dll->GetPersistentDescriptorString()) + 1,
|
|
|
|
NS_REINTERPRET_CAST(char*, dll->GetPersistentDescriptorString()));
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
if (progID)
|
1999-03-31 11:04:12 +04:00
|
|
|
{
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey progIDKey;
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mClassesKey, progID, &progIDKey);
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->SetStringUTF8(progIDKey, classIDValueName, cidString);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey dllPathKey;
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mXPCOMKey,dll->GetPersistentDescriptorString(), &dllPathKey);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
PlatformSetFileInfo(dllPathKey, dll->GetLastModifiedTime(), dll->GetSize());
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-09-29 06:54:18 +04:00
|
|
|
PRInt32 nComponents = 0;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetInt(dllPathKey, componentCountValueName, &nComponents);
|
1999-03-10 12:53:25 +03:00
|
|
|
nComponents++;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->SetInt(dllPathKey,componentCountValueName, nComponents);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
#endif
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
nsresult
|
1999-06-14 06:07:03 +04:00
|
|
|
nsComponentManagerImpl::PlatformUnregister(const char *cidString,
|
|
|
|
const char *aLibrary)
|
2000-05-12 05:24:36 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
PRUint32 length = strlen(aLibrary);
|
|
|
|
char* eLibrary;
|
|
|
|
rv = mRegistry->EscapeKey((PRUint8*)aLibrary, 1, &length, (PRUint8**)&eLibrary);
|
|
|
|
if (rv != NS_OK)
|
|
|
|
{
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (eLibrary == nsnull) // No escaping required
|
|
|
|
eLibrary = (char*)aLibrary;
|
|
|
|
|
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry!=NULL);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey cidKey;
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mCLSIDKey, cidString, &cidKey);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char *progID = NULL;
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->GetStringUTF8(cidKey, progIDValueName, &progID);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_SUCCEEDED(rv))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-06-09 23:18:24 +04:00
|
|
|
mRegistry->RemoveSubtreeRaw(mClassesKey, progID);
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_FREEIF(progID);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
mRegistry->RemoveSubtree(mCLSIDKey, cidString);
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey libKey;
|
2000-05-12 05:24:36 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mXPCOMKey, eLibrary, &libKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
|
|
|
// We need to reduce the ComponentCount by 1.
|
|
|
|
// If the ComponentCount hits 0, delete the entire key.
|
1999-09-29 06:54:18 +04:00
|
|
|
PRInt32 nComponents = 0;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetInt(libKey, componentCountValueName, &nComponents);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
|
|
|
nComponents--;
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (nComponents <= 0)
|
|
|
|
{
|
2000-05-12 05:24:36 +04:00
|
|
|
rv = mRegistry->RemoveSubtreeRaw(mXPCOMKey, eLibrary);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->SetInt(libKey, componentCountValueName, nComponents);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2000-05-12 05:24:36 +04:00
|
|
|
if (eLibrary != aLibrary)
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(eLibrary);
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-01 01:40:21 +04:00
|
|
|
nsComponentManagerImpl::PlatformFind(const nsCID &aCID, nsFactoryEntry* *result)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry!=NULL);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
char *cidString = aCID.ToString();
|
1999-09-01 01:40:21 +04:00
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey cidKey;
|
1999-05-06 08:19:06 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mCLSIDKey, cidString, &cidKey);
|
1999-03-10 12:53:25 +03:00
|
|
|
delete [] cidString;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
1999-11-10 03:28:34 +03:00
|
|
|
nsXPIDLCString library;
|
2000-05-12 05:24:36 +04:00
|
|
|
PRUint32 tmp;
|
|
|
|
rv = mRegistry->GetBytesUTF8(cidKey, inprocServerValueName,
|
|
|
|
&tmp, (PRUint8**)getter_Copies(library).operator char**());
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv))
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Registry inconsistent. No File name for CLSID.
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-11-10 03:28:34 +03:00
|
|
|
nsXPIDLCString componentType;
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->GetStringUTF8(cidKey, componentTypeValueName,
|
1999-11-10 03:28:34 +03:00
|
|
|
getter_Copies(componentType));
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-11-10 03:28:34 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
if (rv == NS_ERROR_REG_NOT_FOUND)
|
1999-09-01 01:40:21 +04:00
|
|
|
/* missing componentType, we assume application/x-moz-native */
|
1999-11-10 03:28:34 +03:00
|
|
|
componentType = nativeComponentType;
|
|
|
|
else
|
1999-09-01 01:40:21 +04:00
|
|
|
return rv; // XXX translate error code?
|
|
|
|
|
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
|
|
|
|
1999-09-02 11:00:29 +04:00
|
|
|
rv = GetLoaderForType(componentType, getter_AddRefs(loader));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
nsFactoryEntry *res = new nsFactoryEntry(aCID, library, componentType,
|
|
|
|
loader);
|
|
|
|
if (res == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
*result = res;
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformProgIDToCLSID(const char *aProgID, nsCID *aClass)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ASSERT(aClass != NULL);
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey progIDKey;
|
1999-04-06 12:52:51 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mClassesKey, aProgID, &progIDKey);
|
1999-11-14 18:41:40 +03:00
|
|
|
if (NS_FAILED(rv)) return NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char *cidString;
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->GetStringUTF8(progIDKey, classIDValueName, &cidString);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
if (!(aClass->Parse(cidString)))
|
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
PR_FREEIF(cidString);
|
1999-11-14 18:41:40 +03:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-05 10:27:42 +04:00
|
|
|
nsComponentManagerImpl::PlatformCLSIDToProgID(const nsCID *aClass,
|
1999-03-09 12:44:27 +03:00
|
|
|
char* *aClassName, char* *aProgID)
|
|
|
|
{
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(aClass);
|
|
|
|
PR_ASSERT(mRegistry);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char* cidStr = aClass->ToString();
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey cidKey;
|
1999-07-31 09:55:04 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mCLSIDKey, cidStr, &cidKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
|
|
|
PR_FREEIF(cidStr);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char* classnameString;
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->GetStringUTF8(cidKey, classNameValueName, &classnameString);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
*aClassName = classnameString;
|
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char* progidString;
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->GetStringUTF8(cidKey,progIDValueName,&progidString);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
*aProgID = progidString;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-07-02 07:35:09 +04:00
|
|
|
nsresult nsComponentManagerImpl::PlatformPrePopulateRegistry()
|
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult rv;
|
1999-07-02 07:35:09 +04:00
|
|
|
|
1999-09-08 08:22:37 +04:00
|
|
|
if (mPrePopulationDone)
|
|
|
|
return NS_OK;
|
1999-09-01 01:40:21 +04:00
|
|
|
// Read in all CID entries and populate the mFactories
|
1999-07-02 07:35:09 +04:00
|
|
|
nsCOMPtr<nsIEnumerator> cidEnum;
|
|
|
|
rv = mRegistry->EnumerateSubtrees( mCLSIDKey, getter_AddRefs(cidEnum));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-04-25 05:11:08 +04:00
|
|
|
nsCOMPtr<nsIRegistryEnumerator> regEnum = do_QueryInterface(cidEnum, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-07-02 07:35:09 +04:00
|
|
|
|
2000-04-25 05:11:08 +04:00
|
|
|
rv = regEnum->First();
|
|
|
|
for (rv = regEnum->First();
|
|
|
|
NS_SUCCEEDED(rv) && (regEnum->IsDone() != NS_OK);
|
|
|
|
rv = regEnum->Next())
|
|
|
|
{
|
|
|
|
const char *cidString;
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey cidKey;
|
2000-04-25 05:11:08 +04:00
|
|
|
/*
|
|
|
|
* CurrentItemInPlaceUTF8 will give us back a _shared_ pointer in
|
|
|
|
* cidString. This is bad XPCOM practice. It is evil, and requires
|
|
|
|
* great care with the relative lifetimes of cidString and regEnum.
|
|
|
|
*
|
|
|
|
* It is also faster, and less painful in the allocation department.
|
|
|
|
*/
|
|
|
|
rv = regEnum->CurrentItemInPlaceUTF8(&cidKey, &cidString);
|
|
|
|
if (NS_FAILED(rv)) continue;
|
1999-07-02 07:35:09 +04:00
|
|
|
|
|
|
|
// Create the CID entry
|
1999-11-10 03:28:34 +03:00
|
|
|
nsXPIDLCString library;
|
2000-05-12 05:24:36 +04:00
|
|
|
PRUint32 tmp;
|
|
|
|
rv = mRegistry->GetBytesUTF8(cidKey, inprocServerValueName,
|
|
|
|
&tmp, (PRUint8**)getter_Copies(library).operator char**());
|
1999-07-02 07:35:09 +04:00
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
nsCID aClass;
|
1999-11-10 03:28:34 +03:00
|
|
|
|
1999-07-02 07:35:09 +04:00
|
|
|
if (!(aClass.Parse(cidString))) continue;
|
|
|
|
|
1999-11-10 03:28:34 +03:00
|
|
|
nsXPIDLCString componentType;
|
2000-02-15 04:32:12 +03:00
|
|
|
if (NS_FAILED(mRegistry->GetStringUTF8(cidKey, componentTypeValueName,
|
1999-11-10 03:28:34 +03:00
|
|
|
getter_Copies(componentType))))
|
1999-09-08 03:18:47 +04:00
|
|
|
continue;
|
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
nsFactoryEntry* entry =
|
1999-09-08 08:22:37 +04:00
|
|
|
new nsFactoryEntry(aClass, library, componentType,
|
1999-09-08 03:18:47 +04:00
|
|
|
nsCRT::strcmp(componentType,
|
|
|
|
nativeComponentType) ?
|
|
|
|
0 : mNativeComponentLoader);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (!entry)
|
|
|
|
continue;
|
1999-07-02 07:35:09 +04:00
|
|
|
|
|
|
|
nsIDKey key(aClass);
|
|
|
|
mFactories->Put(&key, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally read in PROGID -> CID mappings
|
1999-07-31 09:55:04 +04:00
|
|
|
nsCOMPtr<nsIEnumerator> progidEnum;
|
|
|
|
rv = mRegistry->EnumerateSubtrees( mClassesKey, getter_AddRefs(progidEnum));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-04-25 05:11:08 +04:00
|
|
|
regEnum = do_QueryInterface(progidEnum, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-07-31 09:55:04 +04:00
|
|
|
|
2000-04-25 05:11:08 +04:00
|
|
|
rv = regEnum->First();
|
|
|
|
for (rv = regEnum->First();
|
|
|
|
NS_SUCCEEDED(rv) && (regEnum->IsDone() != NS_OK);
|
|
|
|
rv = regEnum->Next())
|
|
|
|
{
|
|
|
|
const char *progidString;
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey progidKey;
|
2000-04-25 05:11:08 +04:00
|
|
|
/*
|
|
|
|
* CurrentItemInPlaceUTF8 will give us back a _shared_ pointer in
|
|
|
|
* progidString. This is bad XPCOM practice. It is evil, and requires
|
|
|
|
* great care with the relative lifetimes of progidString and regEnum.
|
|
|
|
*
|
|
|
|
* It is also faster, and less painful in the allocation department.
|
|
|
|
*/
|
|
|
|
rv = regEnum->CurrentItemInPlaceUTF8(&progidKey, &progidString);
|
1999-07-31 09:55:04 +04:00
|
|
|
if (NS_FAILED(rv)) continue;
|
1999-11-10 03:28:34 +03:00
|
|
|
|
|
|
|
nsXPIDLCString cidString;
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->GetStringUTF8(progidKey, classIDValueName,
|
2000-04-25 05:11:08 +04:00
|
|
|
getter_Copies(cidString));
|
1999-07-31 09:55:04 +04:00
|
|
|
if (NS_FAILED(rv)) continue;
|
1999-11-10 03:28:34 +03:00
|
|
|
|
1999-07-31 09:55:04 +04:00
|
|
|
nsCID *aClass = new nsCID();
|
2000-05-12 05:24:36 +04:00
|
|
|
if (!aClass) continue; // Protect against out of memory.
|
1999-07-31 09:55:04 +04:00
|
|
|
if (!(aClass->Parse(cidString)))
|
|
|
|
{
|
|
|
|
delete aClass;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// put the {progid, Cid} mapping into our map
|
|
|
|
nsStringKey key(progidString);
|
|
|
|
mProgIDs->Put(&key, aClass);
|
|
|
|
// printf("Populating [ %s, %s ]\n", cidString, progidString);
|
|
|
|
}
|
1999-07-02 07:35:09 +04:00
|
|
|
|
1999-08-09 09:02:25 +04:00
|
|
|
mPrePopulationDone = PR_TRUE;
|
1999-07-02 07:35:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
#endif /* USE_REGISTRY */
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
//
|
|
|
|
// HashProgID
|
|
|
|
//
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::HashProgID(const char *aProgID, const nsCID &aClass)
|
|
|
|
{
|
|
|
|
if(!aProgID)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-07-22 06:11:04 +04:00
|
|
|
nsStringKey key(aProgID);
|
1999-06-22 18:02:58 +04:00
|
|
|
nsCID* cid = (nsCID*) mProgIDs->Get(&key);
|
|
|
|
if (cid)
|
|
|
|
{
|
|
|
|
if (cid == &kNoCID)
|
|
|
|
{
|
|
|
|
// we don't delete this ptr as it's static (ugh)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete cid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cid = new nsCID(aClass);
|
|
|
|
if (!cid)
|
|
|
|
{
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProgIDs->Put(&key, cid);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsComponentManagerImpl: Public methods
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LoadFactory()
|
|
|
|
*
|
|
|
|
* Given a FactoryEntry, this loads the dll if it has to, find the NSGetFactory
|
|
|
|
* symbol, calls the routine to create a new factory and returns it to the
|
|
|
|
* caller.
|
|
|
|
*
|
|
|
|
* No attempt is made to store the factory in any form anywhere.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::LoadFactory(nsFactoryEntry *aEntry,
|
|
|
|
nsIFactory **aFactory)
|
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
if (!aFactory)
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*aFactory = NULL;
|
|
|
|
|
1999-09-08 03:18:47 +04:00
|
|
|
nsresult rv;
|
|
|
|
rv = aEntry->GetFactory(aFactory, this);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-08-09 09:40:51 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
2000-03-12 01:44:51 +03:00
|
|
|
("nsComponentManager: FAILED to load factory from %s (%s)\n",
|
1999-11-10 03:28:34 +03:00
|
|
|
(const char *)aEntry->location, (const char *)aEntry->type));
|
1999-03-10 12:53:25 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
|
|
|
|
nsFactoryEntry *
|
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const nsCID &aClass, PRBool checkRegistry)
|
|
|
|
{
|
|
|
|
nsIDKey key(aClass);
|
|
|
|
nsFactoryEntry *entry = (nsFactoryEntry*) mFactories->Get(&key);
|
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
2000-03-12 01:44:51 +03:00
|
|
|
if (!entry)
|
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
if (checkRegistry)
|
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult rv = PlatformFind(aClass, &entry);
|
|
|
|
|
|
|
|
// If we got one, cache it in our hashtable
|
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-07-07 11:47:14 +04:00
|
|
|
{
|
|
|
|
mFactories->Put(&key, entry);
|
|
|
|
}
|
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
2000-03-12 01:44:51 +03:00
|
|
|
#endif /* USE_REGISTRY */
|
1999-07-07 11:47:14 +04:00
|
|
|
|
|
|
|
return (entry);
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/**
|
|
|
|
* FindFactory()
|
|
|
|
*
|
|
|
|
* Given a classID, this finds the factory for this CID by first searching the
|
|
|
|
* local CID<->factory mapping. Next it searches for a Dll that implements
|
|
|
|
* this classID and calls LoadFactory() to create the factory.
|
|
|
|
*
|
|
|
|
* Again, no attempt is made at storing the factory.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::FindFactory(const nsCID &aClass,
|
|
|
|
nsIFactory **aFactory)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ASSERT(aFactory != NULL);
|
1999-06-19 03:27:09 +04:00
|
|
|
|
1999-09-10 09:27:23 +04:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass, !mPrePopulationDone);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
|
1999-09-08 03:18:47 +04:00
|
|
|
return entry->GetFactory(aFactory, this);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-08-19 18:54:12 +04:00
|
|
|
/**
|
|
|
|
* GetClassObject()
|
|
|
|
*
|
|
|
|
* Given a classID, this finds the singleton ClassObject that implements the CID.
|
|
|
|
* Returns an interface of type aIID off the singleton classobject.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFactory> factory;
|
|
|
|
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", buf);
|
|
|
|
delete [] buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_ASSERT(aResult != NULL);
|
|
|
|
|
|
|
|
rv = FindFactory(aClass, getter_AddRefs(factory));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = factory->QueryInterface(aIID, aResult);
|
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-08-19 18:54:12 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/**
|
1999-12-31 01:03:58 +03:00
|
|
|
* ProgIDToClassID()
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
|
|
|
* Mapping function from a ProgID to a classID. Directly talks to the registry.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-12-31 01:03:58 +03:00
|
|
|
nsComponentManagerImpl::ProgIDToClassID(const char *aProgID, nsCID *aClass)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_PRECONDITION(aProgID != NULL, "null ptr");
|
|
|
|
if (! aProgID)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_PRECONDITION(aClass != NULL, "null ptr");
|
|
|
|
if (! aClass)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
1999-07-22 06:11:04 +04:00
|
|
|
nsStringKey key(aProgID);
|
1999-03-10 12:53:25 +03:00
|
|
|
nsCID* cid = (nsCID*) mProgIDs->Get(&key);
|
|
|
|
if (cid) {
|
|
|
|
if (cid == &kNoCID) {
|
|
|
|
// we've already tried to map this ProgID to a CLSID, and found
|
|
|
|
// that there _was_ no such mapping in the registry.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aClass = *cid;
|
|
|
|
res = NS_OK;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-03-10 12:53:25 +03:00
|
|
|
// This is the first time someone has asked for this
|
|
|
|
// ProgID. Go to the registry to find the CID.
|
2000-03-03 04:48:41 +03:00
|
|
|
if (!mPrePopulationDone)
|
|
|
|
res = PlatformProgIDToCLSID(aProgID, aClass);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (NS_SUCCEEDED(res)) {
|
|
|
|
// Found it. So put it into the cache.
|
|
|
|
cid = new nsCID(*aClass);
|
|
|
|
if (!cid)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
mProgIDs->Put(&key, cid);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Didn't find it. Put a special CID in the cache so we
|
|
|
|
// don't need to hit the registry on subsequent requests
|
|
|
|
// for the same ProgID.
|
1999-08-14 03:26:47 +04:00
|
|
|
mProgIDs->Put(&key, (void *)&kNoCID);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
#endif /* USE_REGISTRY */
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS)) {
|
1999-09-02 11:00:29 +04:00
|
|
|
char *buf = 0;
|
1999-03-10 12:53:25 +03:00
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
buf = aClass->ToString();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-12-31 01:03:58 +03:00
|
|
|
("nsComponentManager: ProgIDToClassID(%s)->%s", aProgID,
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_SUCCEEDED(res) ? buf : "[FAILED]"));
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-06-14 06:07:03 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CLSIDToProgID()
|
|
|
|
*
|
|
|
|
* Translates a classID to a {ProgID, Class Name}. Does direct registry
|
|
|
|
* access to do the translation.
|
|
|
|
*
|
2000-05-05 10:37:39 +04:00
|
|
|
* NOTE: Since this isn't heavily used, we arent caching this.
|
1999-03-09 12:44:27 +03:00
|
|
|
*/
|
|
|
|
nsresult
|
1999-09-05 10:27:42 +04:00
|
|
|
nsComponentManagerImpl::CLSIDToProgID(const nsCID &aClass,
|
1999-03-09 12:44:27 +03:00
|
|
|
char* *aClassName,
|
|
|
|
char* *aProgID)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
1999-09-05 10:27:42 +04:00
|
|
|
res = PlatformCLSIDToProgID(&aClass, aClassName, aProgID);
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif /* USE_REGISTRY */
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
1999-09-05 10:27:42 +04:00
|
|
|
char *buf = aClass.ToString();
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("nsComponentManager: CLSIDToProgID(%s)->%s", buf,
|
|
|
|
NS_SUCCEEDED(res) ? *aProgID : "[FAILED]"));
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CreateInstance()
|
|
|
|
*
|
|
|
|
* Create an instance of an object that implements an interface and belongs
|
|
|
|
* to the implementation aClass using the factory. The factory is immediately
|
|
|
|
* released and not held onto for any longer.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
2000-05-05 03:11:30 +04:00
|
|
|
// test this first, since there's no point in creating a component during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gShuttingDown) {
|
|
|
|
// When processing shutdown, dont process new GetService() requests
|
|
|
|
#ifdef DEBUG_dp
|
|
|
|
NS_WARN_IF_FALSE(PR_FALSE, "Creating new instance on shutdown. Denied.");
|
|
|
|
#endif /* DEBUG_dp */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (aResult == NULL)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = NULL;
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsIFactory *factory = NULL;
|
|
|
|
nsresult res = FindFactory(aClass, &factory);
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
res = factory->CreateInstance(aDelegate, aIID, aResult);
|
|
|
|
NS_RELEASE(factory);
|
2000-03-12 01:44:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Translate error values
|
|
|
|
res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
2000-03-12 01:44:51 +03:00
|
|
|
("nsComponentManager: CreateInstance(%s) %s", buf,
|
1999-04-06 09:06:47 +04:00
|
|
|
NS_SUCCEEDED(res) ? "succeeded" : "FAILED"));
|
2000-03-12 01:44:51 +03:00
|
|
|
delete [] buf;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2000-03-12 01:44:51 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-09-07 09:06:37 +04:00
|
|
|
* CreateInstanceByProgID()
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
1999-09-07 09:06:37 +04:00
|
|
|
* A variant of CreateInstance() that creates an instance of the object that
|
1999-03-09 12:44:27 +03:00
|
|
|
* implements the interface aIID and whose implementation has a progID aProgID.
|
|
|
|
*
|
|
|
|
* This is only a convenience routine that turns around can calls the
|
|
|
|
* CreateInstance() with classid and iid.
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-09-05 10:27:42 +04:00
|
|
|
nsComponentManagerImpl::CreateInstanceByProgID(const char *aProgID,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
nsCID clsid;
|
1999-12-31 01:03:58 +03:00
|
|
|
nsresult rv = ProgIDToClassID(aProgID, &clsid);
|
1999-03-10 12:53:25 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
return CreateInstance(clsid, aDelegate, aIID, aResult);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-09-07 09:06:37 +04:00
|
|
|
/*
|
|
|
|
* I want an efficient way to allocate a buffer to the right size
|
|
|
|
* and stick the prefix and dllName in, then be able to hand that buffer
|
|
|
|
* off to the FactoryEntry. Is that so wrong?
|
|
|
|
*
|
|
|
|
* *regName is allocated on success.
|
|
|
|
*
|
|
|
|
* This should live in nsNativeComponentLoader.cpp, I think.
|
|
|
|
*/
|
|
|
|
static nsresult
|
|
|
|
MakeRegistryName(const char *aDllName, const char *prefix, char **regName)
|
|
|
|
{
|
|
|
|
char *registryName;
|
|
|
|
|
|
|
|
PRUint32 len = nsCRT::strlen(prefix);
|
|
|
|
|
|
|
|
PRUint32 registryNameLen = nsCRT::strlen(aDllName) + len;
|
2000-06-03 13:46:12 +04:00
|
|
|
registryName = (char *)nsMemory::Alloc(registryNameLen + 1);
|
1999-09-07 09:06:37 +04:00
|
|
|
|
|
|
|
// from here on it, we want len sans terminating NUL
|
|
|
|
|
|
|
|
if (!registryName)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsCRT::memcpy(registryName, prefix, len);
|
|
|
|
strcpy(registryName + len, aDllName); // no nsCRT::strcpy? for shame!
|
|
|
|
registryName[registryNameLen] = '\0';
|
|
|
|
*regName = registryName;
|
|
|
|
|
|
|
|
#ifdef DEBUG_shaver_off
|
|
|
|
fprintf(stderr, "MakeRegistryName(%s, %s, &[%s])\n",
|
|
|
|
aDllName, prefix, *regName);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegistryNameForLib(const char *aLibName,
|
|
|
|
char **aRegistryName)
|
|
|
|
{
|
|
|
|
return MakeRegistryName(aLibName, XPCOM_LIB_PREFIX, aRegistryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-01-25 00:28:28 +03:00
|
|
|
nsComponentManagerImpl::RegistryLocationForSpec(nsIFile *aSpec,
|
1999-09-07 09:06:37 +04:00
|
|
|
char **aRegistryName)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-25 00:28:28 +03:00
|
|
|
|
|
|
|
if (!mComponentsDir)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
1999-09-07 09:06:37 +04:00
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
PRBool containedIn;
|
2000-01-29 02:54:26 +03:00
|
|
|
mComponentsDir->Contains(aSpec, PR_TRUE, &containedIn);
|
2000-01-25 00:28:28 +03:00
|
|
|
|
|
|
|
char *persistentDescriptor;
|
|
|
|
|
|
|
|
if (containedIn){
|
2000-05-12 05:24:36 +04:00
|
|
|
|
|
|
|
rv = aSpec->GetPath(&persistentDescriptor);
|
2000-01-25 00:28:28 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-02-01 10:54:46 +03:00
|
|
|
|
2000-05-12 05:24:36 +04:00
|
|
|
char* relativeLocation = persistentDescriptor + mComponentsOffset + 1;
|
|
|
|
|
|
|
|
rv = MakeRegistryName(relativeLocation, XPCOM_RELCOMPONENT_PREFIX,
|
1999-09-07 09:06:37 +04:00
|
|
|
aRegistryName);
|
|
|
|
} else {
|
|
|
|
/* absolute names include volume info on Mac, so persistent descriptor */
|
2000-01-25 00:28:28 +03:00
|
|
|
rv = aSpec->GetPath(&persistentDescriptor);
|
1999-09-07 09:06:37 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
rv = MakeRegistryName(persistentDescriptor, XPCOM_ABSCOMPONENT_PREFIX,
|
|
|
|
aRegistryName);
|
|
|
|
}
|
2000-01-25 00:28:28 +03:00
|
|
|
|
|
|
|
if (persistentDescriptor)
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(persistentDescriptor);
|
1999-09-07 09:06:37 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::SpecForRegistryLocation(const char *aLocation,
|
2000-01-25 00:28:28 +03:00
|
|
|
nsIFile **aSpec)
|
1999-09-07 09:06:37 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (!aLocation || !aSpec)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
/* abs:/full/path/to/libcomponent.so */
|
|
|
|
if (!nsCRT::strncmp(aLocation, XPCOM_ABSCOMPONENT_PREFIX, 4)) {
|
2000-01-25 00:28:28 +03:00
|
|
|
|
|
|
|
nsLocalFile* file = new nsLocalFile;
|
|
|
|
if (!file) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = file->InitWithPath(((char *)aLocation + 4));
|
|
|
|
file->QueryInterface(NS_GET_IID(nsILocalFile), (void**)aSpec);
|
|
|
|
return rv;
|
1999-09-07 09:06:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsCRT::strncmp(aLocation, XPCOM_RELCOMPONENT_PREFIX, 4)) {
|
2000-01-25 00:28:28 +03:00
|
|
|
|
|
|
|
if (!mComponentsDir)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsILocalFile* file = nsnull;
|
|
|
|
rv = mComponentsDir->Clone((nsIFile**)&file);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-05-05 10:37:39 +04:00
|
|
|
rv = file->AppendRelativePath(aLocation + 4);
|
2000-01-25 00:28:28 +03:00
|
|
|
*aSpec = file;
|
|
|
|
return rv;
|
1999-09-07 09:06:37 +04:00
|
|
|
}
|
|
|
|
*aSpec = nsnull;
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* RegisterFactory()
|
|
|
|
*
|
|
|
|
* Register a factory to be responsible for creation of implementation of
|
|
|
|
* classID aClass. Plus creates as association of aClassName and aProgID
|
|
|
|
* to the classID. If replace is PR_TRUE, we replace any existing registrations
|
|
|
|
* with this one.
|
|
|
|
*
|
|
|
|
* Once registration is complete, we add the class to the factories cache
|
|
|
|
* that we maintain. The factories cache is the ONLY place where these
|
|
|
|
* registrations are ever kept.
|
1999-09-01 01:40:21 +04:00
|
|
|
*
|
|
|
|
* The other RegisterFunctions create a loader mapping and persistent
|
|
|
|
* location, but we just slam it into the cache here. And we don't call the
|
|
|
|
* loader's OnRegister function, either.
|
1999-03-09 12:44:27 +03:00
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterFactory(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
nsIFactory *aFactory,
|
|
|
|
PRBool aReplace)
|
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
nsFactoryEntry *entry = NULL;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
nsIDKey key(aClass);
|
1999-09-01 01:40:21 +04:00
|
|
|
entry = (nsFactoryEntry *)mFactories->Get(&key);
|
2000-03-12 01:44:51 +03:00
|
|
|
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: RegisterFactory(%s, %s)", buf,
|
|
|
|
(aProgID ? aProgID : "(null)")));
|
|
|
|
delete [] buf;
|
|
|
|
|
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
if (entry && !aReplace) {
|
1999-07-07 11:47:14 +04:00
|
|
|
// Already registered
|
1999-09-01 01:40:21 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("\t\tFactory already registered."));
|
1999-07-07 11:47:14 +04:00
|
|
|
return NS_ERROR_FACTORY_EXISTS;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
|
|
|
|
nsFactoryEntry *newEntry = new nsFactoryEntry(aClass, aFactory);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (newEntry == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (entry) { // aReplace implied by above check
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tdeleting old Factory Entry."));
|
1999-08-03 04:03:38 +04:00
|
|
|
mFactories->RemoveAndDelete(&key);
|
|
|
|
entry = NULL;
|
1999-04-12 16:32:24 +04:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
mFactories->Put(&key, newEntry);
|
1999-04-12 16:32:24 +04:00
|
|
|
|
|
|
|
// Update the ProgID->CLSID Map
|
1999-09-01 01:40:21 +04:00
|
|
|
if (aProgID) {
|
1999-04-12 16:32:24 +04:00
|
|
|
nsresult rv = HashProgID(aProgID, aClass);
|
1999-09-01 01:40:21 +04:00
|
|
|
if(NS_FAILED(rv)) {
|
1999-04-12 16:32:24 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
1999-09-01 01:40:21 +04:00
|
|
|
("\t\tFactory register succeeded. "
|
2000-03-12 01:44:51 +03:00
|
|
|
"Hashing progid (%s) FAILED.", aProgID));
|
1999-09-01 01:40:21 +04:00
|
|
|
return rv;
|
1999-04-12 16:32:24 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tFactory register succeeded progid=%s.",
|
|
|
|
aProgID ? aProgID : "<none>"));
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponent(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
1999-09-01 01:40:21 +04:00
|
|
|
const char *aPersistentDescriptor,
|
1999-03-09 12:44:27 +03:00
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist)
|
|
|
|
{
|
1999-12-09 03:01:46 +03:00
|
|
|
return RegisterComponentCommon(aClass, aClassName, aProgID,
|
|
|
|
aPersistentDescriptor, aReplace, aPersist,
|
|
|
|
nativeComponentType);
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
|
1999-09-06 20:43:09 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponentWithType(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
2000-01-25 00:28:28 +03:00
|
|
|
nsIFile *aSpec,
|
1999-09-07 09:06:37 +04:00
|
|
|
const char *aLocation,
|
1999-09-06 20:43:09 +04:00
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist,
|
|
|
|
const char *aType)
|
|
|
|
{
|
1999-09-07 09:06:37 +04:00
|
|
|
return RegisterComponentCommon(aClass, aClassName, aProgID,
|
1999-11-19 05:14:23 +03:00
|
|
|
aLocation,
|
1999-09-06 20:43:09 +04:00
|
|
|
aReplace, aPersist,
|
|
|
|
aType);
|
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
/*
|
2000-01-25 00:28:28 +03:00
|
|
|
* Register a component, using whatever they stuck in the nsIFile.
|
1999-09-01 01:40:21 +04:00
|
|
|
*/
|
1999-06-22 18:02:58 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponentSpec(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
2000-01-25 00:28:28 +03:00
|
|
|
nsIFile *aLibrarySpec,
|
1999-06-22 18:02:58 +04:00
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist)
|
|
|
|
{
|
1999-11-19 05:14:23 +03:00
|
|
|
nsXPIDLCString registryName;
|
|
|
|
nsresult rv = RegistryLocationForSpec(aLibrarySpec, getter_Copies(registryName));
|
1999-09-07 09:06:37 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = RegisterComponentWithType(aClass, aClassName, aProgID, aLibrarySpec,
|
|
|
|
registryName,
|
|
|
|
aReplace, aPersist,
|
|
|
|
nativeComponentType);
|
|
|
|
return rv;
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a ``library'', which is a DLL location named by a simple filename
|
|
|
|
* such as ``libnsappshell.so'', rather than a relative or absolute path.
|
|
|
|
*
|
|
|
|
* It implies application/x-moz-dll as the component type, and skips the
|
|
|
|
* FindLoaderForType phase.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponentLib(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
const char *aDllName,
|
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist)
|
|
|
|
{
|
1999-11-19 05:14:23 +03:00
|
|
|
nsXPIDLCString registryName;
|
|
|
|
nsresult rv = RegistryNameForLib(aDllName, getter_Copies(registryName));
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
return RegisterComponentCommon(aClass, aClassName, aProgID, registryName,
|
|
|
|
aReplace, aPersist, nativeComponentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a component to the known universe of components.
|
|
|
|
|
|
|
|
* Once we enter this function, we own aRegistryName, and must free it
|
|
|
|
* or hand it to nsFactoryEntry. Common exit point ``out'' helps keep us
|
|
|
|
* sane.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponentCommon(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
1999-11-19 05:14:23 +03:00
|
|
|
const char *aRegistryName,
|
1999-09-01 01:40:21 +04:00
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist,
|
|
|
|
const char *aType)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsFactoryEntry* newEntry = nsnull;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
nsIDKey key(aClass);
|
1999-09-10 09:27:23 +04:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass, !mPrePopulationDone);
|
1999-09-01 01:40:21 +04:00
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
|
|
|
PRBool sanity;
|
1999-07-07 11:47:14 +04:00
|
|
|
|
2000-03-25 09:57:25 +03:00
|
|
|
// Normalize proid and classname
|
|
|
|
const char *progID = (aProgID && *aProgID) ? aProgID : NULL;
|
|
|
|
const char *className = (aClassName && *aClassName) ? aClassName : NULL;
|
|
|
|
|
2000-03-12 01:44:51 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: RegisterComponentCommon(%s, %s, %s, %s)",
|
|
|
|
buf,
|
2000-03-25 09:57:25 +03:00
|
|
|
progID ? progID : "(null)",
|
2000-03-12 01:44:51 +03:00
|
|
|
aRegistryName, aType));
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
if (entry && !aReplace) {
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("\t\tFactory already registered."));
|
|
|
|
rv = NS_ERROR_FACTORY_EXISTS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
|
|
|
if (aPersist) {
|
|
|
|
/* Add to the registry */
|
2000-03-25 09:57:25 +03:00
|
|
|
rv = AddComponentToRegistry(aClass, className, progID,
|
1999-09-01 01:40:21 +04:00
|
|
|
aRegistryName, aType);
|
|
|
|
if (NS_FAILED(rv)) {
|
2000-05-12 05:24:36 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("\t\tadding %s %s to registry FAILED", className, progID));
|
1999-09-01 01:40:21 +04:00
|
|
|
goto out;
|
2000-05-12 05:24:36 +04:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
#endif
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
rv = GetLoaderForType(aType, getter_AddRefs(loader));
|
|
|
|
if (NS_FAILED(rv)) {
|
2000-05-12 05:24:36 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("\t\tgetting loader for %s FAILED\n", aType));
|
1999-09-01 01:40:21 +04:00
|
|
|
goto out;
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
|
1999-11-10 03:28:34 +03:00
|
|
|
newEntry = new nsFactoryEntry(aClass, aRegistryName, aType, loader);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (!newEntry) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry) { // aReplace implicit from test above
|
2000-05-12 05:24:36 +04:00
|
|
|
delete entry;
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* unless the fabric of the universe bends, we'll get entry back */
|
|
|
|
sanity = (entry == mFactories->Put(&key, newEntry));
|
|
|
|
PR_ASSERT(sanity);
|
1999-11-10 03:28:34 +03:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
/* don't try to clean up, just drop everything and run */
|
|
|
|
if (!sanity)
|
2000-05-12 05:24:36 +04:00
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
/* we've put the new entry in the hash table, so don't delete on error */
|
|
|
|
newEntry = nsnull;
|
|
|
|
|
|
|
|
// Update the ProgID->CLSID Map
|
2000-03-25 09:57:25 +03:00
|
|
|
if (progID
|
1999-06-22 18:02:58 +04:00
|
|
|
#ifdef USE_REGISTRY
|
2000-03-03 04:48:41 +03:00
|
|
|
&& (mPrePopulationDone || !aPersist)
|
1999-09-01 01:40:21 +04:00
|
|
|
#endif
|
|
|
|
) {
|
2000-03-25 09:57:25 +03:00
|
|
|
rv = HashProgID(progID, aClass);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2000-05-12 05:24:36 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("\t\tHashProgID(%s) FAILED\n", progID));
|
1999-09-01 01:40:21 +04:00
|
|
|
goto out;
|
2000-05-12 05:24:36 +04:00
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
// Let the loader do magic things now
|
2000-03-25 09:57:25 +03:00
|
|
|
rv = loader->OnRegister(aClass, aType, className, progID, aRegistryName,
|
1999-09-01 01:40:21 +04:00
|
|
|
aReplace, aPersist);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
2000-03-12 01:44:51 +03:00
|
|
|
("\t\tloader->OnRegister FAILED for %s \"%s\" %s %s", aType,
|
2000-03-25 09:57:25 +03:00
|
|
|
className, progID, aRegistryName));
|
1999-09-01 01:40:21 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2000-03-12 01:44:51 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("\t\tRegisterComponentCommon() %s",
|
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
1999-09-01 01:40:21 +04:00
|
|
|
out:
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (newEntry)
|
|
|
|
delete newEntry;
|
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-01 01:40:21 +04:00
|
|
|
nsComponentManagerImpl::GetLoaderForType(const char *aType,
|
|
|
|
nsIComponentLoader **aLoader)
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
nsStringKey typeKey(aType);
|
|
|
|
nsresult rv;
|
1999-06-22 18:02:58 +04:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
|
|
|
loader = NS_STATIC_CAST(nsIComponentLoader *, mLoaders->Get(&typeKey));
|
1999-09-01 01:40:21 +04:00
|
|
|
if (loader) {
|
2000-05-26 08:56:23 +04:00
|
|
|
// nsSupportsHashtable does the AddRef
|
|
|
|
*aLoader = loader;
|
|
|
|
return NS_OK;
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
loader = do_GetServiceFromCategory("component-loader", aType, &rv);
|
1999-09-02 11:00:29 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
1999-09-04 03:51:31 +04:00
|
|
|
rv = loader->Init(this, mRegistry);
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-05-26 08:56:23 +04:00
|
|
|
mLoaders->Put(&typeKey, loader);
|
|
|
|
*aLoader = loader;
|
|
|
|
NS_ADDREF(*aLoader);
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::AddComponentToRegistry(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
const char *aRegistryName,
|
|
|
|
const char *aType)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-05-12 05:24:36 +04:00
|
|
|
PRUint32 length = strlen(aRegistryName);
|
|
|
|
char* eRegistryName;
|
|
|
|
rv = mRegistry->EscapeKey((PRUint8*)aRegistryName, 1, &length, (PRUint8**)&eRegistryName);
|
|
|
|
if (rv != NS_OK)
|
|
|
|
{
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (eRegistryName == nsnull) // No escaping required
|
|
|
|
eRegistryName = (char*)aRegistryName;
|
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey IDKey;
|
1999-09-29 06:54:18 +04:00
|
|
|
PRInt32 nComponents = 0;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
/* so why do we use strings here rather than writing bytes, anyway? */
|
|
|
|
char *cidString = aClass.ToString();
|
|
|
|
if (!cidString)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
rv = mRegistry->AddSubtreeRaw(mCLSIDKey, cidString, &IDKey);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (aClassName) {
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->SetStringUTF8(IDKey, classNameValueName, aClassName);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto out;
|
1999-03-10 12:16:28 +03:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
|
2000-05-12 05:24:36 +04:00
|
|
|
rv = mRegistry->SetBytesUTF8(IDKey, inprocServerValueName,
|
|
|
|
strlen(aRegistryName) + 1,
|
|
|
|
(PRUint8*)aRegistryName);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto out;
|
|
|
|
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->SetStringUTF8(IDKey, componentTypeValueName, aType);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (aProgID) {
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->SetStringUTF8(IDKey, progIDValueName, aProgID);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto out;
|
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey progIDKey;
|
1999-09-01 01:40:21 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mClassesKey, aProgID, &progIDKey);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto out;
|
2000-02-15 04:32:12 +03:00
|
|
|
rv = mRegistry->SetStringUTF8(progIDKey, classIDValueName, cidString);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
1999-09-29 06:35:42 +04:00
|
|
|
nsRegistryKey compKey;
|
2000-05-12 05:24:36 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mXPCOMKey, eRegistryName, &compKey);
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
// update component count
|
|
|
|
rv = mRegistry->GetInt(compKey, componentCountValueName, &nComponents);
|
|
|
|
nComponents++;
|
|
|
|
rv = mRegistry->SetInt(compKey, componentCountValueName, nComponents);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out:
|
|
|
|
// XXX if failed, undo registry adds or set invalid bit? How?
|
1999-09-21 00:53:57 +04:00
|
|
|
nsCRT::free(cidString);
|
2000-05-12 05:24:36 +04:00
|
|
|
if (eRegistryName != aRegistryName)
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(eRegistryName);
|
1999-03-10 12:53:25 +03:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::UnregisterFactory(const nsCID &aClass,
|
|
|
|
nsIFactory *aFactory)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
2000-03-12 01:44:51 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: UnregisterFactory(%s)", buf));
|
1999-03-10 12:53:25 +03:00
|
|
|
delete [] buf;
|
|
|
|
}
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsIDKey key(aClass);
|
|
|
|
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
nsFactoryEntry *old = (nsFactoryEntry *) mFactories->Get(&key);
|
|
|
|
if (old != NULL)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
if (old->factory.get() == aFactory)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
|
|
|
PR_EnterMonitor(mMon);
|
1999-08-03 04:03:38 +04:00
|
|
|
old = (nsFactoryEntry *) mFactories->RemoveAndDelete(&key);
|
|
|
|
old = NULL;
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ExitMonitor(mMon);
|
|
|
|
res = NS_OK;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2000-03-12 01:44:51 +03:00
|
|
|
("\t\tUnregisterFactory() %s",
|
|
|
|
NS_SUCCEEDED(res) ? "succeeded" : "FAILED"));
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::UnregisterComponent(const nsCID &aClass,
|
2000-05-05 10:37:39 +04:00
|
|
|
const char *registryName)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2000-05-05 10:37:39 +04:00
|
|
|
nsresult rv = NS_OK;
|
1999-08-13 23:30:13 +04:00
|
|
|
|
2000-05-05 10:37:39 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(registryName);
|
1999-08-13 23:30:13 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_EnterMonitor(mMon);
|
2000-04-18 09:25:05 +04:00
|
|
|
|
|
|
|
// Remove any stored factory entries
|
|
|
|
nsIDKey key(aClass);
|
|
|
|
nsFactoryEntry *entry = (nsFactoryEntry *) mFactories->Get(&key);
|
|
|
|
if (entry && entry->location && PL_strcasecmp(entry->location, registryName))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
2000-04-18 09:25:05 +04:00
|
|
|
mFactories->RemoveAndDelete(&key);
|
|
|
|
entry = NULL;
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
#ifdef USE_REGISTRY
|
2000-04-18 09:25:05 +04:00
|
|
|
// Remove registry entries for this cid
|
|
|
|
char *cidString = aClass.ToString();
|
|
|
|
rv = PlatformUnregister(cidString, registryName);
|
|
|
|
delete [] cidString;
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ExitMonitor(mMon);
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2000-05-05 10:37:39 +04:00
|
|
|
("nsComponentManager: Factory unregister(%s) %s.", registryName,
|
2000-04-18 09:25:05 +04:00
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2000-05-05 10:37:39 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::UnregisterComponentSpec(const nsCID &aClass,
|
|
|
|
nsIFile *aLibrarySpec)
|
|
|
|
{
|
|
|
|
nsXPIDLCString registryName;
|
|
|
|
nsresult rv = RegistryLocationForSpec(aLibrarySpec, getter_Copies(registryName));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
return UnregisterComponent(aClass, registryName);
|
|
|
|
}
|
|
|
|
|
1999-09-23 04:14:00 +04:00
|
|
|
struct CanUnload_closure {
|
|
|
|
int when;
|
|
|
|
nsresult status; // this is a hack around Enumerate's void return
|
|
|
|
nsIComponentLoader *native;
|
|
|
|
};
|
|
|
|
|
2000-05-03 02:38:04 +04:00
|
|
|
static PRBool PR_CALLBACK
|
1999-09-23 04:14:00 +04:00
|
|
|
CanUnload_enumerate(nsHashKey *key, void *aData, void *aClosure)
|
|
|
|
{
|
|
|
|
nsIComponentLoader *loader = (nsIComponentLoader *)aData;
|
|
|
|
struct CanUnload_closure *closure =
|
2000-05-12 05:24:36 +04:00
|
|
|
(struct CanUnload_closure *)aClosure;
|
1999-09-23 04:14:00 +04:00
|
|
|
|
|
|
|
if (loader == closure->native) {
|
|
|
|
#ifdef DEBUG
|
2000-05-12 05:24:36 +04:00
|
|
|
fprintf(stderr, "CanUnload_enumerate: skipping native\n");
|
1999-09-23 04:14:00 +04:00
|
|
|
#endif
|
2000-05-12 05:24:36 +04:00
|
|
|
return PR_TRUE;
|
1999-09-23 04:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
closure->status = loader->UnloadAll(closure->when);
|
|
|
|
if (NS_FAILED(closure->status))
|
2000-05-12 05:24:36 +04:00
|
|
|
return PR_FALSE;
|
1999-09-23 04:14:00 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-09-26 22:04:27 +04:00
|
|
|
// XXX Need to pass in aWhen and servicemanager
|
1999-03-09 12:44:27 +03:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::FreeLibraries(void)
|
1999-07-31 09:55:04 +04:00
|
|
|
{
|
|
|
|
nsIServiceManager* serviceMgr = NULL;
|
|
|
|
nsresult rv = nsServiceManager::GetGlobalServiceManager(&serviceMgr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-26 22:04:27 +04:00
|
|
|
rv = UnloadLibraries(serviceMgr, NS_Timer); // XXX when
|
1999-07-31 09:55:04 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private implementation of unloading libraries
|
|
|
|
nsresult
|
1999-09-26 22:04:27 +04:00
|
|
|
nsComponentManagerImpl::UnloadLibraries(nsIServiceManager *serviceMgr, PRInt32 aWhen)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-09-23 04:01:53 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_EnterMonitor(mMon);
|
2000-05-12 05:24:36 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-07-31 09:55:04 +04:00
|
|
|
("nsComponentManager: Unloading Libraries."));
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-09-23 04:14:00 +04:00
|
|
|
// UnloadAll the loaders
|
|
|
|
/* iterate over all known loaders and ask them to autoregister. */
|
|
|
|
struct CanUnload_closure closure;
|
1999-09-26 22:04:27 +04:00
|
|
|
closure.when = aWhen;
|
1999-09-23 04:14:00 +04:00
|
|
|
closure.status = NS_OK;
|
|
|
|
closure.native = mNativeComponentLoader;
|
|
|
|
mLoaders->Enumerate(CanUnload_enumerate, &closure);
|
1999-09-23 04:01:53 +04:00
|
|
|
|
|
|
|
// UnloadAll the native loader
|
1999-09-26 22:04:27 +04:00
|
|
|
rv = mNativeComponentLoader->UnloadAll(aWhen);
|
1999-09-23 04:01:53 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ExitMonitor(mMon);
|
1999-07-31 09:55:04 +04:00
|
|
|
|
1999-09-23 04:01:53 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
1999-04-03 00:28:22 +04:00
|
|
|
* AutoRegister(RegistrationInstant, const char *directory)
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
1999-04-03 00:28:22 +04:00
|
|
|
* Given a directory in the following format, this will ensure proper registration
|
|
|
|
* of all components. No default director is looked at.
|
|
|
|
*
|
|
|
|
* Directory and fullname are what NSPR will accept. For eg.
|
2000-05-12 05:24:36 +04:00
|
|
|
* WIN y:/home/dp/mozilla/dist/bin
|
|
|
|
* UNIX /home/dp/mozilla/dist/bin
|
|
|
|
* MAC /Hard drive/mozilla/dist/apprunner
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
|
|
|
* This will take care not loading already registered dlls, finding and
|
|
|
|
* registering new dlls, re-registration of modified dlls
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
struct AutoReg_closure {
|
|
|
|
int when;
|
2000-01-25 00:28:28 +03:00
|
|
|
nsIFile *spec;
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult status; // this is a hack around Enumerate's void return
|
|
|
|
nsIComponentLoader *native;
|
1999-11-10 03:28:34 +03:00
|
|
|
PRBool registered;
|
1999-09-01 01:40:21 +04:00
|
|
|
};
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2000-05-03 02:38:04 +04:00
|
|
|
static PRBool PR_CALLBACK
|
1999-09-01 01:40:21 +04:00
|
|
|
AutoRegister_enumerate(nsHashKey *key, void *aData, void *aClosure)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-11-10 03:28:34 +03:00
|
|
|
nsIComponentLoader *loader = NS_STATIC_CAST(nsIComponentLoader *, aData);
|
1999-09-01 01:40:21 +04:00
|
|
|
struct AutoReg_closure *closure =
|
2000-05-12 05:24:36 +04:00
|
|
|
(struct AutoReg_closure *)aClosure;
|
1999-06-22 18:02:58 +04:00
|
|
|
|
1999-11-10 03:28:34 +03:00
|
|
|
if (loader == closure->native)
|
2000-05-12 05:24:36 +04:00
|
|
|
return PR_TRUE;
|
1999-06-22 18:02:58 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
PR_ASSERT(NS_SUCCEEDED(closure->status));
|
1999-07-25 17:37:16 +04:00
|
|
|
|
1999-11-10 03:28:34 +03:00
|
|
|
closure->status = loader->AutoRegisterComponents(closure->when,
|
|
|
|
closure->spec);
|
|
|
|
return NS_SUCCEEDED(closure->status) ? PR_TRUE : PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-05-03 02:38:04 +04:00
|
|
|
static PRBool PR_CALLBACK
|
1999-11-10 03:28:34 +03:00
|
|
|
RegisterDeferred_enumerate(nsHashKey *key, void *aData, void *aClosure)
|
|
|
|
{
|
|
|
|
nsIComponentLoader *loader = NS_STATIC_CAST(nsIComponentLoader *, aData);
|
|
|
|
struct AutoReg_closure *closure =
|
2000-05-12 05:24:36 +04:00
|
|
|
(struct AutoReg_closure *)aClosure;
|
1999-11-10 03:28:34 +03:00
|
|
|
PR_ASSERT(NS_SUCCEEDED(closure->status));
|
|
|
|
|
|
|
|
PRBool registered;
|
|
|
|
closure->status = loader->RegisterDeferredComponents(closure->when,
|
|
|
|
®istered);
|
|
|
|
closure->registered |= registered;
|
|
|
|
return NS_SUCCEEDED(closure->status) ? PR_TRUE : PR_FALSE;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-01-25 00:28:28 +03:00
|
|
|
nsComponentManagerImpl::AutoRegister(PRInt32 when, nsIFile *inDirSpec)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2000-01-25 00:28:28 +03:00
|
|
|
nsCOMPtr<nsIFile> dir;
|
1999-06-22 18:02:58 +04:00
|
|
|
nsresult rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
2000-05-05 10:37:39 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// testing release behaviour
|
|
|
|
if (getenv("XPCOM_NO_AUTOREG"))
|
|
|
|
return NS_OK;
|
|
|
|
#endif
|
2000-05-02 04:54:11 +04:00
|
|
|
if (inDirSpec)
|
|
|
|
{
|
|
|
|
// Use supplied components' directory
|
|
|
|
dir = inDirSpec;
|
2000-05-12 05:24:36 +04:00
|
|
|
|
2000-05-02 04:54:11 +04:00
|
|
|
// Set components' directory for AutoRegisterInterfces to query
|
|
|
|
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Don't care if undefining fails
|
|
|
|
directoryService->Undefine("xpcom.currentProcess.componentDirectory");
|
|
|
|
rv = directoryService->Define("xpcom.currentProcess.componentDirectory", dir);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
// Do default components directory
|
2000-01-25 00:28:28 +03:00
|
|
|
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = directoryService->Get("xpcom.currentProcess.componentDirectory", NS_GET_IID(nsIFile), getter_AddRefs(dir));
|
2000-05-02 04:54:11 +04:00
|
|
|
if (NS_FAILED(rv)) return rv; // XXX translate error code?
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
2000-04-25 09:11:30 +04:00
|
|
|
// Force the InterfaceInfoManager to do its AutoReg first.
|
|
|
|
nsCOMPtr<nsIInterfaceInfoManager> iim =
|
|
|
|
dont_AddRef(XPTI_GetInterfaceInfoManager());
|
|
|
|
|
2000-05-15 23:28:12 +04:00
|
|
|
|
2000-04-25 09:11:30 +04:00
|
|
|
if (!iim)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-05-15 23:28:12 +04:00
|
|
|
|
|
|
|
// Notify observers of xpcom autoregistration start
|
|
|
|
NS_WITH_SERVICE (nsIObserverService, observerService, NS_OBSERVERSERVICE_PROGID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
|
|
|
|
nsIServiceManager *mgr; // NO COMPtr as we dont release the service manager
|
|
|
|
rv = nsServiceManager::GetGlobalServiceManager(&mgr);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2000-05-17 05:53:50 +04:00
|
|
|
(void) observerService->Notify(mgr,
|
|
|
|
NS_ConvertASCIItoUCS2(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID).GetUnicode(),
|
|
|
|
NS_ConvertASCIItoUCS2("Starting component registration").GetUnicode());
|
2000-05-15 23:28:12 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-25 09:11:30 +04:00
|
|
|
|
|
|
|
rv = iim->AutoRegisterInterfaces();
|
2000-05-26 08:56:23 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-04-25 09:11:30 +04:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
/* do the native loader first, so we can find other loaders */
|
|
|
|
rv = mNativeComponentLoader->AutoRegisterComponents((PRInt32)when, dir);
|
1999-09-01 01:40:21 +04:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
nsCOMPtr<nsICategoryManager> catman =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_PROGID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-02 11:00:29 +04:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> loaderEnum;
|
|
|
|
rv = catman->EnumerateCategory("component-loader",
|
|
|
|
getter_AddRefs(loaderEnum));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-11-10 03:28:34 +03:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
PRBool hasMore;
|
|
|
|
while (NS_SUCCEEDED(loaderEnum->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
if (NS_FAILED(loaderEnum->GetNext(getter_AddRefs(supports))))
|
2000-05-15 23:28:12 +04:00
|
|
|
continue;
|
1999-11-10 03:28:34 +03:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
nsCOMPtr<nsISupportsString> supStr = do_QueryInterface(supports);
|
|
|
|
if (!supStr)
|
|
|
|
continue;
|
2000-05-15 23:28:12 +04:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
nsXPIDLCString loaderType;
|
|
|
|
if (NS_FAILED(supStr->GetData(getter_Copies(loaderType))))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
|
|
|
/* this will create it if we haven't already */
|
|
|
|
GetLoaderForType(loaderType, getter_AddRefs(loader));
|
2000-05-15 23:28:12 +04:00
|
|
|
}
|
2000-05-17 05:53:50 +04:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
/* iterate over all known loaders and ask them to autoregister. */
|
|
|
|
/* XXX convert when to nsIComponentLoader::(when) properly */
|
|
|
|
struct AutoReg_closure closure;
|
|
|
|
closure.when = when;
|
|
|
|
closure.spec = dir.get();
|
|
|
|
closure.status = NS_OK;
|
|
|
|
closure.native = mNativeComponentLoader; // prevent duplicate autoreg
|
|
|
|
|
|
|
|
mLoaders->Enumerate(AutoRegister_enumerate, &closure);
|
|
|
|
rv = closure.status;
|
|
|
|
|
2000-05-15 23:28:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
closure.registered = PR_FALSE;
|
|
|
|
mLoaders->Enumerate(RegisterDeferred_enumerate, &closure);
|
|
|
|
} while (NS_SUCCEEDED(closure.status) && closure.registered);
|
|
|
|
rv = closure.status;
|
|
|
|
|
|
|
|
}
|
2000-05-17 05:53:50 +04:00
|
|
|
|
|
|
|
nsIServiceManager *mgr; // NO COMPtr as we dont release the service manager
|
|
|
|
rv = nsServiceManager::GetGlobalServiceManager(&mgr);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
(void) observerService->Notify(mgr,
|
|
|
|
NS_ConvertASCIItoUCS2(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID).GetUnicode(),
|
|
|
|
NS_ConvertASCIItoUCS2("Component registration finished").GetUnicode());
|
|
|
|
}
|
|
|
|
|
2000-05-15 23:28:12 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2000-05-03 02:38:04 +04:00
|
|
|
static PRBool PR_CALLBACK
|
1999-09-01 01:40:21 +04:00
|
|
|
AutoRegisterComponent_enumerate(nsHashKey *key, void *aData, void *aClosure)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
PRBool didRegister;
|
|
|
|
nsIComponentLoader *loader = (nsIComponentLoader *)aData;
|
|
|
|
struct AutoReg_closure *closure =
|
2000-05-12 05:24:36 +04:00
|
|
|
(struct AutoReg_closure *)aClosure;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
closure->status = loader->AutoRegisterComponent(closure->when,
|
2000-05-12 05:24:36 +04:00
|
|
|
closure->spec,
|
|
|
|
&didRegister);
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(closure->status) && didRegister)
|
2000-05-12 05:24:36 +04:00
|
|
|
return PR_FALSE; // Stop enumeration as we are done
|
2000-04-18 09:25:05 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-06-05 23:18:07 +04:00
|
|
|
static PRBool PR_CALLBACK
|
2000-04-18 09:25:05 +04:00
|
|
|
AutoUnregisterComponent_enumerate(nsHashKey *key, void *aData, void *aClosure)
|
|
|
|
{
|
|
|
|
PRBool didUnregister;
|
|
|
|
nsIComponentLoader *loader = (nsIComponentLoader *)aData;
|
|
|
|
struct AutoReg_closure *closure =
|
2000-05-12 05:24:36 +04:00
|
|
|
(struct AutoReg_closure *)aClosure;
|
2000-04-18 09:25:05 +04:00
|
|
|
|
|
|
|
closure->status = loader->AutoUnregisterComponent(closure->when,
|
|
|
|
closure->spec,
|
|
|
|
&didUnregister);
|
|
|
|
if (NS_SUCCEEDED(closure->status) && didUnregister)
|
|
|
|
return PR_FALSE; // Stop enumeration as we are done
|
|
|
|
return PR_TRUE; // Let enumeration continue
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-05 10:27:42 +04:00
|
|
|
nsComponentManagerImpl::AutoRegisterComponent(PRInt32 when,
|
2000-01-25 00:28:28 +03:00
|
|
|
nsIFile *component)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
struct AutoReg_closure closure;
|
1999-08-09 09:40:51 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
/* XXX convert when to nsIComponentLoader::(when) properly */
|
|
|
|
closure.when = (PRInt32)when;
|
|
|
|
closure.spec = component;
|
|
|
|
closure.status = NS_OK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we have to give the native loader first crack at it?
|
|
|
|
* I vote ``no''.
|
|
|
|
*/
|
|
|
|
mLoaders->Enumerate(AutoRegisterComponent_enumerate, &closure);
|
|
|
|
return NS_FAILED(closure.status)
|
2000-05-12 05:24:36 +04:00
|
|
|
? NS_ERROR_FACTORY_NOT_REGISTERED : NS_OK;
|
1999-08-09 09:40:51 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2000-04-18 09:25:05 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::AutoUnregisterComponent(PRInt32 when,
|
|
|
|
nsIFile *component)
|
|
|
|
{
|
|
|
|
struct AutoReg_closure closure;
|
|
|
|
|
|
|
|
/* XXX convert when to nsIComponentLoader::(when) properly */
|
|
|
|
closure.when = (PRInt32)when;
|
|
|
|
closure.spec = component;
|
|
|
|
closure.status = NS_OK;
|
|
|
|
|
|
|
|
mLoaders->Enumerate(AutoUnregisterComponent_enumerate, &closure);
|
|
|
|
|
|
|
|
return NS_FAILED(closure.status)
|
2000-05-12 05:24:36 +04:00
|
|
|
? NS_ERROR_FACTORY_NOT_REGISTERED : NS_OK;
|
2000-04-18 09:25:05 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-08-09 09:02:25 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::IsRegistered(const nsCID &aClass,
|
|
|
|
PRBool *aRegistered)
|
|
|
|
{
|
|
|
|
if(!aRegistered)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0, "null ptr");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-09-10 09:27:23 +04:00
|
|
|
*aRegistered = (nsnull != GetFactoryEntry(aClass, !mPrePopulationDone));
|
1999-08-09 09:02:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_IMETHODIMP
|
|
|
|
ConvertFactoryEntryToCID(nsHashKey *key, void *data, void *convert_data,
|
|
|
|
nsISupports **retval)
|
|
|
|
{
|
|
|
|
nsComponentManagerImpl *compMgr = (nsComponentManagerImpl*) convert_data;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsISupportsID* cidHolder;
|
|
|
|
|
1999-09-05 10:27:42 +04:00
|
|
|
if(NS_SUCCEEDED(rv =
|
|
|
|
compMgr->CreateInstanceByProgID(NS_SUPPORTS_ID_PROGID,
|
|
|
|
nsnull,
|
|
|
|
NS_GET_IID(nsISupportsID),
|
|
|
|
(void **)&cidHolder)))
|
1999-08-09 09:02:25 +04:00
|
|
|
{
|
|
|
|
nsFactoryEntry *fe = (nsFactoryEntry *) data;
|
|
|
|
cidHolder->SetData(&fe->cid);
|
|
|
|
*retval = cidHolder;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*retval = nsnull;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_IMETHODIMP
|
|
|
|
ConvertProgIDKeyToString(nsHashKey *key, void *data, void *convert_data,
|
|
|
|
nsISupports **retval)
|
|
|
|
{
|
|
|
|
nsComponentManagerImpl *compMgr = (nsComponentManagerImpl*) convert_data;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsISupportsString* strHolder;
|
|
|
|
|
1999-09-05 10:27:42 +04:00
|
|
|
|
|
|
|
rv = compMgr->CreateInstanceByProgID(NS_SUPPORTS_STRING_PROGID, nsnull,
|
|
|
|
NS_GET_IID(nsISupportsString),
|
|
|
|
(void **)&strHolder);
|
|
|
|
if(NS_SUCCEEDED(rv))
|
1999-08-09 09:02:25 +04:00
|
|
|
{
|
|
|
|
nsStringKey *strKey = (nsStringKey *) key;
|
|
|
|
const nsString& str = strKey->GetString();
|
|
|
|
char* yetAnotherCopyOfTheString = str.ToNewCString();
|
|
|
|
if(yetAnotherCopyOfTheString)
|
|
|
|
{
|
|
|
|
strHolder->SetData(yetAnotherCopyOfTheString);
|
|
|
|
delete [] yetAnotherCopyOfTheString;
|
|
|
|
}
|
|
|
|
*retval = strHolder;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*retval = nsnull;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::EnumerateCLSIDs(nsIEnumerator** aEmumerator)
|
|
|
|
{
|
|
|
|
if(!aEmumerator)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0, "null ptr");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aEmumerator = nsnull;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if(!mPrePopulationDone)
|
|
|
|
{
|
|
|
|
rv = PlatformPrePopulateRegistry();
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NewHashtableEnumerator(mFactories, ConvertFactoryEntryToCID,
|
|
|
|
this, aEmumerator);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::EnumerateProgIDs(nsIEnumerator** aEmumerator)
|
|
|
|
{
|
|
|
|
if(!aEmumerator)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0, "null ptr");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aEmumerator = nsnull;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if(!mPrePopulationDone)
|
|
|
|
{
|
|
|
|
rv = PlatformPrePopulateRegistry();
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NewHashtableEnumerator(mProgIDs, ConvertProgIDKeyToString,
|
|
|
|
this, aEmumerator);
|
|
|
|
}
|
|
|
|
|
2000-01-12 01:54:46 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::GetInterface(const nsIID & uuid, void **result)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (uuid.Equals(NS_GET_IID(nsIServiceManager)))
|
|
|
|
{
|
|
|
|
// Return the global service manager
|
|
|
|
rv = nsServiceManager::GetGlobalServiceManager((nsIServiceManager **)result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// fall through to QI as anything QIable is a superset of what canbe
|
|
|
|
// got via the GetInterface()
|
|
|
|
rv = QueryInterface(uuid, result);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_COM nsresult
|
|
|
|
NS_GetGlobalComponentManager(nsIComponentManager* *result)
|
|
|
|
{
|
1999-03-24 02:28:32 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager == NULL)
|
|
|
|
{
|
|
|
|
// XPCOM needs initialization.
|
2000-01-06 04:05:13 +03:00
|
|
|
rv = NS_InitXPCOM(NULL, NULL);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-24 02:28:32 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
// NO ADDREF since this is never intended to be released.
|
|
|
|
*result = nsComponentManagerImpl::gComponentManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|