diff --git a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp index fc86f13a1d8f..b6217b619653 100644 --- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp +++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp @@ -163,25 +163,45 @@ xptiInterfaceInfoManager::~xptiInterfaceInfoManager() static PRBool GetDirectoryFromDirService(const char* codename, nsILocalFile** aDir) { + NS_ASSERTION(codename,"loser!"); NS_ASSERTION(aDir,"loser!"); - // We must make a new nsILocalFile each time because the caller *will* - // modify it. - nsCOMPtr dirService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); - if(dirService) + if(!dirService) + return PR_FALSE; + + return NS_SUCCEEDED(dirService->Get(codename, NS_GET_IID(nsILocalFile), + (void**) aDir)); +} + +static PRBool +AppendFromDirServiceList(const char* codename, nsISupportsArray* aPath) +{ + NS_ASSERTION(codename,"loser!"); + NS_ASSERTION(aPath,"loser!"); + + nsCOMPtr dirService = + do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); + if(!dirService) + return PR_FALSE; + + nsCOMPtr fileList; + dirService->Get(codename, NS_GET_IID(nsISimpleEnumerator), + getter_AddRefs(fileList)); + if(!fileList) + return PR_FALSE; + + PRBool more; + while(NS_SUCCEEDED(fileList->HasMoreElements(&more)) && more) { nsCOMPtr dir; - dirService->Get(codename, NS_GET_IID(nsIFile), getter_AddRefs(dir)); - if(dir) - { - NS_ADDREF(*aDir = dir); - return PR_TRUE; - } + fileList->GetNext(getter_AddRefs(dir)); + if(!dir || !aPath->AppendElement(dir)) + return PR_FALSE; } - return PR_FALSE; -} + return PR_TRUE; +} // static PRBool xptiInterfaceInfoManager::BuildFileSearchPath(nsISupportsArray** aPath) @@ -199,11 +219,7 @@ PRBool xptiInterfaceInfoManager::BuildFileSearchPath(nsISupportsArray** aPath) nsCOMPtr dir; - // XXX We'd like to get the *right* path from the embedding. - - // For now we'll add the following... - - // Add components dir + // Always put components directory first if(NS_FAILED(GetDirectoryFromDirService(NS_XPCOM_COMPONENT_DIR, getter_AddRefs(dir))) || @@ -212,19 +228,10 @@ PRBool xptiInterfaceInfoManager::BuildFileSearchPath(nsISupportsArray** aPath) return PR_FALSE; } -#if 0 - // XXX Let's not do this untill we're sure about what we want to do. - // XXX Without this block we are compatible with previous versions. - - // Add plugins dir + // Add additional plugins dirs // No error checking here since this is optional in some embeddings - if(NS_SUCCEEDED(GetDirectoryFromDirService(NS_APP_PLUGINS_DIR, - getter_AddRefs(dir)))) - { - searchPath->AppendElement(dir); - } -#endif + (void) AppendFromDirServiceList(NS_APP_PLUGINS_DIR_LIST, searchPath); NS_ADDREF(*aPath = searchPath); diff --git a/xpcom/reflect/xptinfo/src/xptiManifest.cpp b/xpcom/reflect/xptinfo/src/xptiManifest.cpp index b52eacceaf0c..0d199099eee5 100644 --- a/xpcom/reflect/xptinfo/src/xptiManifest.cpp +++ b/xpcom/reflect/xptinfo/src/xptiManifest.cpp @@ -528,6 +528,20 @@ PRBool xptiManifest::Read(xptiInterfaceInfoManager* aMgr, if(!ReadSectionHeader(reader, g_TOKEN_Directories, 1, &dirCount)) goto out; + else + { + // To validate that the directory list matches the current search path + // we first confirm that the list lengths match. + + nsCOMPtr searchPath; + aMgr->GetSearchPath(getter_AddRefs(searchPath)); + + PRUint32 searchPathCount; + searchPath->Count(&searchPathCount); + + if(dirCount != (int) searchPathCount) + goto out; + } // Read the directory records diff --git a/xpcom/reflect/xptinfo/src/xptiprivate.h b/xpcom/reflect/xptinfo/src/xptiprivate.h index 1f9313082674..9bc2634f6d36 100644 --- a/xpcom/reflect/xptinfo/src/xptiprivate.h +++ b/xpcom/reflect/xptinfo/src/xptiprivate.h @@ -733,6 +733,9 @@ public: PRBool GetApplicationDir(nsILocalFile** aDir); PRBool GetCloneOfManifestDir(nsILocalFile** aDir); + void GetSearchPath(nsISupportsArray** aSearchPath) + {NS_ADDREF(*aSearchPath = mSearchPath);} + static PRLock* GetResolveLock(xptiInterfaceInfoManager* self = nsnull) {if(!self && !(self = GetInterfaceInfoManagerNoAddRef())) return nsnull; @@ -803,7 +806,6 @@ private: PRLock* mAutoRegLock; nsCOMPtr mManifestDir; nsCOMPtr mSearchPath; - }; /***************************************************************************/