2002-10-06 03:59:57 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-04-18 18:21:17 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK *****
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
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"
|
2001-10-16 07:35:52 +04:00
|
|
|
#include "nspr.h"
|
2002-06-15 01:33:05 +04:00
|
|
|
#include "nsCRT.h" // for atoll
|
2002-05-03 01:25:08 +04:00
|
|
|
// Arena used by component manager for storing contractid string, dll
|
|
|
|
// location strings and small objects
|
|
|
|
// CAUTION: Arena align mask needs to be defined before including plarena.h
|
|
|
|
// currently from nsComponentManager.h
|
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK 7
|
2003-03-14 08:07:24 +03:00
|
|
|
#define NS_CM_BLOCK_SIZE (1024 * 8)
|
2002-05-03 01:25:08 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsAutoLock.h"
|
1999-06-22 18:02:58 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsComponentManager.h"
|
2001-12-19 03:12:41 +03:00
|
|
|
#include "nsComponentManagerObsolete.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsDirectoryService.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2002-07-18 09:09:10 +04:00
|
|
|
#include "nsCategoryManager.h"
|
2002-03-22 02:43:21 +03:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIComponentLoader.h"
|
1999-07-02 07:35:09 +04:00
|
|
|
#include "nsIEnumerator.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIInterfaceInfoManager.h"
|
1999-08-09 09:40:51 +04:00
|
|
|
#include "nsIModule.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
1999-08-09 09:02:25 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsLocalFile.h"
|
1999-09-01 01:40:21 +04:00
|
|
|
#include "nsNativeComponentLoader.h"
|
2003-03-05 06:22:12 +03:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsString.h"
|
1999-11-10 03:28:34 +03:00
|
|
|
#include "nsXPIDLString.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "prcmon.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "xptinfo.h" // this after nsISupports, to pick up IID so that xpt stuff doesn't try to define it itself...
|
2002-06-15 01:33:05 +04:00
|
|
|
|
|
|
|
#include "nsInt64.h"
|
|
|
|
#include "nsManifestLineReader.h"
|
|
|
|
|
2002-08-19 09:19:22 +04:00
|
|
|
#include NEW_H // for placement new
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
|
1999-06-29 14:27:58 +04:00
|
|
|
#ifdef XP_BEOS
|
|
|
|
#include <FindDirectory.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#endif
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
#include "prlog.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
PRLogModuleInfo* nsComponentManagerLog = nsnull;
|
1999-06-14 06:07:03 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
#if 0 || defined (DEBUG_timeless)
|
|
|
|
#define SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
#define SHOW_CI_ON_EXISTING_SERVICE
|
|
|
|
#define XPCOM_CHECK_PENDING_CIDS
|
2002-01-10 09:55:18 +03:00
|
|
|
#endif
|
2002-01-10 05:10:37 +03:00
|
|
|
|
2001-08-30 18:10:41 +04:00
|
|
|
// Loader Types
|
|
|
|
#define NS_LOADER_DATA_ALLOC_STEP 6
|
|
|
|
|
2001-11-30 10:50:03 +03:00
|
|
|
// Bloated registry buffer size to improve startup performance -- needs to
|
|
|
|
// be big enough to fit the entire file into memory or it'll thrash.
|
|
|
|
// 512K is big enough to allow for some future growth in the registry.
|
|
|
|
#define BIG_REGISTRY_BUFLEN (512*1024)
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
// Common Key Names
|
2000-02-20 06:12:59 +03:00
|
|
|
const char classIDKeyName[]="classID";
|
2002-01-30 00:22:13 +03:00
|
|
|
const char classesKeyName[]="contractID";
|
2000-02-16 10:45:20 +03:00
|
|
|
const char componentLoadersKeyName[]="componentLoaders";
|
2002-01-30 00:22:13 +03:00
|
|
|
const char componentsKeyName[]="components";
|
2000-02-16 10:45:20 +03:00
|
|
|
const char xpcomComponentsKeyName[]="software/mozilla/XPCOM/components";
|
2002-01-30 00:22:13 +03:00
|
|
|
const char xpcomKeyName[]="software/mozilla/XPCOM";
|
1999-04-05 04:07:18 +04:00
|
|
|
|
|
|
|
// Common Value Names
|
2000-02-20 06:12:59 +03:00
|
|
|
const char classIDValueName[]="ClassID";
|
2002-01-30 00:22:13 +03:00
|
|
|
const char classNameValueName[]="ClassName";
|
1999-04-05 04:07:18 +04:00
|
|
|
const char componentCountValueName[]="ComponentsCount";
|
2002-01-30 00:22:13 +03:00
|
|
|
const char componentTypeValueName[]="ComponentType";
|
2000-09-14 03:57:52 +04:00
|
|
|
const char contractIDValueName[]="ContractID";
|
2002-01-30 00:22:13 +03:00
|
|
|
const char fileSizeValueName[]="FileSize";
|
1999-04-05 04:07:18 +04:00
|
|
|
const char inprocServerValueName[]="InprocServer";
|
2002-01-30 00:22:13 +03:00
|
|
|
const char lastModValueName[]="LastModTimeStamp";
|
1999-09-02 11:00:29 +04:00
|
|
|
const char nativeComponentType[]="application/x-mozilla-native";
|
2001-06-21 00:21:49 +04:00
|
|
|
const char staticComponentType[]="application/x-mozilla-static";
|
2002-01-30 00:22:13 +03:00
|
|
|
const char versionValueName[]="VersionString";
|
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:";
|
2003-03-05 06:22:12 +03:00
|
|
|
const static char XPCOM_GRECOMPONENT_PREFIX[] = "gre:";
|
1999-09-07 09:06:37 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
static const char gIDFormat[] =
|
2003-03-14 08:07:24 +03:00
|
|
|
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
|
|
|
|
#define NS_EMPTY_IID \
|
|
|
|
{ \
|
|
|
|
0x00000000, \
|
|
|
|
0x0000, \
|
|
|
|
0x0000, \
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DEFINE_CID(kEmptyCID, NS_EMPTY_IID);
|
2002-06-15 01:33:05 +04:00
|
|
|
NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
#define UID_STRING_LENGTH 39
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
// Set to true from NS_ShutdownXPCOM.
|
2001-10-16 07:35:52 +04:00
|
|
|
extern PRBool gXPCOMShuttingDown;
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
static void GetIDString(const nsID& aCID, char buf[UID_STRING_LENGTH])
|
|
|
|
{
|
|
|
|
PR_snprintf(buf, UID_STRING_LENGTH, gIDFormat,
|
|
|
|
aCID.m0, (PRUint32) aCID.m1, (PRUint32) aCID.m2,
|
|
|
|
(PRUint32) aCID.m3[0], (PRUint32) aCID.m3[1],
|
|
|
|
(PRUint32) aCID.m3[2], (PRUint32) aCID.m3[3],
|
|
|
|
(PRUint32) aCID.m3[4], (PRUint32) aCID.m3[5],
|
|
|
|
(PRUint32) aCID.m3[6], (PRUint32) aCID.m3[7]);
|
|
|
|
}
|
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
nsresult
|
2002-10-06 03:59:57 +04:00
|
|
|
nsCreateInstanceFromCategory::operator()(const nsIID& aIID, void** aInstancePtr) const
|
2000-05-26 08:56:23 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If I were a real man, I would consolidate this with
|
2000-09-14 03:57:52 +04:00
|
|
|
* nsGetServiceFromContractID::operator().
|
2000-05-26 08:56:23 +04:00
|
|
|
*/
|
2002-10-06 03:59:57 +04:00
|
|
|
nsresult rv;
|
2000-05-26 08:56:23 +04:00
|
|
|
nsXPIDLCString value;
|
2002-03-22 02:43:21 +03:00
|
|
|
nsCOMPtr<nsIComponentManager> compMgr;
|
2000-05-26 08:56:23 +04:00
|
|
|
nsCOMPtr<nsICategoryManager> catman =
|
2002-10-06 03:59:57 +04:00
|
|
|
do_GetService(kCategoryManagerCID, &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) goto error;
|
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
if (!mCategory || !mEntry) {
|
|
|
|
// when categories have defaults, use that for null mEntry
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
2000-05-26 08:56:23 +04:00
|
|
|
goto error;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
/* find the contractID for category.entry */
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = catman->GetCategoryEntry(mCategory, mEntry,
|
|
|
|
getter_Copies(value));
|
|
|
|
if (NS_FAILED(rv)) goto error;
|
2000-05-26 08:56:23 +04:00
|
|
|
if (!value) {
|
2004-02-29 11:04:46 +03:00
|
|
|
rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
2000-05-26 08:56:23 +04:00
|
|
|
goto error;
|
|
|
|
}
|
2002-03-22 02:43:21 +03:00
|
|
|
NS_GetComponentManager(getter_AddRefs(compMgr));
|
|
|
|
if (!compMgr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-06-19 03:03:08 +04:00
|
|
|
compMgr->CreateInstanceByContractID(value,
|
|
|
|
mOuter,
|
|
|
|
aIID,
|
2002-03-22 02:43:21 +03:00
|
|
|
aInstancePtr);
|
2002-10-06 03:59:57 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
error:
|
2000-05-26 08:56:23 +04:00
|
|
|
*aInstancePtr = 0;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
|
|
|
*mErrorPtr = rv;
|
|
|
|
return rv;
|
2000-05-26 08:56:23 +04:00
|
|
|
}
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
|
|
|
|
nsresult
|
2002-10-06 03:59:57 +04:00
|
|
|
nsGetServiceFromCategory::operator()(const nsIID& aIID, void** aInstancePtr) const
|
2002-03-22 02:43:21 +03:00
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
nsresult rv;
|
2002-03-22 02:43:21 +03:00
|
|
|
nsXPIDLCString value;
|
2004-10-15 21:44:30 +04:00
|
|
|
nsCOMPtr<nsIServiceManager> serviceManager =
|
|
|
|
do_QueryInterface(mServiceManager);
|
|
|
|
// XXX Should we use the provided service manager?
|
2003-06-19 03:03:08 +04:00
|
|
|
nsCOMPtr<nsICategoryManager> catman =
|
2002-10-06 03:59:57 +04:00
|
|
|
do_GetService(kCategoryManagerCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) goto error;
|
2002-03-22 02:43:21 +03:00
|
|
|
if (!mCategory || !mEntry) {
|
|
|
|
// when categories have defaults, use that for null mEntry
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
2002-03-22 02:43:21 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/* find the contractID for category.entry */
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = catman->GetCategoryEntry(mCategory, mEntry,
|
|
|
|
getter_Copies(value));
|
|
|
|
if (NS_FAILED(rv)) goto error;
|
2002-03-22 02:43:21 +03:00
|
|
|
if (!value) {
|
2004-02-29 11:04:46 +03:00
|
|
|
rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
2002-03-22 02:43:21 +03:00
|
|
|
goto error;
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
2004-10-15 21:44:30 +04:00
|
|
|
if (serviceManager) {
|
|
|
|
rv = serviceManager->GetServiceByContractID(value, aIID, (void**)aInstancePtr);
|
2001-10-16 07:35:52 +04:00
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIServiceManager> mgr;
|
|
|
|
NS_GetServiceManager(getter_AddRefs(mgr));
|
|
|
|
if (mgr)
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = mgr->GetServiceByContractID(value, aIID, (void**)aInstancePtr);
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2002-03-22 02:43:21 +03:00
|
|
|
error:
|
2001-10-16 07:35:52 +04:00
|
|
|
*aInstancePtr = 0;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
*mErrorPtr = rv;
|
|
|
|
return rv;
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-05-03 01:25:08 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Arena helper functions
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2003-03-14 08:07:24 +03:00
|
|
|
char *
|
|
|
|
ArenaStrndup(const char *s, PRUint32 len, PLArenaPool *arena)
|
2002-05-03 01:25:08 +04:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
// Include trailing null in the len
|
2003-03-14 08:07:24 +03:00
|
|
|
PL_ARENA_ALLOCATE(mem, arena, len+1);
|
2002-05-03 01:25:08 +04:00
|
|
|
if (mem)
|
2003-03-14 08:07:24 +03:00
|
|
|
memcpy(mem, s, len+1);
|
2002-05-03 01:25:08 +04:00
|
|
|
return NS_STATIC_CAST(char *, mem);
|
|
|
|
}
|
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
char*
|
|
|
|
ArenaStrdup(const char *s, PLArenaPool *arena)
|
|
|
|
{
|
|
|
|
return ArenaStrndup(s, strlen(s), arena);
|
|
|
|
}
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Hashtable Callbacks
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
PR_STATIC_CALLBACK(const void *)
|
|
|
|
factory_GetKey(PLDHashTable *aTable, PLDHashEntryHdr *aHdr)
|
|
|
|
{
|
|
|
|
nsFactoryTableEntry* entry = NS_STATIC_CAST(nsFactoryTableEntry*, aHdr);
|
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
return &entry->mFactoryEntry->mCid;
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PLDHashNumber)
|
|
|
|
factory_HashKey(PLDHashTable *aTable, const void *aKey)
|
|
|
|
{
|
|
|
|
const nsCID *cidp = NS_REINTERPRET_CAST(const nsCID*, aKey);
|
|
|
|
|
|
|
|
return cidp->m0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PRBool)
|
|
|
|
factory_MatchEntry(PLDHashTable *aTable, const PLDHashEntryHdr *aHdr,
|
|
|
|
const void *aKey)
|
|
|
|
{
|
|
|
|
const nsFactoryTableEntry* entry =
|
|
|
|
NS_STATIC_CAST(const nsFactoryTableEntry*, aHdr);
|
|
|
|
const nsCID *cidp = NS_REINTERPRET_CAST(const nsCID*, aKey);
|
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
return (entry->mFactoryEntry->mCid).Equals(*cidp);
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
factory_ClearEntry(PLDHashTable *aTable, PLDHashEntryHdr *aHdr)
|
|
|
|
{
|
|
|
|
nsFactoryTableEntry* entry = NS_STATIC_CAST(nsFactoryTableEntry*, aHdr);
|
2002-05-03 01:25:08 +04:00
|
|
|
// nsFactoryEntry is arena allocated. So we dont delete it.
|
|
|
|
// We call the destructor by hand.
|
|
|
|
entry->mFactoryEntry->~nsFactoryEntry();
|
2001-10-23 06:28:12 +04:00
|
|
|
PL_DHashClearEntryStub(aTable, aHdr);
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-04-04 19:10:37 +04:00
|
|
|
static const PLDHashTableOps factory_DHashTableOps = {
|
2001-10-23 06:28:12 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
factory_GetKey,
|
|
|
|
factory_HashKey,
|
|
|
|
factory_MatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
factory_ClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
};
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
contractID_ClearEntry(PLDHashTable *aTable, PLDHashEntryHdr *aHdr)
|
|
|
|
{
|
|
|
|
nsContractIDTableEntry* entry = NS_STATIC_CAST(nsContractIDTableEntry*, aHdr);
|
2004-04-18 21:35:29 +04:00
|
|
|
if (entry->mFactoryEntry->mTypeIndex == NS_COMPONENT_TYPE_SERVICE_ONLY &&
|
2003-05-14 02:50:03 +04:00
|
|
|
entry->mFactoryEntry->mCid.Equals(kEmptyCID)) {
|
2002-05-03 01:25:08 +04:00
|
|
|
// this object is owned by the hash.
|
|
|
|
// nsFactoryEntry is arena allocated. So we dont delete it.
|
|
|
|
// We call the destructor by hand.
|
|
|
|
entry->mFactoryEntry->~nsFactoryEntry();
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
|
|
|
|
2002-05-03 01:25:08 +04:00
|
|
|
// contractIDs are arena allocated. No need to free them.
|
2002-01-30 00:22:13 +03:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
PL_DHashClearEntryStub(aTable, aHdr);
|
|
|
|
}
|
|
|
|
|
2003-04-04 19:10:37 +04:00
|
|
|
static const PLDHashTableOps contractID_DHashTableOps = {
|
2001-10-23 06:28:12 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
2003-08-06 00:09:21 +04:00
|
|
|
PL_DHashGetKeyStub,
|
2001-10-23 06:28:12 +04:00
|
|
|
PL_DHashStringKey,
|
2003-08-06 00:09:21 +04:00
|
|
|
PL_DHashMatchStringKey,
|
2001-10-23 06:28:12 +04:00
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
contractID_ClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
};
|
2001-09-07 01:13:11 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFactoryEntry
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsFactoryEntry)
|
2003-06-19 03:03:08 +04:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID &aClass,
|
2001-09-07 01:13:11 +04:00
|
|
|
const char *aLocation,
|
2003-03-14 08:07:24 +03:00
|
|
|
PRUint32 locationlen,
|
2003-05-14 02:50:03 +04:00
|
|
|
int aType,
|
|
|
|
class nsFactoryEntry* parent)
|
|
|
|
: mCid(aClass), mTypeIndex(aType), mParent(parent)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2002-05-03 01:25:08 +04:00
|
|
|
// Arena allocate the location string
|
2003-05-14 02:50:03 +04:00
|
|
|
mLocation = ArenaStrndup(aLocation, locationlen, &nsComponentManagerImpl::gComponentManager->mArena);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID &aClass,
|
|
|
|
nsIFactory *aFactory,
|
2003-05-14 02:50:03 +04:00
|
|
|
class nsFactoryEntry* parent)
|
|
|
|
: mCid(aClass), mTypeIndex(NS_COMPONENT_TYPE_FACTORY_ONLY), mParent(parent)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2003-05-14 02:50:03 +04:00
|
|
|
mFactory = aFactory;
|
|
|
|
mLocation = nsnull;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2002-05-03 01:25:08 +04:00
|
|
|
// nsFactoryEntry is usually arena allocated including the strings it
|
|
|
|
// holds. So we call destructor by hand.
|
1999-03-09 12:44:27 +03:00
|
|
|
nsFactoryEntry::~nsFactoryEntry(void)
|
|
|
|
{
|
2002-05-03 01:25:08 +04:00
|
|
|
// Release the reference to the factory
|
2003-05-14 02:50:03 +04:00
|
|
|
mFactory = nsnull;
|
2002-05-03 01:25:08 +04:00
|
|
|
|
|
|
|
// Release any service reference
|
|
|
|
mServiceObject = nsnull;
|
2003-05-14 02:50:03 +04:00
|
|
|
|
|
|
|
// nsFactoryEntry is arena allocated. So we dont delete it.
|
|
|
|
// We call the destructor by hand.
|
|
|
|
if (mParent)
|
|
|
|
mParent->~nsFactoryEntry();
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2001-08-22 02:42:35 +04:00
|
|
|
nsresult
|
2001-08-30 18:10:41 +04:00
|
|
|
nsFactoryEntry::ReInit(const nsCID &aClass, const char *aLocation, int aType)
|
2001-08-22 02:42:35 +04:00
|
|
|
{
|
2003-05-14 02:50:03 +04:00
|
|
|
NS_ENSURE_TRUE(mTypeIndex != NS_COMPONENT_TYPE_FACTORY_ONLY, NS_ERROR_INVALID_ARG);
|
2001-09-08 04:01:03 +04:00
|
|
|
// cid has to match
|
|
|
|
// SERVICE_ONLY entries can be promoted to an entry of another type
|
2003-05-14 02:50:03 +04:00
|
|
|
NS_ENSURE_TRUE((mTypeIndex == NS_COMPONENT_TYPE_SERVICE_ONLY || mCid.Equals(aClass)),
|
2001-09-08 04:01:03 +04:00
|
|
|
NS_ERROR_INVALID_ARG);
|
2002-05-03 01:25:08 +04:00
|
|
|
|
|
|
|
// Arena allocate the location string
|
2003-05-14 02:50:03 +04:00
|
|
|
mLocation = ArenaStrdup(aLocation, &nsComponentManagerImpl::gComponentManager->mArena);
|
2002-05-03 01:25:08 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
mTypeIndex = aType;
|
2001-08-22 02:42:35 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-01-30 00:22:13 +03:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2002-01-30 00:22:13 +03:00
|
|
|
// Hashtable Enumeration
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2002-01-30 00:22:13 +03:00
|
|
|
typedef NS_CALLBACK(EnumeratorConverter)(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *hdr,
|
|
|
|
void *data,
|
|
|
|
nsISupports **retval);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
class PLDHashTableEnumeratorImpl : public nsIBidirectionalEnumerator,
|
2002-01-30 00:22:13 +03:00
|
|
|
public nsISimpleEnumerator
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIENUMERATOR
|
|
|
|
NS_DECL_NSIBIDIRECTIONALENUMERATOR
|
|
|
|
NS_DECL_NSISIMPLEENUMERATOR
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
PLDHashTableEnumeratorImpl(PLDHashTable *table,
|
|
|
|
EnumeratorConverter converter,
|
|
|
|
void *converterData);
|
|
|
|
PRInt32 Count() { return mCount; }
|
|
|
|
private:
|
|
|
|
PLDHashTableEnumeratorImpl(); /* no implementation */
|
2004-01-22 04:01:19 +03:00
|
|
|
|
|
|
|
~PLDHashTableEnumeratorImpl();
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_IMETHODIMP ReleaseElements();
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
nsVoidArray mElements;
|
|
|
|
PRInt32 mCount, mCurrent;
|
|
|
|
PRMonitor* mMonitor;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
struct Closure {
|
|
|
|
PRBool succeeded;
|
|
|
|
EnumeratorConverter converter;
|
|
|
|
void *data;
|
|
|
|
PLDHashTableEnumeratorImpl *impl;
|
|
|
|
};
|
1999-10-22 01:34:39 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
static PLDHashOperator PR_CALLBACK Enumerator(PLDHashTable *table,
|
2003-06-19 03:03:08 +04:00
|
|
|
PLDHashEntryHdr *hdr,
|
2002-01-30 00:22:13 +03:00
|
|
|
PRUint32 number,
|
|
|
|
void *data);
|
|
|
|
};
|
1999-10-22 01:34:39 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
// static
|
|
|
|
PLDHashOperator PR_CALLBACK
|
|
|
|
PLDHashTableEnumeratorImpl::Enumerator(PLDHashTable *table,
|
2003-06-19 03:03:08 +04:00
|
|
|
PLDHashEntryHdr *hdr,
|
2002-01-30 00:22:13 +03:00
|
|
|
PRUint32 number,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
Closure *c = NS_REINTERPRET_CAST(Closure *, data);
|
|
|
|
nsISupports *converted;
|
|
|
|
if (NS_FAILED(c->converter(table, hdr, c->data, &converted)) ||
|
|
|
|
!c->impl->mElements.AppendElement(converted)) {
|
|
|
|
c->succeeded = PR_FALSE;
|
|
|
|
return PL_DHASH_STOP;
|
2000-10-29 02:17:53 +04:00
|
|
|
}
|
1999-06-14 06:07:03 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
c->succeeded = PR_TRUE;
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
PLDHashTableEnumeratorImpl::PLDHashTableEnumeratorImpl(PLDHashTable *table,
|
2002-01-30 00:22:13 +03:00
|
|
|
EnumeratorConverter converter,
|
2003-06-19 03:03:08 +04:00
|
|
|
void *converterData)
|
2002-01-30 00:22:13 +03:00
|
|
|
: mCurrent(0)
|
|
|
|
{
|
|
|
|
mMonitor = nsAutoMonitor::NewMonitor("PLDHashTableEnumeratorImpl");
|
|
|
|
NS_ASSERTION(mMonitor, "NULL Monitor");
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
Closure c = { PR_FALSE, converter, converterData, this };
|
|
|
|
mCount = PL_DHashTableEnumerate(table, Enumerator, &c);
|
|
|
|
if (!c.succeeded) {
|
|
|
|
ReleaseElements();
|
|
|
|
mCount = 0;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMPL_ISUPPORTS3(PLDHashTableEnumeratorImpl,
|
2002-01-30 00:22:13 +03:00
|
|
|
nsIBidirectionalEnumerator,
|
|
|
|
nsIEnumerator,
|
2003-09-08 04:31:50 +04:00
|
|
|
nsISimpleEnumerator)
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
PLDHashTableEnumeratorImpl::~PLDHashTableEnumeratorImpl()
|
|
|
|
{
|
|
|
|
(void) ReleaseElements();
|
1999-09-01 01:40:21 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
// Destroy the Lock
|
|
|
|
if (mMonitor)
|
2002-04-16 02:33:03 +04:00
|
|
|
nsAutoMonitor::DestroyMonitor(mMonitor);
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PLDHashTableEnumeratorImpl::ReleaseElements()
|
|
|
|
{
|
|
|
|
for (PRInt32 i = 0; i < mCount; i++) {
|
|
|
|
nsISupports *supports = NS_REINTERPRET_CAST(nsISupports *,
|
|
|
|
mElements[i]);
|
|
|
|
NS_IF_RELEASE(supports);
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
2002-01-30 00:22:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-06-21 00:21:49 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PL_NewDHashTableEnumerator(PLDHashTable *table,
|
|
|
|
EnumeratorConverter converter,
|
2003-06-19 03:03:08 +04:00
|
|
|
void *converterData,
|
2002-01-30 00:22:13 +03:00
|
|
|
PLDHashTableEnumeratorImpl **retval)
|
|
|
|
{
|
|
|
|
PLDHashTableEnumeratorImpl *impl =
|
|
|
|
new PLDHashTableEnumeratorImpl(table, converter, converterData);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
if (!impl)
|
2001-08-30 18:10:41 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2004-01-22 04:01:19 +03:00
|
|
|
NS_ADDREF(impl);
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
if (impl->Count() == -1) {
|
|
|
|
// conversion failed
|
2004-01-22 04:01:19 +03:00
|
|
|
NS_RELEASE(impl);
|
2002-01-30 00:22:13 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2001-06-21 00:21:49 +04:00
|
|
|
}
|
2001-09-01 01:45:58 +04:00
|
|
|
|
2004-01-22 04:01:19 +03:00
|
|
|
*retval = impl;
|
2002-01-30 00:22:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PLDHashTableEnumeratorImpl::First()
|
|
|
|
{
|
|
|
|
if (!mCount)
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
mCurrent = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-25 00:28:28 +03:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PLDHashTableEnumeratorImpl::Last()
|
|
|
|
{
|
|
|
|
if (!mCount)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
mCurrent = mCount - 1;
|
1999-06-14 06:07:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PLDHashTableEnumeratorImpl::Prev()
|
1999-06-14 06:07:03 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
if (!mCurrent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mCurrent--;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PLDHashTableEnumeratorImpl::Next()
|
|
|
|
{
|
|
|
|
// If empty or we're past the end, or we are at the end return error
|
|
|
|
if (!mCount || (mCurrent == mCount) || (++mCurrent == mCount))
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PLDHashTableEnumeratorImpl::CurrentItem(nsISupports **retval)
|
|
|
|
{
|
|
|
|
if (!mCount || mCurrent == mCount)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*retval = NS_REINTERPRET_CAST(nsISupports *, mElements[mCurrent]);
|
|
|
|
if (*retval)
|
|
|
|
NS_ADDREF(*retval);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PLDHashTableEnumeratorImpl::IsDone()
|
|
|
|
{
|
|
|
|
if (!mCount || (mCurrent == mCount))
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-11-25 14:21:22 +03:00
|
|
|
return NS_ENUMERATOR_FALSE;
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-01-30 00:22:13 +03:00
|
|
|
PLDHashTableEnumeratorImpl::HasMoreElements(PRBool *_retval)
|
|
|
|
{
|
|
|
|
if (!mCount || (mCurrent == mCount))
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
else
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-01-30 00:22:13 +03:00
|
|
|
PLDHashTableEnumeratorImpl::GetNext(nsISupports **_retval)
|
|
|
|
{
|
|
|
|
nsresult rv = Next();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return CurrentItem(_retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_IMETHODIMP
|
|
|
|
ConvertFactoryEntryToCID(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *hdr,
|
|
|
|
void *data, nsISupports **retval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-02-13 23:34:14 +03:00
|
|
|
nsCOMPtr<nsISupportsID> wrapper;
|
|
|
|
|
|
|
|
nsComponentManagerImpl *cm = NS_STATIC_CAST(nsComponentManagerImpl *, data);
|
|
|
|
|
|
|
|
rv = cm->CreateInstanceByContractID(NS_SUPPORTS_ID_CONTRACTID, nsnull,
|
|
|
|
NS_GET_IID(nsISupportsID), getter_AddRefs(wrapper));
|
2002-01-30 00:22:13 +03:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
const nsFactoryTableEntry *entry =
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_REINTERPRET_CAST(const nsFactoryTableEntry *, hdr);
|
2002-10-06 03:59:57 +04:00
|
|
|
if (entry) {
|
2002-01-30 00:22:13 +03:00
|
|
|
nsFactoryEntry *fe = entry->mFactoryEntry;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
wrapper->SetData(&fe->mCid);
|
2002-01-30 00:22:13 +03:00
|
|
|
*retval = wrapper;
|
|
|
|
NS_ADDREF(*retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
*retval = nsnull;
|
2002-01-30 00:22:13 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_IMETHODIMP
|
|
|
|
ConvertContractIDKeyToString(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *hdr,
|
|
|
|
void *data, nsISupports **retval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> wrapper;
|
2002-02-13 23:34:14 +03:00
|
|
|
|
|
|
|
nsComponentManagerImpl *cm = NS_STATIC_CAST(nsComponentManagerImpl *, data);
|
|
|
|
|
2002-08-06 04:53:19 +04:00
|
|
|
rv = cm->CreateInstanceByContractID(NS_SUPPORTS_CSTRING_CONTRACTID, nsnull,
|
|
|
|
NS_GET_IID(nsISupportsCString), getter_AddRefs(wrapper));
|
2002-01-30 00:22:13 +03:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
const nsContractIDTableEntry *entry =
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_REINTERPRET_CAST(const nsContractIDTableEntry *, hdr);
|
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
wrapper->SetData(nsDependentCString(entry->mContractID,
|
|
|
|
entry->mContractIDLen));
|
2002-01-30 00:22:13 +03:00
|
|
|
*retval = wrapper;
|
|
|
|
NS_ADDREF(*retval);
|
2003-06-19 03:03:08 +04:00
|
|
|
return NS_OK;
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
|
|
|
|
2003-01-29 01:07:53 +03:00
|
|
|
// this is safe to call during InitXPCOM
|
2003-06-19 03:03:08 +04:00
|
|
|
static nsresult GetLocationFromDirectoryService(const char* prop,
|
2003-03-05 06:22:12 +03:00
|
|
|
nsIFile** aDirectory)
|
2003-01-29 01:07:53 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProperties> directoryService;
|
2003-06-19 03:03:08 +04:00
|
|
|
nsDirectoryService::Create(nsnull,
|
|
|
|
NS_GET_IID(nsIProperties),
|
|
|
|
getter_AddRefs(directoryService));
|
|
|
|
|
|
|
|
if (!directoryService)
|
2003-01-29 01:07:53 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-06-19 03:03:08 +04:00
|
|
|
|
|
|
|
return directoryService->Get(prop,
|
|
|
|
NS_GET_IID(nsIFile),
|
2003-01-29 01:07:53 +03:00
|
|
|
(void**)aDirectory);
|
|
|
|
}
|
2002-01-30 00:22:13 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsComponentManagerImpl
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
nsComponentManagerImpl::nsComponentManagerImpl()
|
2003-06-19 03:03:08 +04:00
|
|
|
:
|
|
|
|
mMon(NULL),
|
2002-01-30 00:22:13 +03:00
|
|
|
mNativeComponentLoader(0),
|
2003-03-05 06:22:12 +03:00
|
|
|
#ifdef ENABLE_STATIC_COMPONENT_LOADER
|
2002-01-30 00:22:13 +03:00
|
|
|
mStaticComponentLoader(0),
|
2003-03-05 06:22:12 +03:00
|
|
|
#endif
|
2003-06-19 03:03:08 +04:00
|
|
|
mShuttingDown(NS_SHUTDOWN_NEVERHAPPENED),
|
2002-06-15 01:33:05 +04:00
|
|
|
mLoaderData(nsnull),
|
|
|
|
mRegistryDirty(PR_FALSE)
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
mFactories.ops = nsnull;
|
|
|
|
mContractIDs.ops = nsnull;
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
nsresult nsComponentManagerImpl::Init(void)
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
PR_ASSERT(mShuttingDown != NS_SHUTDOWN_INPROGRESS);
|
|
|
|
if (mShuttingDown == NS_SHUTDOWN_INPROGRESS)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mShuttingDown = NS_SHUTDOWN_NEVERHAPPENED;
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
if (nsComponentManagerLog == nsnull)
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
nsComponentManagerLog = PR_NewLogModule("nsComponentManager");
|
|
|
|
}
|
|
|
|
|
2002-05-03 01:25:08 +04:00
|
|
|
// Initialize our arena
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "ComponentManagerArena", NS_CM_BLOCK_SIZE);
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
if (!mFactories.ops) {
|
|
|
|
if (!PL_DHashTableInit(&mFactories, &factory_DHashTableOps,
|
|
|
|
0, sizeof(nsFactoryTableEntry),
|
|
|
|
1024)) {
|
|
|
|
mFactories.ops = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
// Minimum alpha uses k=2 because nsFactoryTableEntry saves two
|
2002-01-30 00:22:13 +03:00
|
|
|
// words compared to what a chained hash table requires.
|
|
|
|
PL_DHashTableSetAlphaBounds(&mFactories,
|
|
|
|
0.875,
|
2003-03-14 08:07:24 +03:00
|
|
|
PL_DHASH_MIN_ALPHA(&mFactories, 2));
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mContractIDs.ops) {
|
|
|
|
if (!PL_DHashTableInit(&mContractIDs, &contractID_DHashTableOps,
|
|
|
|
0, sizeof(nsContractIDTableEntry),
|
|
|
|
1024)) {
|
|
|
|
mContractIDs.ops = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
// Minimum alpha uses k=1 because nsContractIDTableEntry saves one
|
|
|
|
// word compared to what a chained hash table requires.
|
|
|
|
#if 0
|
2002-10-06 03:59:57 +04:00
|
|
|
PL_DHashTableSetAlphaBounds(&mContractIDs,
|
|
|
|
0.875,
|
2003-03-14 08:07:24 +03:00
|
|
|
PL_DHASH_MIN_ALPHA(&mContractIDs, 1));
|
|
|
|
#endif
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
2002-04-16 02:33:03 +04:00
|
|
|
if (mMon == nsnull) {
|
|
|
|
mMon = nsAutoMonitor::NewMonitor("nsComponentManagerImpl");
|
|
|
|
if (mMon == nsnull)
|
2002-01-30 00:22:13 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNativeComponentLoader == nsnull) {
|
|
|
|
/* Create the NativeComponentLoader */
|
|
|
|
mNativeComponentLoader = new nsNativeComponentLoader();
|
|
|
|
if (!mNativeComponentLoader)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mNativeComponentLoader);
|
2002-06-15 01:33:05 +04:00
|
|
|
|
|
|
|
nsresult rv = mNativeComponentLoader->Init(this, nsnull);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add predefined loaders
|
|
|
|
mLoaderData = (nsLoaderdata *) PR_Malloc(sizeof(nsLoaderdata) * NS_LOADER_DATA_ALLOC_STEP);
|
|
|
|
if (!mLoaderData)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
mMaxNLoaderData = NS_LOADER_DATA_ALLOC_STEP;
|
|
|
|
|
|
|
|
mNLoaderData = NS_COMPONENT_TYPE_NATIVE;
|
|
|
|
mLoaderData[mNLoaderData].type = PL_strdup(nativeComponentType);
|
|
|
|
mLoaderData[mNLoaderData].loader = mNativeComponentLoader;
|
|
|
|
NS_ADDREF(mLoaderData[mNLoaderData].loader);
|
|
|
|
mNLoaderData++;
|
|
|
|
|
|
|
|
#ifdef ENABLE_STATIC_COMPONENT_LOADER
|
|
|
|
if (mStaticComponentLoader == nsnull) {
|
|
|
|
extern nsresult NS_NewStaticComponentLoader(nsIComponentLoader **);
|
|
|
|
NS_NewStaticComponentLoader(&mStaticComponentLoader);
|
|
|
|
if (!mStaticComponentLoader)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLoaderData[mNLoaderData].type = PL_strdup(staticComponentType);
|
|
|
|
mLoaderData[mNLoaderData].loader = mStaticComponentLoader;
|
|
|
|
NS_ADDREF(mLoaderData[mNLoaderData].loader);
|
|
|
|
mNLoaderData++;
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (mStaticComponentLoader) {
|
|
|
|
/* Init the static loader */
|
|
|
|
mStaticComponentLoader->Init(this, nsnull);
|
|
|
|
}
|
2002-01-30 00:22:13 +03:00
|
|
|
#endif
|
2003-03-05 06:22:12 +03:00
|
|
|
GetLocationFromDirectoryService(NS_XPCOM_COMPONENT_DIR, getter_AddRefs(mComponentsDir));
|
2002-06-15 01:33:05 +04:00
|
|
|
if (!mComponentsDir)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsCAutoString componentDescriptor;
|
|
|
|
nsresult rv = mComponentsDir->GetNativePath(componentDescriptor);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mComponentsOffset = componentDescriptor.Length();
|
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
GetLocationFromDirectoryService(NS_GRE_COMPONENT_DIR, getter_AddRefs(mGREComponentsDir));
|
|
|
|
if (mGREComponentsDir) {
|
|
|
|
nsresult rv = mGREComponentsDir->GetNativePath(componentDescriptor);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("No GRE component manager");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mGREComponentsOffset = componentDescriptor.Length();
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
GetLocationFromDirectoryService(NS_XPCOM_COMPONENT_REGISTRY_FILE,
|
2003-03-12 00:36:59 +03:00
|
|
|
getter_AddRefs(mRegistryFile));
|
|
|
|
|
|
|
|
if(!mRegistryFile) {
|
|
|
|
NS_WARNING("No Component Registry file was found in the directory service");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
2002-01-30 00:22:13 +03:00
|
|
|
("nsComponentManager: Initialized."));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
PRIntn PR_CALLBACK AutoRegEntryDestroy(nsHashKey *aKey, void *aData, void* aClosure)
|
|
|
|
{
|
|
|
|
delete (AutoRegEntry*)aData;
|
|
|
|
return kHashEnumerateNext;
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
nsresult nsComponentManagerImpl::Shutdown(void)
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
PR_ASSERT(mShuttingDown == NS_SHUTDOWN_NEVERHAPPENED);
|
|
|
|
if (mShuttingDown != NS_SHUTDOWN_NEVERHAPPENED)
|
1999-10-22 01:34:39 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mShuttingDown = NS_SHUTDOWN_INPROGRESS;
|
|
|
|
|
|
|
|
// Shutdown the component manager
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning Shutdown."));
|
1999-07-31 09:55:04 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
PRInt32 i;
|
|
|
|
|
|
|
|
// Write out our component data file.
|
|
|
|
if (mRegistryDirty) {
|
|
|
|
nsresult rv = WritePersistentRegistry();
|
|
|
|
if (NS_FAILED(rv)) {
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, ("nsComponentManager: Could not write out perisistant registry."));
|
2002-06-15 01:33:05 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Could not write out perisistant registry!\n");
|
2003-06-19 03:03:08 +04:00
|
|
|
#endif
|
2002-06-15 01:33:05 +04:00
|
|
|
}
|
2003-06-19 03:03:08 +04:00
|
|
|
}
|
2003-03-05 06:22:12 +03:00
|
|
|
|
|
|
|
mAutoRegEntries.Reset(AutoRegEntryDestroy);
|
2002-06-15 01:33:05 +04:00
|
|
|
|
1999-07-31 09:55:04 +04:00
|
|
|
// Release all cached factories
|
2001-10-23 06:28:12 +04:00
|
|
|
if (mContractIDs.ops) {
|
|
|
|
PL_DHashTableFinish(&mContractIDs);
|
|
|
|
mContractIDs.ops = nsnull;
|
|
|
|
}
|
|
|
|
if (mFactories.ops) {
|
|
|
|
PL_DHashTableFinish(&mFactories);
|
|
|
|
mFactories.ops = nsnull;
|
|
|
|
}
|
1999-07-31 09:55:04 +04:00
|
|
|
// Unload libraries
|
2002-04-16 02:33:03 +04:00
|
|
|
UnloadLibraries(nsnull, NS_Shutdown);
|
1999-07-31 09:55:04 +04:00
|
|
|
|
2002-05-03 01:25:08 +04:00
|
|
|
// delete arena for strings and small objects
|
|
|
|
PL_FinishArenaPool(&mArena);
|
|
|
|
|
2000-05-12 05:24:36 +04:00
|
|
|
mComponentsDir = 0;
|
1999-09-21 00:53:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
mCategoryManager = 0;
|
|
|
|
|
2001-08-30 18:10:41 +04:00
|
|
|
// Release all the component data - loaders and type strings
|
2002-10-06 03:59:57 +04:00
|
|
|
for (i=0; i < mNLoaderData; i++) {
|
2001-08-30 18:10:41 +04:00
|
|
|
NS_IF_RELEASE(mLoaderData[i].loader);
|
|
|
|
PL_strfree((char *)mLoaderData[i].type);
|
|
|
|
}
|
|
|
|
PR_Free(mLoaderData);
|
|
|
|
mLoaderData = nsnull;
|
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);
|
2001-06-21 00:21:49 +04:00
|
|
|
#ifdef ENABLE_STATIC_COMPONENT_LOADER
|
|
|
|
NS_IF_RELEASE(mStaticComponentLoader);
|
|
|
|
#endif
|
2002-10-06 03:59:57 +04:00
|
|
|
|
1999-10-22 01:34:39 +04:00
|
|
|
mShuttingDown = NS_SHUTDOWN_COMPLETE;
|
1999-07-31 09:55:04 +04:00
|
|
|
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Shutdown complete."));
|
1999-10-22 01:34:39 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsComponentManagerImpl::~nsComponentManagerImpl()
|
|
|
|
{
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning destruction."));
|
1999-10-22 01:34:39 +04:00
|
|
|
|
|
|
|
if (mShuttingDown != NS_SHUTDOWN_COMPLETE)
|
|
|
|
Shutdown();
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
if (mMon) {
|
|
|
|
nsAutoMonitor::DestroyMonitor(mMon);
|
|
|
|
}
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Destroyed."));
|
1999-06-14 06:07:03 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS8(nsComponentManagerImpl,
|
|
|
|
nsIComponentManager,
|
2001-10-16 07:35:52 +04:00
|
|
|
nsIServiceManager,
|
2003-06-19 03:03:08 +04:00
|
|
|
nsISupportsWeakReference,
|
2001-10-17 03:39:20 +04:00
|
|
|
nsIInterfaceRequestor,
|
2002-01-30 00:22:13 +03:00
|
|
|
nsIComponentRegistrar,
|
2001-12-19 03:12:41 +03:00
|
|
|
nsIServiceManagerObsolete,
|
2002-06-15 01:33:05 +04:00
|
|
|
nsIComponentManagerObsolete,
|
|
|
|
nsIComponentLoaderManager)
|
1999-06-14 06:07:03 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::GetInterface(const nsIID & uuid, void **result)
|
|
|
|
{
|
2003-03-05 06:22:12 +03:00
|
|
|
if (uuid.Equals(NS_GET_IID(nsINativeComponentLoader)))
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
2003-03-05 06:22:12 +03:00
|
|
|
if (!mNativeComponentLoader)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
return mNativeComponentLoader->QueryInterface(uuid, result);
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
NS_WARNING("This isn't supported");
|
|
|
|
// fall through to QI as anything QIable is a superset of what can be
|
2002-01-30 00:22:13 +03:00
|
|
|
// got via the GetInterface()
|
|
|
|
return QueryInterface(uuid, result);
|
|
|
|
}
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsComponentManagerImpl: Platform methods
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
#define PERSISTENT_REGISTRY_VERSION_MINOR 5
|
|
|
|
#define PERSISTENT_REGISTRY_VERSION_MAJOR 0
|
2002-10-06 03:59:57 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
AutoRegEntry::AutoRegEntry(const nsACString& name, PRInt64* modDate) :
|
|
|
|
mName(ToNewCString(name)),
|
|
|
|
mNameLen(name.Length()),
|
|
|
|
mData(nsnull),
|
|
|
|
mModDate(*modDate)
|
1999-06-14 06:07:03 +04:00
|
|
|
{
|
2002-06-15 01:33:05 +04:00
|
|
|
}
|
2003-03-14 08:07:24 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
AutoRegEntry::~AutoRegEntry()
|
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
if (mName) PL_strfree(mName);
|
2003-03-05 06:22:12 +03:00
|
|
|
if (mData) PL_strfree(mData);
|
2002-06-15 01:33:05 +04:00
|
|
|
}
|
2001-04-17 18:25:19 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
PRBool
|
2002-06-15 01:33:05 +04:00
|
|
|
AutoRegEntry::Modified(PRInt64 *date)
|
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
return !LL_EQ(*date, mModDate);
|
2002-06-15 01:33:05 +04:00
|
|
|
}
|
1999-04-06 12:26:38 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
void
|
|
|
|
AutoRegEntry::SetOptionalData(const char* data)
|
|
|
|
{
|
|
|
|
if (mData)
|
|
|
|
PL_strfree(mData);
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
mData = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mData = PL_strdup(data);
|
|
|
|
}
|
1999-04-06 12:26:38 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
static
|
|
|
|
PRBool ReadSectionHeader(nsManifestLineReader& reader, const char *token)
|
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
while (1)
|
2002-06-15 01:33:05 +04:00
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
if (*reader.LinePtr() == '[')
|
2002-06-15 01:33:05 +04:00
|
|
|
{
|
|
|
|
char* p = reader.LinePtr() + (reader.LineLength() - 1);
|
2002-10-06 03:59:57 +04:00
|
|
|
if (*p != ']')
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
|
|
|
*p = 0;
|
1999-04-06 12:26:38 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
char* values[1];
|
2002-08-27 22:32:12 +04:00
|
|
|
int lengths[1];
|
2002-10-06 03:59:57 +04:00
|
|
|
if (2 != reader.ParseLine(values, lengths, 1))
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
2001-11-30 10:50:03 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
// ignore the leading '['
|
2002-10-06 03:59:57 +04:00
|
|
|
if (0 != PL_strcmp(values[0]+1, token))
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
2001-11-30 10:50:03 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
|
|
|
if (!reader.NextLine())
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::ReadPersistentRegistry()
|
|
|
|
{
|
2001-11-30 10:50:03 +03:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
// populate Category Manager. need to get this early so that we don't get
|
2002-06-15 01:33:05 +04:00
|
|
|
// skipped by 'goto out'
|
2003-06-19 03:03:08 +04:00
|
|
|
nsresult rv = GetService(kCategoryManagerCID,
|
|
|
|
NS_GET_IID(nsICategoryManager),
|
|
|
|
getter_AddRefs(mCategoryManager));
|
2002-04-27 09:33:09 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-12-14 04:27:16 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsManifestLineReader reader;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (!mComponentsDir)
|
2003-03-12 00:36:59 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED; // this should have been set by Init().
|
2001-06-21 00:21:49 +04:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
PRFileDesc* fd = nsnull;
|
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
// Set From Init
|
|
|
|
if (!mRegistryFile) {
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
mRegistryFile->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &fd);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
PRInt64 fileSize;
|
|
|
|
rv = localFile->GetFileSize(&fileSize);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_Close(fd);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 flen = nsInt64(fileSize);
|
|
|
|
if (flen == 0)
|
|
|
|
{
|
|
|
|
PR_Close(fd);
|
|
|
|
NS_WARNING("Persistent Registry Empty!");
|
|
|
|
return NS_OK; // ERROR CONDITION
|
|
|
|
}
|
|
|
|
|
|
|
|
char* registry = new char[flen+1];
|
|
|
|
if (!registry)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (flen > PR_Read(fd, registry, flen))
|
|
|
|
{
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-06-19 03:03:08 +04:00
|
|
|
registry[flen] = '\0';
|
2002-10-06 03:59:57 +04:00
|
|
|
|
|
|
|
reader.Init(registry, flen);
|
|
|
|
|
|
|
|
if (ReadSectionHeader(reader, "HEADER"))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!reader.NextLine())
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
char* values[6];
|
|
|
|
int lengths[6];
|
|
|
|
|
|
|
|
// VersionLiteral,major,minor
|
|
|
|
if (3 != reader.ParseLine(values, lengths, 3))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
// VersionLiteral
|
2004-05-23 02:15:22 +04:00
|
|
|
if (!nsDependentCString(values[0], lengths[0]).EqualsLiteral("Version"))
|
2002-06-15 01:33:05 +04:00
|
|
|
goto out;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
// major
|
2002-10-06 03:59:57 +04:00
|
|
|
if (PERSISTENT_REGISTRY_VERSION_MAJOR != atoi(values[1]))
|
2002-06-15 01:33:05 +04:00
|
|
|
goto out;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
// minor
|
2002-10-06 03:59:57 +04:00
|
|
|
if (PERSISTENT_REGISTRY_VERSION_MINOR != atoi(values[2]))
|
2002-06-15 01:33:05 +04:00
|
|
|
goto out;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (ReadSectionHeader(reader, "COMPONENTS"))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
while (1)
|
1999-03-31 11:04:12 +04:00
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!reader.NextLine())
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
//name,last_modification_date[,optionaldata]
|
|
|
|
int parts = reader.ParseLine(values, lengths, 3);
|
|
|
|
if (2 > parts)
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
2000-02-16 10:45:20 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
PRInt64 a = nsCRT::atoll(values[1]);
|
2003-03-14 08:07:24 +03:00
|
|
|
AutoRegEntry *entry =
|
|
|
|
new AutoRegEntry(nsDependentCString(values[0], lengths[0]), &a);
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-09-02 11:00:29 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
if (parts == 3)
|
|
|
|
entry->SetOptionalData(values[2]);
|
|
|
|
|
|
|
|
nsCStringKey key((const char*)values[0]);
|
|
|
|
mAutoRegEntries.Put(&key, entry);
|
2002-06-15 01:33:05 +04:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (ReadSectionHeader(reader, "CLASSIDS"))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
while (1)
|
2000-05-12 05:24:36 +04:00
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!reader.NextLine())
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
2000-05-12 05:24:36 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
// cid,contract_id,type,class_name,inproc_server
|
2002-10-06 03:59:57 +04:00
|
|
|
if (5 != reader.ParseLine(values, lengths, 5))
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
2000-05-12 05:24:36 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
nsCID aClass;
|
|
|
|
if (!aClass.Parse(values[0]))
|
|
|
|
continue;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
int loadertype = GetLoaderType(values[2]);
|
|
|
|
if (loadertype < 0) {
|
2004-03-10 09:40:36 +03:00
|
|
|
rv = AddLoaderType(values[2], &loadertype);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
2002-06-15 01:33:05 +04:00
|
|
|
}
|
2002-06-21 01:22:50 +04:00
|
|
|
|
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
|
|
|
|
if (!mem)
|
2002-06-15 01:33:05 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-06-21 01:22:50 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
nsFactoryEntry *entry = new (mem) nsFactoryEntry(aClass, values[4], lengths[4], loadertype);
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
nsFactoryTableEntry* factoryTableEntry =
|
|
|
|
NS_STATIC_CAST(nsFactoryTableEntry*,
|
2003-06-19 03:03:08 +04:00
|
|
|
PL_DHashTableOperate(&mFactories,
|
2002-06-15 01:33:05 +04:00
|
|
|
&aClass,
|
|
|
|
PL_DHASH_ADD));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (!factoryTableEntry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
factoryTableEntry->mFactoryEntry = entry;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (ReadSectionHeader(reader, "CONTRACTIDS"))
|
|
|
|
goto out;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
while (1)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!reader.NextLine())
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
//contractID,cid
|
2002-10-06 03:59:57 +04:00
|
|
|
if (2 != reader.ParseLine(values, lengths, 2))
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
nsCID aClass;
|
|
|
|
if (!aClass.Parse(values[1]))
|
|
|
|
continue;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
//need to find the location for this cid.
|
|
|
|
nsFactoryEntry *cidEntry = GetFactoryEntry(aClass);
|
2003-05-14 02:50:03 +04:00
|
|
|
if (!cidEntry || cidEntry->mTypeIndex < 0)
|
2002-06-15 01:33:05 +04:00
|
|
|
continue; //what should we really do?
|
1999-03-31 11:04:12 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
2003-06-19 03:03:08 +04:00
|
|
|
PL_DHashTableOperate(&mContractIDs,
|
2002-06-15 01:33:05 +04:00
|
|
|
values[0],
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (!contractIDTableEntry) {
|
|
|
|
continue;
|
2001-08-30 18:10:41 +04:00
|
|
|
}
|
1999-03-10 12:53:25 +03:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
if (!contractIDTableEntry->mContractID) {
|
|
|
|
contractIDTableEntry->mContractID = ArenaStrndup(values[0], lengths[0], &mArena);
|
|
|
|
contractIDTableEntry->mContractIDLen = lengths[0];
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
contractIDTableEntry->mFactoryEntry = cidEntry;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
#ifdef XPCOM_CHECK_PENDING_CIDS
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If you get Asserts when you define SHOW_CI_ON_EXISTING_SERVICE and want to
|
|
|
|
* track down their cause, then you should add the contracts listed by the
|
|
|
|
* assertion to abusedContracts. The next time you run your xpcom app, xpcom
|
|
|
|
* will assert the first time the object associated with the contract is
|
|
|
|
* instantiated (which in many cases is the source of the problem).
|
|
|
|
*
|
|
|
|
* If you're doing this then you might want to NOP and soft breakpoint the
|
|
|
|
* lines labeled: NOP_AND_BREAK.
|
|
|
|
*
|
|
|
|
* Otherwise XPCOM will refuse to create the object for the caller, which
|
|
|
|
* while reasonable at some level, will almost certainly cause the app to
|
|
|
|
* stop functioning normally.
|
|
|
|
*/
|
|
|
|
static char abusedContracts[][128] = {
|
|
|
|
/*// Example contracts:
|
|
|
|
"@mozilla.org/rdf/container;1",
|
|
|
|
"@mozilla.org/intl/charsetalias;1",
|
|
|
|
"@mozilla.org/locale/win32-locale;1",
|
|
|
|
"@mozilla.org/widget/lookandfeel/win;1",
|
2004-03-10 09:40:36 +03:00
|
|
|
// */
|
2003-06-19 03:03:08 +04:00
|
|
|
0
|
|
|
|
};
|
|
|
|
for (int i=0; abusedContracts[i] && *abusedContracts[i]; i++) {
|
|
|
|
nsFactoryEntry *entry = nsnull;
|
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mContractIDs, abusedContracts[i],
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(contractIDTableEntry)) {
|
|
|
|
entry = contractIDTableEntry->mFactoryEntry;
|
|
|
|
AddPendingCID(entry->mCid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (ReadSectionHeader(reader, "CATEGORIES"))
|
|
|
|
goto out;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
while (1)
|
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!reader.NextLine())
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
//type,name,value
|
2002-10-06 03:59:57 +04:00
|
|
|
if (3 != reader.ParseLine(values, lengths, 3))
|
2002-06-15 01:33:05 +04:00
|
|
|
break;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
mCategoryManager->AddCategoryEntry(values[0],
|
|
|
|
values[1],
|
|
|
|
values[2],
|
|
|
|
PR_TRUE,
|
|
|
|
PR_TRUE,
|
2002-12-04 02:17:03 +03:00
|
|
|
0);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
mRegistryDirty = PR_FALSE;
|
|
|
|
out:
|
|
|
|
if (fd)
|
|
|
|
PR_Close(fd);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (registry)
|
2002-06-22 23:03:11 +04:00
|
|
|
delete [] registry;
|
1999-03-31 11:04:12 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
struct PersistentWriterArgs
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2002-06-15 01:33:05 +04:00
|
|
|
PRFileDesc *mFD;
|
|
|
|
nsLoaderdata *mLoaderData;
|
|
|
|
};
|
1999-03-10 12:53:25 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
2003-06-19 03:03:08 +04:00
|
|
|
ContractIDWriter(PLDHashTable *table,
|
2002-06-15 01:33:05 +04:00
|
|
|
PLDHashEntryHdr *hdr,
|
2003-06-19 03:03:08 +04:00
|
|
|
PRUint32 number,
|
2002-06-15 01:33:05 +04:00
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
char *contractID = ((nsContractIDTableEntry*)hdr)->mContractID;
|
|
|
|
nsFactoryEntry *factoryEntry = ((nsContractIDTableEntry*)hdr)->mFactoryEntry;
|
2003-05-14 02:50:03 +04:00
|
|
|
|
|
|
|
// for now, we only save out the top most parent.
|
2004-04-18 21:35:29 +04:00
|
|
|
while (factoryEntry->mParent)
|
2003-05-14 02:50:03 +04:00
|
|
|
factoryEntry = factoryEntry->mParent;
|
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (factoryEntry->mTypeIndex < 0)
|
2002-06-15 01:33:05 +04:00
|
|
|
return PL_DHASH_NEXT;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
PRFileDesc* fd = ((PersistentWriterArgs*)arg)->mFD;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
char cidString[UID_STRING_LENGTH];
|
2003-05-14 02:50:03 +04:00
|
|
|
GetIDString(factoryEntry->mCid, cidString);
|
2003-03-14 08:07:24 +03:00
|
|
|
PR_fprintf(fd, "%s,%s\n", contractID, cidString); // what if this fails?
|
2002-06-15 01:33:05 +04:00
|
|
|
return PL_DHASH_NEXT;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
2003-06-19 03:03:08 +04:00
|
|
|
ClassIDWriter(PLDHashTable *table,
|
2002-06-15 01:33:05 +04:00
|
|
|
PLDHashEntryHdr *hdr,
|
2003-06-19 03:03:08 +04:00
|
|
|
PRUint32 number,
|
2002-06-15 01:33:05 +04:00
|
|
|
void *arg)
|
1999-07-02 07:35:09 +04:00
|
|
|
{
|
2002-06-15 01:33:05 +04:00
|
|
|
nsFactoryEntry *factoryEntry = ((nsFactoryTableEntry*)hdr)->mFactoryEntry;
|
|
|
|
PRFileDesc* fd = ((PersistentWriterArgs*)arg)->mFD;
|
|
|
|
nsLoaderdata *loaderData = ((PersistentWriterArgs*)arg)->mLoaderData;
|
2000-09-08 05:51:45 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
// for now, we only save out the top most parent.
|
|
|
|
while (factoryEntry->mParent)
|
|
|
|
factoryEntry = factoryEntry->mParent;
|
2000-09-08 05:51:45 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
if (factoryEntry->mTypeIndex < 0) {
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2003-03-14 08:07:24 +03:00
|
|
|
|
|
|
|
char cidString[UID_STRING_LENGTH];
|
2003-05-14 02:50:03 +04:00
|
|
|
GetIDString(factoryEntry->mCid, cidString);
|
2003-03-14 08:07:24 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
char *contractID = nsnull, *className = nsnull;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(factoryEntry->mFactory);
|
2002-10-06 03:59:57 +04:00
|
|
|
if (classInfo)
|
2002-06-15 01:33:05 +04:00
|
|
|
{
|
|
|
|
classInfo->GetContractID(&contractID);
|
|
|
|
classInfo->GetClassDescription(&className);
|
|
|
|
}
|
1999-07-02 07:35:09 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
const char * loaderName = nsnull;
|
2003-05-14 02:50:03 +04:00
|
|
|
if (factoryEntry->mTypeIndex)
|
|
|
|
loaderName = loaderData[factoryEntry->mTypeIndex].type;
|
1999-07-02 07:35:09 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
char* location = factoryEntry->mLocation;
|
1999-09-08 03:18:47 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
// cid,contract_id,type,class_name,inproc_server
|
|
|
|
PR_fprintf(fd,
|
|
|
|
"%s,%s,%s,%s,%s\n",
|
|
|
|
cidString,
|
|
|
|
(contractID ? contractID : ""),
|
|
|
|
(loaderName ? loaderName : ""),
|
2003-06-19 03:03:08 +04:00
|
|
|
(className ? className : ""),
|
|
|
|
(location ? location : ""));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-10-08 10:12:00 +04:00
|
|
|
if (contractID)
|
|
|
|
PR_Free(contractID);
|
|
|
|
if (className)
|
|
|
|
PR_Free(className);
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2001-11-16 05:38:23 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
PRIntn PR_CALLBACK
|
|
|
|
AutoRegEntryWriter(nsHashKey *aKey, void *aData, void* aClosure)
|
2002-06-15 01:33:05 +04:00
|
|
|
{
|
2003-03-05 06:22:12 +03:00
|
|
|
PRFileDesc* fd = (PRFileDesc*) aClosure;
|
|
|
|
AutoRegEntry* entry = (AutoRegEntry*) aData;
|
2001-11-30 10:50:03 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
const char* extraData = entry->GetOptionalData();
|
|
|
|
const char *fmt;
|
|
|
|
if (extraData)
|
|
|
|
fmt = "%s,%lld,%s\n";
|
|
|
|
else
|
|
|
|
fmt = "%s,%lld\n";
|
2003-03-14 08:07:24 +03:00
|
|
|
PR_fprintf(fd, fmt, entry->GetName().get(), entry->GetDate(), extraData);
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2001-11-30 10:50:03 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::WritePersistentRegistry()
|
|
|
|
{
|
2003-03-12 00:36:59 +03:00
|
|
|
if (!mRegistryFile)
|
2002-06-15 01:33:05 +04:00
|
|
|
return NS_ERROR_FAILURE; // this should have been set by Init().
|
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
mRegistryFile->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
nsCAutoString originalLeafName;
|
|
|
|
localFile->GetNativeLeafName(originalLeafName);
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
nsCAutoString leafName;
|
|
|
|
leafName.Assign(originalLeafName + NS_LITERAL_CSTRING(".tmp"));
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
localFile->SetNativeLeafName(leafName);
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
PRFileDesc* fd = nsnull;
|
|
|
|
nsresult rv = localFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0666, &fd);
|
2002-10-06 03:59:57 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
if (PR_fprintf(fd, "Generated File. Do not edit.\n") == (PRUint32) -1) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2002-10-06 03:59:57 +04:00
|
|
|
goto out;
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
if (PR_fprintf(fd, "\n[HEADER]\nVersion,%d,%d\n",
|
|
|
|
PERSISTENT_REGISTRY_VERSION_MAJOR,
|
|
|
|
PERSISTENT_REGISTRY_VERSION_MINOR) == (PRUint32) -1) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2002-10-06 03:59:57 +04:00
|
|
|
goto out;
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
if (PR_fprintf(fd, "\n[COMPONENTS]\n") == (PRUint32) -1) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2002-10-06 03:59:57 +04:00
|
|
|
goto out;
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
mAutoRegEntries.Enumerate(AutoRegEntryWriter, (void*)fd);
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
PersistentWriterArgs args;
|
|
|
|
args.mFD = fd;
|
|
|
|
args.mLoaderData = mLoaderData;
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
if (PR_fprintf(fd, "\n[CLASSIDS]\n") == (PRUint32) -1) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2002-10-06 03:59:57 +04:00
|
|
|
goto out;
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
|
|
|
|
PL_DHashTableEnumerate(&mFactories, ClassIDWriter, (void*)&args);
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
if (PR_fprintf(fd, "\n[CONTRACTIDS]\n") == (PRUint32) -1) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2002-10-06 03:59:57 +04:00
|
|
|
goto out;
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
PL_DHashTableEnumerate(&mContractIDs, ContractIDWriter, (void*)&args);
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
if (PR_fprintf(fd, "\n[CATEGORIES]\n") == (PRUint32) -1) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2002-10-06 03:59:57 +04:00
|
|
|
goto out;
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
2002-06-15 01:33:05 +04:00
|
|
|
|
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!mCategoryManager) {
|
|
|
|
NS_WARNING("Could not access category manager. Will not be able to save categories!");
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
} else {
|
|
|
|
rv = mCategoryManager->WriteCategoryManagerToRegistry(fd);
|
|
|
|
}
|
2002-06-15 01:33:05 +04:00
|
|
|
|
|
|
|
out:
|
2002-10-06 03:59:57 +04:00
|
|
|
if (fd)
|
|
|
|
PR_Close(fd);
|
2001-11-30 10:50:03 +03:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
// don't create the file is there was a problem????
|
2003-06-18 15:26:27 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
if (!mRegistryFile)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
|
|
|
PRBool exists;
|
2003-03-12 00:36:59 +03:00
|
|
|
if(NS_FAILED(mRegistryFile->Exists(&exists)))
|
|
|
|
return PR_FALSE;
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
if(exists && NS_FAILED(mRegistryFile->Remove(PR_FALSE)))
|
|
|
|
return PR_FALSE;
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
nsCOMPtr<nsIFile> parent;
|
|
|
|
mRegistryFile->GetParent(getter_AddRefs(parent));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-12 00:36:59 +03:00
|
|
|
rv = localFile->MoveToNative(parent, originalLeafName);
|
2002-10-06 03:59:57 +04:00
|
|
|
mRegistryDirty = PR_FALSE;
|
|
|
|
|
|
|
|
return rv;
|
1999-07-02 07:35:09 +04:00
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Hash Functions
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2003-06-19 03:03:08 +04:00
|
|
|
nsresult
|
2003-03-14 08:07:24 +03:00
|
|
|
nsComponentManagerImpl::HashContractID(const char *aContractID,
|
|
|
|
PRUint32 aContractIDLen,
|
|
|
|
nsFactoryEntry *fe)
|
2001-08-22 02:42:35 +04:00
|
|
|
{
|
2003-03-14 08:07:24 +03:00
|
|
|
if(!aContractID || !aContractIDLen)
|
2001-08-22 02:42:35 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mContractIDs, aContractID,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (!contractIDTableEntry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2002-05-03 01:25:08 +04:00
|
|
|
NS_ASSERTION(!contractIDTableEntry->mContractID || !strcmp(contractIDTableEntry->mContractID, aContractID), "contractid conflict");
|
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
if (!contractIDTableEntry->mContractID) {
|
|
|
|
contractIDTableEntry->mContractID = ArenaStrndup(aContractID, aContractIDLen, &mArena);
|
|
|
|
contractIDTableEntry->mContractIDLen = aContractIDLen;
|
|
|
|
}
|
2001-10-23 06:28:12 +04:00
|
|
|
|
|
|
|
contractIDTableEntry->mFactoryEntry = fe;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/**
|
|
|
|
* 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;
|
2002-04-16 02:33:03 +04:00
|
|
|
*aFactory = nsnull;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
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",
|
2003-05-14 02:50:03 +04:00
|
|
|
(const char *)aEntry->mLocation, mLoaderData[aEntry->mTypeIndex].type));
|
1999-03-10 12:53:25 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2002-10-06 03:59:57 +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 *
|
2003-03-14 08:07:24 +03:00
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const char *aContractID,
|
|
|
|
PRUint32 aContractIDLen)
|
1999-07-07 11:47:14 +04:00
|
|
|
{
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry *fe = nsnull;
|
|
|
|
{
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
|
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mContractIDs, aContractID,
|
|
|
|
PL_DHASH_LOOKUP));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(contractIDTableEntry)) {
|
|
|
|
fe = contractIDTableEntry->mFactoryEntry;
|
|
|
|
}
|
|
|
|
} //exit monitor
|
1999-07-07 11:47:14 +04:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
return fe;
|
2001-08-22 02:42:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsFactoryEntry *
|
2002-06-15 01:33:05 +04:00
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const nsCID &aClass)
|
2001-08-22 02:42:35 +04:00
|
|
|
{
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry *entry = nsnull;
|
|
|
|
{
|
|
|
|
nsAutoMonitor mon(mMon);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryTableEntry* factoryTableEntry =
|
|
|
|
NS_STATIC_CAST(nsFactoryTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mFactories, &aClass,
|
|
|
|
PL_DHASH_LOOKUP));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
|
|
|
|
entry = factoryTableEntry->mFactoryEntry;
|
|
|
|
}
|
|
|
|
} // exit monitor
|
2001-08-22 02:42:35 +04:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
return entry;
|
1999-07-07 11:47:14 +04:00
|
|
|
}
|
|
|
|
|
2001-08-22 02:42:35 +04:00
|
|
|
|
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,
|
2003-06-19 03:03:08 +04:00
|
|
|
nsIFactory **aFactory)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2002-04-16 02:33:03 +04:00
|
|
|
PR_ASSERT(aFactory != nsnull);
|
1999-06-19 03:27:09 +04:00
|
|
|
|
2001-08-22 02:42:35 +04:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass);
|
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
|
|
|
}
|
|
|
|
|
2001-08-22 02:42:35 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::FindFactory(const char *contractID,
|
2003-03-14 08:07:24 +03:00
|
|
|
PRUint32 aContractIDLen,
|
2003-06-19 03:03:08 +04:00
|
|
|
nsIFactory **aFactory)
|
2001-08-22 02:42:35 +04:00
|
|
|
{
|
2002-04-16 02:33:03 +04:00
|
|
|
PR_ASSERT(aFactory != nsnull);
|
2001-08-22 02:42:35 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(contractID, aContractIDLen);
|
2001-08-22 02:42:35 +04:00
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (!entry)
|
2001-08-22 02:42:35 +04:00
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
|
|
|
|
return entry->GetFactory(aFactory, this);
|
|
|
|
}
|
|
|
|
|
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,
|
2003-06-19 03:03:08 +04:00
|
|
|
void **aResult)
|
1999-08-19 18:54:12 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFactory> factory;
|
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-17 21:50:00 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG))
|
1999-08-19 18:54:12 +04:00
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", buf);
|
2002-10-08 10:12:00 +04:00
|
|
|
if (buf)
|
|
|
|
PR_Free(buf);
|
1999-08-19 18:54:12 +04:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
1999-08-19 18:54:12 +04:00
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
PR_ASSERT(aResult != nsnull);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
1999-08-19 18:54:12 +04:00
|
|
|
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"));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
1999-08-19 18:54:12 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-12-19 03:12:41 +03:00
|
|
|
|
|
|
|
nsresult
|
2003-06-19 03:03:08 +04:00
|
|
|
nsComponentManagerImpl::GetClassObjectByContractID(const char *contractID,
|
2001-12-19 03:12:41 +03:00
|
|
|
const nsIID &aIID,
|
2003-06-19 03:03:08 +04:00
|
|
|
void **aResult)
|
2001-12-19 03:12:41 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFactory> factory;
|
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-17 21:50:00 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG))
|
2001-12-19 03:12:41 +03:00
|
|
|
{
|
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", contractID);
|
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
PR_ASSERT(aResult != nsnull);
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
rv = FindFactory(contractID, strlen(contractID), getter_AddRefs(factory));
|
2001-12-19 03:12:41 +03:00
|
|
|
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"));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-12-19 03:12:41 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/**
|
2000-09-14 03:57:52 +04:00
|
|
|
* ContractIDToClassID()
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
2000-09-14 03:57:52 +04:00
|
|
|
* Mapping function from a ContractID to a classID. Directly talks to the registry.
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsresult
|
2002-01-30 00:22:13 +03:00
|
|
|
nsComponentManagerImpl::ContractIDToClassID(const char *aContractID, nsCID *aClass)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2002-04-16 02:33:03 +04:00
|
|
|
NS_PRECONDITION(aContractID != nsnull, "null ptr");
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!aContractID)
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
NS_PRECONDITION(aClass != nsnull, "null ptr");
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!aClass)
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
nsresult rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
nsFactoryEntry *fe = GetFactoryEntry(aContractID, strlen(aContractID));
|
2004-04-18 21:35:29 +04:00
|
|
|
if (fe) {
|
2003-05-14 02:50:03 +04:00
|
|
|
*aClass = fe->mCid;
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-17 21:50:00 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING)) {
|
1999-09-02 11:00:29 +04:00
|
|
|
char *buf = 0;
|
2002-10-06 03:59:57 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-03-10 12:53:25 +03:00
|
|
|
buf = aClass->ToString();
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2000-09-14 03:57:52 +04:00
|
|
|
("nsComponentManager: ContractIDToClassID(%s)->%s", aContractID,
|
2002-10-06 03:59:57 +04:00
|
|
|
NS_SUCCEEDED(rv) ? buf : "[FAILED]"));
|
2002-10-08 10:12:00 +04:00
|
|
|
if (buf)
|
|
|
|
PR_Free(buf);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
2002-10-06 03:59:57 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2000-09-14 03:57:52 +04:00
|
|
|
* CLSIDToContractID()
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
2000-09-14 03:57:52 +04:00
|
|
|
* Translates a classID to a {ContractID, Class Name}. Does direct registry
|
1999-03-09 12:44:27 +03:00
|
|
|
* 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
|
2000-09-14 03:57:52 +04:00
|
|
|
nsComponentManagerImpl::CLSIDToContractID(const nsCID &aClass,
|
2002-01-30 00:22:13 +03:00
|
|
|
char* *aClassName,
|
|
|
|
char* *aContractID)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2002-06-15 01:33:05 +04:00
|
|
|
NS_WARNING("Need to implement CLSIDToContractID");
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
nsresult rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-17 21:50:00 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
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,
|
2000-09-14 03:57:52 +04:00
|
|
|
("nsComponentManager: CLSIDToContractID(%s)->%s", buf,
|
2002-10-06 03:59:57 +04:00
|
|
|
NS_SUCCEEDED(rv) ? *aContractID : "[FAILED]"));
|
2002-10-08 10:12:00 +04:00
|
|
|
if (buf)
|
|
|
|
PR_Free(buf);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
2002-10-06 03:59:57 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2003-03-12 06:58:33 +03:00
|
|
|
#ifdef XPCOM_CHECK_PENDING_CIDS
|
2003-04-15 00:50:14 +04:00
|
|
|
|
|
|
|
// This method must be called from within the mMon monitor
|
2003-03-12 06:58:33 +03:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::AddPendingCID(const nsCID &aClass)
|
|
|
|
{
|
|
|
|
int max = mPendingCIDs.Count();
|
|
|
|
for (int index = 0; index < max; index++)
|
|
|
|
{
|
|
|
|
nsCID *cidp = (nsCID*) mPendingCIDs.ElementAt(index);
|
|
|
|
NS_ASSERTION(cidp, "Bad CID in pending list");
|
|
|
|
if (cidp->Equals(aClass)) {
|
2003-06-19 03:03:08 +04:00
|
|
|
nsXPIDLCString cid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
nsCAutoString message;
|
|
|
|
message = NS_LITERAL_CSTRING("Creation of \"") +
|
|
|
|
cid + NS_LITERAL_CSTRING("\" in progress (Reentrant GS - see bug 194568)");
|
|
|
|
// Note that you may see this assertion by near-simultaneous
|
2003-04-15 00:50:14 +04:00
|
|
|
// calls to GetService on multiple threads.
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_WARNING(message.get());
|
2003-03-12 06:58:33 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mPendingCIDs.AppendElement((void*)&aClass);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-15 00:50:14 +04:00
|
|
|
// This method must be called from within the mMon monitor
|
2003-06-19 03:03:08 +04:00
|
|
|
void
|
2003-03-12 06:58:33 +03:00
|
|
|
nsComponentManagerImpl::RemovePendingCID(const nsCID &aClass)
|
|
|
|
{
|
|
|
|
mPendingCIDs.RemoveElement((void*)&aClass);
|
|
|
|
}
|
|
|
|
#endif
|
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.
|
|
|
|
*/
|
2003-06-19 03:03:08 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
|
1999-03-09 12:44:27 +03:00
|
|
|
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
|
2001-10-16 07:35:52 +04:00
|
|
|
if (gXPCOMShuttingDown) {
|
2000-05-05 03:11:30 +04:00
|
|
|
// When processing shutdown, dont process new GetService() requests
|
2002-01-10 05:10:37 +03:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
2002-05-12 01:15:06 +04:00
|
|
|
fprintf(stderr, "Creating new instance on shutdown. Denied.\n"
|
2002-01-10 05:10:37 +03:00
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2000-05-05 03:11:30 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
if (aResult == nsnull)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2002-04-16 02:33:03 +04:00
|
|
|
*aResult = nsnull;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-12 06:58:33 +03:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass);
|
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (!entry)
|
2003-03-12 06:58:33 +03:00
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
|
|
|
|
#ifdef SHOW_CI_ON_EXISTING_SERVICE
|
2003-06-19 03:03:08 +04:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsXPIDLCString cid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
nsCAutoString message;
|
|
|
|
message = NS_LITERAL_CSTRING("You are calling CreateInstance \"") +
|
|
|
|
cid + NS_LITERAL_CSTRING("\" when a service for this CID already exists!");
|
|
|
|
NS_ERROR(message.get());
|
|
|
|
}
|
2003-03-12 06:58:33 +03:00
|
|
|
#endif
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
nsIFactory *factory = nsnull;
|
2003-03-12 06:58:33 +03:00
|
|
|
nsresult rv = entry->GetFactory(&factory, this);
|
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = factory->CreateInstance(aDelegate, aIID, aResult);
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_RELEASE(factory);
|
2000-03-12 01:44:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Translate error values
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
2000-03-12 01:44:51 +03:00
|
|
|
}
|
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-19 03:03:08 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
|
2000-03-12 01:44:51 +03:00
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2000-03-12 01:44:51 +03:00
|
|
|
("nsComponentManager: CreateInstance(%s) %s", buf,
|
2002-10-06 03:59:57 +04:00
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2002-10-08 10:12:00 +04:00
|
|
|
if (buf)
|
|
|
|
PR_Free(buf);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2000-09-14 03:57:52 +04:00
|
|
|
* CreateInstanceByContractID()
|
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
|
2000-09-14 03:57:52 +04:00
|
|
|
* implements the interface aIID and whose implementation has a contractID aContractID.
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
|
|
|
* This is only a convenience routine that turns around can calls the
|
|
|
|
* CreateInstance() with classid and iid.
|
|
|
|
*/
|
|
|
|
nsresult
|
2000-09-14 03:57:52 +04:00
|
|
|
nsComponentManagerImpl::CreateInstanceByContractID(const char *aContractID,
|
2003-03-05 06:22:12 +03:00
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
2001-08-22 02:42:35 +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
|
2001-10-16 07:35:52 +04:00
|
|
|
if (gXPCOMShuttingDown) {
|
2001-08-22 02:42:35 +04:00
|
|
|
// When processing shutdown, dont process new GetService() requests
|
2002-01-10 05:10:37 +03:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
2002-05-12 01:15:06 +04:00
|
|
|
fprintf(stderr, "Creating new instance on shutdown. Denied.\n"
|
2002-01-10 05:10:37 +03:00
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2001-08-22 02:42:35 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
if (aResult == nsnull)
|
2001-08-22 02:42:35 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2002-04-16 02:33:03 +04:00
|
|
|
*aResult = nsnull;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aContractID, strlen(aContractID));
|
2003-03-12 06:58:33 +03:00
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (!entry)
|
2003-03-12 06:58:33 +03:00
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
|
|
|
|
#ifdef SHOW_CI_ON_EXISTING_SERVICE
|
2003-06-19 03:03:08 +04:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsCAutoString message;
|
|
|
|
message =
|
|
|
|
NS_LITERAL_CSTRING("You are calling CreateInstance \"") +
|
|
|
|
nsDependentCString(aContractID) +
|
|
|
|
NS_LITERAL_CSTRING("\" when a service for this CID already exists! "
|
|
|
|
"Add it to abusedContracts to track down the service consumer.");
|
|
|
|
NS_ERROR(message.get());
|
|
|
|
}
|
2003-03-12 06:58:33 +03:00
|
|
|
#endif
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
nsIFactory *factory = nsnull;
|
2003-03-12 06:58:33 +03:00
|
|
|
nsresult rv = entry->GetFactory(&factory, this);
|
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2001-08-22 02:42:35 +04:00
|
|
|
{
|
2003-04-15 00:50:14 +04:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = factory->CreateInstance(aDelegate, aIID, aResult);
|
2001-08-22 02:42:35 +04:00
|
|
|
NS_RELEASE(factory);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Translate error values
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
2001-08-22 02:42:35 +04:00
|
|
|
}
|
|
|
|
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2001-08-22 02:42:35 +04:00
|
|
|
("nsComponentManager: CreateInstanceByContractID(%s) %s", aContractID,
|
2002-10-06 03:59:57 +04:00
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
// Service Manager Impl
|
2002-01-30 00:22:13 +03:00
|
|
|
static
|
2001-10-23 06:28:12 +04:00
|
|
|
PLDHashOperator PR_CALLBACK
|
|
|
|
FreeServiceFactoryEntryEnumerate(PLDHashTable *aTable,
|
|
|
|
PLDHashEntryHdr *aHdr,
|
|
|
|
PRUint32 aNumber,
|
|
|
|
void *aData)
|
2001-09-07 01:13:11 +04:00
|
|
|
{
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryTableEntry* entry = NS_STATIC_CAST(nsFactoryTableEntry*, aHdr);
|
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (!entry->mFactoryEntry)
|
2001-10-23 06:28:12 +04:00
|
|
|
return PL_DHASH_NEXT;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry* factoryEntry = entry->mFactoryEntry;
|
2001-11-16 16:53:04 +03:00
|
|
|
factoryEntry->mServiceObject = nsnull;
|
2001-10-23 06:28:12 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
static
|
2001-10-23 06:28:12 +04:00
|
|
|
PLDHashOperator PR_CALLBACK
|
|
|
|
FreeServiceContractIDEntryEnumerate(PLDHashTable *aTable,
|
|
|
|
PLDHashEntryHdr *aHdr,
|
|
|
|
PRUint32 aNumber,
|
|
|
|
void *aData)
|
|
|
|
{
|
|
|
|
nsContractIDTableEntry* entry = NS_STATIC_CAST(nsContractIDTableEntry*, aHdr);
|
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (!entry->mFactoryEntry)
|
2001-10-23 06:28:12 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
|
|
|
nsFactoryEntry* factoryEntry = entry->mFactoryEntry;
|
2001-11-16 16:53:04 +03:00
|
|
|
factoryEntry->mServiceObject = nsnull;
|
2001-10-23 06:28:12 +04:00
|
|
|
return PL_DHASH_NEXT;
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
nsresult
|
2001-09-07 01:13:11 +04:00
|
|
|
nsComponentManagerImpl::FreeServices()
|
|
|
|
{
|
2002-01-13 02:35:57 +03:00
|
|
|
NS_ASSERTION(gXPCOMShuttingDown, "Must be shutting down in order to free all services");
|
|
|
|
|
|
|
|
if (!gXPCOMShuttingDown)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (mContractIDs.ops) {
|
|
|
|
PL_DHashTableEnumerate(&mContractIDs, FreeServiceContractIDEntryEnumerate, nsnull);
|
|
|
|
}
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
if (mFactories.ops) {
|
|
|
|
PL_DHashTableEnumerate(&mFactories, FreeServiceFactoryEntryEnumerate, nsnull);
|
|
|
|
}
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
NS_IMETHODIMP
|
2003-06-19 03:03:08 +04:00
|
|
|
nsComponentManagerImpl::GetService(const nsCID& aClass,
|
2001-10-16 07:35:52 +04:00
|
|
|
const nsIID& aIID,
|
|
|
|
void* *result)
|
2001-09-07 01:13:11 +04:00
|
|
|
{
|
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
2001-10-16 07:35:52 +04:00
|
|
|
if (gXPCOMShuttingDown) {
|
2001-09-07 01:13:11 +04:00
|
|
|
// When processing shutdown, dont process new GetService() requests
|
2002-01-10 05:10:37 +03:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
2002-05-12 01:15:06 +04:00
|
|
|
fprintf(stderr, "Getting service on shutdown. Denied.\n"
|
2002-01-10 05:10:37 +03:00
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIDKey key(aClass);
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry* entry = nsnull;
|
|
|
|
nsFactoryTableEntry* factoryTableEntry =
|
|
|
|
NS_STATIC_CAST(nsFactoryTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mFactories, &aClass,
|
|
|
|
PL_DHASH_LOOKUP));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
|
|
|
|
entry = factoryTableEntry->mFactoryEntry;
|
|
|
|
}
|
2001-11-16 16:53:04 +03:00
|
|
|
|
|
|
|
if (entry && entry->mServiceObject) {
|
2003-06-19 03:03:08 +04:00
|
|
|
return entry->mServiceObject->QueryInterface(aIID, result);
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
|
|
|
|
2003-04-15 00:50:14 +04:00
|
|
|
#ifdef XPCOM_CHECK_PENDING_CIDS
|
|
|
|
rv = AddPendingCID(aClass);
|
|
|
|
if (NS_FAILED(rv))
|
2003-06-19 03:03:08 +04:00
|
|
|
return rv; // NOP_AND_BREAK
|
2003-04-15 00:50:14 +04:00
|
|
|
#endif
|
2001-11-16 16:53:04 +03:00
|
|
|
nsCOMPtr<nsISupports> service;
|
2003-06-19 03:03:08 +04:00
|
|
|
// We need to not be holding the service manager's monitor while calling
|
2001-09-07 01:13:11 +04:00
|
|
|
// CreateInstance, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager:
|
|
|
|
mon.Exit();
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
rv = CreateInstance(aClass, nsnull, aIID, getter_AddRefs(service));
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
mon.Enter();
|
|
|
|
|
2003-04-15 00:50:14 +04:00
|
|
|
#ifdef XPCOM_CHECK_PENDING_CIDS
|
|
|
|
RemovePendingCID(aClass);
|
|
|
|
#endif
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
if (!entry) { // second hash lookup for GetService
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryTableEntry* factoryTableEntry =
|
|
|
|
NS_STATIC_CAST(nsFactoryTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mFactories, &aClass,
|
|
|
|
PL_DHASH_LOOKUP));
|
2001-11-16 16:53:04 +03:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
|
|
|
|
entry = factoryTableEntry->mFactoryEntry;
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
2001-11-16 16:53:04 +03:00
|
|
|
NS_ASSERTION(entry, "we should have a factory entry since CI succeeded - we should not get here");
|
2003-06-19 03:03:08 +04:00
|
|
|
if (!entry) return NS_ERROR_FAILURE;
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
entry->mServiceObject = service;
|
2001-11-16 16:53:04 +03:00
|
|
|
*result = service.get();
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_ADDREF(NS_STATIC_CAST(nsISupports*, (*result)));
|
2001-09-07 01:13:11 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::RegisterService(const nsCID& aClass, nsISupports* aService)
|
|
|
|
{
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
|
|
|
|
// check to see if we have a factory entry for the service
|
2004-04-18 21:35:29 +04:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass);
|
2001-09-07 01:13:11 +04:00
|
|
|
|
|
|
|
if (!entry) { // XXXdougt - should we require that all services register factories?? probably not.
|
2002-05-03 01:25:08 +04:00
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
|
|
|
|
if (!mem)
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-05-03 01:25:08 +04:00
|
|
|
entry = new (mem) nsFactoryEntry(aClass, nsnull);
|
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
entry->mTypeIndex = NS_COMPONENT_TYPE_SERVICE_ONLY;
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryTableEntry* factoryTableEntry =
|
|
|
|
NS_STATIC_CAST(nsFactoryTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mFactories, &aClass,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (!factoryTableEntry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
factoryTableEntry->mFactoryEntry = entry;
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
|
|
|
else {
|
2001-11-16 16:53:04 +03:00
|
|
|
if (entry->mServiceObject)
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-11-16 16:53:04 +03:00
|
|
|
entry->mServiceObject = aService;
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::UnregisterService(const nsCID& aClass)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry* entry = nsnull;
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryTableEntry* factoryTableEntry =
|
|
|
|
NS_STATIC_CAST(nsFactoryTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mFactories, &aClass,
|
|
|
|
PL_DHASH_LOOKUP));
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
|
|
|
|
entry = factoryTableEntry->mFactoryEntry;
|
|
|
|
}
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2001-11-16 16:53:04 +03:00
|
|
|
if (!entry || !entry->mServiceObject)
|
2004-02-29 11:04:46 +03:00
|
|
|
return NS_ERROR_SERVICE_NOT_AVAILABLE;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-11-16 16:53:04 +03:00
|
|
|
entry->mServiceObject = nsnull;
|
2001-09-07 01:13:11 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-10-17 03:39:20 +04:00
|
|
|
nsComponentManagerImpl::RegisterService(const char* aContractID, nsISupports* aService)
|
2001-09-07 01:13:11 +04:00
|
|
|
{
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
|
|
|
|
// check to see if we have a factory entry for the service
|
2003-03-14 08:07:24 +03:00
|
|
|
PRUint32 contractIDLen = strlen(aContractID);
|
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aContractID, contractIDLen);
|
2001-09-07 01:13:11 +04:00
|
|
|
|
|
|
|
if (!entry) { // XXXdougt - should we require that all services register factories?? probably not.
|
2002-05-03 01:25:08 +04:00
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
|
|
|
|
if (!mem)
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-05-03 01:25:08 +04:00
|
|
|
entry = new (mem) nsFactoryEntry(kEmptyCID, nsnull);
|
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
entry->mTypeIndex = NS_COMPONENT_TYPE_SERVICE_ONLY;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mContractIDs, aContractID,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (!contractIDTableEntry) {
|
|
|
|
delete entry;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
if (!contractIDTableEntry->mContractID) {
|
|
|
|
contractIDTableEntry->mContractID =
|
|
|
|
ArenaStrndup(aContractID, contractIDLen, &mArena);
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
contractIDTableEntry->mContractIDLen = contractIDLen;
|
|
|
|
}
|
2001-10-23 06:28:12 +04:00
|
|
|
|
|
|
|
contractIDTableEntry->mFactoryEntry = entry;
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
|
|
|
else {
|
2001-11-16 16:53:04 +03:00
|
|
|
if (entry->mServiceObject)
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-11-16 16:53:04 +03:00
|
|
|
entry->mServiceObject = aService;
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-16 07:35:52 +04:00
|
|
|
nsComponentManagerImpl::IsServiceInstantiated(const nsCID & aClass,
|
|
|
|
const nsIID& aIID,
|
|
|
|
PRBool *result)
|
|
|
|
{
|
|
|
|
// Now we want to get the service if we already got it. If not, we dont want
|
|
|
|
// to create an instance of it. mmh!
|
|
|
|
|
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, dont process new GetService() requests
|
2002-01-10 05:10:37 +03:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
2002-05-12 01:15:06 +04:00
|
|
|
fprintf(stderr, "Checking for service on shutdown. Denied.\n"
|
2002-01-10 05:10:37 +03:00
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2001-10-16 07:35:52 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2004-02-29 11:04:46 +03:00
|
|
|
nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry* entry = nsnull;
|
|
|
|
nsFactoryTableEntry* factoryTableEntry =
|
|
|
|
NS_STATIC_CAST(nsFactoryTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mFactories, &aClass,
|
|
|
|
PL_DHASH_LOOKUP));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
|
|
|
|
entry = factoryTableEntry->mFactoryEntry;
|
|
|
|
}
|
2001-10-16 07:35:52 +04:00
|
|
|
|
2001-11-16 16:53:04 +03:00
|
|
|
if (entry && entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
|
2002-10-06 03:59:57 +04:00
|
|
|
*result = (service!=nsnull);
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP nsComponentManagerImpl::IsServiceInstantiatedByContractID(const char *aContractID,
|
2001-10-16 07:35:52 +04:00
|
|
|
const nsIID& aIID,
|
|
|
|
PRBool *result)
|
|
|
|
{
|
|
|
|
// Now we want to get the service if we already got it. If not, we dont want
|
|
|
|
// to create an instance of it. mmh!
|
|
|
|
|
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, dont process new GetService() requests
|
2002-01-10 05:10:37 +03:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
2002-05-12 01:15:06 +04:00
|
|
|
fprintf(stderr, "Checking for service on shutdown. Denied.\n"
|
2002-01-10 05:10:37 +03:00
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2001-10-16 07:35:52 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2004-02-29 11:04:46 +03:00
|
|
|
nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry *entry = nsnull;
|
|
|
|
{
|
|
|
|
nsAutoMonitor mon(mMon);
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mContractIDs, aContractID,
|
|
|
|
PL_DHASH_LOOKUP));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(contractIDTableEntry)) {
|
|
|
|
entry = contractIDTableEntry->mFactoryEntry;
|
|
|
|
}
|
|
|
|
} // exit monitor
|
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (entry && entry->mServiceObject) {
|
2001-11-16 16:53:04 +03:00
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
|
2002-10-06 03:59:57 +04:00
|
|
|
*result = (service!=nsnull);
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-17 03:39:20 +04:00
|
|
|
nsComponentManagerImpl::UnregisterService(const char* aContractID)
|
2001-09-07 01:13:11 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry *entry = nsnull;
|
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mContractIDs, aContractID,
|
|
|
|
PL_DHASH_LOOKUP));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(contractIDTableEntry)) {
|
|
|
|
entry = contractIDTableEntry->mFactoryEntry;
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (!entry || !entry->mServiceObject)
|
2004-02-29 11:04:46 +03:00
|
|
|
return NS_ERROR_SERVICE_NOT_AVAILABLE;
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2001-11-16 16:53:04 +03:00
|
|
|
entry->mServiceObject = nsnull;
|
|
|
|
return rv;
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-06-19 03:03:08 +04:00
|
|
|
nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
|
2001-10-16 07:35:52 +04:00
|
|
|
const nsIID& aIID,
|
|
|
|
void* *result)
|
2001-09-07 01:13:11 +04:00
|
|
|
{
|
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
2001-10-16 07:35:52 +04:00
|
|
|
if (gXPCOMShuttingDown) {
|
2001-09-07 01:13:11 +04:00
|
|
|
// When processing shutdown, dont process new GetService() requests
|
2002-01-10 05:10:37 +03:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
2002-05-12 01:15:06 +04:00
|
|
|
fprintf(stderr, "Getting service on shutdown. Denied.\n"
|
2002-01-10 05:10:37 +03:00
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2001-09-07 01:13:11 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
nsresult rv = NS_OK;
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryEntry *entry = nsnull;
|
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mContractIDs, aContractID,
|
|
|
|
PL_DHASH_LOOKUP));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(contractIDTableEntry)) {
|
|
|
|
entry = contractIDTableEntry->mFactoryEntry;
|
|
|
|
}
|
2001-11-16 16:53:04 +03:00
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (entry) {
|
2003-06-19 03:03:08 +04:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, result);
|
|
|
|
}
|
|
|
|
#ifdef XPCOM_CHECK_PENDING_CIDS
|
2003-06-18 01:12:11 +04:00
|
|
|
rv = AddPendingCID(entry->mCid);
|
|
|
|
if (NS_FAILED(rv))
|
2003-06-19 03:03:08 +04:00
|
|
|
return rv; // NOP_AND_BREAK
|
2003-04-15 00:50:14 +04:00
|
|
|
#endif
|
2003-06-19 03:03:08 +04:00
|
|
|
}
|
|
|
|
|
2001-11-16 16:53:04 +03:00
|
|
|
nsCOMPtr<nsISupports> service;
|
2003-06-19 03:03:08 +04:00
|
|
|
// We need to not be holding the service manager's monitor while calling
|
2001-09-07 01:13:11 +04:00
|
|
|
// CreateInstance, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager:
|
|
|
|
mon.Exit();
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
rv = CreateInstanceByContractID(aContractID, nsnull, aIID, getter_AddRefs(service));
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
mon.Enter();
|
|
|
|
|
2003-04-15 00:50:14 +04:00
|
|
|
#ifdef XPCOM_CHECK_PENDING_CIDS
|
2004-04-18 21:35:29 +04:00
|
|
|
if (entry)
|
2003-06-18 01:12:11 +04:00
|
|
|
RemovePendingCID(entry->mCid);
|
2003-04-15 00:50:14 +04:00
|
|
|
#endif
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
if (!entry) { // second hash lookup for GetService
|
2001-10-23 06:28:12 +04:00
|
|
|
nsContractIDTableEntry* contractIDTableEntry =
|
|
|
|
NS_STATIC_CAST(nsContractIDTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mContractIDs, aContractID,
|
|
|
|
PL_DHASH_LOOKUP));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(contractIDTableEntry)) {
|
|
|
|
entry = contractIDTableEntry->mFactoryEntry;
|
|
|
|
}
|
2001-09-07 01:13:11 +04:00
|
|
|
NS_ASSERTION(entry, "we should have a factory entry since CI succeeded - we should not get here");
|
2003-06-19 03:03:08 +04:00
|
|
|
if (!entry) return NS_ERROR_FAILURE;
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-11-16 16:53:04 +03:00
|
|
|
entry->mServiceObject = service;
|
|
|
|
*result = service.get();
|
2002-10-06 03:59:57 +04:00
|
|
|
NS_ADDREF(NS_STATIC_CAST(nsISupports*, *result));
|
2001-09-07 01:13:11 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-17 03:39:20 +04:00
|
|
|
nsComponentManagerImpl::GetService(const nsCID& aClass, const nsIID& aIID,
|
|
|
|
nsISupports* *result,
|
|
|
|
nsIShutdownListener* shutdownListener)
|
|
|
|
{
|
|
|
|
return GetService(aClass, aIID, (void**)result);
|
2003-09-08 04:31:50 +04:00
|
|
|
}
|
2001-10-17 03:39:20 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-17 03:39:20 +04:00
|
|
|
nsComponentManagerImpl::GetService(const char* aContractID, const nsIID& aIID,
|
|
|
|
nsISupports* *result,
|
2002-10-06 03:59:57 +04:00
|
|
|
nsIShutdownListener* shutdownListener)
|
2001-10-17 03:39:20 +04:00
|
|
|
{
|
|
|
|
return GetServiceByContractID(aContractID, aIID, (void**)result);
|
2003-09-08 04:31:50 +04:00
|
|
|
}
|
2001-10-17 03:39:20 +04:00
|
|
|
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-17 03:39:20 +04:00
|
|
|
nsComponentManagerImpl::ReleaseService(const nsCID& aClass, nsISupports* service,
|
2002-10-06 03:59:57 +04:00
|
|
|
nsIShutdownListener* shutdownListener)
|
2001-10-17 03:39:20 +04:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(service);
|
|
|
|
return NS_OK;
|
2003-09-08 04:31:50 +04:00
|
|
|
}
|
2001-10-17 03:39:20 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-17 03:39:20 +04:00
|
|
|
nsComponentManagerImpl::ReleaseService(const char* aContractID, nsISupports* service,
|
2002-10-06 03:59:57 +04:00
|
|
|
nsIShutdownListener* shutdownListener)
|
2001-10-17 03:39:20 +04:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(service);
|
|
|
|
return NS_OK;
|
2003-09-08 04:31:50 +04:00
|
|
|
}
|
2001-09-07 01:13:11 +04: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;
|
|
|
|
|
2002-02-20 09:38:38 +03:00
|
|
|
PRUint32 len = strlen(prefix);
|
1999-09-07 09:06:37 +04:00
|
|
|
|
2002-02-20 09:38:38 +03:00
|
|
|
PRUint32 registryNameLen = strlen(aDllName) + len;
|
2000-06-03 13:46:12 +04:00
|
|
|
registryName = (char *)nsMemory::Alloc(registryNameLen + 1);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
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;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-12 06:18:55 +03:00
|
|
|
memcpy(registryName, prefix, len);
|
2003-06-19 03:03:08 +04:00
|
|
|
strcpy(registryName + len, aDllName);
|
1999-09-07 09:06:37 +04:00
|
|
|
registryName[registryNameLen] = '\0';
|
|
|
|
*regName = registryName;
|
|
|
|
|
|
|
|
#ifdef DEBUG_shaver_off
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stderr, "MakeRegistryName(%s, %s, &[%s])\n",
|
1999-09-07 09:06:37 +04:00
|
|
|
aDllName, prefix, *regName);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
if (!mComponentsDir)
|
2000-01-25 00:28:28 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
1999-09-07 09:06:37 +04:00
|
|
|
|
2001-06-21 00:21:49 +04:00
|
|
|
if (!aSpec) {
|
2002-06-15 02:25:24 +04:00
|
|
|
*aRegistryName = PL_strdup("");
|
2001-06-21 00:21:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
|
|
|
|
// First check to see if this component is in the application
|
|
|
|
// components directory
|
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
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
nsCAutoString nativePathString;
|
2001-12-14 04:27:16 +03:00
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
if (containedIn){
|
2003-03-05 06:22:12 +03:00
|
|
|
rv = aSpec->GetNativePath(nativePathString);
|
2001-12-14 04:27:16 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
const char* relativeLocation = nativePathString.get() + mComponentsOffset + 1;
|
|
|
|
return MakeRegistryName(relativeLocation, XPCOM_RELCOMPONENT_PREFIX, aRegistryName);
|
2003-06-19 03:03:08 +04:00
|
|
|
}
|
2003-03-05 06:22:12 +03:00
|
|
|
|
|
|
|
// Next check to see if this component is in the GRE
|
|
|
|
// components directory
|
2003-03-01 00:30:35 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
mGREComponentsDir->Contains(aSpec, PR_TRUE, &containedIn);
|
|
|
|
|
|
|
|
if (containedIn){
|
|
|
|
rv = aSpec->GetNativePath(nativePathString);
|
1999-09-07 09:06:37 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
const char* relativeLocation = nativePathString.get() + mGREComponentsOffset + 1;
|
|
|
|
return MakeRegistryName(relativeLocation, XPCOM_GRECOMPONENT_PREFIX, aRegistryName);
|
2003-06-19 03:03:08 +04:00
|
|
|
}
|
2000-01-25 00:28:28 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
/* absolute names include volume info on Mac, so persistent descriptor */
|
|
|
|
rv = aSpec->GetNativePath(nativePathString);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
return MakeRegistryName(nativePathString.get(), XPCOM_ABSCOMPONENT_PREFIX, aRegistryName);
|
1999-09-07 09:06:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::SpecForRegistryLocation(const char *aLocation,
|
2000-01-25 00:28:28 +03:00
|
|
|
nsIFile **aSpec)
|
1999-09-07 09:06:37 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
// i18n: assuming aLocation is encoded for the current locale
|
2002-10-06 03:59:57 +04:00
|
|
|
|
1999-09-07 09:06:37 +04:00
|
|
|
nsresult rv;
|
|
|
|
if (!aLocation || !aSpec)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
/* abs:/full/path/to/libcomponent.so */
|
2002-06-15 01:33:05 +04:00
|
|
|
if (!strncmp(aLocation, XPCOM_ABSCOMPONENT_PREFIX, 4)) {
|
2000-01-25 00:28:28 +03:00
|
|
|
|
|
|
|
nsLocalFile* file = new nsLocalFile;
|
|
|
|
if (!file) return NS_ERROR_FAILURE;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = file->InitWithNativePath(nsDependentCString((char *)aLocation + 4));
|
2000-01-25 00:28:28 +03:00
|
|
|
file->QueryInterface(NS_GET_IID(nsILocalFile), (void**)aSpec);
|
|
|
|
return rv;
|
1999-09-07 09:06:37 +04:00
|
|
|
}
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
if (!strncmp(aLocation, XPCOM_RELCOMPONENT_PREFIX, 4)) {
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
if (!mComponentsDir)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsILocalFile* file = nsnull;
|
2003-06-19 03:03:08 +04:00
|
|
|
rv = mComponentsDir->Clone((nsIFile**)&file);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = file->AppendRelativeNativePath(nsDependentCString(aLocation + 4));
|
2000-01-25 00:28:28 +03:00
|
|
|
*aSpec = file;
|
|
|
|
return rv;
|
1999-09-07 09:06:37 +04:00
|
|
|
}
|
2003-03-05 06:22:12 +03:00
|
|
|
|
|
|
|
if (!strncmp(aLocation, XPCOM_GRECOMPONENT_PREFIX, 4)) {
|
|
|
|
|
|
|
|
if (!mGREComponentsDir)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsILocalFile* file = nsnull;
|
2003-06-19 03:03:08 +04:00
|
|
|
rv = mGREComponentsDir->Clone((nsIFile**)&file);
|
2003-03-05 06:22:12 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = file->AppendRelativeNativePath(nsDependentCString(aLocation + 4));
|
|
|
|
*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
|
2000-09-14 03:57:52 +04:00
|
|
|
* classID aClass. Plus creates as association of aClassName and aContractID
|
1999-03-09 12:44:27 +03:00
|
|
|
* 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,
|
2000-09-14 03:57:52 +04:00
|
|
|
const char *aContractID,
|
2003-06-19 03:03:08 +04:00
|
|
|
nsIFactory *aFactory,
|
1999-03-09 12:44:27 +03:00
|
|
|
PRBool aReplace)
|
|
|
|
{
|
2001-10-23 06:28:12 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-17 21:50:00 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
|
2000-03-12 01:44:51 +03:00
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2000-03-12 01:44:51 +03:00
|
|
|
("nsComponentManager: RegisterFactory(%s, %s)", buf,
|
2000-09-14 03:57:52 +04:00
|
|
|
(aContractID ? aContractID : "(null)")));
|
2002-10-08 10:12:00 +04:00
|
|
|
if (buf)
|
|
|
|
PR_Free(buf);
|
2000-03-12 01:44:51 +03:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
|
|
|
nsFactoryEntry *entry = nsnull;
|
|
|
|
nsFactoryTableEntry* factoryTableEntry = NS_STATIC_CAST(nsFactoryTableEntry*,
|
2003-06-19 03:03:08 +04:00
|
|
|
PL_DHashTableOperate(&mFactories,
|
2003-05-14 02:50:03 +04:00
|
|
|
&aClass,
|
|
|
|
PL_DHASH_ADD));
|
2003-06-19 03:03:08 +04:00
|
|
|
|
|
|
|
if (!factoryTableEntry)
|
2003-05-14 02:50:03 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-06-19 03:03:08 +04:00
|
|
|
|
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
|
|
|
|
entry = factoryTableEntry->mFactoryEntry;
|
2003-06-19 03:03:08 +04:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
if (entry && !aReplace)
|
2003-05-14 02:50:03 +04:00
|
|
|
{
|
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
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
|
|
|
|
if (!mem)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
entry = new (mem) nsFactoryEntry(aClass, aFactory, entry);
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
factoryTableEntry->mFactoryEntry = entry;
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
// Update the ContractID->CLSID Map
|
|
|
|
if (aContractID) {
|
2003-03-14 08:07:24 +03:00
|
|
|
nsresult rv = HashContractID(aContractID, strlen(aContractID), entry);
|
2002-10-06 03:59:57 +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-09-14 03:57:52 +04:00
|
|
|
"Hashing contractid (%s) FAILED.", aContractID));
|
1999-09-01 01:40:21 +04:00
|
|
|
return rv;
|
1999-04-12 16:32:24 +04:00
|
|
|
}
|
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2000-09-14 03:57:52 +04:00
|
|
|
("\t\tFactory register succeeded contractid=%s.",
|
|
|
|
aContractID ? aContractID : "<none>"));
|
2002-10-06 03:59:57 +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,
|
2000-09-14 03:57:52 +04:00
|
|
|
const char *aContractID,
|
1999-09-01 01:40:21 +04:00
|
|
|
const char *aPersistentDescriptor,
|
1999-03-09 12:44:27 +03:00
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist)
|
|
|
|
{
|
2003-03-14 08:07:24 +03:00
|
|
|
return RegisterComponentCommon(aClass, aClassName,
|
|
|
|
aContractID,
|
|
|
|
aContractID ? strlen(aContractID) : 0,
|
|
|
|
aPersistentDescriptor,
|
|
|
|
aPersistentDescriptor ?
|
|
|
|
strlen(aPersistentDescriptor) : 0,
|
|
|
|
aReplace, aPersist,
|
1999-12-09 03:01:46 +03:00
|
|
|
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,
|
2000-09-14 03:57:52 +04:00
|
|
|
const char *aContractID,
|
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)
|
|
|
|
{
|
2003-03-14 08:07:24 +03:00
|
|
|
return RegisterComponentCommon(aClass, aClassName,
|
|
|
|
aContractID,
|
|
|
|
aContractID ? strlen(aContractID) : 0,
|
1999-11-19 05:14:23 +03:00
|
|
|
aLocation,
|
2003-03-14 08:07:24 +03:00
|
|
|
aLocation ? strlen(aLocation) : 0,
|
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,
|
2000-09-14 03:57:52 +04:00
|
|
|
const char *aContractID,
|
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;
|
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
rv = RegisterComponentWithType(aClass, aClassName,
|
|
|
|
aContractID,
|
|
|
|
aLibrarySpec,
|
1999-09-07 09:06:37 +04:00
|
|
|
registryName,
|
|
|
|
aReplace, aPersist,
|
|
|
|
nativeComponentType);
|
|
|
|
return rv;
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponentLib(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
2000-09-14 03:57:52 +04:00
|
|
|
const char *aContractID,
|
1999-09-01 01:40:21 +04:00
|
|
|
const char *aDllName,
|
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist)
|
|
|
|
{
|
2003-03-05 06:22:12 +03:00
|
|
|
// deprecated and obsolete.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-08-22 02:42:35 +04:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponentCommon(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
2000-09-14 03:57:52 +04:00
|
|
|
const char *aContractID,
|
2003-03-14 08:07:24 +03:00
|
|
|
PRUint32 aContractIDLen,
|
1999-11-19 05:14:23 +03:00
|
|
|
const char *aRegistryName,
|
2003-03-14 08:07:24 +03:00
|
|
|
PRUint32 aRegistryNameLen,
|
1999-09-01 01:40:21 +04:00
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist,
|
|
|
|
const char *aType)
|
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
nsIDKey key(aClass);
|
2001-10-23 06:28:12 +04:00
|
|
|
nsAutoMonitor mon(mMon);
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass);
|
1999-07-07 11:47:14 +04:00
|
|
|
|
2000-03-25 09:57:25 +03:00
|
|
|
// Normalize proid and classname
|
2002-04-16 02:33:03 +04:00
|
|
|
const char *contractID = (aContractID && *aContractID) ? aContractID : nsnull;
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-17 21:50:00 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
|
2000-03-12 01:44:51 +03:00
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2000-03-12 01:44:51 +03:00
|
|
|
("nsComponentManager: RegisterComponentCommon(%s, %s, %s, %s)",
|
|
|
|
buf,
|
2000-09-14 03:57:52 +04:00
|
|
|
contractID ? contractID : "(null)",
|
2000-03-12 01:44:51 +03:00
|
|
|
aRegistryName, aType));
|
2002-10-08 10:12:00 +04:00
|
|
|
if (buf)
|
|
|
|
PR_Free(buf);
|
2000-03-12 01:44:51 +03:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
1999-09-01 01:40:21 +04:00
|
|
|
if (entry && !aReplace) {
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("\t\tFactory already registered."));
|
2001-08-22 02:42:35 +04:00
|
|
|
return NS_ERROR_FACTORY_EXISTS;
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
|
|
|
|
2001-08-30 18:10:41 +04:00
|
|
|
int typeIndex = GetLoaderType(aType);
|
|
|
|
|
2001-08-22 02:42:35 +04:00
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
2002-10-08 10:12:00 +04:00
|
|
|
nsresult rv = GetLoaderForType(typeIndex, getter_AddRefs(loader));
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-08-22 02:42:35 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("\t\tgetting loader for %s FAILED\n", aType));
|
|
|
|
return rv;
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-08-22 02:42:35 +04:00
|
|
|
if (entry) {
|
2001-08-30 18:10:41 +04:00
|
|
|
entry->ReInit(aClass, aRegistryName, typeIndex);
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
2001-08-22 02:42:35 +04:00
|
|
|
else {
|
2002-06-15 01:33:05 +04:00
|
|
|
|
|
|
|
// Arena allocate the nsFactoryEntry
|
2002-05-03 01:25:08 +04:00
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
|
|
|
|
if (!mem)
|
2001-08-22 02:42:35 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-06-15 01:33:05 +04:00
|
|
|
|
|
|
|
mRegistryDirty = PR_TRUE;
|
2003-03-14 08:07:24 +03:00
|
|
|
entry = new (mem) nsFactoryEntry(aClass,
|
|
|
|
aRegistryName, aRegistryNameLen,
|
|
|
|
typeIndex);
|
2002-06-15 01:33:05 +04:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
nsFactoryTableEntry* factoryTableEntry =
|
|
|
|
NS_STATIC_CAST(nsFactoryTableEntry*,
|
|
|
|
PL_DHashTableOperate(&mFactories, &aClass,
|
|
|
|
PL_DHASH_ADD));
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
if (!factoryTableEntry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
factoryTableEntry->mFactoryEntry = entry;
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
// Update the ContractID->CLSID Map
|
2002-06-15 01:33:05 +04:00
|
|
|
if (contractID) {
|
2003-03-14 08:07:24 +03:00
|
|
|
rv = HashContractID(contractID, aContractIDLen, entry);
|
1999-09-01 01:40:21 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-08-22 02:42:35 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("\t\tHashContractID(%s) FAILED\n", contractID));
|
|
|
|
return rv;
|
|
|
|
}
|
1999-09-01 01:40:21 +04:00
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
nsresult
|
2001-08-30 18:10:41 +04:00
|
|
|
nsComponentManagerImpl::GetLoaderForType(int aType,
|
1999-09-01 01:40:21 +04:00
|
|
|
nsIComponentLoader **aLoader)
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult rv;
|
1999-06-22 18:02:58 +04:00
|
|
|
|
2001-08-30 18:10:41 +04:00
|
|
|
// Make sure we have a valid type
|
|
|
|
if (aType < 0 || aType >= mNLoaderData)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
*aLoader = mLoaderData[aType].loader;
|
|
|
|
if (*aLoader) {
|
|
|
|
NS_ADDREF(*aLoader);
|
2000-05-26 08:56:23 +04:00
|
|
|
return NS_OK;
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
|
2001-08-30 18:10:41 +04:00
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
|
|
|
loader = do_GetServiceFromCategory("component-loader", mLoaderData[aType].type, &rv);
|
1999-09-02 11:00:29 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
rv = loader->Init(this, nsnull);
|
1999-09-01 01:40:21 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-08-30 18:10:41 +04:00
|
|
|
mLoaderData[aType].loader = loader;
|
|
|
|
NS_ADDREF(mLoaderData[aType].loader);
|
2000-05-26 08:56:23 +04:00
|
|
|
*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
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
// Convert a loader type string into an index into the component data
|
|
|
|
// array. Empty loader types are converted to NATIVE. Returns -1 if
|
|
|
|
// loader type cannot be determined.
|
|
|
|
int
|
|
|
|
nsComponentManagerImpl::GetLoaderType(const char *typeStr)
|
|
|
|
{
|
|
|
|
if (!typeStr || !*typeStr) {
|
|
|
|
// Empty type strings are NATIVE
|
|
|
|
return NS_COMPONENT_TYPE_NATIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=NS_COMPONENT_TYPE_NATIVE; i<mNLoaderData; i++) {
|
|
|
|
if (!strcmp(typeStr, mLoaderData[i].type))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
// Not found
|
|
|
|
return NS_COMPONENT_TYPE_FACTORY_ONLY;
|
|
|
|
}
|
|
|
|
|
2004-03-10 09:40:36 +03:00
|
|
|
// Add a loader type if not already known. Out the typeIndex
|
2002-01-30 00:22:13 +03:00
|
|
|
// if the loader type is either added or already there.
|
2004-03-10 09:40:36 +03:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::AddLoaderType(const char *typeStr, int *aTypeIndex)
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
int typeIndex = GetLoaderType(typeStr);
|
|
|
|
if (typeIndex >= 0) {
|
2004-03-10 09:40:36 +03:00
|
|
|
*aTypeIndex = typeIndex;
|
|
|
|
return NS_OK;
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the loader type
|
|
|
|
if (mNLoaderData >= mMaxNLoaderData) {
|
|
|
|
NS_ASSERTION(mNLoaderData == mMaxNLoaderData,
|
|
|
|
"Memory corruption. nsComponentManagerImpl::mLoaderData array overrun.");
|
|
|
|
// Need to increase our loader array
|
|
|
|
nsLoaderdata *new_mLoaderData = (nsLoaderdata *) PR_Realloc(mLoaderData, (mMaxNLoaderData + NS_LOADER_DATA_ALLOC_STEP) * sizeof(nsLoaderdata));
|
|
|
|
if (!new_mLoaderData)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
mLoaderData = new_mLoaderData;
|
|
|
|
mMaxNLoaderData += NS_LOADER_DATA_ALLOC_STEP;
|
|
|
|
}
|
|
|
|
|
|
|
|
typeIndex = mNLoaderData;
|
|
|
|
mLoaderData[typeIndex].type = PL_strdup(typeStr);
|
|
|
|
if (!mLoaderData[typeIndex].type) {
|
|
|
|
// mmh! no memory. return failure.
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mLoaderData[typeIndex].loader = nsnull;
|
|
|
|
mNLoaderData++;
|
|
|
|
|
2004-03-10 09:40:36 +03:00
|
|
|
*aTypeIndex = typeIndex;
|
|
|
|
return NS_OK;
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const nsCID* cid;
|
|
|
|
const char* regName;
|
|
|
|
nsIFactory* factory;
|
|
|
|
} UnregisterConditions;
|
|
|
|
|
|
|
|
static PLDHashOperator PR_CALLBACK
|
|
|
|
DeleteFoundCIDs(PLDHashTable *aTable,
|
|
|
|
PLDHashEntryHdr *aHdr,
|
|
|
|
PRUint32 aNumber,
|
|
|
|
void *aData)
|
|
|
|
{
|
|
|
|
nsContractIDTableEntry* entry = NS_STATIC_CAST(nsContractIDTableEntry*, aHdr);
|
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (!entry->mFactoryEntry)
|
2002-01-30 00:22:13 +03:00
|
|
|
return PL_DHASH_NEXT;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
UnregisterConditions* data = (UnregisterConditions*)aData;
|
|
|
|
|
|
|
|
nsFactoryEntry* factoryEntry = entry->mFactoryEntry;
|
2003-06-19 03:03:08 +04:00
|
|
|
if (data->cid->Equals(factoryEntry->mCid) &&
|
2003-05-14 02:50:03 +04:00
|
|
|
((data->regName && !PL_strcasecmp(factoryEntry->mLocation, data->regName)) ||
|
|
|
|
(data->factory && data->factory == factoryEntry->mFactory.get())))
|
2002-01-30 00:22:13 +03:00
|
|
|
return PL_DHASH_REMOVE;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
void
|
2002-01-30 00:22:13 +03:00
|
|
|
nsComponentManagerImpl::DeleteContractIDEntriesByCID(const nsCID* aClass, const char*registryName)
|
|
|
|
{
|
|
|
|
UnregisterConditions aData;
|
|
|
|
aData.cid = aClass;
|
|
|
|
aData.regName = registryName;
|
|
|
|
aData.factory = nsnull;
|
|
|
|
PL_DHashTableEnumerate(&mContractIDs, DeleteFoundCIDs, (void*)&aData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
void
|
2002-01-30 00:22:13 +03:00
|
|
|
nsComponentManagerImpl::DeleteContractIDEntriesByCID(const nsCID* aClass, nsIFactory* factory)
|
|
|
|
{
|
|
|
|
UnregisterConditions aData;
|
|
|
|
aData.cid = aClass;
|
|
|
|
aData.regName = nsnull;
|
2003-06-19 03:03:08 +04:00
|
|
|
aData.factory = factory;
|
2002-01-30 00:22:13 +03:00
|
|
|
PL_DHashTableEnumerate(&mContractIDs, DeleteFoundCIDs, (void*)&aData);
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::UnregisterFactory(const nsCID &aClass,
|
|
|
|
nsIFactory *aFactory)
|
|
|
|
{
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-19 03:03:08 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2000-03-12 01:44:51 +03:00
|
|
|
("nsComponentManager: UnregisterFactory(%s)", buf));
|
2002-10-08 10:12:00 +04:00
|
|
|
if (buf)
|
|
|
|
PR_Free(buf);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
2002-01-30 00:22:13 +03:00
|
|
|
nsFactoryEntry *old;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
// first delete all contract id entries that are registered with this cid.
|
2002-01-30 00:22:13 +03:00
|
|
|
DeleteContractIDEntriesByCID(&aClass, aFactory);
|
|
|
|
|
|
|
|
// next check to see if there is a CID registered
|
2002-10-06 03:59:57 +04:00
|
|
|
nsresult rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
2004-04-18 21:35:29 +04:00
|
|
|
old = GetFactoryEntry(aClass);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-05-14 02:50:03 +04:00
|
|
|
if (old && (old->mFactory.get() == aFactory))
|
2003-06-19 03:03:08 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
PL_DHashTableOperate(&mFactories, &aClass, PL_DHASH_REMOVE);
|
2002-10-06 03:59:57 +04:00
|
|
|
rv = NS_OK;
|
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",
|
2002-10-06 03:59:57 +04:00
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
|
|
|
return rv;
|
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
|
|
|
{
|
2003-05-14 02:50:03 +04:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-19 03:03:08 +04:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
2003-06-17 21:50:00 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2002-01-30 00:22:13 +03:00
|
|
|
("nsComponentManager: UnregisterComponent(%s)", buf));
|
2002-10-08 10:12:00 +04:00
|
|
|
if (buf)
|
|
|
|
PR_Free(buf);
|
2002-01-30 00:22:13 +03:00
|
|
|
}
|
2003-05-14 02:50:03 +04:00
|
|
|
#endif
|
1999-08-13 23:30:13 +04:00
|
|
|
|
2000-05-05 10:37:39 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(registryName);
|
2002-01-30 00:22:13 +03:00
|
|
|
nsFactoryEntry *old;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
// first delete all contract id entries that are registered with this cid.
|
2002-01-30 00:22:13 +03:00
|
|
|
DeleteContractIDEntriesByCID(&aClass, registryName);
|
1999-08-13 23:30:13 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
// next check to see if there is a CID registered
|
2004-04-18 21:35:29 +04:00
|
|
|
old = GetFactoryEntry(aClass);
|
2003-05-14 02:50:03 +04:00
|
|
|
if (old && old->mLocation && !PL_strcasecmp(old->mLocation, registryName))
|
2003-06-19 03:03:08 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
nsAutoMonitor mon(mMon);
|
2001-10-23 06:28:12 +04:00
|
|
|
PL_DHashTableOperate(&mFactories, &aClass, PL_DHASH_REMOVE);
|
2000-04-18 09:25:05 +04:00
|
|
|
}
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
2002-10-08 10:12:00 +04:00
|
|
|
("nsComponentManager: Factory unregister(%s) succeeded.", registryName));
|
2000-04-18 09:25:05 +04:00
|
|
|
|
2002-10-08 10:12:00 +04:00
|
|
|
return NS_OK;
|
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-26 22:04:27 +04:00
|
|
|
// XXX Need to pass in aWhen and servicemanager
|
1999-03-09 12:44:27 +03:00
|
|
|
nsresult
|
2003-06-19 03:03:08 +04:00
|
|
|
nsComponentManagerImpl::FreeLibraries(void)
|
1999-07-31 09:55:04 +04:00
|
|
|
{
|
2001-10-16 07:35:52 +04:00
|
|
|
return UnloadLibraries(NS_STATIC_CAST(nsIServiceManager*, this), NS_Timer); // XXX when
|
1999-07-31 09:55:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2001-12-19 03:12:41 +03:00
|
|
|
nsAutoMonitor mon(mMon);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
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
|
2004-10-07 22:20:19 +04:00
|
|
|
// iterate over all known loaders and ask them to Unload.
|
2001-08-30 18:10:41 +04:00
|
|
|
// Skip mNativeComponentLoader
|
|
|
|
for (int i=NS_COMPONENT_TYPE_NATIVE + 1; i<mNLoaderData; i++) {
|
2001-08-31 21:45:51 +04:00
|
|
|
if (mLoaderData[i].loader) {
|
|
|
|
rv = mLoaderData[i].loader->UnloadAll(aWhen);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
}
|
2001-08-30 18:10:41 +04:00
|
|
|
}
|
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
|
|
|
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
|
2002-01-30 00:22:13 +03:00
|
|
|
* of all components. No default directory is looked at.
|
1999-04-03 00:28:22 +04:00
|
|
|
*
|
|
|
|
* Directory and fullname are what NSPR will accept. For eg.
|
2002-01-30 00:22:13 +03:00
|
|
|
* WIN y:/home/dp/mozilla/dist/bin
|
|
|
|
* UNIX /home/dp/mozilla/dist/bin
|
2000-05-12 05:24:36 +04:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsresult
|
2000-01-25 00:28:28 +03:00
|
|
|
nsComponentManagerImpl::AutoRegister(PRInt32 when, nsIFile *inDirSpec)
|
2000-09-08 05:51:45 +04:00
|
|
|
{
|
2002-06-15 01:33:05 +04:00
|
|
|
return AutoRegisterImpl(when, inDirSpec);
|
2000-09-08 05:51:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2003-06-19 03:03:08 +04:00
|
|
|
nsComponentManagerImpl::AutoRegisterImpl(PRInt32 when,
|
|
|
|
nsIFile *inDirSpec,
|
2002-01-30 00:22:13 +03:00
|
|
|
PRBool fileIsCompDir)
|
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
|
2003-06-19 03:03:08 +04:00
|
|
|
if (inDirSpec)
|
2000-05-02 04:54:11 +04:00
|
|
|
{
|
2003-06-19 03:03:08 +04:00
|
|
|
// Use supplied components' directory
|
2000-05-02 04:54:11 +04:00
|
|
|
dir = inDirSpec;
|
2003-06-19 03:03:08 +04:00
|
|
|
}
|
|
|
|
else
|
2000-05-02 04:54:11 +04:00
|
|
|
{
|
2003-03-12 00:36:59 +03:00
|
|
|
mComponentsDir->Clone(getter_AddRefs(dir));
|
2003-01-29 01:07:53 +03:00
|
|
|
if (!dir)
|
2003-03-12 00:36:59 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager> iim =
|
2000-04-25 09:11:30 +04:00
|
|
|
dont_AddRef(XPTI_GetInterfaceInfoManager());
|
|
|
|
|
|
|
|
if (!iim)
|
2003-06-19 03:03:08 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2000-05-15 23:28:12 +04:00
|
|
|
// Notify observers of xpcom autoregistration start
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_CreateServicesFromCategory(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID,
|
2002-01-30 00:22:13 +03:00
|
|
|
nsnull,
|
2001-11-01 02:17:30 +03:00
|
|
|
"start");
|
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);
|
2000-09-09 05:36:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-06-21 00:21:49 +04:00
|
|
|
#ifdef ENABLE_STATIC_COMPONENT_LOADER
|
2003-11-01 17:46:08 +03:00
|
|
|
rv = mStaticComponentLoader->AutoRegisterComponents((PRInt32)when, inDirSpec);
|
2001-06-21 00:21:49 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
#endif
|
|
|
|
|
2000-09-09 05:36:18 +04:00
|
|
|
/* do InterfaceInfoManager after native loader so it can use components. */
|
|
|
|
rv = iim->AutoRegisterInterfaces();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-01 01:40:21 +04:00
|
|
|
|
2002-12-04 02:17:03 +03:00
|
|
|
if (!mCategoryManager) {
|
|
|
|
NS_WARNING("mCategoryManager is null");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-05-14 02:50:03 +04:00
|
|
|
}
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2000-05-26 08:56:23 +04:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> loaderEnum;
|
2002-12-04 02:17:03 +03:00
|
|
|
rv = mCategoryManager->EnumerateCategory("component-loader",
|
2000-05-26 08:56:23 +04:00
|
|
|
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
|
|
|
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> supStr = do_QueryInterface(supports);
|
2000-05-26 08:56:23 +04:00
|
|
|
if (!supStr)
|
|
|
|
continue;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-08-27 01:20:34 +04:00
|
|
|
nsCAutoString loaderType;
|
|
|
|
if (NS_FAILED(supStr->GetData(loaderType)))
|
2000-05-26 08:56:23 +04:00
|
|
|
continue;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2001-08-30 18:10:41 +04:00
|
|
|
// We depend on the loader being created. Add the loader type and
|
|
|
|
// create the loader object too.
|
2000-05-26 08:56:23 +04:00
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
2004-03-10 09:40:36 +03:00
|
|
|
int typeIndex;
|
|
|
|
rv = AddLoaderType(loaderType.get(), &typeIndex);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
GetLoaderForType(typeIndex, getter_AddRefs(loader));
|
2000-05-15 23:28:12 +04:00
|
|
|
}
|
2003-06-19 03:03:08 +04:00
|
|
|
|
|
|
|
rv = AutoRegisterNonNativeComponents(dir.get());
|
|
|
|
|
2003-01-29 01:07:53 +03:00
|
|
|
// Notify observers of xpcom autoregistration completion
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_CreateServicesFromCategory(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID,
|
2003-01-29 01:07:53 +03:00
|
|
|
nsnull,
|
2003-06-19 03:03:08 +04:00
|
|
|
"end");
|
2003-01-29 01:07:53 +03:00
|
|
|
|
|
|
|
if (mRegistryDirty)
|
|
|
|
FlushPersistentStore(PR_TRUE);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::AutoRegisterNonNativeComponents(nsIFile* spec)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIFile> directory = spec;
|
|
|
|
|
|
|
|
if (!directory) {
|
2003-03-12 00:36:59 +03:00
|
|
|
mComponentsDir->Clone(getter_AddRefs(directory));
|
2003-01-29 01:07:53 +03:00
|
|
|
if (!directory)
|
2003-03-12 00:36:59 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2003-01-29 01:07:53 +03:00
|
|
|
}
|
2000-05-17 05:53:50 +04:00
|
|
|
|
2003-01-29 01:07:53 +03:00
|
|
|
for (int i = 1; i < mNLoaderData; i++) {
|
2001-11-18 23:19:44 +03:00
|
|
|
if (!mLoaderData[i].loader) {
|
|
|
|
rv = GetLoaderForType(i, &mLoaderData[i].loader);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
}
|
2003-01-29 01:07:53 +03:00
|
|
|
rv = mLoaderData[i].loader->AutoRegisterComponents(0, directory);
|
2001-08-30 18:10:41 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
}
|
2000-05-26 08:56:23 +04:00
|
|
|
|
2000-05-15 23:28:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2001-08-30 18:10:41 +04:00
|
|
|
PRBool registered;
|
2000-05-15 23:28:12 +04:00
|
|
|
do {
|
2001-08-30 18:10:41 +04:00
|
|
|
registered = PR_FALSE;
|
2003-01-29 01:07:53 +03:00
|
|
|
for (int i = 0; i < mNLoaderData; i++) {
|
2001-08-30 18:10:41 +04:00
|
|
|
PRBool b = PR_FALSE;
|
2001-11-18 23:19:44 +03:00
|
|
|
if (mLoaderData[i].loader) {
|
2003-01-29 01:07:53 +03:00
|
|
|
rv = mLoaderData[i].loader->RegisterDeferredComponents(0, &b);
|
2001-11-18 23:19:44 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
registered |= b;
|
|
|
|
}
|
2001-08-30 18:10:41 +04:00
|
|
|
}
|
|
|
|
} while (NS_SUCCEEDED(rv) && registered);
|
2000-05-15 23:28:12 +04:00
|
|
|
}
|
|
|
|
return rv;
|
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
|
|
|
{
|
2003-08-03 13:59:05 +04:00
|
|
|
nsresult rv = NS_OK, res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-09-01 01:40:21 +04:00
|
|
|
/*
|
|
|
|
* Do we have to give the native loader first crack at it?
|
|
|
|
* I vote ``no''.
|
|
|
|
*/
|
2001-08-30 18:10:41 +04:00
|
|
|
for (int i = 0; i < mNLoaderData; i++) {
|
|
|
|
PRBool didRegister;
|
2001-11-18 23:19:44 +03:00
|
|
|
if (!mLoaderData[i].loader) {
|
2003-01-28 04:42:56 +03:00
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
|
|
|
rv = GetLoaderForType(i, getter_AddRefs(loader));
|
2001-11-18 23:19:44 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
2003-01-28 04:42:56 +03:00
|
|
|
// |GetLoaderForType| has filled in |mLoaderData[i].loader|:
|
|
|
|
NS_ASSERTION(loader == mLoaderData[i].loader, "oops");
|
2001-11-18 23:19:44 +03:00
|
|
|
}
|
2001-08-30 18:10:41 +04:00
|
|
|
rv = mLoaderData[i].loader->AutoRegisterComponent((int)when, component, &didRegister);
|
2003-08-03 13:59:05 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
res = rv;
|
|
|
|
} else if (didRegister) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-08-30 18:10:41 +04:00
|
|
|
}
|
2003-08-03 13:59:05 +04:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2000-04-18 09:25:05 +04:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::AutoUnregisterComponent(PRInt32 when,
|
|
|
|
nsIFile *component)
|
|
|
|
{
|
2001-08-30 18:10:41 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
for (int i = 0; i < mNLoaderData; i++) {
|
|
|
|
PRBool didUnRegister;
|
2001-11-18 23:19:44 +03:00
|
|
|
if (!mLoaderData[i].loader) {
|
|
|
|
rv = GetLoaderForType(i, &mLoaderData[i].loader);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
}
|
2001-08-30 18:10:41 +04:00
|
|
|
rv = mLoaderData[i].loader->AutoUnregisterComponent(when, component, &didUnRegister);
|
2003-04-18 04:46:34 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && didUnRegister) {
|
|
|
|
// we need to remove this file from our list of known libraries.
|
|
|
|
RemoveFileInfo(component, nsnull);
|
|
|
|
mRegistryDirty = PR_TRUE;
|
2001-08-30 18:10:41 +04:00
|
|
|
break;
|
2003-04-18 04:46:34 +04:00
|
|
|
}
|
2001-08-30 18:10:41 +04:00
|
|
|
}
|
|
|
|
return NS_FAILED(rv) ? 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)
|
|
|
|
{
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!aRegistered)
|
1999-08-09 09:02:25 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(0, "null ptr");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-08-22 02:42:35 +04:00
|
|
|
*aRegistered = (nsnull != GetFactoryEntry(aClass));
|
1999-08-09 09:02:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::EnumerateCLSIDs(nsIEnumerator** aEnumerator)
|
2001-10-23 06:28:12 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_ASSERTION(aEnumerator != nsnull, "null ptr");
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!aEnumerator)
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
2002-01-30 00:22:13 +03:00
|
|
|
*aEnumerator = nsnull;
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
nsresult rv;
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
PLDHashTableEnumeratorImpl *aEnum;
|
|
|
|
rv = PL_NewDHashTableEnumerator(&mFactories,
|
|
|
|
ConvertFactoryEntryToCID,
|
2003-06-19 03:03:08 +04:00
|
|
|
(void*)this,
|
2002-01-30 00:22:13 +03:00
|
|
|
&aEnum);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-03-05 11:06:25 +03:00
|
|
|
*aEnumerator = NS_STATIC_CAST(nsIEnumerator*, aEnum);
|
2002-01-30 00:22:13 +03:00
|
|
|
return NS_OK;
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::EnumerateContractIDs(nsIEnumerator** aEnumerator)
|
2001-10-23 06:28:12 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_ASSERTION(aEnumerator != nsnull, "null ptr");
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!aEnumerator)
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
*aEnumerator = nsnull;
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
nsresult rv;
|
|
|
|
PLDHashTableEnumeratorImpl *aEnum;
|
|
|
|
rv = PL_NewDHashTableEnumerator(&mContractIDs,
|
|
|
|
ConvertContractIDKeyToString,
|
2003-06-19 03:03:08 +04:00
|
|
|
(void*)this,
|
2002-01-30 00:22:13 +03:00
|
|
|
&aEnum);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-03-05 11:06:25 +03:00
|
|
|
*aEnumerator = NS_STATIC_CAST(nsIEnumerator*, aEnum);
|
2001-10-23 06:28:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
// nsIComponentRegistrar
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-01-30 00:22:13 +03:00
|
|
|
nsComponentManagerImpl::AutoRegister(nsIFile *aSpec)
|
2001-10-23 06:28:12 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
if (aSpec == nsnull)
|
|
|
|
return AutoRegisterImpl(0, aSpec);
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
PRBool directory;
|
|
|
|
aSpec->IsDirectory(&directory);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
if (directory)
|
|
|
|
return AutoRegisterImpl(0, aSpec, PR_FALSE);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
return AutoRegisterComponent(0, aSpec);
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-01-30 00:22:13 +03:00
|
|
|
nsComponentManagerImpl::AutoUnregister(nsIFile *aSpec)
|
2001-10-23 06:28:12 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
// unregistering a complete directory is not implmeneted yet...FIX
|
|
|
|
if (aSpec == nsnull)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
PRBool directory;
|
|
|
|
aSpec->IsDirectory(&directory);
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
if (directory)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
return AutoUnregisterComponent(0, aSpec);
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::RegisterFactory(const nsCID & aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aContractID,
|
2002-01-30 00:22:13 +03:00
|
|
|
nsIFactory *aFactory)
|
2001-10-23 06:28:12 +04:00
|
|
|
{
|
2003-06-19 03:03:08 +04:00
|
|
|
return RegisterFactory(aClass,
|
2002-01-30 00:22:13 +03:00
|
|
|
aClassName,
|
|
|
|
aContractID,
|
2003-06-19 03:03:08 +04:00
|
|
|
aFactory,
|
2002-01-30 00:22:13 +03:00
|
|
|
PR_TRUE);
|
2001-10-23 06:28:12 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::RegisterFactoryLocation(const nsCID & aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aContractID,
|
|
|
|
nsIFile *aFile,
|
|
|
|
const char *loaderStr,
|
2002-01-30 00:22:13 +03:00
|
|
|
const char *aType)
|
1999-08-09 09:02:25 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
nsXPIDLCString registryName;
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
if (!loaderStr)
|
|
|
|
{
|
|
|
|
nsresult rv = RegistryLocationForSpec(aFile, getter_Copies(registryName));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-08-09 09:02:25 +04:00
|
|
|
}
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
nsresult rv;
|
2003-06-19 03:03:08 +04:00
|
|
|
rv = RegisterComponentWithType(aClass,
|
|
|
|
aClassName,
|
|
|
|
aContractID,
|
2002-01-30 00:22:13 +03:00
|
|
|
aFile,
|
2002-01-30 06:51:47 +03:00
|
|
|
(loaderStr ? loaderStr : registryName.get()),
|
2003-06-19 03:03:08 +04:00
|
|
|
PR_TRUE,
|
2002-01-30 00:22:13 +03:00
|
|
|
PR_TRUE,
|
2002-10-06 03:59:57 +04:00
|
|
|
(aType ? aType : nativeComponentType));
|
1999-08-09 09:02:25 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::UnregisterFactoryLocation(const nsCID & aClass,
|
2002-01-30 00:22:13 +03:00
|
|
|
nsIFile *aFile)
|
1999-08-09 09:02:25 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
return UnregisterComponentSpec(aClass, aFile);
|
|
|
|
}
|
1999-08-09 09:02:25 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::IsCIDRegistered(const nsCID & aClass,
|
2002-01-30 00:22:13 +03:00
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
return IsRegistered(aClass, _retval);
|
|
|
|
}
|
1999-09-05 10:27:42 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::IsContractIDRegistered(const char *aClass,
|
2002-01-30 00:22:13 +03:00
|
|
|
PRBool *_retval)
|
|
|
|
{
|
2003-03-14 08:07:24 +03:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass, strlen(aClass));
|
1999-08-09 09:02:25 +04:00
|
|
|
|
2004-04-18 21:35:29 +04:00
|
|
|
if (entry)
|
2002-01-30 00:22:13 +03:00
|
|
|
*_retval = PR_TRUE;
|
2004-04-18 21:35:29 +04:00
|
|
|
else
|
|
|
|
*_retval = PR_FALSE;
|
2001-10-23 06:28:12 +04:00
|
|
|
return NS_OK;
|
1999-08-09 09:02:25 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-01-30 00:22:13 +03:00
|
|
|
nsComponentManagerImpl::EnumerateCIDs(nsISimpleEnumerator **aEnumerator)
|
1999-08-09 09:02:25 +04:00
|
|
|
{
|
2001-10-23 06:28:12 +04:00
|
|
|
NS_ASSERTION(aEnumerator != nsnull, "null ptr");
|
2002-01-30 00:22:13 +03:00
|
|
|
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!aEnumerator)
|
1999-08-09 09:02:25 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2002-01-30 00:22:13 +03:00
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
*aEnumerator = nsnull;
|
1999-08-09 09:02:25 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
2002-01-30 00:22:13 +03:00
|
|
|
PLDHashTableEnumeratorImpl *aEnum;
|
|
|
|
rv = PL_NewDHashTableEnumerator(&mFactories,
|
|
|
|
ConvertFactoryEntryToCID,
|
2003-06-19 03:03:08 +04:00
|
|
|
(void*)this,
|
2002-01-30 00:22:13 +03:00
|
|
|
&aEnum);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-08-09 09:02:25 +04:00
|
|
|
|
2002-03-05 11:06:25 +03:00
|
|
|
*aEnumerator = NS_STATIC_CAST(nsISimpleEnumerator*, aEnum);
|
2002-01-30 00:22:13 +03:00
|
|
|
return NS_OK;
|
1999-08-09 09:02:25 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-01-30 00:22:13 +03:00
|
|
|
nsComponentManagerImpl::EnumerateContractIDs(nsISimpleEnumerator **aEnumerator)
|
1999-08-09 09:02:25 +04:00
|
|
|
{
|
2001-10-23 06:28:12 +04:00
|
|
|
NS_ASSERTION(aEnumerator != nsnull, "null ptr");
|
2002-10-06 03:59:57 +04:00
|
|
|
if (!aEnumerator)
|
1999-08-09 09:02:25 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2001-10-23 06:28:12 +04:00
|
|
|
*aEnumerator = nsnull;
|
1999-08-09 09:02:25 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
2002-01-30 00:22:13 +03:00
|
|
|
PLDHashTableEnumeratorImpl *aEnum;
|
|
|
|
rv = PL_NewDHashTableEnumerator(&mContractIDs,
|
|
|
|
ConvertContractIDKeyToString,
|
2003-06-19 03:03:08 +04:00
|
|
|
(void*)this,
|
2002-01-30 00:22:13 +03:00
|
|
|
&aEnum);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-08-09 09:02:25 +04:00
|
|
|
|
2002-03-05 11:06:25 +03:00
|
|
|
*aEnumerator = NS_STATIC_CAST(nsISimpleEnumerator*, aEnum);
|
2002-01-30 00:22:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-12 01:54:46 +03:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::CIDToContractID(const nsCID & aClass,
|
2002-01-30 00:22:13 +03:00
|
|
|
char **_retval)
|
2000-01-12 01:54:46 +03:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
return CLSIDToContractID(aClass,
|
|
|
|
nsnull,
|
|
|
|
_retval);
|
2000-01-12 01:54:46 +03:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::ContractIDToCID(const char *aContractID,
|
2002-01-30 00:22:13 +03:00
|
|
|
nsCID * *_retval)
|
2001-08-30 18:10:41 +04:00
|
|
|
{
|
2002-01-30 00:22:13 +03:00
|
|
|
*_retval = (nsCID*) nsMemory::Alloc(sizeof(nsCID));
|
2002-04-08 04:18:14 +04:00
|
|
|
if (!*_retval)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv = ContractIDToClassID(aContractID, *_retval);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsMemory::Free(*_retval);
|
|
|
|
*_retval = nsnull;
|
|
|
|
}
|
|
|
|
return rv;
|
2001-08-30 18:10:41 +04:00
|
|
|
}
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
// end nsIComponentRegistrar
|
2001-08-30 18:10:41 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-06-15 01:33:05 +04:00
|
|
|
nsComponentManagerImpl::HasFileChanged(nsIFile *file, const char *loaderString, PRInt64 modDate, PRBool *_retval)
|
|
|
|
{
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
|
|
|
|
nsXPIDLCString registryName;
|
|
|
|
nsresult rv = RegistryLocationForSpec(file, getter_Copies(registryName));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
nsCStringKey key(registryName);
|
|
|
|
AutoRegEntry* entry = (AutoRegEntry*)mAutoRegEntries.Get(&key);
|
|
|
|
if (entry)
|
|
|
|
*_retval = entry->Modified(&modDate);
|
|
|
|
else
|
|
|
|
*_retval = PR_TRUE;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-06-15 01:33:05 +04:00
|
|
|
nsComponentManagerImpl::SaveFileInfo(nsIFile *file, const char *loaderString, PRInt64 modDate)
|
|
|
|
{
|
|
|
|
mRegistryDirty = PR_TRUE;
|
|
|
|
nsXPIDLCString registryName;
|
|
|
|
nsresult rv = RegistryLocationForSpec(file, getter_Copies(registryName));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
// check to see if exists in the array before adding it so that we don't have dups.
|
2003-03-05 06:22:12 +03:00
|
|
|
nsCStringKey key(registryName);
|
|
|
|
AutoRegEntry* entry = (AutoRegEntry*)mAutoRegEntries.Get(&key);
|
2003-03-04 00:00:07 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
entry->SetDate(&modDate);
|
|
|
|
return NS_OK;
|
2002-06-15 01:33:05 +04:00
|
|
|
}
|
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
entry = new AutoRegEntry(registryName, &modDate);
|
2002-06-15 01:33:05 +04:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
mAutoRegEntries.Put(&key, entry);
|
2002-06-15 01:33:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-06-15 01:33:05 +04:00
|
|
|
nsComponentManagerImpl::RemoveFileInfo(nsIFile *file, const char *loaderString)
|
|
|
|
{
|
|
|
|
mRegistryDirty = PR_TRUE;
|
|
|
|
nsXPIDLCString registryName;
|
|
|
|
nsresult rv = RegistryLocationForSpec(file, getter_Copies(registryName));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
nsCStringKey key(registryName);
|
|
|
|
AutoRegEntry* entry = (AutoRegEntry*)mAutoRegEntries.Remove(&key);
|
|
|
|
if (entry)
|
|
|
|
delete entry;
|
2003-03-01 00:30:35 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2003-03-04 00:00:07 +03:00
|
|
|
}
|
2003-03-01 00:30:35 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
NS_IMETHODIMP
|
2003-06-19 03:03:08 +04:00
|
|
|
nsComponentManagerImpl::GetOptionalData(nsIFile *file,
|
|
|
|
const char *loaderString,
|
2003-03-05 06:22:12 +03:00
|
|
|
char **_retval)
|
|
|
|
{
|
|
|
|
nsXPIDLCString registryName;
|
|
|
|
nsresult rv = RegistryLocationForSpec(file, getter_Copies(registryName));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCStringKey key(registryName);
|
|
|
|
AutoRegEntry* entry = (AutoRegEntry*)mAutoRegEntries.Get(&key);
|
|
|
|
if (!entry) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
const char* opData = entry->GetOptionalData();
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
if (opData)
|
|
|
|
*_retval = ToNewCString(nsDependentCString(opData));
|
|
|
|
else
|
|
|
|
*_retval = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-06-19 03:03:08 +04:00
|
|
|
nsComponentManagerImpl::SetOptionalData(nsIFile *file,
|
|
|
|
const char *loaderString,
|
2003-03-05 06:22:12 +03:00
|
|
|
const char *data)
|
|
|
|
{
|
|
|
|
nsXPIDLCString registryName;
|
|
|
|
nsresult rv = RegistryLocationForSpec(file, getter_Copies(registryName));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCStringKey key(registryName);
|
|
|
|
AutoRegEntry* entry = (AutoRegEntry*)mAutoRegEntries.Get(&key);
|
|
|
|
|
|
|
|
if (!entry) {
|
|
|
|
PRInt64 zero = LL_Zero();
|
|
|
|
entry = new AutoRegEntry(registryName, &zero);
|
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-06-19 03:03:08 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
mAutoRegEntries.Put(&key, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->SetOptionalData(data);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
NS_IMETHODIMP
|
2002-06-15 01:33:05 +04:00
|
|
|
nsComponentManagerImpl::FlushPersistentStore(PRBool now)
|
|
|
|
{
|
|
|
|
mRegistryDirty = PR_TRUE;
|
2003-06-19 03:03:08 +04:00
|
|
|
if (now)
|
2002-06-15 01:33:05 +04:00
|
|
|
return WritePersistentRegistry();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Static Access Functions
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_COM nsresult
|
|
|
|
NS_GetGlobalComponentManager(nsIComponentManager* *result)
|
|
|
|
{
|
2001-12-19 03:12:41 +03:00
|
|
|
#ifdef DEBUG_dougt
|
|
|
|
// NS_WARNING("DEPRECATED FUNCTION: Use NS_GetComponentManager");
|
|
|
|
#endif
|
1999-03-24 02:28:32 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
if (nsComponentManagerImpl::gComponentManager == nsnull)
|
1999-03-24 02:28:32 +03:00
|
|
|
{
|
|
|
|
// XPCOM needs initialization.
|
2001-10-16 07:35:52 +04:00
|
|
|
rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
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.
|
2001-12-19 03:12:41 +03:00
|
|
|
// See nsComponentManagerObsolete.h for the reason for such
|
2003-06-19 03:03:08 +04:00
|
|
|
// casting uglyness
|
2001-12-19 03:12:41 +03:00
|
|
|
*result = (nsIComponentManager*)(void*)(nsIComponentManagerObsolete*) nsComponentManagerImpl::gComponentManager;
|
1999-03-24 02:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
NS_COM nsresult
|
2001-12-19 03:12:41 +03:00
|
|
|
NS_GetComponentManager(nsIComponentManager* *result)
|
2001-10-16 07:35:52 +04:00
|
|
|
{
|
2002-04-16 02:33:03 +04:00
|
|
|
if (nsComponentManagerImpl::gComponentManager == nsnull)
|
2001-10-16 07:35:52 +04:00
|
|
|
{
|
|
|
|
// XPCOM needs initialization.
|
2002-10-06 03:59:57 +04:00
|
|
|
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
*result = NS_STATIC_CAST(nsIComponentManager*,
|
2001-10-16 07:35:52 +04:00
|
|
|
nsComponentManagerImpl::gComponentManager);
|
|
|
|
NS_IF_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-19 03:12:41 +03:00
|
|
|
NS_COM nsresult
|
|
|
|
NS_GetServiceManager(nsIServiceManager* *result)
|
2001-09-07 01:13:11 +04:00
|
|
|
{
|
2001-12-19 03:12:41 +03:00
|
|
|
nsresult rv = NS_OK;
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
if (nsComponentManagerImpl::gComponentManager == nsnull)
|
2001-12-19 03:12:41 +03:00
|
|
|
{
|
|
|
|
// XPCOM needs initialization.
|
|
|
|
rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
|
|
|
}
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2001-12-19 03:12:41 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
*result = NS_STATIC_CAST(nsIServiceManager*,
|
2001-12-19 03:12:41 +03:00
|
|
|
nsComponentManagerImpl::gComponentManager);
|
|
|
|
NS_IF_ADDREF(*result);
|
|
|
|
return NS_OK;
|
2001-09-07 01:13:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_COM nsresult
|
|
|
|
NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-04-16 02:33:03 +04:00
|
|
|
if (nsComponentManagerImpl::gComponentManager == nsnull)
|
2002-01-30 00:22:13 +03:00
|
|
|
{
|
|
|
|
// XPCOM needs initialization.
|
|
|
|
rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
*result = NS_STATIC_CAST(nsIComponentRegistrar*,
|
2002-01-30 00:22:13 +03:00
|
|
|
nsComponentManagerImpl::gComponentManager);
|
|
|
|
NS_IF_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
|
|
|
|
// nsIComponentLoaderManager is not frozen, but is defined here
|
|
|
|
// so that I can use it internally in xpcom.
|
|
|
|
nsresult
|
|
|
|
NS_GetComponentLoaderManager(nsIComponentLoaderManager* *result)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager == NULL)
|
|
|
|
{
|
|
|
|
// XPCOM needs initialization.
|
|
|
|
rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-10-06 03:59:57 +04:00
|
|
|
|
2003-06-19 03:03:08 +04:00
|
|
|
*result = NS_STATIC_CAST(nsIComponentLoaderManager*,
|
2002-06-15 01:33:05 +04:00
|
|
|
nsComponentManagerImpl::gComponentManager);
|
|
|
|
NS_IF_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|