1999-08-31 21:40:21 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (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) 1999 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
2000-05-02 22:38:04 +00:00
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* 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-08-31 21:40:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "prerror.h"
|
|
|
|
#include "prsystem.h" // PR_GetDirectorySeparator
|
|
|
|
#include "nsNativeComponentLoader.h"
|
|
|
|
#include "nsComponentManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIModule.h"
|
|
|
|
#include "xcDll.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsHashtableEnumerator.h"
|
1999-11-10 00:28:34 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2000-03-31 09:04:29 +00:00
|
|
|
#include "nsCRT.h"
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2000-05-15 19:28:12 +00:00
|
|
|
#include "nsIObserverService.h"
|
2001-08-17 02:03:34 +00:00
|
|
|
#include "nsITimelineService.h"
|
2000-05-15 19:28:12 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
#ifdef XP_MAC // sdagley dougt fix
|
|
|
|
#include <Files.h>
|
|
|
|
#include <Errors.h>
|
2000-02-23 23:09:02 +00:00
|
|
|
#include "nsILocalFileMac.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#endif
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
#define PRINT_CRITICAL_ERROR_TO_SCREEN 1
|
|
|
|
#define USE_REGISTRY 1
|
|
|
|
#define XPCOM_USE_NSGETFACTORY 1
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
// Logging of debug output
|
2001-05-05 10:18:53 +00:00
|
|
|
#ifdef MOZ_LOGGING
|
2000-10-28 22:17:53 +00:00
|
|
|
#define FORCE_PR_LOG /* Allow logging in the release build */
|
2001-05-05 10:18:53 +00:00
|
|
|
#endif
|
2000-10-28 22:17:53 +00:00
|
|
|
#include "prlog.h"
|
|
|
|
extern PRLogModuleInfo *nsComponentManagerLog;
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
nsNativeComponentLoader::nsNativeComponentLoader() :
|
|
|
|
mRegistry(nsnull), mCompMgr(nsnull), mDllStore(nsnull)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
2000-05-02 22:38:04 +00:00
|
|
|
static PRBool PR_CALLBACK
|
1999-08-31 21:40:21 +00:00
|
|
|
nsDll_Destroy(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
|
|
|
nsDll* entry = NS_STATIC_CAST(nsDll*, aData);
|
|
|
|
delete entry;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNativeComponentLoader::~nsNativeComponentLoader()
|
|
|
|
{
|
|
|
|
mRegistry = nsnull;
|
|
|
|
mCompMgr = nsnull;
|
|
|
|
|
|
|
|
delete mDllStore;
|
|
|
|
}
|
|
|
|
|
2000-11-17 03:41:41 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsNativeComponentLoader, nsIComponentLoader);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeComponentLoader::GetFactory(const nsIID & aCID,
|
|
|
|
const char *aLocation,
|
|
|
|
const char *aType,
|
|
|
|
nsIFactory **_retval)
|
|
|
|
{
|
2001-08-17 02:03:34 +00:00
|
|
|
NS_TIMELINE_MARKV(("nsNativeComponentLoader::GetFactory(%s)...",
|
|
|
|
aLocation));
|
|
|
|
NS_TIMELINE_INDENT();
|
|
|
|
NS_TIMELINE_START_TIMER("nsNativeComponentLoader::GetFactory");
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!_retval)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
/* use a hashtable of WeakRefs to store the factory object? */
|
|
|
|
|
|
|
|
/* Should this all live in xcDll? */
|
|
|
|
nsDll *dll;
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 mod = LL_Zero(), size = LL_Zero();
|
|
|
|
rv = CreateDll(nsnull, aLocation, &mod, &size, &dll);
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!dll)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-03-11 22:44:51 +00:00
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
if (!dll->IsLoaded()) {
|
2000-03-11 22:44:51 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
1999-08-31 21:40:21 +00:00
|
|
|
("nsNativeComponentLoader: loading \"%s\"",
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath()));
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
if (!dll->Load()) {
|
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsNativeComponentLoader: load FAILED"));
|
|
|
|
|
|
|
|
char errorMsg[1024] = "<unknown; can't get error from NSPR>";
|
|
|
|
|
|
|
|
if (PR_GetErrorTextLength() < (int) sizeof(errorMsg))
|
|
|
|
PR_GetErrorText(errorMsg);
|
|
|
|
|
1999-09-14 13:40:22 +00:00
|
|
|
DumpLoadError(dll, "GetFactory", errorMsg);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get service manager for factory */
|
2001-10-16 03:35:52 +00:00
|
|
|
nsCOMPtr<nsIServiceManager> serviceMgr;
|
|
|
|
rv = NS_GetServiceManager(getter_AddRefs(serviceMgr));
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv; // XXX translate error code?
|
|
|
|
|
|
|
|
rv = GetFactoryFromModule(dll, aCID, _retval);
|
|
|
|
#ifdef XPCOM_USE_NSGETFACTORY
|
1999-10-22 01:04:16 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-08-31 21:40:21 +00:00
|
|
|
if (rv == NS_ERROR_FACTORY_NOT_LOADED) {
|
|
|
|
rv = GetFactoryFromNSGetFactory(dll, aCID, serviceMgr, _retval);
|
|
|
|
}
|
|
|
|
}
|
1999-10-22 01:04:16 +00:00
|
|
|
#endif
|
2000-03-11 22:44:51 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsNativeComponentLoader: Factory creation %s for %s",
|
|
|
|
(NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"),
|
|
|
|
aLocation));
|
1999-10-22 01:04:16 +00:00
|
|
|
|
|
|
|
// If the dll failed to get us a factory. But the dll registered that
|
|
|
|
// it would be able to create a factory for this CID. mmh!
|
|
|
|
// We cannot just delete the dll as the dll could be hosting
|
|
|
|
// other CID for which factory creation can pass.
|
|
|
|
// We will just let it be. The effect will be next time we try
|
|
|
|
// creating the object, we will query the dll again. Since the
|
|
|
|
// dll is loaded, this aint a big hit. So for optimized builds
|
|
|
|
// this is ok to limp along.
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Factory creation failed");
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2001-08-17 02:03:34 +00:00
|
|
|
NS_TIMELINE_STOP_TIMER("nsNativeComponentLoader::GetFactory");
|
|
|
|
NS_TIMELINE_OUTDENT();
|
|
|
|
NS_TIMELINE_MARKV(("...nsNativeComponentLoader::GetFactory(%s) done",
|
|
|
|
aLocation));
|
|
|
|
NS_TIMELINE_MARK_TIMER("nsNativeComponentLoader::GetFactory");
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-06 16:43:09 +00:00
|
|
|
nsNativeComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-09-06 16:43:09 +00:00
|
|
|
mCompMgr = aCompMgr;
|
1999-08-31 21:40:21 +00:00
|
|
|
mRegistry = do_QueryInterface(aReg);
|
1999-09-20 20:54:04 +00:00
|
|
|
if (!mCompMgr || !mRegistry)
|
1999-08-31 21:40:21 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2000-02-16 07:45:20 +00:00
|
|
|
rv = mRegistry->GetSubtree(nsIRegistry::Common, xpcomComponentsKeyName,
|
1999-08-31 21:40:21 +00:00
|
|
|
&mXPCOMKey);
|
1999-11-10 00:28:34 +00:00
|
|
|
if (NS_FAILED(rv))
|
1999-08-31 21:40:21 +00:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!mDllStore) {
|
|
|
|
mDllStore = new nsObjectHashtable(nsnull, nsnull, // never copy
|
|
|
|
nsDll_Destroy, nsnull,
|
|
|
|
256, /* Thead Safe */ PR_TRUE);
|
1999-11-10 00:28:34 +00:00
|
|
|
if (!mDllStore)
|
1999-08-31 21:40:21 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1999-09-11 14:49:55 +00:00
|
|
|
|
|
|
|
// Read in all dll entries and populate the mDllStore
|
|
|
|
nsCOMPtr<nsIEnumerator> dllEnum;
|
|
|
|
rv = mRegistry->EnumerateSubtrees( mXPCOMKey, getter_AddRefs(dllEnum));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = dllEnum->First();
|
1999-09-21 01:28:18 +00:00
|
|
|
for (; NS_SUCCEEDED(rv) && (dllEnum->IsDone() != NS_OK); (rv = dllEnum->Next()))
|
1999-09-11 14:49:55 +00:00
|
|
|
{
|
|
|
|
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
|
1999-11-10 00:28:34 +00:00
|
|
|
nsXPIDLCString library;
|
2000-02-20 03:12:59 +00:00
|
|
|
rv = node->GetNameUTF8(getter_Copies(library));
|
2000-05-12 01:24:36 +00:00
|
|
|
|
1999-09-11 14:49:55 +00:00
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
|
2000-05-12 01:24:36 +00:00
|
|
|
char* uLibrary;
|
|
|
|
char* eLibrary = (char*)library.operator const char*();
|
|
|
|
PRUint32 length = strlen(eLibrary);
|
|
|
|
rv = mRegistry->UnescapeKey((PRUint8*)eLibrary, 1, &length, (PRUint8**)&uLibrary);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
|
|
|
|
if (uLibrary == nsnull)
|
|
|
|
uLibrary = eLibrary;
|
|
|
|
|
1999-09-11 14:49:55 +00:00
|
|
|
// Get key associated with library
|
1999-09-29 02:35:42 +00:00
|
|
|
nsRegistryKey libKey;
|
1999-09-11 14:49:55 +00:00
|
|
|
rv = node->GetKey(&libKey);
|
2000-08-16 22:40:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) // Cannot continue here, because we have to free unescape
|
2000-05-12 01:24:36 +00:00
|
|
|
{
|
|
|
|
// Create nsDll with this name
|
|
|
|
nsDll *dll = NULL;
|
|
|
|
PRInt64 lastModTime;
|
|
|
|
PRInt64 fileSize;
|
|
|
|
GetRegistryDllInfo(libKey, &lastModTime, &fileSize);
|
|
|
|
rv = CreateDll(NULL, uLibrary, &lastModTime, &fileSize, &dll);
|
|
|
|
}
|
2000-08-16 22:40:27 +00:00
|
|
|
if (uLibrary && (uLibrary != eLibrary))
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(uLibrary);
|
1999-09-11 14:49:55 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) continue;
|
|
|
|
}
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeComponentLoader::AutoRegisterComponents(PRInt32 aWhen,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile *aDirectory)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* do we _really_ want to print this every time? */
|
|
|
|
printf("nsNativeComponentLoader: autoregistering begins.\n");
|
|
|
|
#endif
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-10-15 07:12:08 +00:00
|
|
|
nsresult rv = RegisterComponentsInDir(aWhen, aDirectory);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("nsNativeComponentLoader: autoregistering %s\n",
|
1999-08-31 21:40:21 +00:00
|
|
|
NS_FAILED(rv) ? "FAILED" : "succeeded");
|
2000-10-28 22:17:53 +00:00
|
|
|
#endif
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::RegisterComponentsInDir(PRInt32 when,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile *dir)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
PRBool isDir = PR_FALSE;
|
|
|
|
|
1999-10-15 07:12:08 +00:00
|
|
|
#if 0
|
|
|
|
// Going to many of these checks is a performance hit on the mac.
|
|
|
|
// Since these routines are called relatively infrequently and
|
|
|
|
// we will fail anyway down the line if a directory aint there,
|
|
|
|
// we are commenting this check out.
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
// Make sure we are dealing with a directory
|
|
|
|
rv = dir->IsDirectory(&isDir);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!isDir)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
1999-10-15 07:12:08 +00:00
|
|
|
#endif /* 0 */
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
// Create a directory iterator
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> dirIterator;
|
|
|
|
rv = dir->GetDirectoryEntries(getter_AddRefs(dirIterator));
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
// whip through the directory to register every file
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFile> dirEntry;
|
1999-08-31 21:40:21 +00:00
|
|
|
PRBool more = PR_FALSE;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
rv = dirIterator->HasMoreElements(&more);
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
while (more == PR_TRUE)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry));
|
1999-10-22 06:32:26 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
1999-10-22 06:32:26 +00:00
|
|
|
rv = dirEntry->IsDirectory(&isDir);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
if (isDir == PR_TRUE)
|
|
|
|
{
|
|
|
|
// This is a directory. Grovel for components into the directory.
|
|
|
|
rv = RegisterComponentsInDir(when, dirEntry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PRBool registered;
|
|
|
|
// This is a file. Try to register it.
|
|
|
|
rv = AutoRegisterComponent(when, dirEntry, ®istered);
|
|
|
|
}
|
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = dirIterator->HasMoreElements(&more);
|
1999-10-22 04:47:14 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-05-02 22:38:04 +00:00
|
|
|
static nsresult PR_CALLBACK
|
1999-09-26 18:06:41 +00:00
|
|
|
nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!dll || dll->IsLoaded() == PR_FALSE)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
// Get if the dll was marked for unload in an earlier round
|
|
|
|
PRBool dllMarkedForUnload = dll->IsMarkedForUnload();
|
|
|
|
|
|
|
|
// Reset dll marking for unload just in case we return with
|
|
|
|
// an error.
|
|
|
|
dll->MarkForUnload(PR_FALSE);
|
|
|
|
|
1999-09-23 00:01:53 +00:00
|
|
|
PRBool canUnload = PR_FALSE;
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
// Get the module object
|
|
|
|
nsCOMPtr<nsIModule> mobj;
|
|
|
|
/* XXXshaver cheat and use the global component manager */
|
1999-10-15 21:14:43 +00:00
|
|
|
rv = dll->GetModule(NS_STATIC_CAST(nsIComponentManager*, nsComponentManagerImpl::gComponentManager),
|
1999-08-31 21:40:21 +00:00
|
|
|
getter_AddRefs(mobj));
|
1999-09-23 00:01:53 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
rv = mobj->CanUnload(nsComponentManagerImpl::gComponentManager, &canUnload);
|
|
|
|
}
|
1999-09-23 00:01:53 +00:00
|
|
|
#ifndef OBSOLETE_MODULE_LOADING
|
|
|
|
else
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
// Try the old method of module unloading
|
|
|
|
nsCanUnloadProc proc = (nsCanUnloadProc)dll->FindSymbol("NSCanUnload");
|
|
|
|
if (proc)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
1999-10-22 04:47:14 +00:00
|
|
|
canUnload = proc(serviceMgr);
|
2000-05-12 01:24:36 +00:00
|
|
|
rv = NS_OK; // No error status returned by call.
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-03-11 22:44:51 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsNativeComponentLoader: Unload cant get nsIModule or NSCanUnload for %s",
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00:00
|
|
|
return rv;
|
1999-08-31 21:40:21 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
1999-09-23 00:01:53 +00:00
|
|
|
#endif /* OBSOLETE_MODULE_LOADING */
|
|
|
|
|
1999-09-26 18:06:41 +00:00
|
|
|
mobj = nsnull; // Release our reference to the module object
|
|
|
|
|
|
|
|
// When shutting down, whether we can unload the dll or not,
|
|
|
|
// we will shutdown the dll to release any memory it has got
|
|
|
|
if (when == nsIComponentManager::NS_Shutdown)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
dll->Shutdown();
|
|
|
|
}
|
1999-09-26 18:06:41 +00:00
|
|
|
|
|
|
|
// Check error status on CanUnload() call
|
|
|
|
if (NS_FAILED(rv))
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
2000-03-11 22:44:51 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsNativeComponentLoader: nsIModule::CanUnload() returned error for %s.",
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-09-26 18:06:41 +00:00
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
if (canUnload)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
if (dllMarkedForUnload)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
2000-03-11 22:44:51 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsNativeComponentLoader: + Unloading \"%s\".", dll->GetDisplayPath()));
|
1999-08-31 21:40:21 +00:00
|
|
|
#if 0
|
1999-10-22 04:47:14 +00:00
|
|
|
// XXX dlls aren't counting their outstanding instances correctly
|
|
|
|
// XXX hence, dont unload until this gets enforced.
|
|
|
|
rv = dll->Unload();
|
1999-08-31 21:40:21 +00:00
|
|
|
#endif /* 0 */
|
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
else
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
2000-03-11 22:44:51 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsNativeComponentLoader: Ready for unload \"%s\".", dll->GetDisplayPath()));
|
1999-08-31 21:40:21 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
2000-03-11 22:44:51 +00:00
|
|
|
("nsNativeComponentLoader: NOT ready for unload %s", dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-26 18:06:41 +00:00
|
|
|
struct freeLibrariesClosure
|
|
|
|
{
|
|
|
|
nsIServiceManager *serviceMgr;
|
|
|
|
PRInt32 when;
|
|
|
|
};
|
|
|
|
|
2000-05-02 22:38:04 +00:00
|
|
|
static PRBool PR_CALLBACK
|
1999-08-31 21:40:21 +00:00
|
|
|
nsFreeLibraryEnum(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
|
|
|
nsDll *dll = (nsDll *) aData;
|
1999-09-26 18:06:41 +00:00
|
|
|
struct freeLibrariesClosure *callData = (struct freeLibrariesClosure *) closure;
|
|
|
|
nsFreeLibrary(dll,
|
|
|
|
(callData ? callData->serviceMgr : NULL),
|
|
|
|
(callData ? callData->when : nsIComponentManager::NS_Timer));
|
1999-08-31 21:40:21 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SelfRegisterDll
|
|
|
|
*
|
|
|
|
* Given a dll abstraction, this will load, selfregister the dll and
|
|
|
|
* unload the dll.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-11-10 00:28:34 +00:00
|
|
|
nsNativeComponentLoader::SelfRegisterDll(nsDll *dll,
|
|
|
|
const char *registryLocation,
|
|
|
|
PRBool deferred)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
1999-11-10 00:28:34 +00:00
|
|
|
// Precondition: dll is not loaded already, unless we're deferred
|
|
|
|
PR_ASSERT(deferred || dll->IsLoaded() == PR_FALSE);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2001-10-16 03:35:52 +00:00
|
|
|
nsresult res;
|
|
|
|
nsCOMPtr<nsIServiceManager> serviceMgr;
|
|
|
|
res = NS_GetServiceManager(getter_AddRefs(serviceMgr));
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
|
|
|
if (dll->Load() == PR_FALSE)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
// Cannot load. Probably not a dll.
|
|
|
|
char errorMsg[1024] = "Cannot get error from nspr. Not enough memory.";
|
|
|
|
if (PR_GetErrorTextLength() < (int) sizeof(errorMsg))
|
|
|
|
PR_GetErrorText(errorMsg);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-10-22 04:47:14 +00:00
|
|
|
DumpLoadError(dll, "SelfRegisterDll", errorMsg);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-10-22 04:47:14 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2000-03-11 22:44:51 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsNativeComponentLoader: Loaded \"%s\".", dll->GetDisplayPath()));
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
// Tell the module to self register
|
|
|
|
nsCOMPtr<nsIModule> mobj;
|
|
|
|
res = dll->GetModule(mCompMgr, getter_AddRefs(mobj));
|
|
|
|
if (NS_SUCCEEDED(res))
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFile> fs;
|
2000-02-08 11:45:40 +00:00
|
|
|
/*************************************************************
|
|
|
|
* WARNING: Why are use introducing 'res2' here and then *
|
|
|
|
* later assigning it to 'res' rather than just using 'res'? *
|
|
|
|
* This is because this code turns up a code-generation bug *
|
|
|
|
* in VC6 on NT. Assigning to 'res' on the next line causes *
|
|
|
|
* the value of 'dll' to get nulled out! The two seem to be *
|
|
|
|
* getting aliased together during compilation. *
|
|
|
|
*************************************************************/
|
|
|
|
nsresult res2 = dll->GetDllSpec(getter_AddRefs(fs)); // don't change 'res2' -- see warning, above
|
|
|
|
if (NS_SUCCEEDED(res2)) {
|
1999-10-22 04:47:14 +00:00
|
|
|
res = mobj->RegisterSelf(mCompMgr, fs, registryLocation,
|
|
|
|
nativeComponentType);
|
2000-02-08 11:45:40 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
else
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
2000-02-08 11:45:40 +00:00
|
|
|
res = res2; // don't take this out -- see warning, above
|
1999-08-31 21:40:21 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
1999-10-22 04:47:14 +00:00
|
|
|
("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.",
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath()));
|
1999-08-31 21:40:21 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
mobj = NULL; // Force a release of the Module object before unload()
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
#ifndef OBSOLETE_MODULE_LOADING
|
|
|
|
else
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
res = NS_ERROR_NO_INTERFACE;
|
|
|
|
nsRegisterProc regproc = (nsRegisterProc)dll->FindSymbol("NSRegisterSelf");
|
|
|
|
if (regproc)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
1999-10-22 04:47:14 +00:00
|
|
|
// Call the NSRegisterSelfProc to enable dll registration
|
|
|
|
res = regproc(serviceMgr, registryLocation);
|
2000-03-11 22:44:51 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsNativeComponentLoader: %s using OBSOLETE NSRegisterSelf()",
|
|
|
|
dll->GetDisplayPath()));
|
1999-08-31 21:40:21 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
#endif /* OBSOLETE_MODULE_LOADING */
|
|
|
|
|
1999-09-01 06:25:20 +00:00
|
|
|
// Update the timestamp and size of the dll in registry
|
1999-11-10 00:28:34 +00:00
|
|
|
// Don't enter deferred modules in the registry, because it might only be
|
|
|
|
// able to register on some later autoreg, after another component has been
|
|
|
|
// installed.
|
|
|
|
if (res != NS_ERROR_FACTORY_REGISTER_AGAIN) {
|
|
|
|
dll->Sync();
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
PRInt64 modTime, size;
|
|
|
|
dll->GetLastModifiedTime(&modTime);
|
|
|
|
dll->GetSize(&size);
|
|
|
|
|
|
|
|
SetRegistryDllInfo(registryLocation, &modTime, &size);
|
1999-11-10 00:28:34 +00:00
|
|
|
}
|
1999-09-01 06:25:20 +00:00
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1999-09-14 13:40:22 +00:00
|
|
|
//
|
|
|
|
// MOZ_DEMANGLE_SYMBOLS is only a linux + MOZ_DEBUG thing.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if defined(MOZ_DEMANGLE_SYMBOLS)
|
|
|
|
#include "nsTraceRefcnt.h" // for nsTraceRefcnt::DemangleSymbol()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::DumpLoadError(nsDll *dll,
|
|
|
|
const char *aCallerName,
|
|
|
|
const char *aNsprErrorMsg)
|
|
|
|
{
|
|
|
|
PR_ASSERT(aCallerName != NULL);
|
|
|
|
|
|
|
|
if (nsnull == dll || nsnull == aNsprErrorMsg)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCAutoString errorMsg(aNsprErrorMsg);
|
|
|
|
|
|
|
|
#if defined(MOZ_DEMANGLE_SYMBOLS)
|
2000-05-12 01:24:36 +00:00
|
|
|
// Demangle undefined symbols
|
|
|
|
nsCAutoString undefinedMagicString("undefined symbol:");
|
1999-09-14 13:40:22 +00:00
|
|
|
|
2000-05-12 01:24:36 +00:00
|
|
|
PRInt32 offset = errorMsg.Find(undefinedMagicString, PR_TRUE);
|
1999-09-14 13:40:22 +00:00
|
|
|
|
2000-05-12 01:24:36 +00:00
|
|
|
if (offset != kNotFound)
|
|
|
|
{
|
1999-09-14 13:40:22 +00:00
|
|
|
nsCAutoString symbol(errorMsg);
|
2000-09-03 04:04:41 +00:00
|
|
|
nsCAutoString demangledSymbol;
|
1999-09-14 13:40:22 +00:00
|
|
|
|
|
|
|
symbol.Cut(0,offset);
|
|
|
|
|
|
|
|
symbol.Cut(0,undefinedMagicString.Length());
|
|
|
|
|
|
|
|
symbol.StripWhitespace();
|
|
|
|
|
|
|
|
char demangled[4096] = "\0";
|
|
|
|
|
|
|
|
nsTraceRefcnt::DemangleSymbol(symbol,demangled,sizeof(demangled));
|
|
|
|
|
2001-03-23 07:34:34 +00:00
|
|
|
if (demangled && *demangled != '\0')
|
1999-09-14 13:40:22 +00:00
|
|
|
demangledSymbol = demangled;
|
|
|
|
|
2000-09-03 04:04:41 +00:00
|
|
|
if (!demangledSymbol.IsEmpty())
|
1999-09-14 13:40:22 +00:00
|
|
|
{
|
|
|
|
nsCAutoString tmp(errorMsg);
|
|
|
|
|
|
|
|
|
|
|
|
tmp.Cut(offset + undefinedMagicString.Length(),
|
|
|
|
tmp.Length() - offset - undefinedMagicString.Length());
|
|
|
|
|
|
|
|
tmp += " \n";
|
|
|
|
|
|
|
|
tmp += demangledSymbol;
|
|
|
|
|
|
|
|
errorMsg = tmp;
|
2000-05-12 01:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-14 13:40:22 +00:00
|
|
|
#endif // MOZ_DEMANGLE_SYMBOLS
|
|
|
|
|
|
|
|
// Do NSPR log
|
1999-11-10 00:28:34 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
1999-09-14 13:40:22 +00:00
|
|
|
("nsNativeComponentLoader: %s(%s) Load FAILED with error:%s",
|
|
|
|
aCallerName,
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath(),
|
1999-09-14 13:40:22 +00:00
|
|
|
(const char *) errorMsg));
|
|
|
|
|
|
|
|
|
|
|
|
// Dump to screen if needed
|
|
|
|
#ifdef PRINT_CRITICAL_ERROR_TO_SCREEN
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("**************************************************\n"
|
1999-09-14 13:40:22 +00:00
|
|
|
"nsNativeComponentLoader: %s(%s) Load FAILED with error: %s\n"
|
|
|
|
"**************************************************\n",
|
|
|
|
aCallerName,
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath(),
|
1999-09-14 13:40:22 +00:00
|
|
|
(const char *) errorMsg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::SelfUnregisterDll(nsDll *dll)
|
|
|
|
{
|
2001-10-16 03:35:52 +00:00
|
|
|
nsresult res;
|
|
|
|
nsCOMPtr<nsIServiceManager> serviceMgr;
|
|
|
|
res = NS_GetServiceManager(getter_AddRefs(serviceMgr));
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
|
|
|
if (dll->Load() == PR_FALSE)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
// Cannot load. Probably not a dll.
|
|
|
|
return(NS_ERROR_FAILURE);
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
// Tell the module to self register
|
|
|
|
nsCOMPtr<nsIModule> mobj;
|
|
|
|
res = dll->GetModule(mCompMgr, getter_AddRefs(mobj));
|
|
|
|
if (NS_SUCCEEDED(res))
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
2000-01-24 21:28:28 +00:00
|
|
|
("nsNativeComponentLoader: %s using nsIModule to unregister self.", dll->GetDisplayPath()));
|
|
|
|
nsCOMPtr<nsIFile> fs;
|
1999-10-22 04:47:14 +00:00
|
|
|
res = dll->GetDllSpec(getter_AddRefs(fs));
|
2000-05-05 06:34:39 +00:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
// Get registry location for spec
|
|
|
|
nsXPIDLCString registryName;
|
|
|
|
res = mCompMgr->RegistryLocationForSpec(fs, getter_Copies(registryName));
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
mobj->UnregisterSelf(mCompMgr, fs, registryName);
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
#ifndef OBSOLETE_MODULE_LOADING
|
|
|
|
else
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
res = NS_ERROR_NO_INTERFACE;
|
|
|
|
nsUnregisterProc unregproc =
|
|
|
|
(nsUnregisterProc) dll->FindSymbol("NSUnregisterSelf");
|
|
|
|
if (unregproc)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
1999-10-22 04:47:14 +00:00
|
|
|
// Call the NSUnregisterSelfProc to enable dll de-registration
|
|
|
|
res = unregproc(serviceMgr, dll->GetPersistentDescriptorString());
|
1999-08-31 21:40:21 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
#endif /* OBSOLETE_MODULE_LOADING */
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-04-18 05:25:05 +00:00
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::AutoUnregisterComponent(PRInt32 when,
|
|
|
|
nsIFile *component,
|
|
|
|
PRBool *unregistered)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsXPIDLCString persistentDescriptor;
|
|
|
|
rv = mCompMgr->RegistryLocationForSpec(component,
|
|
|
|
getter_Copies(persistentDescriptor));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-05-15 19:28:12 +00:00
|
|
|
// Notify observers, if any, of autoregistration work
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
2000-05-15 19:28:12 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2001-10-16 03:35:52 +00:00
|
|
|
nsCOMPtr<nsIServiceManager> mgr;
|
|
|
|
rv = NS_GetServiceManager(getter_AddRefs(mgr));
|
2000-05-17 01:53:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
(void) observerService->Notify(mgr,
|
2001-06-30 11:02:25 +00:00
|
|
|
NS_ConvertASCIItoUCS2(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID).get(),
|
|
|
|
NS_ConvertASCIItoUCS2("Unregistering native component").get());
|
2000-05-17 01:53:50 +00:00
|
|
|
}
|
2000-05-15 19:28:12 +00:00
|
|
|
}
|
|
|
|
|
2000-04-18 05:25:05 +00:00
|
|
|
nsDll *dll = NULL;
|
|
|
|
PRInt64 mod = LL_Zero(), size = LL_Zero();
|
|
|
|
rv = CreateDll(component, persistentDescriptor, &mod, &size, &dll);
|
|
|
|
if (NS_FAILED(rv) || dll == NULL) return rv;
|
|
|
|
|
|
|
|
rv = SelfUnregisterDll(dll);
|
|
|
|
|
|
|
|
// Remove any autoreg info about this dll
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
RemoveRegistryDllInfo(persistentDescriptor);
|
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsNativeComponentLoader: AutoUnregistration for %s %s.",
|
|
|
|
(NS_FAILED(rv) ? "FAILED" : "succeeded"), dll->GetDisplayPath()));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile *component,
|
1999-08-31 21:40:21 +00:00
|
|
|
PRBool *registered)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (!registered)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
/* this should be a pref or registry entry, or something */
|
2001-05-15 05:50:24 +00:00
|
|
|
static const char *ValidDllExtensions[] = {
|
1999-08-31 21:40:21 +00:00
|
|
|
".dll", /* Windows */
|
1999-11-10 00:28:34 +00:00
|
|
|
".so", /* Unix */
|
|
|
|
".shlb", /* Mac ? */
|
1999-08-31 21:40:21 +00:00
|
|
|
".dso", /* Unix ? */
|
|
|
|
".dylib", /* Unix: Rhapsody */
|
|
|
|
".so.1.0", /* Unix: BSD */
|
|
|
|
".sl", /* Unix: HP-UX */
|
|
|
|
#if defined(VMS)
|
|
|
|
".exe", /* Open VMS */
|
|
|
|
#endif
|
|
|
|
".dlm", /* new for all platforms */
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
*registered = PR_FALSE;
|
|
|
|
|
1999-10-15 07:12:08 +00:00
|
|
|
#if 0
|
|
|
|
// This is a performance hit on mac. Since we have already checked
|
|
|
|
// this; plus is we dont, load will fail anyway later on, this
|
|
|
|
// is being commented out.
|
1999-10-19 05:49:04 +00:00
|
|
|
|
|
|
|
// Ensure we are dealing with a file as opposed to a dir
|
|
|
|
PRBool b = PR_FALSE;
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
rv = component->IsFile(&b);
|
|
|
|
if (NS_FAILED(rv) || !b)
|
|
|
|
return rv;
|
1999-10-15 07:12:08 +00:00
|
|
|
#endif /* 0 */
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
// deal only with files that have a valid extension
|
|
|
|
PRBool validExtension = PR_FALSE;
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
#ifdef XP_MAC // sdagley dougt fix
|
1999-08-31 21:40:21 +00:00
|
|
|
// rjc - on Mac, check the file's type code (skip checking the creator code)
|
2000-05-12 01:24:36 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFileMac> localFileMac = do_QueryInterface(component);
|
|
|
|
if (localFileMac)
|
|
|
|
{
|
2000-05-17 01:53:50 +00:00
|
|
|
OSType type, creator;
|
|
|
|
rv = localFileMac->GetFileTypeAndCreator(&type, &creator);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
// on Mac, Mozilla shared libraries are of type 'shlb'
|
|
|
|
// Note: we don't check the creator (which for Mozilla is 'MOZZ')
|
|
|
|
// so that 3rd party shared libraries will be noticed!
|
2000-10-17 18:06:23 +00:00
|
|
|
validExtension = ((type == 'shlb') || (type == 'NSPL'));
|
2000-05-17 01:53:50 +00:00
|
|
|
}
|
2000-05-12 01:24:36 +00:00
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
#else
|
|
|
|
char *leafName = NULL;
|
|
|
|
rv = component->GetLeafName(&leafName);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
int flen = PL_strlen(leafName);
|
|
|
|
for (int i=0; ValidDllExtensions[i] != NULL; i++)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
int extlen = PL_strlen(ValidDllExtensions[i]);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-10-22 04:47:14 +00:00
|
|
|
// Does fullname end with this extension
|
|
|
|
if (flen >= extlen &&
|
|
|
|
!PL_strcasecmp(&(leafName[flen - extlen]), ValidDllExtensions[i])
|
|
|
|
)
|
|
|
|
{
|
|
|
|
validExtension = PR_TRUE;
|
|
|
|
break;
|
1999-08-31 21:40:21 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
2000-06-03 09:46:12 +00:00
|
|
|
if (leafName) nsMemory::Free(leafName);
|
1999-08-31 21:40:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (validExtension == PR_FALSE)
|
|
|
|
// Skip invalid extensions
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-11-10 00:28:34 +00:00
|
|
|
nsXPIDLCString persistentDescriptor;
|
|
|
|
rv = mCompMgr->RegistryLocationForSpec(component,
|
|
|
|
getter_Copies(persistentDescriptor));
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-06-29 23:16:52 +00:00
|
|
|
nsCStringKey key(persistentDescriptor);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-09-11 14:49:55 +00:00
|
|
|
// Get the registry representation of the dll, if any
|
1999-08-31 21:40:21 +00:00
|
|
|
nsDll *dll;
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 mod = LL_Zero(), size = LL_Zero();
|
|
|
|
rv = CreateDll(component, persistentDescriptor, &mod, &size, &dll);
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (dll != NULL)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
// Make sure the dll is OK
|
|
|
|
if (dll->GetStatus() != NS_OK)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
1999-10-22 04:47:14 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsNativeComponentLoader: + nsDll not NS_OK \"%s\". Skipping...",
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-10-22 04:47:14 +00:00
|
|
|
// We already have seen this dll. Check if this dll changed
|
|
|
|
if (!dll->HasChanged())
|
|
|
|
{
|
|
|
|
// Dll hasn't changed. Skip.
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
2000-03-11 22:44:51 +00:00
|
|
|
("nsNativeComponentLoader: + nsDll not changed \"%s\". Skipping...",
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Aagh! the dll has changed since the last time we saw it.
|
|
|
|
// re-register dll
|
2000-05-15 19:28:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Notify observers, if any, of autoregistration work
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
2000-05-15 19:28:12 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2001-10-16 03:35:52 +00:00
|
|
|
nsCOMPtr<nsIServiceManager> mgr;
|
|
|
|
rv = NS_GetServiceManager(getter_AddRefs(mgr));
|
2000-05-17 01:53:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
// this string can't come from a string bundle, because we don't have string
|
|
|
|
// bundles yet.
|
|
|
|
NS_ConvertASCIItoUCS2 statusMsg("Registering native component ");
|
|
|
|
NS_ConvertASCIItoUCS2 fileName("(no name)");
|
|
|
|
|
|
|
|
// get the file name
|
|
|
|
nsCOMPtr<nsIFile> dllSpec;
|
|
|
|
if (NS_SUCCEEDED(dll->GetDllSpec(getter_AddRefs(dllSpec))) && dllSpec)
|
2000-05-15 19:28:12 +00:00
|
|
|
{
|
2001-03-12 20:43:02 +00:00
|
|
|
nsXPIDLCString dllLeafName;
|
|
|
|
dllSpec->GetLeafName(getter_Copies(dllLeafName));
|
|
|
|
fileName.AssignWithConversion(dllLeafName);
|
2000-05-15 19:28:12 +00:00
|
|
|
}
|
2000-05-17 01:53:50 +00:00
|
|
|
statusMsg.Append(fileName);
|
|
|
|
|
|
|
|
(void) observerService->Notify(mgr,
|
2001-06-30 11:02:25 +00:00
|
|
|
NS_ConvertASCIItoUCS2(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID).get(),
|
|
|
|
statusMsg.get());
|
2000-05-17 01:53:50 +00:00
|
|
|
}
|
2000-05-15 19:28:12 +00:00
|
|
|
}
|
|
|
|
|
1999-10-22 04:47:14 +00:00
|
|
|
if (dll->IsLoaded())
|
|
|
|
{
|
|
|
|
// We loaded the old version of the dll and now we find that the
|
|
|
|
// on-disk copy if newer. Try to unload the dll.
|
2001-10-16 03:35:52 +00:00
|
|
|
nsCOMPtr<nsIServiceManager> serviceMgr;
|
|
|
|
rv = NS_GetServiceManager(getter_AddRefs(serviceMgr));
|
|
|
|
|
1999-10-22 04:47:14 +00:00
|
|
|
rv = nsFreeLibrary(dll, serviceMgr, when);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
// 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,
|
|
|
|
("nsNativeComponentLoader: *** Dll already loaded. "
|
|
|
|
"Cannot unload either. Hence cannot re-register "
|
2000-01-24 21:28:28 +00:00
|
|
|
"\"%s\". Skipping...", dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else {
|
1999-08-31 21:40:21 +00:00
|
|
|
// dll doesn't have a CanUnload proc. Guess it is
|
|
|
|
// ok to unload it.
|
1999-10-22 04:47:14 +00:00
|
|
|
dll->Unload();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsNativeComponentLoader: + Unloading \"%s\". (no CanUnloadProc).",
|
2000-01-24 21:28:28 +00:00
|
|
|
dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-10-22 04:47:14 +00:00
|
|
|
} // dll isloaded
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-10-22 04:47:14 +00:00
|
|
|
// Sanity.
|
|
|
|
if (dll->IsLoaded())
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
1999-10-22 04:47:14 +00:00
|
|
|
// 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,
|
|
|
|
("nsNativeComponentLoader: Dll still loaded. Cannot re-register "
|
2000-01-24 21:28:28 +00:00
|
|
|
"\"%s\". Skipping...", dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00: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.
|
|
|
|
dll = new nsDll(persistentDescriptor);
|
|
|
|
if (dll == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
mDllStore->Put(&key, (void *) dll);
|
|
|
|
} // dll == NULL
|
1999-08-31 21:40:21 +00: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.
|
1999-11-10 00:28:34 +00:00
|
|
|
nsresult res = SelfRegisterDll(dll, persistentDescriptor, PR_FALSE);
|
1999-08-31 21:40:21 +00:00
|
|
|
if (NS_FAILED(res))
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
1999-11-10 00:28:34 +00:00
|
|
|
if (res == NS_ERROR_FACTORY_REGISTER_AGAIN) {
|
|
|
|
/* defer for later loading */
|
|
|
|
mDeferredComponents.AppendElement(dll);
|
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
|
|
|
("nsNativeComponentLoader: Autoregistration FAILED for "
|
2000-01-24 21:28:28 +00:00
|
|
|
"\"%s\". Skipping...", dll->GetDisplayPath()));
|
1999-11-10 00:28:34 +00:00
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
else
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
|
|
|
("nsNativeComponentLoader: Autoregistration Passed for "
|
2000-01-24 21:28:28 +00:00
|
|
|
"\"%s\".", dll->GetDisplayPath()));
|
1999-10-22 04:47:14 +00:00
|
|
|
// Marking dll along with modified time and size in the
|
|
|
|
// registry happens at PlatformRegister(). No need to do it
|
|
|
|
// here again.
|
|
|
|
}
|
1999-11-10 00:28:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::RegisterDeferredComponents(PRInt32 aWhen,
|
|
|
|
PRBool *aRegistered)
|
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "nNCL: registering deferred (%d)\n",
|
1999-11-10 00:28:34 +00:00
|
|
|
mDeferredComponents.Count());
|
2000-10-28 22:17:53 +00:00
|
|
|
#endif
|
1999-11-10 00:28:34 +00:00
|
|
|
*aRegistered = PR_FALSE;
|
|
|
|
if (!mDeferredComponents.Count())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
for (int i = mDeferredComponents.Count() - 1; i >= 0; i--) {
|
|
|
|
nsDll *dll = NS_STATIC_CAST(nsDll *, mDeferredComponents[i]);
|
|
|
|
nsresult rv = SelfRegisterDll(dll,
|
|
|
|
dll->GetRegistryLocation(),
|
|
|
|
PR_TRUE);
|
|
|
|
if (rv != NS_ERROR_FACTORY_REGISTER_AGAIN) {
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
*aRegistered = PR_TRUE;
|
|
|
|
mDeferredComponents.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*aRegistered)
|
2000-10-28 22:17:53 +00:00
|
|
|
fprintf(stderr, "nNCL: registered deferred, %d left\n",
|
1999-11-10 00:28:34 +00:00
|
|
|
mDeferredComponents.Count());
|
|
|
|
else
|
2000-10-28 22:17:53 +00:00
|
|
|
fprintf(stderr, "nNCL: didn't register any components, %d left\n",
|
1999-11-10 00:28:34 +00:00
|
|
|
mDeferredComponents.Count());
|
|
|
|
/* are there any fatal errors? */
|
|
|
|
return NS_OK;
|
1999-08-31 21:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::OnRegister(const nsIID &aCID, const char *aType,
|
|
|
|
const char *aClassName,
|
2000-09-13 23:57:52 +00:00
|
|
|
const char *aContractID, const char *aLocation,
|
1999-08-31 21:40:21 +00:00
|
|
|
PRBool aReplace, PRBool aPersist)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::UnloadAll(PRInt32 aWhen)
|
|
|
|
{
|
1999-09-23 00:01:53 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsNativeComponentLoader: Unloading...."));
|
|
|
|
|
1999-09-26 18:06:41 +00:00
|
|
|
struct freeLibrariesClosure callData;
|
|
|
|
callData.serviceMgr = NULL; // XXX need to get this as a parameter
|
|
|
|
callData.when = aWhen;
|
|
|
|
|
1999-09-23 00:01:53 +00:00
|
|
|
// Cycle through the dlls checking to see if they want to be unloaded
|
2000-08-18 20:54:04 +00:00
|
|
|
if (mDllStore) {
|
|
|
|
mDllStore->Enumerate(nsFreeLibraryEnum, &callData);
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-01 06:25:20 +00:00
|
|
|
nsresult
|
1999-08-31 21:40:21 +00:00
|
|
|
nsNativeComponentLoader::GetRegistryDllInfo(const char *aLocation,
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 *lastModifiedTime,
|
|
|
|
PRInt64 *fileSize)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-05-12 01:24:36 +00:00
|
|
|
PRUint32 length = strlen(aLocation);
|
|
|
|
char* eLocation;
|
|
|
|
rv = mRegistry->EscapeKey((PRUint8*)aLocation, 1, &length, (PRUint8**)&eLocation);
|
|
|
|
if (rv != NS_OK)
|
|
|
|
{
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (eLocation == nsnull) // No escaping required
|
|
|
|
eLocation = (char*)aLocation;
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-09-29 02:35:42 +00:00
|
|
|
nsRegistryKey key;
|
2000-05-12 01:24:36 +00:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mXPCOMKey, eLocation, &key);
|
1999-09-01 06:25:20 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2000-05-12 01:24:36 +00:00
|
|
|
rv = GetRegistryDllInfo(key, lastModifiedTime, fileSize);
|
|
|
|
if (aLocation != eLocation)
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(eLocation);
|
2000-05-12 01:24:36 +00:00
|
|
|
return rv;
|
1999-09-11 14:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-29 02:35:42 +00:00
|
|
|
nsNativeComponentLoader::GetRegistryDllInfo(nsRegistryKey key,
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 *lastModifiedTime,
|
|
|
|
PRInt64 *fileSize)
|
1999-09-11 14:49:55 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 lastMod;
|
|
|
|
nsresult rv = mRegistry->GetLongLong(key, lastModValueName, &lastMod);
|
1999-09-01 06:25:20 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
*lastModifiedTime = lastMod;
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 fsize;
|
|
|
|
rv = mRegistry->GetLongLong(key, fileSizeValueName, &fsize);
|
1999-09-01 06:25:20 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-05-12 01:24:36 +00:00
|
|
|
*fileSize = fsize;
|
1999-09-01 06:25:20 +00:00
|
|
|
return NS_OK;
|
1999-08-31 21:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-01 06:25:20 +00:00
|
|
|
nsNativeComponentLoader::SetRegistryDllInfo(const char *aLocation,
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 *lastModifiedTime,
|
|
|
|
PRInt64 *fileSize)
|
1999-09-01 06:25:20 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-05-12 01:24:36 +00:00
|
|
|
PRUint32 length = strlen(aLocation);
|
|
|
|
char* eLocation;
|
|
|
|
rv = mRegistry->EscapeKey((PRUint8*)aLocation, 1, &length, (PRUint8**)&eLocation);
|
|
|
|
if (rv != NS_OK)
|
|
|
|
{
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (eLocation == nsnull) // No escaping required
|
|
|
|
eLocation = (char*)aLocation;
|
|
|
|
|
1999-09-29 02:35:42 +00:00
|
|
|
nsRegistryKey key;
|
2000-05-12 01:24:36 +00:00
|
|
|
rv = mRegistry->GetSubtreeRaw(mXPCOMKey, eLocation, &key);
|
1999-09-01 06:25:20 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = mRegistry->SetLongLong(key, lastModValueName, lastModifiedTime);
|
1999-09-01 06:25:20 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = mRegistry->SetLongLong(key, fileSizeValueName, fileSize);
|
2000-05-12 01:24:36 +00:00
|
|
|
if (aLocation != eLocation)
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(eLocation);
|
1999-09-01 06:25:20 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-09-11 14:49:55 +00:00
|
|
|
|
2000-04-18 05:25:05 +00:00
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::RemoveRegistryDllInfo(const char *aLocation)
|
|
|
|
{
|
2000-05-12 01:24:36 +00:00
|
|
|
nsresult rv;
|
|
|
|
PRUint32 length = strlen(aLocation);
|
|
|
|
char* eLocation;
|
|
|
|
rv = mRegistry->EscapeKey((PRUint8*)aLocation, 1, &length, (PRUint8**)&eLocation);
|
|
|
|
if (rv != NS_OK)
|
|
|
|
{
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (eLocation == nsnull) // No escaping required
|
|
|
|
eLocation = (char*)aLocation;
|
|
|
|
|
|
|
|
rv = mRegistry->RemoveSubtree(mXPCOMKey, eLocation);
|
|
|
|
if (aLocation != eLocation)
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(eLocation);
|
2000-05-12 01:24:36 +00:00
|
|
|
return rv;
|
2000-04-18 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
1999-09-11 14:49:55 +00:00
|
|
|
//
|
|
|
|
// CreateDll
|
|
|
|
// The only way to create a dll or get it from the dll cache. This will
|
|
|
|
// be called in multiple situations:
|
|
|
|
//
|
|
|
|
// 1. Autoregister will create one for each dll it is trying to register. This
|
2000-05-12 01:24:36 +00:00
|
|
|
// call will be passing a spec in.
|
|
|
|
// {spec, NULL, 0, 0}
|
1999-09-11 14:49:55 +00:00
|
|
|
//
|
|
|
|
// 2. GetFactory() This will call CreateDll() with a null spec but will give
|
2000-05-12 01:24:36 +00:00
|
|
|
// the registry represented name of the dll. If modtime and size are zero,
|
|
|
|
// we will go the registry to find the right modtime and size.
|
|
|
|
// {NULL, rel:libpref.so, 0, 0}
|
1999-09-11 14:49:55 +00:00
|
|
|
//
|
|
|
|
// 3. Prepopulation of dllCache A dll object created off a registry entry.
|
2000-05-12 01:24:36 +00:00
|
|
|
// Specifically dll name is stored in rel: or abs: or lib: formats in the
|
|
|
|
// registry along with its lastModTime and fileSize.
|
|
|
|
// {NULL, rel:libpref.so, 8985659, 20987}
|
1999-09-01 06:25:20 +00:00
|
|
|
nsresult
|
2000-01-24 21:28:28 +00:00
|
|
|
nsNativeComponentLoader::CreateDll(nsIFile *aSpec, const char *aLocation,
|
|
|
|
PRInt64 *modificationTime, PRInt64 *fileSize,
|
1999-09-11 14:49:55 +00:00
|
|
|
nsDll **aDll)
|
1999-08-31 21:40:21 +00:00
|
|
|
{
|
|
|
|
nsDll *dll;
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFile> dllSpec;
|
|
|
|
nsCOMPtr<nsIFile> spec;
|
1999-08-31 21:40:21 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2000-08-10 06:19:37 +00:00
|
|
|
nsCStringKey key(aLocation);
|
1999-08-31 21:40:21 +00:00
|
|
|
dll = (nsDll *)mDllStore->Get(&key);
|
1999-09-01 06:25:20 +00:00
|
|
|
if (dll)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
*aDll = dll;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-09-01 06:25:20 +00:00
|
|
|
if (!aSpec)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
if (!nsCRT::strncmp(aLocation, XPCOM_LIB_PREFIX, 4)) {
|
|
|
|
dll = new nsDll(aLocation+4, 1 /* dumb magic flag */);
|
|
|
|
if (!dll) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
} else {
|
|
|
|
rv = mCompMgr->SpecForRegistryLocation(aLocation,
|
|
|
|
getter_AddRefs(spec));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-09-01 06:25:20 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
}
|
1999-09-01 06:25:20 +00:00
|
|
|
else
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
|
|
|
spec = aSpec;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-09-01 06:25:20 +00:00
|
|
|
if (!dll)
|
1999-10-22 04:47:14 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
PR_ASSERT(modificationTime != NULL);
|
|
|
|
PR_ASSERT(fileSize != NULL);
|
|
|
|
|
|
|
|
PRInt64 zit = LL_Zero();
|
|
|
|
|
|
|
|
if (LL_EQ(*modificationTime,zit) && LL_EQ(*fileSize,zit))
|
1999-09-01 06:25:20 +00:00
|
|
|
{
|
1999-10-22 04:47:14 +00:00
|
|
|
// Get the modtime and filesize from the registry
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = GetRegistryDllInfo(aLocation, modificationTime, fileSize);
|
1999-09-01 06:25:20 +00:00
|
|
|
}
|
1999-10-22 04:47:14 +00:00
|
|
|
dll = new nsDll(spec, aLocation, modificationTime, fileSize);
|
|
|
|
}
|
1999-09-02 07:00:29 +00:00
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
if (!dll)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aDll = dll;
|
|
|
|
mDllStore->Put(&key, dll);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::GetFactoryFromModule(nsDll *aDll, const nsCID &aCID,
|
|
|
|
nsIFactory **aFactory)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIModule> module;
|
|
|
|
rv = aDll->GetModule(mCompMgr, getter_AddRefs(module));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return module->GetClassObject(mCompMgr, aCID, NS_GET_IID(nsIFactory),
|
|
|
|
(void **)aFactory);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNativeComponentLoader::GetFactoryFromNSGetFactory(nsDll *aDll,
|
|
|
|
const nsCID &aCID,
|
|
|
|
nsIServiceManager *aServMgr,
|
|
|
|
nsIFactory **aFactory)
|
|
|
|
{
|
|
|
|
#ifdef XPCOM_USE_NSGETFACTORY
|
|
|
|
nsFactoryProc getFactory =
|
|
|
|
(nsFactoryProc) aDll->FindSymbol("NSGetFactory");
|
|
|
|
|
|
|
|
if (!getFactory)
|
|
|
|
return NS_ERROR_FACTORY_NOT_LOADED;
|
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
2000-03-11 22:44:51 +00:00
|
|
|
("nsNativeComponentLoader: %s using OBSOLETE NSGetFactory()\n",
|
2000-01-24 21:28:28 +00:00
|
|
|
aDll->GetDisplayPath()));
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
/*
|
2000-09-13 23:57:52 +00:00
|
|
|
* There was a time when CLSIDToContractID was used to get className
|
|
|
|
* and contractID, but that day is long past. This code is not long
|
1999-08-31 21:40:21 +00:00
|
|
|
* for this earth, so we just pass nsnull.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return getFactory(aServMgr, aCID, nsnull /*className */,
|
2000-09-13 23:57:52 +00:00
|
|
|
nsnull /* contractID */, aFactory);
|
1999-08-31 21:40:21 +00:00
|
|
|
|
|
|
|
#else /* !XPCOM_USE_NSGETFACTORY */
|
|
|
|
return NS_ERROR_FACTORY_NOT_LOADED;
|
|
|
|
#endif /* XPCOM_USE_NSGETFACTORY */
|
|
|
|
}
|