properly initialize loaders on creation, and remove code that's now in nsFileSpec

This commit is contained in:
shaver%netscape.com 1999-09-03 23:51:31 +00:00
parent f7e8b6cd05
commit 942e382e8a
3 changed files with 10 additions and 65 deletions

View File

@ -1520,6 +1520,10 @@ nsComponentManagerImpl::GetLoaderForType(const char *aType,
rv = CreateInstance(progID, nsnull, NS_GET_IID(nsIComponentLoader), (void **)&loader);
PR_FREEIF(progID);
if (NS_FAILED(rv))
return rv;
rv = loader->Init(this, mRegistry);
if (NS_SUCCEEDED(rv)) {
mLoaders->Put(&typeKey, loader);

View File

@ -787,67 +787,6 @@ nsNativeComponentLoader::CreateCachedDll(const char *location,
}
#endif
PRBool
nsNativeComponentLoader::IsRelativePath(nsIFileSpec *aPath)
{
#define USE_GETPARENT
#ifdef USE_GETPARENT
nsFileSpec spec, parent;
if (NS_FAILED(aPath->GetFileSpec(&spec)))
return PR_FALSE;
#ifdef DEBUG_shaver
int iters = 0;
#endif
while(1) {
#ifdef DEBUG_shaver
PR_ASSERT(iters < 10); // XXX sanity
#endif
if (spec == *mComponentsDir)
return PR_TRUE;
spec.GetParent(parent);
if (spec.Failed()) // shouldn't this be an error on parent?
return PR_FALSE;
if (spec == parent)
return PR_FALSE;
spec = parent;
#ifdef DEBUG_shaver
iters++;
#endif
}
#else
#ifdef XP_MAC
/* relative paths on the Mac are rilly rilly hard. Need more thinking. */
return PR_FALSE;
#endif
const char *componentsDir = mComponentsDir->GetNativePathCString();
char *path;
if (NS_FAILED(aPath->GetNativePath(&path)))
return PR_FALSE; // can't get path, ergo it's not relative =)
if (componentsDir) {
int n = strlen(componentsDir);
if (!PL_strncmp(path, componentsDir, n)) {
nsAllocator::Free(path); // XXX right Free?
return PR_TRUE;
}
}
/* if we don't have a components dir, or we don't have that as a prefix */
nsAllocator::Free(path); // XXX right Free?
return PR_FALSE;
#endif
}
nsresult
nsNativeComponentLoader::OnRegister(const nsIID &aCID, const char *aType,
const char *aClassName,
@ -915,8 +854,11 @@ nsNativeComponentLoader::RegistryNameForSpec(nsIFileSpec *aSpec,
char **aRegistryName)
{
nsresult rv;
nsFileSpec spec;
if (NS_FAILED(rv = aSpec->GetFileSpec(&spec)))
return rv;
if (IsRelativePath(aSpec)){
if (spec.IsChildOf(*mComponentsDir)){
/*
* According to sfraser, this sort of string magic is ``Mac-safe''.
* Who knew?

View File

@ -38,11 +38,10 @@ class nsNativeComponentLoader : public nsIComponentLoader {
nsNativeComponentLoader();
virtual ~nsNativeComponentLoader();
PRBool IsRelativePath(nsIFileSpec *path);
nsresult RegistryNameForLib(const char *aLibName,
char **aRegistryName);
char **aRegistryName);
nsresult RegistryNameForSpec(nsIFileSpec *aSpec,
char **aRegistryName);
char **aRegistryName);
protected:
nsCOMPtr<nsIRegistry> mRegistry;