1999-03-10 12:53:25 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
1999-03-09 12:44:27 +03:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "nsCOMPtr.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
1999-06-22 18:02:58 +04:00
|
|
|
#include "nsSpecialSystemDirectory.h"
|
1999-07-02 07:35:09 +04:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIEnumerator.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prlink.h"
|
|
|
|
#include "prsystem.h"
|
|
|
|
#include "prprf.h"
|
1999-03-12 14:25:17 +03:00
|
|
|
#include "xcDll.h"
|
1999-03-11 01:07:34 +03:00
|
|
|
#include "prerror.h"
|
1999-03-31 11:04:12 +04:00
|
|
|
#include "prmem.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#include "prcmon.h"
|
|
|
|
#include "prthread.h" /* XXX: only used for the NSPR initialization hack (rick) */
|
|
|
|
|
1999-06-29 14:27:58 +04:00
|
|
|
#ifdef XP_BEOS
|
|
|
|
#include <FindDirectory.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#endif
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
// Logging of debug output
|
1999-06-29 01:51:46 +04:00
|
|
|
#define FORCE_PR_LOG /* Allow logging in the release build */
|
|
|
|
#include "prlog.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
PRLogModuleInfo* nsComponentManagerLog = NULL;
|
1999-06-14 06:07:03 +04:00
|
|
|
|
|
|
|
// Enable printing of critical errors on screen even for release builds
|
|
|
|
#define PRINT_CRITICAL_ERROR_TO_SCREEN
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-04-05 04:07:18 +04:00
|
|
|
// Common Key Names
|
|
|
|
const char xpcomBaseName[]="XPCOM";
|
|
|
|
const char xpcomKeyName[] ="Software/Netscape/XPCOM";
|
|
|
|
const char netscapeKeyName[]="Software/Netscape";
|
|
|
|
const char classesKeyName[]="Classes";
|
|
|
|
const char classIDKeyName[]="CLSID";
|
|
|
|
const char classesClassIDKeyName[]="Classes/CLSID";
|
|
|
|
|
|
|
|
|
|
|
|
// Common Value Names
|
|
|
|
const char classIDValueName[]="CLSID";
|
|
|
|
const char versionValueName[]="VersionString";
|
|
|
|
const char lastModValueName[]="LastModTimeStamp";
|
|
|
|
const char fileSizeValueName[]="FileSize";
|
|
|
|
const char componentCountValueName[]="ComponentsCount";
|
|
|
|
const char progIDValueName[]="ProgID";
|
|
|
|
const char classNameValueName[]="ClassName";
|
|
|
|
const char inprocServerValueName[]="InprocServer";
|
|
|
|
|
1999-04-12 16:32:24 +04:00
|
|
|
// We define a CID that is used to indicate the non-existence of a
|
|
|
|
// progid in the hash table.
|
|
|
|
#define NS_NO_CID { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
|
|
|
static NS_DEFINE_CID(kNoCID, NS_NO_CID);
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
// Build is using USE_NSREG to turn off xpcom using registry
|
|
|
|
// but internally we use USE_REGISTRY. Map them propertly.
|
|
|
|
#ifdef USE_NSREG
|
|
|
|
#define USE_REGISTRY
|
|
|
|
#endif /* USE_NSREG */
|
1999-04-12 16:32:24 +04:00
|
|
|
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFactoryEntry
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, nsDll *aDll)
|
|
|
|
: cid(aClass), factory(NULL), dll(aDll)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, nsIFactory *aFactory)
|
|
|
|
: cid(aClass), factory(aFactory), dll(NULL)
|
|
|
|
|
|
|
|
{
|
1999-03-24 02:28:32 +03:00
|
|
|
NS_ADDREF(aFactory);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFactoryEntry::~nsFactoryEntry(void)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
if (factory != NULL) {
|
|
|
|
NS_RELEASE(factory);
|
|
|
|
}
|
|
|
|
// DO NOT DELETE nsDll *dll;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// autoFree
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//
|
1999-06-22 18:02:58 +04:00
|
|
|
// To prevent leaks, we are using this class. Typical use would be
|
1999-03-31 11:04:12 +04:00
|
|
|
// for each ptr to be deleted, create an object of these types with that ptr.
|
|
|
|
// Once that object goes out of scope, deletion and hence memory free will
|
|
|
|
// automatically happen.
|
|
|
|
//
|
1999-07-15 04:11:20 +04:00
|
|
|
class autoStringFree
|
1999-03-31 11:04:12 +04:00
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
public:
|
|
|
|
enum DeleteModel {
|
|
|
|
NSPR_Delete = 1,
|
1999-07-15 04:11:20 +04:00
|
|
|
nsCRT_String_Delete = 2
|
1999-06-22 18:02:58 +04:00
|
|
|
};
|
1999-07-15 04:11:20 +04:00
|
|
|
autoStringFree(char *Ptr, DeleteModel whichDelete): mPtr(Ptr), mWhichDelete(whichDelete) {}
|
|
|
|
~autoStringFree() {
|
1999-06-22 18:02:58 +04:00
|
|
|
if (mPtr)
|
|
|
|
if (mWhichDelete == NSPR_Delete) { PR_FREEIF(mPtr); }
|
1999-07-15 04:11:20 +04:00
|
|
|
else if (mWhichDelete == nsCRT_String_Delete) nsCRT::free(mPtr);
|
1999-06-22 18:02:58 +04:00
|
|
|
else PR_ASSERT(0);
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
private:
|
1999-07-15 04:11:20 +04:00
|
|
|
char *mPtr;
|
1999-06-22 18:02:58 +04:00
|
|
|
DeleteModel mWhichDelete;
|
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsComponentManagerImpl
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManagerImpl::nsComponentManagerImpl()
|
1999-03-31 11:04:12 +04:00
|
|
|
: mFactories(NULL), mProgIDs(NULL), mMon(NULL), mDllStore(NULL), mRegistry(NULL)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsComponentManagerImpl::Init(void)
|
|
|
|
{
|
1999-06-14 06:07:03 +04:00
|
|
|
if (nsComponentManagerLog == NULL)
|
|
|
|
{
|
|
|
|
nsComponentManagerLog = PR_NewLogModule("nsComponentManager");
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
if (mFactories == NULL) {
|
1999-05-06 17:29:37 +04:00
|
|
|
mFactories = new nsHashtable(256, /* Thread Safe */ PR_TRUE);
|
1999-03-09 12:44:27 +03:00
|
|
|
if (mFactories == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if (mProgIDs == NULL) {
|
1999-05-06 17:29:37 +04:00
|
|
|
mProgIDs = new nsHashtable(256, /* Thread Safe */ PR_TRUE);
|
1999-03-09 12:44:27 +03:00
|
|
|
if (mProgIDs == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-03-09 13:15:54 +03:00
|
|
|
if (mMon == NULL) {
|
|
|
|
mMon = PR_NewMonitor();
|
|
|
|
if (mMon == NULL)
|
1999-03-09 12:44:27 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if (mDllStore == NULL) {
|
1999-05-06 17:29:37 +04:00
|
|
|
mDllStore = new nsHashtable(256, /* Thead Safe */ PR_TRUE);
|
1999-03-09 12:44:27 +03:00
|
|
|
if (mDllStore == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-06-14 06:07:03 +04:00
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Initialized."));
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
#ifdef USE_REGISTRY
|
|
|
|
PlatformInit();
|
|
|
|
#endif
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
nsComponentManagerImpl::~nsComponentManagerImpl()
|
|
|
|
{
|
|
|
|
if (mFactories)
|
|
|
|
delete mFactories;
|
|
|
|
if (mProgIDs)
|
|
|
|
delete mProgIDs;
|
|
|
|
if (mMon)
|
|
|
|
PR_DestroyMonitor(mMon);
|
|
|
|
if (mDllStore)
|
|
|
|
delete mDllStore;
|
|
|
|
#ifdef USE_REGISTRY
|
|
|
|
if(mRegistry)
|
|
|
|
NS_RELEASE(mRegistry);
|
|
|
|
#endif /* USE_REGISTRY */
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsComponentManagerImpl, nsIComponentManager::GetIID());
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsComponentManagerImpl: Platform methods
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformInit(void)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
// We need to create our registry. Since we are in the constructor
|
1999-06-14 06:07:03 +04:00
|
|
|
// we haven't gone as far as registering the registry factory.
|
|
|
|
// Hence, we hand create a registry.
|
|
|
|
if (mRegistry == NULL) {
|
|
|
|
nsIFactory *registryFactory = NULL;
|
|
|
|
rv = NS_RegistryGetFactory(®istryFactory);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
NS_DEFINE_IID(kRegistryIID, NS_IREGISTRY_IID);
|
|
|
|
rv = registryFactory->CreateInstance(NULL, kRegistryIID,(void **)&mRegistry);
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-31 11:04:12 +04:00
|
|
|
NS_RELEASE(registryFactory);
|
|
|
|
}
|
|
|
|
}
|
1999-03-11 10:44:23 +03:00
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
// Create ~/.mozilla as that is the default place for the registry file
|
|
|
|
|
|
|
|
/* The default registry on the unix system is $HOME/.mozilla/registry per
|
|
|
|
* vr_findGlobalRegName(). vr_findRegFile() will create the registry file
|
|
|
|
* if it doesn't exist. But it wont create directories.
|
|
|
|
*
|
|
|
|
* Hence we need to create the directory if it doesn't exist already.
|
|
|
|
*
|
|
|
|
* Why create it here as opposed to the app ?
|
|
|
|
* ------------------------------------------
|
|
|
|
* The app cannot create the directory in main() as most of the registry
|
|
|
|
* and initialization happens due to use of static variables.
|
|
|
|
* And we dont want to be dependent on the order in which
|
|
|
|
* these static stuff happen.
|
|
|
|
*
|
|
|
|
* Permission for the $HOME/.mozilla will be Read,Write,Execute
|
|
|
|
* for user only. Nothing to group and others.
|
|
|
|
*/
|
|
|
|
char *home = getenv("HOME");
|
|
|
|
if (home != NULL)
|
|
|
|
{
|
|
|
|
char dotMozillaDir[1024];
|
|
|
|
PR_snprintf(dotMozillaDir, sizeof(dotMozillaDir),
|
|
|
|
"%s/" NS_MOZILLA_DIR_NAME, home);
|
|
|
|
if (PR_Access(dotMozillaDir, PR_ACCESS_EXISTS) != PR_SUCCESS)
|
|
|
|
{
|
|
|
|
PR_MkDir(dotMozillaDir, NS_MOZILLA_DIR_PERMISSION);
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-03-31 11:04:12 +04:00
|
|
|
("nsComponentManager: Creating Directory %s", dotMozillaDir));
|
1999-03-11 10:44:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* XP_UNIX */
|
1999-06-29 14:27:58 +04:00
|
|
|
|
|
|
|
#ifdef XP_BEOS
|
|
|
|
BPath p;
|
|
|
|
const char *settings = "/boot/home/config/settings";
|
|
|
|
if(find_directory(B_USER_SETTINGS_DIRECTORY, &p) == B_OK)
|
|
|
|
settings = p.Path();
|
|
|
|
char settingsMozillaDir[1024];
|
|
|
|
PR_snprintf(settingsMozillaDir, sizeof(settingsMozillaDir),
|
|
|
|
"%s/" NS_MOZILLA_DIR_NAME, settings);
|
|
|
|
if (PR_Access(settingsMozillaDir, PR_ACCESS_EXISTS) != PR_SUCCESS) {
|
|
|
|
PR_MkDir(settingsMozillaDir, NS_MOZILLA_DIR_PERMISSION);
|
|
|
|
printf("nsComponentManager: Creating Directory %s\n", settingsMozillaDir);
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Creating Directory %s", settingsMozillaDir));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-06-09 23:18:24 +04:00
|
|
|
// Open the App Components registry. We will keep it open forever!
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
// Check the version of registry. Nuke old versions.
|
1999-03-11 10:44:23 +03:00
|
|
|
PlatformVersionCheck();
|
1999-04-06 12:26:38 +04:00
|
|
|
|
1999-05-06 17:29:37 +04:00
|
|
|
// Open common registry keys here to speed access
|
|
|
|
// Do this after PlatformVersionCheck as it may re-create our keys
|
1999-04-06 12:26:38 +04:00
|
|
|
rv = mRegistry->AddSubtree(nsIRegistry::Common, xpcomKeyName, &mXPCOMKey);
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-06 12:26:38 +04:00
|
|
|
|
1999-05-06 08:19:06 +04:00
|
|
|
rv = mRegistry->AddSubtree(nsIRegistry::Common, classesKeyName, &mClassesKey);
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-06 12:26:38 +04:00
|
|
|
|
1999-05-06 08:19:06 +04:00
|
|
|
rv = mRegistry->AddSubtree(nsIRegistry::Common, classIDKeyName, &mCLSIDKey);
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PlatformVersionCheck()
|
|
|
|
*
|
|
|
|
* Checks to see if the XPCOM hierarchy in the registry is the same as that of
|
|
|
|
* the software as defined by NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformVersionCheck()
|
|
|
|
{
|
1999-04-12 16:32:24 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
nsIRegistry::Key xpcomKey;
|
|
|
|
nsresult rv;
|
|
|
|
rv = mRegistry->AddSubtree(nsIRegistry::Common, xpcomKeyName, &xpcomKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
char *buf;
|
1999-04-05 04:07:18 +04:00
|
|
|
nsresult err = mRegistry->GetString(xpcomKey, versionValueName, &buf);
|
1999-07-15 04:11:20 +04:00
|
|
|
autoStringFree delete_buf(buf, autoStringFree::NSPR_Delete);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// If there is a version mismatch or no version string, we got an old registry.
|
|
|
|
// Delete the old repository hierarchies and recreate version string
|
1999-05-06 17:29:37 +04:00
|
|
|
if (NS_FAILED(err) || PL_strcmp(buf, NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Registry version mismatch (%s vs %s). Nuking xpcom "
|
|
|
|
"registry hierarchy.", buf, NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING));
|
|
|
|
|
|
|
|
// Delete the XPCOM and CLSID hierarchy
|
1999-03-31 11:04:12 +04:00
|
|
|
nsIRegistry::Key netscapeKey;
|
1999-04-06 12:52:51 +04:00
|
|
|
rv = mRegistry->GetSubtree(nsIRegistry::Common,netscapeKeyName, &netscapeKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-04-06 12:52:51 +04:00
|
|
|
("nsComponentManager: Failed To Get Subtree (%s)",netscapeKeyName));
|
1999-05-06 17:29:37 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = mRegistry->RemoveSubtreeRaw(netscapeKey, xpcomBaseName);
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Failed To Nuke Subtree (%s)",xpcomKeyName));
|
|
|
|
return rv;
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
}
|
|
|
|
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetSubtree(nsIRegistry::Common,classesKeyName, &netscapeKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-04-05 04:07:18 +04:00
|
|
|
("nsComponentManager: Failed To Get Subtree (%s)",classesKeyName));
|
1999-05-06 17:29:37 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = mRegistry->RemoveSubtreeRaw(netscapeKey, classIDKeyName);
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Failed To Nuke Subtree (%s/%s)",classesKeyName,classIDKeyName));
|
|
|
|
return rv;
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
}
|
1999-03-10 12:16:28 +03:00
|
|
|
|
1999-04-12 16:32:24 +04:00
|
|
|
// Recreate XPCOM and CLSID keys
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->AddSubtree(nsIRegistry::Common,xpcomKeyName, &xpcomKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-04-05 04:07:18 +04:00
|
|
|
("nsComponentManager: Failed To Add Subtree (%s)",xpcomKeyName));
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->AddSubtree(nsIRegistry::Common,classesClassIDKeyName, NULL);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-04-05 04:07:18 +04:00
|
|
|
("nsComponentManager: Failed To Add Subtree (%s)",classesClassIDKeyName));
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->SetString(xpcomKey,versionValueName, NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-04-05 04:07:18 +04:00
|
|
|
("nsComponentManager: Failed To Set String (Version) Under (%s)",xpcomKeyName));
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
else
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: platformVersionCheck() passed."));
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
|
|
|
|
void
|
1999-06-22 18:02:58 +04:00
|
|
|
nsComponentManagerImpl::PlatformGetFileInfo(nsIRegistry::Key key, PRUint32 *lastModifiedTime, PRUint32 *fileSize)
|
1999-03-31 11:04:12 +04:00
|
|
|
{
|
|
|
|
PR_ASSERT(lastModifiedTime);
|
|
|
|
PR_ASSERT(fileSize);
|
|
|
|
|
|
|
|
nsresult rv;
|
1999-06-22 18:02:58 +04:00
|
|
|
int32 lastMod;
|
|
|
|
rv = mRegistry->GetInt(key, lastModValueName, &lastMod);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-03-31 11:04:12 +04:00
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
*lastModifiedTime = lastMod;
|
1999-03-31 11:04:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 fsize = 0;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetInt(key, fileSizeValueName, &fsize);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
*fileSize = fsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::PlatformSetFileInfo(nsIRegistry::Key key, PRUint32 lastModifiedTime, PRUint32 fileSize)
|
|
|
|
{
|
|
|
|
mRegistry->SetInt(key, lastModValueName, lastModifiedTime);
|
|
|
|
mRegistry->SetInt(key, fileSizeValueName, fileSize);
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/**
|
|
|
|
* PlatformCreateDll(const char *fullname)
|
|
|
|
*
|
|
|
|
* Creates a nsDll from the registry representation of dll 'fullname'.
|
|
|
|
* Looks under
|
|
|
|
* ROOTKEY_COMMON/Software/Netscape/XPCOM/fullname
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformCreateDll(const char *fullname, nsDll* *result)
|
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry!=NULL);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsIRegistry::Key fullnameKey;
|
|
|
|
|
1999-04-06 12:52:51 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mXPCOMKey,fullname, &fullnameKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
PRUint32 lastModTime = 0;
|
|
|
|
PRUint32 fileSize = 0;
|
|
|
|
PlatformGetFileInfo(fullnameKey, &lastModTime, &fileSize);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsDll *dll = new nsDll(fullname, lastModTime, fileSize);
|
|
|
|
if (dll == NULL)
|
1999-03-12 22:49:31 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-12 22:49:31 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
*result = dll;
|
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PlatformMarkNoComponents(nsDll *dll)
|
|
|
|
*
|
|
|
|
* Stores the dll name, last modified time, size and 0 for number of
|
|
|
|
* components in dll in the registry at location
|
|
|
|
* ROOTKEY_COMMON/Software/Netscape/XPCOM/dllname
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformMarkNoComponents(nsDll *dll)
|
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry!=NULL);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsIRegistry::Key dllPathKey;
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mXPCOMKey, dll->GetPersistentDescriptorString(), &dllPathKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
PlatformSetFileInfo(dllPathKey, dll->GetLastModifiedTime(), dll->GetSize());
|
|
|
|
rv = mRegistry->SetInt(dllPathKey, componentCountValueName, 0);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
// XXX PlatformRegister needs to deal with dllName type dlls
|
1999-03-09 12:44:27 +03:00
|
|
|
nsresult
|
1999-06-14 06:07:03 +04:00
|
|
|
nsComponentManagerImpl::PlatformRegister(const char *cidString,
|
|
|
|
const char *className,
|
|
|
|
const char * progID, nsDll *dll)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Preconditions
|
1999-06-14 06:07:03 +04:00
|
|
|
PR_ASSERT(cidString != NULL);
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ASSERT(dll != NULL);
|
1999-06-14 06:07:03 +04:00
|
|
|
PR_ASSERT(mRegistry !=NULL);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
1999-04-06 12:26:38 +04:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsIRegistry::Key IDkey;
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mCLSIDKey, cidString, &IDkey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv)) return (rv);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->SetString(IDkey,classNameValueName, className);
|
|
|
|
if (progID)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->SetString(IDkey,progIDValueName, progID);
|
1999-03-31 11:04:12 +04:00
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = mRegistry->SetString(IDkey, inprocServerValueName, dll->GetPersistentDescriptorString());
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
if (progID)
|
1999-03-31 11:04:12 +04:00
|
|
|
{
|
|
|
|
nsIRegistry::Key progIDKey;
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mClassesKey, progID, &progIDKey);
|
|
|
|
rv = mRegistry->SetString(progIDKey, classIDValueName, cidString);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Gross. LongLongs dont have a serialization format. This makes
|
|
|
|
// XXX the registry non-xp. Someone beat on the nspr people to get
|
|
|
|
// XXX a longlong serialization function please!
|
1999-04-06 12:26:38 +04:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsIRegistry::Key dllPathKey;
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mXPCOMKey,dll->GetPersistentDescriptorString(), &dllPathKey);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
PlatformSetFileInfo(dllPathKey, dll->GetLastModifiedTime(), dll->GetSize());
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
int32 nComponents = 0;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetInt(dllPathKey, componentCountValueName, &nComponents);
|
1999-03-10 12:53:25 +03:00
|
|
|
nComponents++;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->SetInt(dllPathKey,componentCountValueName, nComponents);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-06-14 06:07:03 +04:00
|
|
|
nsComponentManagerImpl::PlatformUnregister(const char *cidString,
|
|
|
|
const char *aLibrary)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry!=NULL);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsIRegistry::Key cidKey;
|
1999-06-14 06:07:03 +04:00
|
|
|
rv = mRegistry->AddSubtreeRaw(mCLSIDKey, cidString, &cidKey);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char *progID = NULL;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetString(cidKey, progIDValueName, &progID);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_SUCCEEDED(rv))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-06-09 23:18:24 +04:00
|
|
|
mRegistry->RemoveSubtreeRaw(mClassesKey, progID);
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_FREEIF(progID);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
mRegistry->RemoveSubtree(mCLSIDKey, cidString);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
|
|
|
nsIRegistry::Key libKey;
|
1999-06-09 23:18:24 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mXPCOMKey, aLibrary, &libKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
|
|
|
// We need to reduce the ComponentCount by 1.
|
|
|
|
// If the ComponentCount hits 0, delete the entire key.
|
1999-03-31 11:04:12 +04:00
|
|
|
int32 nComponents = 0;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetInt(libKey, componentCountValueName, &nComponents);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
|
|
|
nComponents--;
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (nComponents <= 0)
|
|
|
|
{
|
1999-06-09 23:18:24 +04:00
|
|
|
rv = mRegistry->RemoveSubtreeRaw(mXPCOMKey, aLibrary);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->SetInt(libKey, componentCountValueName, nComponents);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformFind(const nsCID &aCID, nsFactoryEntry* *result)
|
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry!=NULL);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
char *cidString = aCID.ToString();
|
1999-03-31 11:04:12 +04:00
|
|
|
nsIRegistry::Key cidKey;
|
1999-05-06 08:19:06 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mCLSIDKey, cidString, &cidKey);
|
1999-03-10 12:53:25 +03:00
|
|
|
delete [] cidString;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
char *library = NULL;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetString(cidKey, inprocServerValueName, &library);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv))
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Registry inconsistent. No File name for CLSID.
|
1999-03-31 11:04:12 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-07-15 04:11:20 +04:00
|
|
|
autoStringFree delete_library(library, autoStringFree::NSPR_Delete);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
|
|
|
// Get the library name, modifiedtime and size
|
1999-06-22 18:02:58 +04:00
|
|
|
PRUint32 lastModTime = 0;
|
1999-03-31 11:04:12 +04:00
|
|
|
PRUint32 fileSize = 0;
|
|
|
|
|
1999-04-06 12:26:38 +04:00
|
|
|
nsIRegistry::Key key;
|
|
|
|
rv = mRegistry->GetSubtreeRaw(mXPCOMKey, library, &key);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-04-06 12:26:38 +04:00
|
|
|
PlatformGetFileInfo(key, &lastModTime, &fileSize);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
nsDll *dll = CreateCachedDll(library, lastModTime, fileSize);
|
|
|
|
if (dll == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
nsFactoryEntry *res = new nsFactoryEntry(aCID, dll);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (res == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
|
|
|
*result = res;
|
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformProgIDToCLSID(const char *aProgID, nsCID *aClass)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ASSERT(aClass != NULL);
|
1999-03-31 11:04:12 +04:00
|
|
|
PR_ASSERT(mRegistry);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsIRegistry::Key progIDKey;
|
1999-04-06 12:52:51 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mClassesKey, aProgID, &progIDKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char *cidString;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetString(progIDKey, classIDValueName, &cidString);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
if (!(aClass->Parse(cidString)))
|
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
PR_FREEIF(cidString);
|
1999-03-31 11:04:12 +04:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::PlatformCLSIDToProgID(nsCID *aClass,
|
|
|
|
char* *aClassName, char* *aProgID)
|
|
|
|
{
|
1999-03-31 11:04:12 +04:00
|
|
|
|
|
|
|
PR_ASSERT(aClass);
|
|
|
|
PR_ASSERT(mRegistry);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
nsresult rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char* cidStr = aClass->ToString();
|
|
|
|
nsIRegistry::Key cidKey;
|
1999-04-06 12:26:38 +04:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mClassesKey,cidStr,&cidKey);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
|
|
|
PR_FREEIF(cidStr);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char* classnameString;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetString(cidKey, classNameValueName, &classnameString);
|
1999-03-31 11:04:12 +04:00
|
|
|
if(NS_FAILED(rv)) return rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
*aClassName = classnameString;
|
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
char* progidString;
|
1999-04-05 04:07:18 +04:00
|
|
|
rv = mRegistry->GetString(cidKey,progIDValueName,&progidString);
|
1999-03-31 11:04:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
*aProgID = progidString;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-31 11:04:12 +04:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-07-02 07:35:09 +04:00
|
|
|
nsresult nsComponentManagerImpl::PlatformPrePopulateRegistry()
|
|
|
|
{
|
|
|
|
// Read in all dll entries and populate the mDllStore
|
|
|
|
nsCOMPtr<nsIEnumerator> dllEnum;
|
|
|
|
nsresult rv = mRegistry->EnumerateSubtrees( mXPCOMKey, getter_AddRefs(dllEnum));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = dllEnum->First();
|
|
|
|
for (; NS_SUCCEEDED(rv) && !dllEnum->IsDone(); (rv = dllEnum->Next()))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> base;
|
|
|
|
rv = dllEnum->CurrentItem(getter_AddRefs(base));
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
|
|
|
|
// Get specific interface.
|
|
|
|
nsIID nodeIID = NS_IREGISTRYNODE_IID;
|
|
|
|
nsCOMPtr<nsIRegistryNode> node;
|
|
|
|
rv = base->QueryInterface( nodeIID, getter_AddRefs(node) );
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
|
|
|
|
// Get library name
|
|
|
|
char *library = NULL;
|
|
|
|
rv = node->GetName(&library);
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
// XXX make sure the following will work
|
1999-07-15 04:11:20 +04:00
|
|
|
autoStringFree delete_library(library, autoStringFree::nsCRT_String_Delete);
|
1999-07-02 07:35:09 +04:00
|
|
|
|
|
|
|
// Get key associated with library
|
|
|
|
nsIRegistry::Key libKey;
|
|
|
|
rv = node->GetKey(&libKey);
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
|
|
|
|
// Create nsDll with this name
|
|
|
|
PRUint32 lastModTime = 0;
|
|
|
|
PRUint32 fileSize = 0;
|
|
|
|
PlatformGetFileInfo(libKey, &lastModTime, &fileSize);
|
|
|
|
|
|
|
|
// printf("Populating dll: %s, %d, %d\n", library, lastModTime, fileSize);
|
|
|
|
|
|
|
|
nsDll *dll = CreateCachedDll(library, lastModTime, fileSize);
|
|
|
|
if (dll == NULL)
|
|
|
|
{
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then read in all CID entries and populate the mFactories
|
|
|
|
nsCOMPtr<nsIEnumerator> cidEnum;
|
|
|
|
rv = mRegistry->EnumerateSubtrees( mCLSIDKey, getter_AddRefs(cidEnum));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = cidEnum->First();
|
|
|
|
for (; NS_SUCCEEDED(rv) && !cidEnum->IsDone(); (rv = cidEnum->Next()))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> base;
|
|
|
|
rv = cidEnum->CurrentItem(getter_AddRefs(base));
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
|
|
|
|
// Get specific interface.
|
|
|
|
nsIID nodeIID = NS_IREGISTRYNODE_IID;
|
|
|
|
nsCOMPtr<nsIRegistryNode> node;
|
|
|
|
rv = base->QueryInterface( nodeIID, getter_AddRefs(node) );
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
|
|
|
|
// Get library name
|
|
|
|
char *cidString = NULL;
|
|
|
|
rv = node->GetName(&cidString);
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
// XXX make sure the following will work
|
1999-07-15 04:11:20 +04:00
|
|
|
autoStringFree delete_cidString(cidString, autoStringFree::nsCRT_String_Delete);
|
1999-07-02 07:35:09 +04:00
|
|
|
|
|
|
|
// Get key associated with library
|
|
|
|
nsIRegistry::Key cidKey;
|
|
|
|
rv = node->GetKey(&cidKey);
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
|
|
|
|
// Create the CID entry
|
|
|
|
char *library = NULL;
|
|
|
|
rv = mRegistry->GetString(cidKey, inprocServerValueName, &library);
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
// XXX wont work in this scope
|
1999-07-15 04:11:20 +04:00
|
|
|
autoStringFree delete_library(library, autoStringFree::NSPR_Delete);
|
1999-07-02 07:35:09 +04:00
|
|
|
nsCID aClass;
|
|
|
|
if (!(aClass.Parse(cidString))) continue;
|
|
|
|
|
|
|
|
nsDll *dll = CreateCachedDll(library, 0, 0);
|
|
|
|
if (!dll) continue;
|
|
|
|
nsFactoryEntry* entry = new nsFactoryEntry(aClass, dll);
|
|
|
|
if (!entry) continue;
|
|
|
|
|
|
|
|
nsIDKey key(aClass);
|
|
|
|
mFactories->Put(&key, entry);
|
|
|
|
// printf("Populating cid: %s, %s\n", cidString, library);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally read in PROGID -> CID mappings
|
1999-07-07 11:47:14 +04:00
|
|
|
// Naa. Only about 20 progid are always got. So prepopulating this
|
|
|
|
// doesn't make much sense now. If this gets higher, more close to
|
|
|
|
// the number of progid that exist, this would make sense.
|
1999-07-02 07:35:09 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
#endif /* USE_REGISTRY */
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
//
|
|
|
|
// HashProgID
|
|
|
|
//
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::HashProgID(const char *aProgID, const nsCID &aClass)
|
|
|
|
{
|
|
|
|
if(!aProgID)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-07-22 06:11:04 +04:00
|
|
|
nsStringKey key(aProgID);
|
1999-06-22 18:02:58 +04:00
|
|
|
nsCID* cid = (nsCID*) mProgIDs->Get(&key);
|
|
|
|
if (cid)
|
|
|
|
{
|
|
|
|
if (cid == &kNoCID)
|
|
|
|
{
|
|
|
|
// we don't delete this ptr as it's static (ugh)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete cid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cid = new nsCID(aClass);
|
|
|
|
if (!cid)
|
|
|
|
{
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProgIDs->Put(&key, cid);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDll* nsComponentManagerImpl::CreateCachedDllName(const char *dllName)
|
|
|
|
{
|
|
|
|
// Check our dllCollection for a dll with matching name
|
1999-07-22 06:11:04 +04:00
|
|
|
nsStringKey key(dllName);
|
1999-06-22 18:02:58 +04:00
|
|
|
nsDll *dll = (nsDll *) mDllStore->Get(&key);
|
|
|
|
|
|
|
|
if (dll == NULL)
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: New dll \"%s\".", dllName));
|
|
|
|
|
|
|
|
// Add a new Dll into the nsDllStore
|
|
|
|
dll = new nsDll(dllName, 1 /* dummy */);
|
|
|
|
if (dll == NULL) return NULL;
|
|
|
|
if (dll->GetStatus() != DLL_OK)
|
|
|
|
{
|
|
|
|
// Cant create a nsDll. Backoff.
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: ERROR in creating nsDll from \"%s\".", dllName));
|
|
|
|
delete dll;
|
|
|
|
dll = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Adding New dll \"%s\" to mDllStore.",
|
|
|
|
dllName));
|
|
|
|
|
|
|
|
mDllStore->Put(&key, (void *)dll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Found in mDllStore \"%s\".", dllName));
|
|
|
|
}
|
|
|
|
|
|
|
|
return dll;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsDll* nsComponentManagerImpl::CreateCachedDll(const char *persistentDescriptor,
|
|
|
|
PRUint32 modDate, PRUint32 fileSize)
|
|
|
|
{
|
|
|
|
// Check our dllCollection for a dll with matching name
|
1999-07-22 06:11:04 +04:00
|
|
|
nsStringKey key(persistentDescriptor);
|
1999-06-22 18:02:58 +04:00
|
|
|
nsDll *dll = (nsDll *) mDllStore->Get(&key);
|
|
|
|
|
|
|
|
if (dll == NULL)
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: New dll \"%s\".", persistentDescriptor));
|
|
|
|
|
|
|
|
// Add a new Dll into the nsDllStore
|
|
|
|
dll = new nsDll(persistentDescriptor, modDate, fileSize);
|
|
|
|
if (dll == NULL) return NULL;
|
|
|
|
if (dll->GetStatus() != DLL_OK)
|
|
|
|
{
|
|
|
|
// Cant create a nsDll. Backoff.
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: ERROR in creating nsDll from \"%s\".", persistentDescriptor));
|
|
|
|
delete dll;
|
|
|
|
dll = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Adding New dll \"%s\" to mDllStore.",
|
|
|
|
persistentDescriptor));
|
|
|
|
|
|
|
|
mDllStore->Put(&key, (void *)dll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Found in mDllStore \"%s\".", persistentDescriptor));
|
|
|
|
// XXX We found the dll in the dllCollection.
|
|
|
|
// XXX Consistency check: dll needs to have the same
|
|
|
|
// XXX lastModTime and fileSize. If not that would mean
|
|
|
|
// XXX that the dll wasn't registered properly.
|
|
|
|
}
|
|
|
|
|
|
|
|
return dll;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsDll* nsComponentManagerImpl::CreateCachedDll(nsIFileSpec *dllSpec)
|
|
|
|
{
|
1999-07-09 07:45:19 +04:00
|
|
|
nsDll *dll = NULL;
|
1999-06-22 18:02:58 +04:00
|
|
|
PRUint32 modDate;
|
|
|
|
PRUint32 size;
|
1999-07-09 07:45:19 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
if (NS_FAILED(dllSpec->GetModDate(&modDate)) ||
|
|
|
|
NS_FAILED(dllSpec->GetFileSize(&size)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
char *persistentDescriptor = NULL;
|
|
|
|
if (NS_FAILED(dllSpec->GetPersistentDescriptorString(&persistentDescriptor)))
|
|
|
|
return NULL;
|
1999-07-09 07:45:19 +04:00
|
|
|
dll = CreateCachedDll(persistentDescriptor, modDate, size);
|
|
|
|
nsCRT::free(persistentDescriptor);
|
|
|
|
|
|
|
|
return dll;
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsComponentManagerImpl: Public methods
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LoadFactory()
|
|
|
|
*
|
|
|
|
* Given a FactoryEntry, this loads the dll if it has to, find the NSGetFactory
|
|
|
|
* symbol, calls the routine to create a new factory and returns it to the
|
|
|
|
* caller.
|
|
|
|
*
|
|
|
|
* No attempt is made to store the factory in any form anywhere.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::LoadFactory(nsFactoryEntry *aEntry,
|
|
|
|
nsIFactory **aFactory)
|
|
|
|
{
|
1999-07-02 07:35:09 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: LoadFactory() \"%s\".", aEntry->dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
if (aFactory == NULL)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aFactory = NULL;
|
|
|
|
|
|
|
|
// LoadFactory() cannot be called for entries that are CID<->factory
|
|
|
|
// mapping entries for the session.
|
|
|
|
PR_ASSERT(aEntry->dll != NULL);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (aEntry->dll->IsLoaded() == PR_FALSE)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Load the dll
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-06-22 18:02:58 +04:00
|
|
|
("nsComponentManager: + Loading \"%s\".", aEntry->dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
if (aEntry->dll->Load() == PR_FALSE)
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsComponentManager: Library load unsuccessful."));
|
1999-03-11 01:07:34 +03:00
|
|
|
|
|
|
|
char errorMsg[1024] = "Cannot get error from nspr. Not enough memory.";
|
1999-03-11 02:30:25 +03:00
|
|
|
if (PR_GetErrorTextLength() < (int) sizeof(errorMsg))
|
1999-03-11 01:07:34 +03:00
|
|
|
PR_GetErrorText(errorMsg);
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-06-22 18:02:58 +04:00
|
|
|
("nsComponentManager: Load(%s) FAILED with error:%s", aEntry->dll->GetNativePath(), errorMsg));
|
1999-05-06 17:29:37 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
#ifdef PRINT_CRITICAL_ERROR_TO_SCREEN
|
1999-03-31 11:04:12 +04:00
|
|
|
// Put the error message on the screen.
|
1999-03-26 21:23:04 +03:00
|
|
|
printf("**************************************************\n"
|
1999-03-31 11:04:12 +04:00
|
|
|
"nsComponentManager: Load(%s) FAILED with error: %s\n"
|
1999-03-26 21:23:04 +03:00
|
|
|
"**************************************************\n",
|
1999-06-22 18:02:58 +04:00
|
|
|
aEntry->dll->GetNativePath(), errorMsg);
|
1999-06-14 06:07:03 +04:00
|
|
|
#endif
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
1999-03-10 12:53:25 +03:00
|
|
|
// Inform refcnt tracer of new library so that calls through the
|
|
|
|
// new library can be traced.
|
1999-06-22 18:02:58 +04:00
|
|
|
nsTraceRefcnt::LoadLibrarySymbols(aEntry->dll->GetNativePath(), aEntry->dll->GetInstance());
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif
|
1999-03-10 12:53:25 +03:00
|
|
|
nsFactoryProc proc = (nsFactoryProc) aEntry->dll->FindSymbol("NSGetFactory");
|
|
|
|
if (proc != NULL)
|
|
|
|
{
|
|
|
|
char* className = NULL;
|
|
|
|
char* progID = NULL;
|
|
|
|
nsresult rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// XXX dp, warren: deal with this!
|
1999-03-09 12:44:27 +03:00
|
|
|
#if 0
|
1999-03-10 12:53:25 +03:00
|
|
|
rv = CLSIDToProgID(&aEntry->cid, &className, &progID);
|
|
|
|
// if CLSIDToProgID fails, just pass null to NSGetFactory
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsIServiceManager* serviceMgr = NULL;
|
|
|
|
rv = nsServiceManager::GetGlobalServiceManager(&serviceMgr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
rv = proc(serviceMgr, aEntry->cid, className, progID, aFactory);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (className)
|
|
|
|
delete[] className;
|
|
|
|
if (progID)
|
|
|
|
delete[] progID;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsComponentManager: NSGetFactory entrypoint not found."));
|
|
|
|
return NS_ERROR_FACTORY_NOT_LOADED;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
|
|
|
|
nsFactoryEntry *
|
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const nsCID &aClass, PRBool checkRegistry)
|
|
|
|
{
|
|
|
|
nsIDKey key(aClass);
|
|
|
|
nsFactoryEntry *entry = (nsFactoryEntry*) mFactories->Get(&key);
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("\t\tfound in factory cache."));
|
|
|
|
else
|
|
|
|
#ifdef USE_REGISTRY
|
|
|
|
if (checkRegistry)
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("\t\tnot found in factory cache. Looking in registry"));
|
|
|
|
|
|
|
|
nsresult rv = PlatformFind(aClass, &entry);
|
|
|
|
|
|
|
|
// If we got one, cache it in our hashtable
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("\t\tfound in registry."));
|
|
|
|
mFactories->Put(&key, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USE_REGISTRY */
|
|
|
|
|
|
|
|
return (entry);
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/**
|
|
|
|
* FindFactory()
|
|
|
|
*
|
|
|
|
* Given a classID, this finds the factory for this CID by first searching the
|
|
|
|
* local CID<->factory mapping. Next it searches for a Dll that implements
|
|
|
|
* this classID and calls LoadFactory() to create the factory.
|
|
|
|
*
|
|
|
|
* Again, no attempt is made at storing the factory.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::FindFactory(const nsCID &aClass,
|
|
|
|
nsIFactory **aFactory)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: FindFactory(%s)", buf);
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ASSERT(aFactory != NULL);
|
1999-06-19 03:27:09 +04:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass, PR_TRUE);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
if (entry)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
if (entry->factory == NULL)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
|
|
|
res = LoadFactory(entry, aFactory);
|
1999-07-02 07:35:09 +04:00
|
|
|
// XXX Cache factory that we created for performance.
|
|
|
|
// XXX Need a way to release this factory else dlls will never
|
|
|
|
// XXX get unloaded
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
entry->factory = *aFactory;
|
|
|
|
NS_ADDREF(entry->factory);
|
|
|
|
}
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*aFactory = entry->factory;
|
|
|
|
NS_ADDREF(*aFactory);
|
|
|
|
res = NS_OK;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
1999-07-07 11:47:14 +04:00
|
|
|
("\t\tFindFactory() %s", NS_SUCCEEDED(res) ? "succeeded" : "FAILED"));
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ProgIDToCLSID()
|
|
|
|
*
|
|
|
|
* Mapping function from a ProgID to a classID. Directly talks to the registry.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::ProgIDToCLSID(const char *aProgID, nsCID *aClass)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_PRECONDITION(aProgID != NULL, "null ptr");
|
|
|
|
if (! aProgID)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_PRECONDITION(aClass != NULL, "null ptr");
|
|
|
|
if (! aClass)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
1999-03-10 12:53:25 +03:00
|
|
|
// XXX This isn't quite the best way to do this: we should
|
|
|
|
// probably move an nsArray<ProgID> into the FactoryEntry class,
|
|
|
|
// and then have the construct/destructor of the factory entry
|
|
|
|
// keep the ProgID to CID cache up-to-date. However, doing this
|
|
|
|
// significantly improves performance, so it'll do for now.
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-07-22 06:11:04 +04:00
|
|
|
nsStringKey key(aProgID);
|
1999-03-10 12:53:25 +03:00
|
|
|
nsCID* cid = (nsCID*) mProgIDs->Get(&key);
|
|
|
|
if (cid) {
|
|
|
|
if (cid == &kNoCID) {
|
|
|
|
// we've already tried to map this ProgID to a CLSID, and found
|
|
|
|
// that there _was_ no such mapping in the registry.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aClass = *cid;
|
|
|
|
res = NS_OK;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-03-10 12:53:25 +03:00
|
|
|
// This is the first time someone has asked for this
|
|
|
|
// ProgID. Go to the registry to find the CID.
|
|
|
|
res = PlatformProgIDToCLSID(aProgID, aClass);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (NS_SUCCEEDED(res)) {
|
|
|
|
// Found it. So put it into the cache.
|
|
|
|
cid = new nsCID(*aClass);
|
|
|
|
if (!cid)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
mProgIDs->Put(&key, cid);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Didn't find it. Put a special CID in the cache so we
|
|
|
|
// don't need to hit the registry on subsequent requests
|
|
|
|
// for the same ProgID.
|
|
|
|
mProgIDs->Put(&key, (void*) &kNoCID);
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
#endif /* USE_REGISTRY */
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS)) {
|
|
|
|
char *buf;
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
buf = aClass->ToString();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: ProgIDToCLSID(%s)->%s", aProgID,
|
|
|
|
NS_SUCCEEDED(res) ? buf : "[FAILED]"));
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-06-14 06:07:03 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CLSIDToProgID()
|
|
|
|
*
|
|
|
|
* Translates a classID to a {ProgID, Class Name}. Does direct registry
|
|
|
|
* access to do the translation.
|
|
|
|
*
|
|
|
|
* XXX Would be nice to hook in a cache here too.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::CLSIDToProgID(nsCID *aClass,
|
|
|
|
char* *aClassName,
|
|
|
|
char* *aProgID)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
1999-03-10 12:53:25 +03:00
|
|
|
res = PlatformCLSIDToProgID(aClass, aClassName, aProgID);
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif /* USE_REGISTRY */
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass->ToString();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("nsComponentManager: CLSIDToProgID(%s)->%s", buf,
|
|
|
|
NS_SUCCEEDED(res) ? *aProgID : "[FAILED]"));
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CreateInstance()
|
|
|
|
*
|
|
|
|
* Create an instance of an object that implements an interface and belongs
|
|
|
|
* to the implementation aClass using the factory. The factory is immediately
|
|
|
|
* released and not held onto for any longer.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: CreateInstance(%s)", buf);
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-06-14 06:07:03 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (aResult == NULL)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = NULL;
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsIFactory *factory = NULL;
|
|
|
|
nsresult res = FindFactory(aClass, &factory);
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
res = factory->CreateInstance(aDelegate, aIID, aResult);
|
|
|
|
NS_RELEASE(factory);
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-04-06 09:06:47 +04:00
|
|
|
("\t\tFactory CreateInstance() %s.",
|
|
|
|
NS_SUCCEEDED(res) ? "succeeded" : "FAILED"));
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("\t\tCreateInstance() FAILED."));
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CreateInstance()
|
|
|
|
*
|
|
|
|
* An overload of CreateInstance() that creates an instance of the object that
|
|
|
|
* implements the interface aIID and whose implementation has a progID aProgID.
|
|
|
|
*
|
|
|
|
* This is only a convenience routine that turns around can calls the
|
|
|
|
* CreateInstance() with classid and iid.
|
|
|
|
*
|
|
|
|
* XXX This is a function overload. We need to remove it.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::CreateInstance(const char *aProgID,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
nsCID clsid;
|
|
|
|
nsresult rv = ProgIDToCLSID(aProgID, &clsid);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
return CreateInstance(clsid, aDelegate, aIID, aResult);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RegisterFactory()
|
|
|
|
*
|
|
|
|
* Register a factory to be responsible for creation of implementation of
|
|
|
|
* classID aClass. Plus creates as association of aClassName and aProgID
|
|
|
|
* to the classID. If replace is PR_TRUE, we replace any existing registrations
|
|
|
|
* with this one.
|
|
|
|
*
|
|
|
|
* Once registration is complete, we add the class to the factories cache
|
|
|
|
* that we maintain. The factories cache is the ONLY place where these
|
|
|
|
* registrations are ever kept.
|
|
|
|
*
|
|
|
|
* XXX This uses FindFactory() to test if a factory already exists. This
|
|
|
|
* XXX has the bad side effect of loading the factory if the previous
|
|
|
|
* XXX registration was a dll for this class. We might be able to do away
|
|
|
|
* XXX with such a load.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterFactory(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
nsIFactory *aFactory,
|
|
|
|
PRBool aReplace)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
1999-04-05 08:32:36 +04:00
|
|
|
PR_LogPrint("nsComponentManager: RegisterFactory(%s, %s, %s), replace = %d.",
|
|
|
|
buf, aClassName, aProgID, (int)aReplace);
|
1999-03-10 12:53:25 +03:00
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
nsFactoryEntry *entry = NULL;
|
|
|
|
nsIDKey key(aClass);
|
|
|
|
entry = GetFactoryEntry(aClass, PR_TRUE);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
if (entry && !aReplace)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
// Already registered
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, ("\t\tFactory already registered."));
|
|
|
|
return NS_ERROR_FACTORY_EXISTS;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
|
|
|
|
nsFactoryEntry *newEntry = new nsFactoryEntry(aClass, aFactory);
|
|
|
|
if (newEntry == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (entry)
|
1999-04-12 16:32:24 +04:00
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, ("\t\tdeleting old Factory Entry."));
|
|
|
|
mFactories->Remove(&key);
|
|
|
|
delete entry;
|
1999-04-12 16:32:24 +04:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
mFactories->Put(&key, newEntry);
|
1999-04-12 16:32:24 +04:00
|
|
|
|
|
|
|
// Update the ProgID->CLSID Map
|
|
|
|
if (aProgID)
|
|
|
|
{
|
|
|
|
nsresult rv = HashProgID(aProgID, aClass);
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tFactory register succeeded. PROGID->CLSID mapping failed."));
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, ("\t\tFactory register succeeded."));
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponent(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
1999-06-22 18:02:58 +04:00
|
|
|
const char *aLibraryPersistentDescriptor,
|
1999-03-09 12:44:27 +03:00
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult rv = NS_OK;
|
1999-06-14 06:07:03 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: RegisterComponent(%s, %s, %s, %s), replace = %d, persist = %d.",
|
1999-06-22 18:02:58 +04:00
|
|
|
buf, aClassName, aProgID, aLibraryPersistentDescriptor, (int)aReplace, (int)aPersist);
|
|
|
|
delete [] buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the persistent descriptor into a nsIFileSpec
|
|
|
|
nsCOMPtr<nsIFileSpec>libSpec;
|
|
|
|
NS_DEFINE_IID(kFileSpecIID, NS_IFILESPEC_IID);
|
|
|
|
rv = CreateInstance(NS_FILESPEC_PROGID, NULL, kFileSpecIID, getter_AddRefs(libSpec));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = libSpec->SetPersistentDescriptorString((char *)aLibraryPersistentDescriptor);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Call the register component with FileSpec routine
|
|
|
|
rv = RegisterComponentSpec(aClass, aClassName, aProgID, libSpec, aReplace, aPersist);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponentSpec(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
nsIFileSpec *aLibrarySpec,
|
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *fullName = NULL;
|
|
|
|
aLibrarySpec->GetNativePath(&fullName);
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: RegisterComponentSpec(%s, %s, %s, %s), replace = %d, persist = %d.",
|
|
|
|
buf, aClassName, aProgID, fullName, (int)aReplace, (int)aPersist);
|
1999-03-10 12:53:25 +03:00
|
|
|
delete [] buf;
|
1999-06-22 18:02:58 +04:00
|
|
|
if (fullName) delete [] fullName;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
nsIDKey key(aClass);
|
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass, PR_TRUE);
|
|
|
|
|
|
|
|
if (entry && !aReplace)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, ("\t\tFactory already registered."));
|
|
|
|
return NS_ERROR_FACTORY_EXISTS;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
#ifdef USE_REGISTRY
|
1999-07-07 11:47:14 +04:00
|
|
|
if (aPersist)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
|
|
|
// Add it to the registry
|
1999-06-22 18:02:58 +04:00
|
|
|
nsDll *dll = new nsDll(aLibrarySpec);
|
1999-07-07 11:47:14 +04:00
|
|
|
if (dll == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-14 06:07:03 +04:00
|
|
|
char *cidString = aClass.ToString();
|
1999-07-07 11:47:14 +04:00
|
|
|
if (cidString == NULL)
|
|
|
|
{
|
|
|
|
delete dll;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-06-14 06:07:03 +04:00
|
|
|
PlatformRegister(cidString, aClassName, aProgID, dll);
|
|
|
|
delete [] cidString;
|
1999-03-10 12:53:25 +03:00
|
|
|
delete dll;
|
|
|
|
}
|
|
|
|
else
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
// Create a dll from the librarySpec
|
|
|
|
nsDll *dll = CreateCachedDll(aLibrarySpec);
|
1999-07-07 11:47:14 +04:00
|
|
|
if (dll == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-22 18:02:58 +04:00
|
|
|
|
|
|
|
// Use the dll to create a factoryEntry
|
1999-07-07 11:47:14 +04:00
|
|
|
nsFactoryEntry *newEntry = new nsFactoryEntry(aClass, dll);
|
|
|
|
if (newEntry == NULL)
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
delete dll;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
mFactories->Remove(&key);
|
|
|
|
delete entry;
|
|
|
|
entry = NULL;
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, ("\t\tdeleting registered Factory."));
|
|
|
|
}
|
|
|
|
mFactories->Put(&key, newEntry);
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
// Update the ProgID->CLSID Map if this isnt stored in registry
|
1999-06-22 18:02:58 +04:00
|
|
|
#ifdef USE_REGISTRY
|
1999-07-07 11:47:14 +04:00
|
|
|
if (aProgID && aPersist != PR_TRUE)
|
|
|
|
rv = HashProgID(aProgID, aClass);
|
1999-06-22 18:02:58 +04:00
|
|
|
#else /* USE_REGISTRY */
|
1999-07-07 11:47:14 +04:00
|
|
|
if (aProgID)
|
|
|
|
rv = HashProgID(aProgID, aClass);
|
1999-06-22 18:02:58 +04:00
|
|
|
#endif /* USE_REGISTRY */
|
1999-07-07 11:47:14 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
1999-07-07 11:47:14 +04:00
|
|
|
("\t\tFactory register %s.", NS_SUCCEEDED(rv) ? "succeeded" : "failed"));
|
1999-06-22 18:02:58 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::RegisterComponentLib(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
const char *aDllName,
|
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist /* has to be PR_FALSE */)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// XXX We cant store dllName registrations in the registry yet.
|
|
|
|
PR_ASSERT(aPersist == PR_FALSE);
|
|
|
|
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: RegisterComponentLib(%s, %s, %s, %s), replace = %d, persist = %d.",
|
|
|
|
buf, aClassName, aProgID, aDllName, (int)aReplace, (int)aPersist);
|
|
|
|
delete [] buf;
|
|
|
|
}
|
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
nsIDKey key(aClass);
|
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass, PR_TRUE);
|
|
|
|
|
|
|
|
if (entry && !aReplace)
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, ("\t\tFactory already registered."));
|
|
|
|
return NS_ERROR_FACTORY_EXISTS;
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_REGISTRY
|
1999-07-07 11:47:14 +04:00
|
|
|
if (aPersist)
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
|
|
|
// Add it to the registry
|
|
|
|
nsDll *dll = new nsDll(aDllName, 1/* dummy */);
|
1999-07-07 11:47:14 +04:00
|
|
|
if (dll == NULL) rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
char *cidString = aClass.ToString();
|
|
|
|
if (cidString == NULL)
|
|
|
|
{
|
|
|
|
delete dll;
|
1999-03-10 12:53:25 +03:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
PlatformRegister(cidString, aClassName, aProgID, dll);
|
|
|
|
delete [] cidString;
|
1999-03-10 12:16:28 +03:00
|
|
|
delete dll;
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
// Create a dll from the DllName
|
1999-06-22 18:02:58 +04:00
|
|
|
nsDll *dll = CreateCachedDllName(aDllName);
|
1999-07-07 11:47:14 +04:00
|
|
|
if (dll == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-22 18:02:58 +04:00
|
|
|
|
|
|
|
// Use the dll to create a factoryEntry
|
1999-07-07 11:47:14 +04:00
|
|
|
nsFactoryEntry* newEntry = new nsFactoryEntry(aClass, dll);
|
|
|
|
if (newEntry == NULL)
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
1999-07-07 11:47:14 +04:00
|
|
|
delete dll;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-07-07 11:47:14 +04:00
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
mFactories->Remove(&key);
|
|
|
|
delete entry;
|
|
|
|
entry = NULL;
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, ("\t\tdeleting registered Factory."));
|
|
|
|
}
|
|
|
|
mFactories->Put(&key, newEntry);
|
1999-03-10 12:16:28 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-07-07 11:47:14 +04:00
|
|
|
// Update the ProgID->CLSID Map if this isn't stored in registry
|
1999-04-12 16:32:24 +04:00
|
|
|
#ifdef USE_REGISTRY
|
1999-07-07 11:47:14 +04:00
|
|
|
if (aProgID && aPersist != PR_TRUE)
|
|
|
|
rv = HashProgID(aProgID, aClass);
|
1999-04-12 16:32:24 +04:00
|
|
|
#else /* USE_REGISTRY */
|
1999-07-07 11:47:14 +04:00
|
|
|
if (aProgID)
|
|
|
|
rv = HashProgID(aProgID, aClass);
|
1999-04-12 16:32:24 +04:00
|
|
|
#endif /* USE_REGISTRY */
|
1999-07-07 11:47:14 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
1999-07-07 11:47:14 +04:00
|
|
|
("\t\tFactory register %s.", rv == NS_OK ? "succeeded" : "failed"));
|
1999-03-10 12:53:25 +03:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::UnregisterFactory(const nsCID &aClass,
|
|
|
|
nsIFactory *aFactory)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: Unregistering Factory.");
|
|
|
|
PR_LogPrint("nsComponentManager: + %s.", buf);
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsIDKey key(aClass);
|
|
|
|
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
nsFactoryEntry *old = (nsFactoryEntry *) mFactories->Get(&key);
|
|
|
|
if (old != NULL)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
if (old->factory == aFactory)
|
|
|
|
{
|
|
|
|
PR_EnterMonitor(mMon);
|
|
|
|
old = (nsFactoryEntry *) mFactories->Remove(&key);
|
|
|
|
PR_ExitMonitor(mMon);
|
|
|
|
delete old;
|
|
|
|
res = NS_OK;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("nsComponentManager: ! Factory unregister %s.",
|
1999-05-06 17:29:37 +04:00
|
|
|
NS_SUCCEEDED(res) ? "succeeded" : "failed"));
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::UnregisterComponent(const nsCID &aClass,
|
|
|
|
const char *aLibrary)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: Unregistering Factory.");
|
|
|
|
PR_LogPrint("nsComponentManager: + %s in \"%s\".", buf, aLibrary);
|
|
|
|
delete [] buf;
|
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsIDKey key(aClass);
|
|
|
|
nsFactoryEntry *old = (nsFactoryEntry *) mFactories->Get(&key);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_EnterMonitor(mMon);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (old != NULL && old->dll != NULL)
|
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
if (old->dll->GetPersistentDescriptorString() != NULL &&
|
1999-06-29 14:27:58 +04:00
|
|
|
#if defined(XP_UNIX) || defined(XP_BEOS)
|
1999-06-22 18:02:58 +04:00
|
|
|
PL_strcasecmp(old->dll->GetPersistentDescriptorString(), aLibrary)
|
1999-03-09 12:44:27 +03:00
|
|
|
#else
|
1999-06-22 18:02:58 +04:00
|
|
|
PL_strcmp(old->dll->GetPersistentDescriptorString(), aLibrary)
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif
|
1999-03-10 12:53:25 +03:00
|
|
|
)
|
|
|
|
{
|
|
|
|
nsFactoryEntry *entry = (nsFactoryEntry *) mFactories->Remove(&key);
|
|
|
|
delete entry;
|
|
|
|
res = NS_OK;
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
#ifdef USE_REGISTRY
|
1999-06-14 06:07:03 +04:00
|
|
|
char *cidString = aClass.ToString();
|
|
|
|
res = PlatformUnregister(cidString, aLibrary);
|
|
|
|
delete [] cidString;
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ExitMonitor(mMon);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("nsComponentManager: ! Factory unregister %s.",
|
1999-05-06 17:29:37 +04:00
|
|
|
NS_SUCCEEDED(res) ? "succeeded" : "failed"));
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
nsFreeLibraryEnum(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
nsFactoryEntry *entry = (nsFactoryEntry *) aData;
|
|
|
|
nsIServiceManager* serviceMgr = (nsIServiceManager*)closure;
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (entry->dll && entry->dll->IsLoaded() == PR_TRUE)
|
|
|
|
{
|
|
|
|
nsCanUnloadProc proc = (nsCanUnloadProc) entry->dll->FindSymbol("NSCanUnload");
|
|
|
|
if (proc != NULL) {
|
|
|
|
nsresult rv = proc(serviceMgr);
|
1999-05-06 17:29:37 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-06-22 18:02:58 +04:00
|
|
|
("nsComponentManager: + Unloading \"%s\".", entry->dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
entry->dll->Unload();
|
|
|
|
}
|
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return PR_TRUE;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::FreeLibraries(void)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_EnterMonitor(mMon);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Freeing Libraries."));
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsIServiceManager* serviceMgr = NULL;
|
|
|
|
nsresult rv = nsServiceManager::GetGlobalServiceManager(&serviceMgr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mFactories->Enumerate(nsFreeLibraryEnum, serviceMgr);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_ExitMonitor(mMon);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
1999-04-03 00:28:22 +04:00
|
|
|
* AutoRegister(RegistrationInstant, const char *directory)
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
1999-04-03 00:28:22 +04:00
|
|
|
* Given a directory in the following format, this will ensure proper registration
|
|
|
|
* of all components. No default director is looked at.
|
|
|
|
*
|
|
|
|
* Directory and fullname are what NSPR will accept. For eg.
|
|
|
|
* WIN y:/home/dp/mozilla/dist/bin
|
|
|
|
* UNIX /home/dp/mozilla/dist/bin
|
|
|
|
* MAC /Hard drive/mozilla/dist/apprunner
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
|
|
|
* This will take care not loading already registered dlls, finding and
|
|
|
|
* registering new dlls, re-registration of modified dlls
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsresult
|
1999-06-22 18:02:58 +04:00
|
|
|
nsComponentManagerImpl::AutoRegister(RegistrationTime when, nsIFileSpec *inDirSpec)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
nsCOMPtr<nsIFileSpec> dirSpec;
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
if (inDirSpec == NULL)
|
1999-03-31 11:04:12 +04:00
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
// Do default components directory
|
|
|
|
nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::XPCOM_CurrentProcessComponentDirectory);
|
|
|
|
nsresult rv = NS_NewFileSpecWithSpec(sysdir, getter_AddRefs(dirSpec));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dirSpec = inDirSpec;
|
|
|
|
|
|
|
|
char *nativePath = NULL;
|
|
|
|
nsresult rv = dirSpec->GetNativePath(&nativePath);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (nativePath == NULL)
|
|
|
|
{
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Autoregistration begins. dir = %s", nativePath));
|
1999-06-14 06:07:03 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-22 18:02:58 +04:00
|
|
|
printf("nsComponentManager: Autoregistration begins. dir = %s\n", nativePath);
|
1999-05-06 17:29:37 +04:00
|
|
|
#endif /* DEBUG */
|
1999-06-22 18:02:58 +04:00
|
|
|
|
|
|
|
rv = SyncComponentsInDir(when, dirSpec);
|
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Autoregistration ends. dir = %s", nativePath));
|
1999-06-14 06:07:03 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-22 18:02:58 +04:00
|
|
|
printf("nsComponentManager: Autoregistration ends. dir = %s\n", nativePath);
|
1999-05-06 17:29:37 +04:00
|
|
|
#endif /* DEBUG */
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-07-09 07:45:19 +04:00
|
|
|
nsCRT::free(nativePath);
|
|
|
|
|
1999-05-06 17:29:37 +04:00
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-06-22 18:02:58 +04:00
|
|
|
nsComponentManagerImpl::SyncComponentsInDir(RegistrationTime when, nsIFileSpec *dirSpec)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
PRBool isDir = PR_FALSE;
|
|
|
|
|
|
|
|
// Maker sure we are dealing with a directory
|
|
|
|
rv = dirSpec->isDirectory(&isDir);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (isDir == PR_FALSE)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
return NS_ERROR_INVALID_POINTER;
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
|
|
|
// Create a directory iterator
|
|
|
|
NS_DEFINE_IID(kDirectoryIteratorIID, NS_IDIRECTORYITERATOR_IID);
|
|
|
|
nsCOMPtr<nsIDirectoryIterator>dirIterator;
|
|
|
|
rv = CreateInstance(NS_DIRECTORYITERATOR_PROGID, NULL, kDirectoryIteratorIID, getter_AddRefs(dirIterator));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-07-28 03:33:54 +04:00
|
|
|
rv = dirIterator->Init(dirSpec, PR_TRUE);
|
1999-06-22 18:02:58 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// whip through the directory to register every file
|
|
|
|
nsIFileSpec *dirEntry = NULL;
|
|
|
|
PRBool more = PR_FALSE;
|
|
|
|
rv = dirIterator->exists(&more);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
while (more == PR_TRUE)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = dirIterator->GetCurrentSpec(&dirEntry);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = dirEntry->isDirectory(&isDir);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (isDir == PR_TRUE)
|
|
|
|
{
|
|
|
|
// This is a directory. Grovel for components into the directory.
|
|
|
|
rv = SyncComponentsInDir(when, dirEntry);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// This is a file. Try to register it.
|
|
|
|
rv = AutoRegisterComponent(when, dirEntry);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
// This means either of AutoRegisterComponent or
|
|
|
|
// SyncComponentsInDir failed. It could be because
|
|
|
|
// the file isn't a component like initpref.js
|
|
|
|
// So dont break on these errors.
|
|
|
|
}
|
1999-07-25 17:37:16 +04:00
|
|
|
|
|
|
|
NS_RELEASE(dirEntry);
|
1999-06-22 18:02:58 +04:00
|
|
|
|
|
|
|
rv = dirIterator->next();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = dirIterator->exists(&more);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-06-22 18:02:58 +04:00
|
|
|
nsComponentManagerImpl::AutoRegisterComponent(RegistrationTime when, nsIFileSpec *component)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
const char *ValidDllExtensions[] = {
|
1999-06-05 02:17:30 +04:00
|
|
|
".dll", /* Windows */
|
|
|
|
".dso", /* Unix ? */
|
|
|
|
".dylib", /* Unix: Rhapsody */
|
|
|
|
".so", /* Unix */
|
|
|
|
".so.1.0", /* Unix: BSD */
|
|
|
|
".sl", /* Unix: HP-UX */
|
1999-03-10 12:53:25 +03:00
|
|
|
".shlb", /* Mac ? */
|
1999-06-05 02:17:30 +04:00
|
|
|
".dlm", /* new for all platforms */
|
1999-03-10 12:53:25 +03:00
|
|
|
NULL
|
|
|
|
};
|
1999-06-22 18:02:58 +04:00
|
|
|
nsresult rv;
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
// Ensure we are dealing with a file as opposed to a dir
|
|
|
|
PRBool b = PR_FALSE;
|
|
|
|
|
|
|
|
rv = component->isFile(&b);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (b == PR_FALSE) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// deal only with files that have a valid extension
|
1999-03-10 12:53:25 +03:00
|
|
|
PRBool validExtension = PR_FALSE;
|
1999-06-22 18:02:58 +04:00
|
|
|
char *leafName = NULL;
|
|
|
|
rv = component->GetLeafName(&leafName);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
int flen = PL_strlen(leafName);
|
1999-03-10 12:53:25 +03:00
|
|
|
for (int i=0; ValidDllExtensions[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
int extlen = PL_strlen(ValidDllExtensions[i]);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Does fullname end with this extension
|
|
|
|
if (flen >= extlen &&
|
1999-06-22 18:02:58 +04:00
|
|
|
!PL_strcasecmp(&(leafName[flen - extlen]), ValidDllExtensions[i])
|
1999-03-10 12:53:25 +03:00
|
|
|
)
|
|
|
|
{
|
|
|
|
validExtension = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-07-09 07:45:19 +04:00
|
|
|
if (leafName) nsCRT::free(leafName);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (validExtension == PR_FALSE)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Skip invalid extensions
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
|
|
|
// Get the name of the dll
|
|
|
|
char *persistentDescriptor = NULL;
|
|
|
|
rv = component->GetPersistentDescriptorString(&persistentDescriptor);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-07-15 04:11:20 +04:00
|
|
|
autoStringFree delete_persistentDescriptor(persistentDescriptor, autoStringFree::nsCRT_String_Delete);
|
1999-07-22 06:11:04 +04:00
|
|
|
nsStringKey key(persistentDescriptor);
|
1999-06-22 18:02:58 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Check if dll is one that we have already seen
|
1999-03-12 14:25:17 +03:00
|
|
|
nsDll *dll = (nsDll *) mDllStore->Get(&key);
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = NS_OK;
|
1999-03-10 12:53:25 +03:00
|
|
|
if (dll == NULL)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-05-06 17:29:37 +04:00
|
|
|
// Create nsDll for this from registry and
|
|
|
|
// add it to our dll cache mDllStore.
|
1999-03-10 12:53:25 +03:00
|
|
|
#ifdef USE_REGISTRY
|
1999-06-22 18:02:58 +04:00
|
|
|
rv = PlatformCreateDll(persistentDescriptor, &dll);
|
1999-05-06 17:29:37 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
mDllStore->Put(&key, (void *) dll);
|
|
|
|
}
|
1999-03-10 12:53:25 +03:00
|
|
|
#endif /* USE_REGISTRY */
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
|
|
|
if (dll != NULL)
|
1999-03-10 12:53:25 +03:00
|
|
|
{
|
|
|
|
// Make sure the dll is OK
|
|
|
|
if (dll->GetStatus() != NS_OK)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: + nsDll not NS_OK \"%s\". Skipping...",
|
1999-06-22 18:02:58 +04:00
|
|
|
dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// We already have seen this dll. Check if this dll changed
|
1999-06-22 18:02:58 +04:00
|
|
|
if (!dll->HasChanged())
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Dll hasn't changed. Skip.
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: + nsDll not changed \"%s\". Skipping...",
|
1999-06-22 18:02:58 +04:00
|
|
|
dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_OK;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Aagh! the dll has changed since the last time we saw it.
|
|
|
|
// re-register dll
|
|
|
|
if (dll->IsLoaded())
|
|
|
|
{
|
|
|
|
// We are screwed. We loaded the old version of the dll
|
|
|
|
// and now we find that the on-disk copy if newer.
|
|
|
|
// The only thing to do would be to ask the dll if it can
|
|
|
|
// unload itself. It can do that if it hasn't created objects
|
|
|
|
// yet.
|
|
|
|
nsCanUnloadProc proc = (nsCanUnloadProc)
|
|
|
|
dll->FindSymbol("NSCanUnload");
|
|
|
|
if (proc != NULL)
|
|
|
|
{
|
|
|
|
PRBool res = proc(this /*, PR_TRUE*/);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: + Unloading \"%s\".",
|
1999-06-22 18:02:58 +04:00
|
|
|
dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
dll->Unload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// THIS IS THE WORST SITUATION TO BE IN.
|
|
|
|
// Dll doesn't want to be unloaded. Cannot re-register
|
|
|
|
// this dll.
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: *** Dll already loaded. "
|
|
|
|
"Cannot unload either. Hence cannot re-register "
|
1999-06-22 18:02:58 +04:00
|
|
|
"\"%s\". Skipping...", dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// dll doesn't have a CanUnload proc. Guess it is
|
|
|
|
// ok to unload it.
|
|
|
|
dll->Unload();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: + Unloading \"%s\". (no CanUnloadProc).",
|
1999-06-22 18:02:58 +04:00
|
|
|
dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
} // dll isloaded
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Sanity.
|
|
|
|
if (dll->IsLoaded())
|
|
|
|
{
|
|
|
|
// We went through all the above to make sure the dll
|
|
|
|
// is unloaded. And here we are with the dll still
|
|
|
|
// loaded. Whoever taught dp programming...
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Dll still loaded. Cannot re-register "
|
1999-06-22 18:02:58 +04:00
|
|
|
"\"%s\". Skipping...", dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
} // dll != NULL
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Create and add the dll to the mDllStore
|
|
|
|
// It is ok to do this even if the creation of nsDll
|
|
|
|
// didnt succeed. That way we wont do this again
|
|
|
|
// when we encounter the same dll.
|
1999-06-22 18:02:58 +04:00
|
|
|
dll = new nsDll(persistentDescriptor);
|
1999-03-10 12:53:25 +03:00
|
|
|
if (dll == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-12 14:25:17 +03:00
|
|
|
mDllStore->Put(&key, (void *) dll);
|
1999-03-10 12:53:25 +03:00
|
|
|
} // dll == NULL
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Either we are seeing the dll for the first time or the dll has
|
|
|
|
// changed since we last saw it and it is unloaded successfully.
|
|
|
|
//
|
|
|
|
// Now we can try register the dll for sure.
|
|
|
|
nsresult res = SelfRegisterDll(dll);
|
|
|
|
nsresult ret = NS_OK;
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Autoregistration FAILED for "
|
1999-06-22 18:02:58 +04:00
|
|
|
"\"%s\". Skipping...", dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
// Mark dll as not xpcom dll along with modified time and size in
|
|
|
|
// the registry so that we wont need to load the dll again every
|
|
|
|
// session until the dll changes.
|
1999-03-09 12:44:27 +03:00
|
|
|
#ifdef USE_REGISTRY
|
1999-03-10 12:53:25 +03:00
|
|
|
PlatformMarkNoComponents(dll);
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif /* USE_REGISTRY */
|
1999-03-10 12:53:25 +03:00
|
|
|
ret = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: Autoregistration Passed for "
|
1999-06-22 18:02:58 +04:00
|
|
|
"\"%s\".", dll->GetNativePath()));
|
1999-03-10 12:53:25 +03:00
|
|
|
// Marking dll along with modified time and size in the
|
|
|
|
// registry happens at PlatformRegister(). No need to do it
|
|
|
|
// here again.
|
|
|
|
}
|
|
|
|
return ret;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/*
|
1999-03-31 11:04:12 +04:00
|
|
|
* SelfRegisterDll
|
|
|
|
*
|
|
|
|
* Given a dll abstraction, this will load, selfregister the dll and
|
|
|
|
* unload the dll.
|
|
|
|
*
|
|
|
|
*/
|
1999-03-09 12:44:27 +03:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::SelfRegisterDll(nsDll *dll)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Precondition: dll is not loaded already
|
|
|
|
PR_ASSERT(dll->IsLoaded() == PR_FALSE);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult res = NS_ERROR_FAILURE;
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (dll->Load() == PR_FALSE)
|
|
|
|
{
|
|
|
|
// Cannot load. Probably not a dll.
|
1999-03-11 01:07:34 +03:00
|
|
|
char errorMsg[1024] = "Cannot get error from nspr. Not enough memory.";
|
1999-03-11 02:30:25 +03:00
|
|
|
if (PR_GetErrorTextLength() < (int) sizeof(errorMsg))
|
1999-03-11 01:07:34 +03:00
|
|
|
PR_GetErrorText(errorMsg);
|
1999-05-26 05:38:36 +04:00
|
|
|
|
1999-03-11 01:07:34 +03:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
1999-06-22 18:02:58 +04:00
|
|
|
("nsComponentManager: SelfRegisterDll(%s) Load FAILED with error:%s", dll->GetNativePath(), errorMsg));
|
1999-05-26 05:38:36 +04:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
#ifdef PRINT_CRITICAL_ERROR_TO_SCREEN
|
1999-03-26 21:49:46 +03:00
|
|
|
printf("**************************************************\n"
|
1999-03-31 11:04:12 +04:00
|
|
|
"nsComponentManager: Load(%s) FAILED with error: %s\n"
|
|
|
|
"**************************************************\n",
|
1999-06-22 18:02:58 +04:00
|
|
|
dll->GetNativePath(), errorMsg);
|
1999-06-14 06:07:03 +04:00
|
|
|
#endif
|
1999-03-10 12:53:25 +03:00
|
|
|
return(NS_ERROR_FAILURE);
|
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsComponentManager: + Loaded \"%s\".", dll->GetNativePath()));
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsRegisterProc regproc = (nsRegisterProc)dll->FindSymbol("NSRegisterSelf");
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (regproc == NULL)
|
1999-03-09 12:44:27 +03:00
|
|
|
{
|
1999-06-14 06:07:03 +04:00
|
|
|
res = NS_ERROR_NO_INTERFACE;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Call the NSRegisterSelfProc to enable dll registration
|
|
|
|
nsIServiceManager* serviceMgr = NULL;
|
|
|
|
res = nsServiceManager::GetGlobalServiceManager(&serviceMgr);
|
|
|
|
if (NS_SUCCEEDED(res)) {
|
1999-06-22 18:02:58 +04:00
|
|
|
res = regproc(serviceMgr, dll->GetPersistentDescriptorString());
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-10 12:53:25 +03:00
|
|
|
dll->Unload();
|
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::SelfUnregisterDll(nsDll *dll)
|
|
|
|
{
|
1999-03-10 12:53:25 +03:00
|
|
|
// Precondition: dll is not loaded
|
|
|
|
PR_ASSERT(dll->IsLoaded() == PR_FALSE);
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (dll->Load() == PR_FALSE)
|
|
|
|
{
|
|
|
|
// Cannot load. Probably not a dll.
|
|
|
|
return(NS_ERROR_FAILURE);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsUnregisterProc unregproc =
|
|
|
|
(nsUnregisterProc) dll->FindSymbol("NSUnregisterSelf");
|
|
|
|
nsresult res = NS_OK;
|
1999-03-31 11:04:12 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
if (unregproc == NULL)
|
|
|
|
{
|
1999-06-14 06:07:03 +04:00
|
|
|
return(NS_ERROR_NO_INTERFACE);
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Call the NSUnregisterSelfProc to enable dll de-registration
|
|
|
|
nsIServiceManager* serviceMgr = NULL;
|
|
|
|
res = nsServiceManager::GetGlobalServiceManager(&serviceMgr);
|
|
|
|
if (NS_SUCCEEDED(res)) {
|
1999-06-22 18:02:58 +04:00
|
|
|
res = unregproc(serviceMgr, dll->GetPersistentDescriptorString());
|
1999-03-10 12:53:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dll->Unload();
|
|
|
|
return res;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_COM nsresult
|
|
|
|
NS_GetGlobalComponentManager(nsIComponentManager* *result)
|
|
|
|
{
|
1999-03-24 02:28:32 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager == NULL)
|
|
|
|
{
|
|
|
|
// XPCOM needs initialization.
|
|
|
|
rv = NS_InitXPCOM(NULL);
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
1999-03-24 02:28:32 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
// NO ADDREF since this is never intended to be released.
|
|
|
|
*result = nsComponentManagerImpl::gComponentManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-03-09 12:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|