Landing nsIFile.

git-svn-id: svn://10.0.0.236/trunk@58490 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dougt%netscape.com
2000-01-24 21:28:28 +00:00
parent 1f351b9156
commit 714da09a59
162 changed files with 4387 additions and 2566 deletions

View File

@@ -30,6 +30,12 @@
#include "nsHashtableEnumerator.h"
#include "nsXPIDLString.h"
#ifdef XP_MAC // sdagley dougt fix
#include <Files.h>
#include <Errors.h>
#include "nsLocalFileMac.h"
#endif
#define PRINT_CRITICAL_ERROR_TO_SCREEN 1
#define USE_REGISTRY 1
#define XPCOM_USE_NSGETFACTORY 1
@@ -75,7 +81,8 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID,
/* Should this all live in xcDll? */
nsDll *dll;
rv = CreateDll(nsnull, aLocation, 0, 0, &dll);
PRInt64 mod = LL_Zero(), size = LL_Zero();
rv = CreateDll(nsnull, aLocation, &mod, &size, &dll);
if (NS_FAILED(rv))
return rv;
@@ -85,7 +92,7 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID,
if (!dll->IsLoaded()) {
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsNativeComponentLoader: loading \"%s\"",
dll->GetNativePath()));
dll->GetDisplayPath()));
if (!dll->Load()) {
@@ -119,7 +126,7 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID,
fprintf(stderr,
"XPCOM: Component %s uses DEPRECATED\n"
" NSGetFactory interface. This could break "
"AT ANY TIME.\n", dll->GetNativePath());
"AT ANY TIME.\n", dll->GetDisplayPath());
}
#endif
}
@@ -128,7 +135,7 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID,
PR_LOG(nsComponentManagerLog, (NS_SUCCEEDED(rv) ? PR_LOG_DEBUG : PR_LOG_ERROR),
("nsNativeComponentLoader: Factory creation %s "
"%s -> %s\n", (NS_SUCCEEDED(rv) ? "passed" : "FAILED"),
aLocation, dll->GetNativePath()));
aLocation, dll->GetDisplayPath()));
// 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!
@@ -197,10 +204,10 @@ nsNativeComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg)
// Create nsDll with this name
nsDll *dll = NULL;
PRUint32 lastModTime = 0;
PRUint32 fileSize = 0;
PRInt64 lastModTime;
PRInt64 fileSize;
GetRegistryDllInfo(libKey, &lastModTime, &fileSize);
rv = CreateDll(NULL, library, lastModTime, fileSize, &dll);
rv = CreateDll(NULL, library, &lastModTime, &fileSize, &dll);
if (NS_FAILED(rv)) continue;
}
@@ -209,7 +216,7 @@ nsNativeComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg)
NS_IMETHODIMP
nsNativeComponentLoader::AutoRegisterComponents(PRInt32 aWhen,
nsIFileSpec *aDirectory)
nsIFile *aDirectory)
{
#ifdef DEBUG
/* do we _really_ want to print this every time? */
@@ -228,7 +235,7 @@ nsNativeComponentLoader::AutoRegisterComponents(PRInt32 aWhen,
nsresult
nsNativeComponentLoader::RegisterComponentsInDir(PRInt32 when,
nsIFileSpec *dir)
nsIFile *dir)
{
nsresult rv = NS_ERROR_FAILURE;
PRBool isDir = PR_FALSE;
@@ -248,22 +255,20 @@ nsNativeComponentLoader::RegisterComponentsInDir(PRInt32 when,
#endif /* 0 */
// Create a directory iterator
nsCOMPtr<nsIDirectoryIterator>dirIterator;
rv = nsComponentManager::CreateInstance(NS_DIRECTORYITERATOR_PROGID, NULL,
NS_GET_IID(nsIDirectoryIterator),
getter_AddRefs(dirIterator));
nsCOMPtr<nsISimpleEnumerator> dirIterator;
rv = dir->GetDirectoryEntries(getter_AddRefs(dirIterator));
if (NS_FAILED(rv)) return rv;
rv = dirIterator->Init(dir, PR_FALSE);
if (NS_FAILED(rv)) return rv;
// whip through the directory to register every file
nsIFileSpec *dirEntry = NULL;
nsCOMPtr<nsIFile> dirEntry;
PRBool more = PR_FALSE;
rv = dirIterator->Exists(&more);
rv = dirIterator->HasMoreElements(&more);
if (NS_FAILED(rv)) return rv;
while (more == PR_TRUE)
{
rv = dirIterator->GetCurrentSpec(&dirEntry);
rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry));
if (NS_SUCCEEDED(rv))
{
rv = dirEntry->IsDirectory(&isDir);
@@ -281,11 +286,8 @@ nsNativeComponentLoader::RegisterComponentsInDir(PRInt32 when,
rv = AutoRegisterComponent(when, dirEntry, &registered);
}
}
NS_RELEASE(dirEntry);
}
rv = dirIterator->Next();
if (NS_FAILED(rv)) return rv;
rv = dirIterator->Exists(&more);
rv = dirIterator->HasMoreElements(&more);
if (NS_FAILED(rv)) return rv;
}
@@ -334,7 +336,7 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when)
{
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsComponentManager: Unload cant get nsIModule or CanUnload for %s",
dll->GetNativePath()));
dll->GetDisplayPath()));
return rv;
}
}
@@ -354,7 +356,7 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when)
{
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsComponentManager: nsIModule::CanUnload() returned error for %s.",
dll->GetNativePath()));
dll->GetDisplayPath()));
return rv;
}
@@ -363,7 +365,7 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when)
if (dllMarkedForUnload)
{
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsComponentManager: + Unloading \"%s\".", dll->GetNativePath()));
("nsComponentManager: + Unloading \"%s\".", dll->GetDisplayPath()));
#if 0
// XXX dlls aren't counting their outstanding instances correctly
// XXX hence, dont unload until this gets enforced.
@@ -373,13 +375,13 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when)
else
{
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsComponentManager: Ready for unload \"%s\".", dll->GetNativePath()));
("nsComponentManager: Ready for unload \"%s\".", dll->GetDisplayPath()));
}
}
else
{
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsComponentManager: + NOT Unloading %s", dll->GetNativePath()));
("nsComponentManager: + NOT Unloading %s", dll->GetDisplayPath()));
rv = NS_ERROR_FAILURE;
}
return rv;
@@ -434,7 +436,7 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll,
}
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsNativeComponentLoader: + Loaded \"%s\".", dll->GetNativePath()));
("nsNativeComponentLoader: + Loaded \"%s\".", dll->GetDisplayPath()));
// Tell the module to self register
nsCOMPtr<nsIModule> mobj;
@@ -443,8 +445,8 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll,
{
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
("nsNativeComponentLoader: %s using nsIModule to register self.",
dll->GetNativePath()));
nsCOMPtr<nsIFileSpec> fs;
dll->GetDisplayPath()));
nsCOMPtr<nsIFile> fs;
res = dll->GetDllSpec(getter_AddRefs(fs));
if (NS_SUCCEEDED(res))
res = mobj->RegisterSelf(mCompMgr, fs, registryLocation,
@@ -453,7 +455,7 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll,
{
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.",
dll->GetNativePath()));
dll->GetDisplayPath()));
}
mobj = NULL; // Force a release of the Module object before unload()
}
@@ -481,8 +483,12 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll,
// installed.
if (res != NS_ERROR_FACTORY_REGISTER_AGAIN) {
dll->Sync();
SetRegistryDllInfo(registryLocation, dll->GetLastModifiedTime(),
dll->GetSize());
PRInt64 modTime, size;
dll->GetLastModifiedTime(&modTime);
dll->GetSize(&size);
SetRegistryDllInfo(registryLocation, &modTime, &size);
}
return res;
@@ -553,7 +559,7 @@ nsNativeComponentLoader::DumpLoadError(nsDll *dll,
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
("nsNativeComponentLoader: %s(%s) Load FAILED with error:%s",
aCallerName,
dll->GetNativePath(),
dll->GetDisplayPath(),
(const char *) errorMsg));
@@ -563,7 +569,7 @@ nsNativeComponentLoader::DumpLoadError(nsDll *dll,
"nsNativeComponentLoader: %s(%s) Load FAILED with error: %s\n"
"**************************************************\n",
aCallerName,
dll->GetNativePath(),
dll->GetDisplayPath(),
(const char *) errorMsg);
#endif
@@ -592,15 +598,15 @@ nsNativeComponentLoader::SelfUnregisterDll(nsDll *dll)
if (NS_SUCCEEDED(res))
{
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
("nsNativeComponentLoader: %s using nsIModule to unregister self.", dll->GetNativePath()));
nsCOMPtr<nsIFileSpec> fs;
("nsNativeComponentLoader: %s using nsIModule to unregister self.", dll->GetDisplayPath()));
nsCOMPtr<nsIFile> fs;
res = dll->GetDllSpec(getter_AddRefs(fs));
if (NS_SUCCEEDED(res))
res = mobj->UnregisterSelf(mCompMgr, fs, /* XXX location */ "");
else
{
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.", dll->GetNativePath()));
("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.", dll->GetDisplayPath()));
}
mobj = NULL; // Force a release of the Module object before unload()
}
@@ -623,7 +629,7 @@ nsNativeComponentLoader::SelfUnregisterDll(nsDll *dll)
nsresult
nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
nsIFileSpec *component,
nsIFile *component,
PRBool *registered)
{
nsresult rv;
@@ -664,25 +670,28 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
// deal only with files that have a valid extension
PRBool validExtension = PR_FALSE;
#ifdef XP_MAC
// rjc - on Mac, check the file's type code (skip checking the creator code)
nsFileSpec fs;
if (NS_FAILED(rv = component->GetFileSpec(&fs)))
return(rv);
#ifdef XP_MAC // sdagley dougt fix
// rjc - on Mac, check the file's type code (skip checking the creator code)
nsCOMPtr<nsILocalFileMac> localFileMac = do_QueryInterface(component);
if (localFileMac)
{
OSType type;
OSType 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!
if (type == 'shlb')
{
validExtension = PR_TRUE;
}
}
}
CInfoPBRec catInfo;
OSErr err = fs.GetCatInfo(catInfo);
if (!err)
{
// 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!
if ((catInfo.hFileInfo.ioFlFndrInfo.fdType == 'shlb')
/* && (catInfo.hFileInfo.ioFlFndrInfo.fdCreator == 'MOZZ') */ )
{
validExtension = PR_TRUE;
}
}
#else
char *leafName = NULL;
rv = component->GetLeafName(&leafName);
@@ -701,7 +710,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
break;
}
}
if (leafName) nsCRT::free(leafName);
if (leafName) nsAllocator::Free(leafName);
#endif
if (validExtension == PR_FALSE)
@@ -718,7 +727,8 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
// Get the registry representation of the dll, if any
nsDll *dll;
rv = CreateDll(component, persistentDescriptor, 0, 0, &dll);
PRInt64 mod = LL_Zero(), size = LL_Zero();
rv = CreateDll(component, persistentDescriptor, &mod, &size, &dll);
if (NS_FAILED(rv))
return rv;
@@ -729,7 +739,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
{
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsNativeComponentLoader: + nsDll not NS_OK \"%s\". Skipping...",
dll->GetNativePath()));
dll->GetDisplayPath()));
return NS_ERROR_FAILURE;
}
@@ -739,7 +749,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
// Dll hasn't changed. Skip.
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsComponentManager: + nsDll not changed \"%s\". Skipping...",
dll->GetNativePath()));
dll->GetDisplayPath()));
return NS_OK;
}
@@ -760,7 +770,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsNativeComponentLoader: *** Dll already loaded. "
"Cannot unload either. Hence cannot re-register "
"\"%s\". Skipping...", dll->GetNativePath()));
"\"%s\". Skipping...", dll->GetDisplayPath()));
return rv;
}
else {
@@ -769,7 +779,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
dll->Unload();
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsNativeComponentLoader: + Unloading \"%s\". (no CanUnloadProc).",
dll->GetNativePath()));
dll->GetDisplayPath()));
}
} // dll isloaded
@@ -782,7 +792,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
// loaded. Whoever taught dp programming...
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsNativeComponentLoader: Dll still loaded. Cannot re-register "
"\"%s\". Skipping...", dll->GetNativePath()));
"\"%s\". Skipping...", dll->GetDisplayPath()));
return NS_ERROR_FAILURE;
}
} // dll != NULL
@@ -812,7 +822,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
} else {
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
("nsNativeComponentLoader: Autoregistration FAILED for "
"\"%s\". Skipping...", dll->GetNativePath()));
"\"%s\". Skipping...", dll->GetDisplayPath()));
return NS_ERROR_FACTORY_NOT_REGISTERED;
}
}
@@ -820,7 +830,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
{
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
("nsNativeComponentLoader: Autoregistration Passed for "
"\"%s\".", dll->GetNativePath()));
"\"%s\".", dll->GetDisplayPath()));
// Marking dll along with modified time and size in the
// registry happens at PlatformRegister(). No need to do it
// here again.
@@ -885,8 +895,8 @@ nsNativeComponentLoader::UnloadAll(PRInt32 aWhen)
nsresult
nsNativeComponentLoader::GetRegistryDllInfo(const char *aLocation,
PRUint32 *lastModifiedTime,
PRUint32 *fileSize)
PRInt64 *lastModifiedTime,
PRInt64 *fileSize)
{
nsresult rv;
@@ -899,16 +909,16 @@ nsNativeComponentLoader::GetRegistryDllInfo(const char *aLocation,
nsresult
nsNativeComponentLoader::GetRegistryDllInfo(nsRegistryKey key,
PRUint32 *lastModifiedTime,
PRUint32 *fileSize)
PRInt64 *lastModifiedTime,
PRInt64 *fileSize)
{
PRInt32 lastMod;
nsresult rv = mRegistry->GetInt(key, lastModValueName, &lastMod);
PRInt64 lastMod;
nsresult rv = mRegistry->GetLongLong(key, lastModValueName, &lastMod);
if (NS_FAILED(rv)) return rv;
*lastModifiedTime = lastMod;
PRInt32 fsize;
rv = mRegistry->GetInt(key, fileSizeValueName, &fsize);
PRInt64 fsize;
rv = mRegistry->GetLongLong(key, fileSizeValueName, &fsize);
if (NS_FAILED(rv)) return rv;
*fileSize = fsize;
@@ -917,17 +927,17 @@ nsNativeComponentLoader::GetRegistryDllInfo(nsRegistryKey key,
nsresult
nsNativeComponentLoader::SetRegistryDllInfo(const char *aLocation,
PRUint32 lastModifiedTime,
PRUint32 fileSize)
PRInt64 *lastModifiedTime,
PRInt64 *fileSize)
{
nsresult rv;
nsRegistryKey key;
rv = mRegistry->GetSubtreeRaw(mXPCOMKey, aLocation, &key);
if (NS_FAILED(rv)) return rv;
rv = mRegistry->SetInt(key, lastModValueName, lastModifiedTime);
rv = mRegistry->SetLongLong(key, lastModValueName, lastModifiedTime);
if (NS_FAILED(rv)) return rv;
rv = mRegistry->SetInt(key, fileSizeValueName, fileSize);
rv = mRegistry->SetLongLong(key, fileSizeValueName, fileSize);
return rv;
}
@@ -950,13 +960,13 @@ nsNativeComponentLoader::SetRegistryDllInfo(const char *aLocation,
// registry along with its lastModTime and fileSize.
// {NULL, rel:libpref.so, 8985659, 20987}
nsresult
nsNativeComponentLoader::CreateDll(nsIFileSpec *aSpec, const char *aLocation,
PRUint32 modificationTime, PRUint32 fileSize,
nsNativeComponentLoader::CreateDll(nsIFile *aSpec, const char *aLocation,
PRInt64 *modificationTime, PRInt64 *fileSize,
nsDll **aDll)
{
nsDll *dll;
nsFileSpec dllSpec;
nsCOMPtr<nsIFileSpec> spec;
nsCOMPtr<nsIFile> dllSpec;
nsCOMPtr<nsIFile> spec;
nsresult rv;
nsStringKey key(aLocation);
@@ -986,10 +996,15 @@ nsNativeComponentLoader::CreateDll(nsIFileSpec *aSpec, const char *aLocation,
if (!dll)
{
if (modificationTime == 0 && fileSize == 0)
PR_ASSERT(modificationTime != NULL);
PR_ASSERT(fileSize != NULL);
PRInt64 zit = LL_Zero();
if (LL_EQ(*modificationTime,zit) && LL_EQ(*fileSize,zit))
{
// Get the modtime and filesize from the registry
rv = GetRegistryDllInfo(aLocation, &modificationTime, &fileSize);
rv = GetRegistryDllInfo(aLocation, modificationTime, fileSize);
}
dll = new nsDll(spec, aLocation, modificationTime, fileSize);
}
@@ -1016,7 +1031,7 @@ nsNativeComponentLoader::GetFactoryFromModule(nsDll *aDll, const nsCID &aCID,
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
("nsNativeComponentLoader: %s using nsIModule to get factory",
aDll->GetNativePath()));
aDll->GetDisplayPath()));
return module->GetClassObject(mCompMgr, aCID, NS_GET_IID(nsIFactory),
(void **)aFactory);
@@ -1037,7 +1052,7 @@ nsNativeComponentLoader::GetFactoryFromNSGetFactory(nsDll *aDll,
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
("nsNativeComponentLoader: %s using OBSOLETE NSGetFactory\n",
aDll->GetNativePath()));
aDll->GetDisplayPath()));
/*
* There was a time when CLSIDToProgID was used to get className