From 879a12160162e465dbf350e63f3c73aad058036b Mon Sep 17 00:00:00 2001 From: "peterlubczynski%netscape.com" Date: Tue, 20 Nov 2001 01:19:33 +0000 Subject: [PATCH] Fix for not weeding out plugin duplicates because we were only checking the filename. Now, do a deep comparison of the name, description, and order of mime types. This will prevent two plugins with these same properties but with diferent names from loading. bug 110781 r=av sr=beard git-svn-id: svn://10.0.0.236/trunk@108522 18797224-902f-48f8-a5cc-f745e15eee43 --- .../plugin/base/src/nsPluginHostImpl.cpp | 55 +++++++------------ .../plugin/base/src/nsPluginHostImpl.h | 2 + 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 17be237bee0..bbdee946b04 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -1022,6 +1022,25 @@ void nsPluginTag::TryUnloadPlugin(PRBool aForceShutdown) } +//////////////////////////////////////////////////////////////////////// +PRBool nsPluginTag::Equals(nsPluginTag *aPluginTag) +{ + NS_ENSURE_TRUE(aPluginTag, PR_FALSE); + + if ( (PL_strcmp(mName, aPluginTag->mName) != 0) || + (PL_strcmp(mDescription, aPluginTag->mDescription) != 0) || + (mVariants != aPluginTag->mVariants) ) + return PR_FALSE; + + if (0 != mVariants && mMimeTypeArray && aPluginTag->mMimeTypeArray) + for (PRInt32 i = 0; i < mVariants; i++) + if (PL_strcmp(mMimeTypeArray[i], aPluginTag->mMimeTypeArray[i]) != 0) + return PR_FALSE; + + return PR_TRUE; +} + + //////////////////////////////////////////////////////////////////////// class nsPluginStreamListenerPeer; @@ -4332,38 +4351,6 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi } -//////////////////////////////////////////////////////////////////////// -static PRBool areTheSameFileNames(char * aPath1, char * aPath2) -{ - if((aPath1 == nsnull) || (aPath2 == nsnull)) - return PR_FALSE; - - nsresult rv = NS_OK; - - nsXPIDLCString filename1; - nsXPIDLCString filename2; - - nsCOMPtr file1; - nsCOMPtr file2; - - if (NS_SUCCEEDED(NS_NewLocalFile(aPath1, PR_FALSE, getter_AddRefs(file1)))) - file1->GetLeafName(getter_Copies(filename1)); - else //XXX if we couldn't create an nsILocalFile, try comparing raw string anyway - filename1.Adopt(PL_strdup(aPath1)); - - if (NS_SUCCEEDED(NS_NewLocalFile(aPath2, PR_FALSE, getter_AddRefs(file2)))) - file2->GetLeafName(getter_Copies(filename2)); - else //XXX workaround for Mac that sometimes passes in just a leaf name - filename2.Adopt(PL_strdup(aPath2)); - - if(PL_strlen(filename1.get()) != PL_strlen(filename2.get())) - return PR_FALSE; - - // XXX this one MUST be case insensitive for Windows and MUST be case - // sensitive for Unix. How about Win2000? - return (nsnull == PL_strncasecmp(filename1.get(), filename2.get(), PL_strlen(filename1.get()))); -} - //////////////////////////////////////////////////////////////////////// // currently 'unwanted' plugins are Java, and all other plugins except // RealPlayer, Acrobat, Flash @@ -4523,7 +4510,7 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, { for(nsPluginTag* tag = mPlugins; tag != nsnull; tag = tag->mNext) { - if(areTheSameFileNames(tag->mFileName, pluginTag->mFileName)) + if(tag->Equals(pluginTag)) { bAddIt = PR_FALSE; break; @@ -4965,7 +4952,7 @@ nsPluginHostImpl::LoadXPCOMPlugins(nsIComponentManager* aComponentManager, nsIFi PRBool bAddIt = PR_TRUE; for(nsPluginTag* existingtag = mPlugins; existingtag != nsnull; existingtag = existingtag->mNext) { - if(areTheSameFileNames(tag->mFileName, existingtag->mFileName)) + if(tag->Equals(existingtag)) { bAddIt = PR_FALSE; break; diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h index 6415c26a343..9f2d2453a82 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h @@ -87,6 +87,8 @@ public: void TryUnloadPlugin(PRBool aForceShutdown = PR_FALSE); void Mark(PRUint32 mask) { mFlags |= mask; } + PRBool Equals(nsPluginTag* aPluginTag); + nsPluginTag *mNext; char *mName;