From 19f0a77d814d9957a73e73a0d00f8ac8aa6e8971 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 8 Nov 2011 18:18:12 +0100 Subject: [PATCH] Bug 695843 part 6 - Don't separate file and JAR modules in component manager. r=bsmedberg --- xpcom/components/nsComponentManager.cpp | 52 +++++++++++++++++-------- xpcom/components/nsComponentManager.h | 6 +-- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index 52a2d4c5218..956b66b814c 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -99,6 +99,7 @@ #include "nsArrayEnumerator.h" #include "nsStringEnumerator.h" #include "mozilla/FileUtils.h" +#include "nsURLHelper.h" #include NEW_H // for placement new @@ -345,8 +346,7 @@ nsresult nsComponentManagerImpl::Init() mFactories.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE); mContractIDs.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE); mLoaderMap.Init(); - mKnownFileModules.Init(); - mKnownJARModules.Init(); + mKnownModules.Init(); nsCOMPtr greDir = GetLocationFromDirectoryService(NS_GRE_DIR); @@ -417,11 +417,16 @@ nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule, KnownModule* m = new KnownModule(aModule, aFile); if (aFile) { - nsCOMPtr h = do_QueryInterface(aFile); - NS_ASSERTION(!mKnownFileModules.Get(h), + nsCAutoString uri; + nsresult rv = net_GetURLSpecFromActualFile(aFile, uri); + if (NS_FAILED(rv)) { + NS_WARNING("net_GetURLSpecFromActualFile failed"); + return; + } + NS_ASSERTION(!mKnownModules.Get(uri), "Must not register a binary module twice."); - mKnownFileModules.Put(h, m); + mKnownModules.Put(uri, m); } else mKnownStaticModules.AppendElement(m); @@ -691,9 +696,13 @@ nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& cx, i return; } - nsCOMPtr h = do_QueryInterface(clfile); - NS_ASSERTION(h, "nsILocalFile doesn't implement nsIHashable"); - if (mKnownFileModules.Get(h)) { + nsCAutoString uri; + rv = net_GetURLSpecFromActualFile(clfile, uri); + if (NS_FAILED(rv)) { + NS_WARNING("net_GetURLSpecFromActualFile failed"); + return; + } + if (mKnownModules.Get(uri)) { NS_WARNING("Attempting to register a binary component twice."); LogMessageWithContext(cx.mFile, cx.mPath, lineno, "Attempting to register a binary component twice."); @@ -785,14 +794,19 @@ nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& cx, int lin AppendFileToManifestPath(manifest, file); nsCAutoString hash; - cx.mFile->GetNativePath(hash); - hash.AppendLiteral("|"); + nsresult rv = net_GetURLSpecFromActualFile(cx.mFile, hash); + if (NS_FAILED(rv)) { + NS_WARNING("net_GetURLSpecFromActualFile failed"); + return; + } + hash.Insert("jar:", 0); + hash.Append("!/"); hash.Append(manifest); - km = mKnownJARModules.Get(hash); + km = mKnownModules.Get(hash); if (!km) { km = new KnownModule(cx.mFile, manifest); - mKnownJARModules.Put(hash, km); + mKnownModules.Put(hash, km); } } else { @@ -808,12 +822,17 @@ nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& cx, int lin NS_WARNING("Couldn't append relative path?"); return; } + nsCAutoString hash; + rv = net_GetURLSpecFromActualFile(clfile, hash); + if (NS_FAILED(rv)) { + NS_WARNING("net_GetURLSpecFromActualFile failed"); + return; + } - nsCOMPtr h = do_QueryInterface(clfile); - km = mKnownFileModules.Get(h); + km = mKnownModules.Get(hash); if (!km) { km = new KnownModule(clfile); - mKnownFileModules.Put(h, km); + mKnownModules.Put(hash, km); } } @@ -968,8 +987,7 @@ nsresult nsComponentManagerImpl::Shutdown(void) mContractIDs.Clear(); mFactories.Clear(); // XXX release the objects, don't just clear mLoaderMap.Clear(); - mKnownJARModules.Clear(); - mKnownFileModules.Clear(); + mKnownModules.Clear(); mKnownStaticModules.Clear(); mLoaderData.Clear(); diff --git a/xpcom/components/nsComponentManager.h b/xpcom/components/nsComponentManager.h index 3fd075a7a65..5689c0c18cd 100644 --- a/xpcom/components/nsComponentManager.h +++ b/xpcom/components/nsComponentManager.h @@ -180,7 +180,6 @@ public: static nsTArray* sStaticModules; static nsTArray* sModuleLocations; - static nsTArray* sJarModuleLocations; nsNativeModuleLoader mNativeModuleLoader; @@ -246,9 +245,8 @@ public: // The KnownModule is kept alive by these members, it is // referenced by pointer from the factory entries. nsTArray< nsAutoPtr > mKnownStaticModules; - nsClassHashtable mKnownFileModules; - // The key is a string in this format "|" - nsClassHashtable mKnownJARModules; + // The key is the URI string of the module + nsClassHashtable mKnownModules; void RegisterModule(const mozilla::Module* aModule, nsILocalFile* aFile);