diff --git a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp index fcc071e196fd..3b118b0ff753 100644 --- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp +++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp @@ -72,7 +72,6 @@ xptiInterfaceInfoManager::FreeInterfaceInfoManager() NS_IF_RELEASE(gInterfaceInfoManager); } - PRBool xptiInterfaceInfoManager::IsValid() { @@ -127,14 +126,18 @@ xptiInterfaceInfoManager::~xptiInterfaceInfoManager() // We only do this on shutdown of the service. mWorkingSet.InvalidateInterfaceInfos(); +#ifdef XPTI_HAS_ZIP_SUPPORT + xptiZipLoader::Shutdown(); +#endif /* XPTI_HAS_ZIP_SUPPORT */ + if(mResolveLock) PR_DestroyLock(mResolveLock); if(mAutoRegLock) PR_DestroyLock(mAutoRegLock); } -PRBool -xptiInterfaceInfoManager::GetComponentsDir(nsILocalFile** aDir) +static PRBool +GetDirectoryFromDirService(const char* codename, nsILocalFile** aDir) { NS_ASSERTION(aDir,"loser!"); @@ -146,8 +149,7 @@ xptiInterfaceInfoManager::GetComponentsDir(nsILocalFile** aDir) if(dirService) { nsCOMPtr dir; - dirService->Get(NS_XPCOM_COMPONENT_DIR, - NS_GET_IID(nsIFile), getter_AddRefs(dir)); + dirService->Get(codename, NS_GET_IID(nsIFile), getter_AddRefs(dir)); if(dir) { NS_ADDREF(*aDir = dir); @@ -157,6 +159,20 @@ xptiInterfaceInfoManager::GetComponentsDir(nsILocalFile** aDir) return PR_FALSE; } +PRBool +xptiInterfaceInfoManager::GetComponentsDir(nsILocalFile** aDir) +{ + return GetDirectoryFromDirService(NS_XPCOM_COMPONENT_DIR, aDir); +} + +PRBool +xptiInterfaceInfoManager::GetManifestDir(nsILocalFile** aDir) +{ + // XXX This does not look like the right place yet. + // return GetDirectoryFromDirService(NS_XPCOM_APPLICATION_REGISTRY_DIR, aDir); + return GetDirectoryFromDirService(NS_XPCOM_COMPONENT_DIR, aDir); +} + PRBool xptiInterfaceInfoManager::BuildFileList(nsISupportsArray** aFileList) { @@ -308,9 +324,13 @@ xptiInterfaceInfoManager::LoadFile(const xptiTypelib& aTypelibRecord, if(aTypelibRecord.IsZip()) { +#ifdef XPTI_HAS_ZIP_SUPPORT zipItem = &aWorkingSet->GetZipItemAt(aTypelibRecord.GetZipItemIndex()); LOG_LOAD(("# loading zip item %s::%s\n", fileRecord->GetName(), zipItem->GetName())); header = xptiZipLoader::ReadXPTFileFromZip(file, zipItem->GetName(), aWorkingSet); +#else + header = nsnull; +#endif /* XPTI_HAS_ZIP_SUPPORT */ } else { @@ -734,6 +754,7 @@ xptiInterfaceInfoManager::AddOnlyNewFileFromFileList(nsISupportsArray* aFileList // This will correspond to typelibRecord above. aWorkingSet->AppendFile(fileRecord); } +#ifdef XPTI_HAS_ZIP_SUPPORT else // It is a zip file, Oh boy! { if(!xptiZipLoader::EnumerateZipEntries(file, @@ -746,6 +767,7 @@ xptiInterfaceInfoManager::AddOnlyNewFileFromFileList(nsISupportsArray* aFileList // xptiInterfaceInfoManager::FoundEntry. aWorkingSet->AppendFile(fileRecord); } +#endif /* XPTI_HAS_ZIP_SUPPORT */ } return PR_TRUE; @@ -859,6 +881,7 @@ xptiInterfaceInfoManager::DoFullValidationMergeFromFileList(nsISupportsArray* aF // This will correspond to typelibRecord above. aWorkingSet->AppendFile(fileRecord); } +#ifdef XPTI_HAS_ZIP_SUPPORT else // It is a zip file, Oh boy! { if(!xptiZipLoader::EnumerateZipEntries(file, @@ -871,6 +894,7 @@ xptiInterfaceInfoManager::DoFullValidationMergeFromFileList(nsISupportsArray* aF // xptiInterfaceInfoManager::FoundEntry. aWorkingSet->AppendFile(fileRecord); } +#endif /* XPTI_HAS_ZIP_SUPPORT */ } return PR_TRUE; } diff --git a/xpcom/reflect/xptinfo/src/xptiManifest.cpp b/xpcom/reflect/xptinfo/src/xptiManifest.cpp index 4ef9de3c3f99..4537c820417f 100644 --- a/xpcom/reflect/xptinfo/src/xptiManifest.cpp +++ b/xpcom/reflect/xptinfo/src/xptiManifest.cpp @@ -85,7 +85,7 @@ PRBool xptiManifest::Write(xptiInterfaceInfoManager* aMgr, PRIntn interfaceCount = 0; nsCOMPtr tempFile; - if(!aMgr->GetComponentsDir(getter_AddRefs(tempFile)) || !tempFile) + if(!aMgr->GetManifestDir(getter_AddRefs(tempFile)) || !tempFile) return PR_FALSE; if(NS_FAILED(tempFile->Append(g_TempManifestFilename))) @@ -176,7 +176,7 @@ out: { // delete the old file and rename this nsCOMPtr mainFile; - if(!aMgr->GetComponentsDir(getter_AddRefs(mainFile)) || !mainFile) + if(!aMgr->GetManifestDir(getter_AddRefs(mainFile)) || !mainFile) return PR_FALSE; if(NS_FAILED(mainFile->Append(g_MainManifestFilename))) @@ -192,13 +192,18 @@ out: // XXX Would prefer MoveTo with a 'null' newdir, the but nsILocalFile // implementation are broken. // http://bugzilla.mozilla.org/show_bug.cgi?id=33098 - +#if 1 nsCOMPtr dir; - if(!aMgr->GetComponentsDir(getter_AddRefs(dir)) || !dir) + if(!aMgr->GetManifestDir(getter_AddRefs(dir)) || !dir) return PR_FALSE; if(NS_FAILED(tempFile->CopyTo(dir, g_MainManifestFilename))) return PR_FALSE; +#else + // so let's try the MoveTo! + if(NS_FAILED(tempFile->MoveTo(nsnull, g_MainManifestFilename))) + return PR_FALSE; +#endif } return succeeded; @@ -215,12 +220,25 @@ ReadManifestIntoMemory(xptiInterfaceInfoManager* aMgr, char* whole = nsnull; nsCOMPtr aFile; - if(!aMgr->GetComponentsDir(getter_AddRefs(aFile)) || !aFile) + if(!aMgr->GetManifestDir(getter_AddRefs(aFile)) || !aFile) return nsnull; if(NS_FAILED(aFile->Append(g_MainManifestFilename))) return nsnull; - + +#ifdef DEBUG + { + static PRBool shown = PR_FALSE; + char* path; + if(!shown && NS_SUCCEEDED(aFile->GetPath(&path)) && path) + { + printf("Type Manifest File: %s\n", path); + nsMemory::Free(path); + shown = PR_TRUE; + } + } +#endif + if(NS_FAILED(aFile->GetFileSize(&fileSize)) || !(flen = nsInt64(fileSize))) return nsnull; diff --git a/xpcom/reflect/xptinfo/src/xptiZipLoader.cpp b/xpcom/reflect/xptinfo/src/xptiZipLoader.cpp index 865deee285ee..b9b614d2c528 100644 --- a/xpcom/reflect/xptinfo/src/xptiZipLoader.cpp +++ b/xpcom/reflect/xptinfo/src/xptiZipLoader.cpp @@ -24,7 +24,41 @@ #include "xptiprivate.h" -static const char g_ZipReaderProgID[] = "component://netscape/libjar/zip-reader"; +#ifdef XPTI_HAS_ZIP_SUPPORT + +static const char gCacheProgID[] = "component://netscape/libjar/zip-reader-cache"; + +static const PRUint32 gCacheSize = 1; + +nsCOMPtr xptiZipLoader::gCache = nsnull; + +// static +nsIZipReader* +xptiZipLoader::GetZipReader(nsILocalFile* file) +{ + NS_ASSERTION(file, "bad file"); + + if(!gCache) + { + gCache = do_CreateInstance(gCacheProgID); + if(!gCache || NS_FAILED(gCache->Init(gCacheSize))) + return nsnull; + } + + nsIZipReader* reader = nsnull; + + if(NS_FAILED(gCache->GetZip(file, &reader))) + return nsnull; + + return reader; +} + +// static +void +xptiZipLoader::Shutdown() +{ + gCache = nsnull; +} // static PRBool @@ -32,22 +66,14 @@ xptiZipLoader::EnumerateZipEntries(nsILocalFile* file, xptiEntrySink* sink, xptiWorkingSet* aWorkingSet) { -#ifndef XPCOM_STANDALONE NS_ASSERTION(file, "loser!"); NS_ASSERTION(sink, "loser!"); NS_ASSERTION(aWorkingSet, "loser!"); - nsCOMPtr zip = do_CreateInstance(g_ZipReaderProgID); + nsCOMPtr zip = dont_AddRef(GetZipReader(file)); if(!zip) return PR_FALSE; - if(NS_FAILED(zip->Init(file)) || NS_FAILED(zip->Open())) - return PR_FALSE; - // This is required before getting streams for some reason. - // XXX and then someopne removed it from that interface! - // if(NS_FAILED(zip->ParseManifest())) - // return PR_FALSE; - nsCOMPtr entries; if(NS_FAILED(zip->FindEntries("*.xpt", getter_AddRefs(entries))) || !entries) @@ -97,9 +123,6 @@ xptiZipLoader::EnumerateZipEntries(nsILocalFile* file, } while(1); return PR_TRUE; -#else - return PR_FALSE; -#endif /* XPCOM_STANDALONE */ } // static @@ -108,25 +131,9 @@ xptiZipLoader::ReadXPTFileFromZip(nsILocalFile* file, const char* entryName, xptiWorkingSet* aWorkingSet) { -#ifndef XPCOM_STANDALONE - nsCOMPtr zip = - do_CreateInstance(g_ZipReaderProgID); + nsCOMPtr zip = dont_AddRef(GetZipReader(file)); if(!zip) - { return nsnull; - } - - if(NS_FAILED(zip->Init(file)) || NS_FAILED(zip->Open())) - { - return nsnull; - } - - // This is required before getting streams for some reason. - // XXX and then someopne removed it from that interface! - //if(NS_FAILED(zip->ParseManifest())) - //{ - // return nsnull; - //} nsCOMPtr entry; if(NS_FAILED(zip->GetEntry(entryName, getter_AddRefs(entry))) || !entry) @@ -135,12 +142,8 @@ xptiZipLoader::ReadXPTFileFromZip(nsILocalFile* file, } return ReadXPTFileFromOpenZip(zip, entry, entryName, aWorkingSet); -#else - return nsnull; -#endif /* XPCOM_STANDALONE */ } -#ifndef XPCOM_STANDALONE // static XPTHeader* xptiZipLoader::ReadXPTFileFromOpenZip(nsIZipReader* zip, @@ -228,8 +231,5 @@ xptiZipLoader::ReadXPTFileFromOpenZip(nsIZipReader* zip, delete [] whole; return header; } -#endif /* XPCOM_STANDALONE */ - - - +#endif /* XPTI_HAS_ZIP_SUPPORT */ diff --git a/xpcom/reflect/xptinfo/src/xptiprivate.h b/xpcom/reflect/xptinfo/src/xptiprivate.h index 7eff07b6ea4e..3179495d64ab 100644 --- a/xpcom/reflect/xptinfo/src/xptiprivate.h +++ b/xpcom/reflect/xptinfo/src/xptiprivate.h @@ -25,6 +25,10 @@ #ifndef xptiprivate_h___ #define xptiprivate_h___ +#ifndef XPCOM_STANDALONE +#define XPTI_HAS_ZIP_SUPPORT 1 +#endif /* XPCOM_STANDALONE */ + #include "nscore.h" #include "nsISupports.h" @@ -50,9 +54,11 @@ #include "nsInt64.h" #include "nsQuickSort.h" -#ifndef XPCOM_STANDALONE + +#ifdef XPTI_HAS_ZIP_SUPPORT #include "nsIZipReader.h" -#endif /* XPCOM_STANDALONE */ +#endif /* XPTI_HAS_ZIP_SUPPORT */ + #include "nsIInputStream.h" #include "nsAutoLock.h" @@ -575,6 +581,8 @@ public: xptiWorkingSet* aWorkingSet) = 0; }; +#ifdef XPTI_HAS_ZIP_SUPPORT + class xptiZipLoader { public: @@ -590,16 +598,24 @@ public: const char* entryName, xptiWorkingSet* aWorkingSet); + static void + Shutdown(); + private: -#ifndef XPCOM_STANDALONE static XPTHeader* - ReadXPTFileFromOpenZip(nsIZipReader * zip, + ReadXPTFileFromOpenZip(nsIZipReader* zip, nsIZipEntry* entry, const char* entryName, xptiWorkingSet* aWorkingSet); -#endif /* XPCOM_STANDALONE */ + + static nsIZipReader* + GetZipReader(nsILocalFile* file); + + static nsCOMPtr gCache; }; +#endif /* XPTI_HAS_ZIP_SUPPORT */ + /***************************************************************************/ class xptiFileType @@ -671,6 +687,7 @@ public: xptiWorkingSet* aWorkingSet = nsnull); PRBool GetComponentsDir(nsILocalFile** aDir); + PRBool GetManifestDir(nsILocalFile** aDir); static PRLock* GetResolveLock(xptiInterfaceInfoManager* self = nsnull) {if(!self && !(self = GetInterfaceInfoManagerNoAddRef()))