From 6f3cc2ec32f13fc704f8c7383a42da60448679dd Mon Sep 17 00:00:00 2001 From: "av%netscape.com" Date: Wed, 13 Feb 2002 02:18:57 +0000 Subject: [PATCH] Fixing 124936 -- refresh loop with dup plugins, r=peterl, sr=beard git-svn-id: svn://10.0.0.236/trunk@114365 18797224-902f-48f8-a5cc-f745e15eee43 --- .../plugin/base/src/nsPluginHostImpl.cpp | 75 ++++++++++++------- .../plugin/base/src/nsPluginHostImpl.h | 17 ++++- 2 files changed, 62 insertions(+), 30 deletions(-) diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 1a7f47db520..172fb534894 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -1046,7 +1046,6 @@ PRBool nsPluginTag::Equals(nsPluginTag *aPluginTag) return PR_TRUE; } - //////////////////////////////////////////////////////////////////////// class nsPluginStreamListenerPeer; @@ -4452,6 +4451,37 @@ static PRBool isUnwantedPlugin(nsPluginTag * tag) return PR_TRUE; } +nsPluginTag * nsPluginHostImpl::HaveSamePlugin(nsPluginTag * aPluginTag) +{ + for(nsPluginTag* tag = mPlugins; tag; tag = tag->mNext) { + if(tag->Equals(aPluginTag)) + return tag; + } + return nsnull; +} + +PRBool nsPluginHostImpl::IsDuplicatePlugin(nsPluginTag * aPluginTag) +{ + nsPluginTag * tag = HaveSamePlugin(aPluginTag); + if (tag) { + // if we got the same plugin, check the full path to see if this is a dup; + + // mFileName contains full path on Windows and Unix and leaf name on Mac + // if those are not equal, we have the same plugin with different path, + // i.e. duplicate, return true + if (PL_strcmp(tag->mFileName, aPluginTag->mFileName)) + return PR_TRUE; + + // if they are equal, compare mFullPath fields just in case + // mFileName contained leaf name only, and if not equal, return true + if (tag->mFullPath && aPluginTag->mFullPath && PL_strcmp(tag->mFullPath, aPluginTag->mFullPath)) + return PR_TRUE; + } + + // we do not have it at all, return false + return PR_FALSE; +} + // Structure for collecting plugin files found during directory scanning struct pluginFileinDirectory { @@ -4568,7 +4598,8 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, } else { // if it is unwanted plugin we are checking for, get it back to the cache info list - if(checkForUnwantedPlugins && isUnwantedPlugin(pluginTag)) { + // if this is a duplicate plugin, too place it back in the cache info list marking unwantedness + if((checkForUnwantedPlugins && isUnwantedPlugin(pluginTag)) || IsDuplicatePlugin(pluginTag)) { pluginTag->Mark(NS_PLUGIN_FLAG_UNWANTED); pluginTag->mNext = mCachedPlugins; mCachedPlugins = pluginTag; @@ -4621,9 +4652,10 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, pluginTag->mLibrary = pluginLibrary; pluginTag->mLastModifiedTime = fileModTime; - // if this is unwanted plugin we are checkin for, add it to our cache info list so we - // can cache the unwantedness of this plugin when we sync cached plugins to registry - if(checkForUnwantedPlugins && isUnwantedPlugin(pluginTag)) { + // if this is unwanted plugin we are checkin for, or this is a duplicate plugin, + // add it to our cache info list so we can cache the unwantedness of this plugin + // when we sync cached plugins to registry + if((checkForUnwantedPlugins && isUnwantedPlugin(pluginTag)) || IsDuplicatePlugin(pluginTag)) { pluginTag->Mark(NS_PLUGIN_FLAG_UNWANTED); pluginTag->mNext = mCachedPlugins; mCachedPlugins = pluginTag; @@ -4641,15 +4673,12 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, // check if we already have this plugin in the list which // is possible if we do refresh if(bAddIt) { - for(nsPluginTag* tag = mPlugins; tag != nsnull; tag = tag->mNext) { - if(tag->Equals(pluginTag)) { - bAddIt = PR_FALSE; - // we cannot get here if the plugin has just been added - // and thus |pluginTag| is not from cache, because otherwise - // it would not be present in the list; - // so there is no need to delete |pluginTag| -- it _is_ from the cache info list. - break; - } + if (HaveSamePlugin(pluginTag)) { + // we cannot get here if the plugin has just been added + // and thus |pluginTag| is not from cache, because otherwise + // it would not be present in the list; + // so there is no need to delete |pluginTag| -- it _is_ from the cache info list. + bAddIt = PR_FALSE; } } @@ -5221,19 +5250,13 @@ nsPluginHostImpl::LoadXPCOMPlugins(nsIComponentManager* aComponentManager, nsIFi if (NS_FAILED(rv)) continue; - // skip it if we already have it PRBool bAddIt = PR_TRUE; - for(nsPluginTag* existingtag = mPlugins; existingtag != nsnull; existingtag = existingtag->mNext) - { - if(tag->Equals(existingtag)) - { - bAddIt = PR_FALSE; - break; - } - } - if(!bAddIt) - { + // skip it if we already have it + if (HaveSamePlugin(tag)) + bAddIt = PR_FALSE; + + if(!bAddIt) { if(tag) delete tag; continue; @@ -5330,7 +5353,7 @@ nsPluginHostImpl::CachePluginsInfo(nsIRegistry* registry) if (! registry) return NS_ERROR_FAILURE; - // We dont want any old plugins that dont exist anymore hanging around + // We don't want any old plugins that don't exist anymore hanging around // So remove and re-add the root of the plugins info nsresult rv = registry->RemoveSubtree(nsIRegistry::Common, kPluginsRootKey); diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h index 13b319bba3a..cbe0307ac83 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h @@ -88,7 +88,6 @@ public: void TryUnloadPlugin(PRBool aForceShutdown = PR_FALSE); void Mark(PRUint32 mask) { mFlags |= mask; } PRBool Equals(nsPluginTag* aPluginTag); - nsPluginTag *mNext; char *mName; @@ -171,7 +170,7 @@ public: #define NS_PLUGIN_FLAG_ENABLED 0x0001 //is this plugin enabled? #define NS_PLUGIN_FLAG_OLDSCHOOL 0x0002 //is this a pre-xpcom plugin? #define NS_PLUGIN_FLAG_FROMCACHE 0x0004 // this plugintag info was loaded from cache -#define NS_PLUGIN_FLAG_UNWANTED 0x0008 // this is an unwanted plugins +#define NS_PLUGIN_FLAG_UNWANTED 0x0008 // this is an unwanted plugin class nsPluginHostImpl : public nsIPluginManager2, public nsIPluginHost, @@ -447,12 +446,22 @@ private: // Loads all cached plugins info into mCachedPlugins nsresult LoadCachedPluginsInfo(nsIRegistry* registry); + // Stores all plugins info into the registry nsresult CachePluginsInfo(nsIRegistry* registry); - // Given a filename, returns the plugins info from our cache and removes - // it from the cache. + + // Given a filename, returns the plugins info from our cache + // and removes it from the cache. nsPluginTag* RemoveCachedPluginsInfo(const char *filename); + //checks if the list already have the same plugin as given + nsPluginTag* HaveSamePlugin(nsPluginTag * aPluginTag); + + // checks if given plugin is a duplicate of what we already have + // in the plugin list but found in some different place + PRBool IsDuplicatePlugin(nsPluginTag * aPluginTag); + + // destroys plugin info list void ClearCachedPluginInfoList(); nsresult EnsurePrivateDirServiceProvider();