Bug 596078: Remove old 4.x plugin directory scan. Patch by Scott Greenlay and Josh Aas. r=bsmedberg
authorScott Greenlay <scott@greenlay.net>
Thu, 31 Mar 2011 14:26:57 -0400
changeset 64520 8b86086e5f0e395447713e39c6e1a3402f49c3d7
parent 64519 e88652085a4e3734cf6f5d1dedad63ef5c2e0ad7
child 64521 4a0faa67237d824db19bb4f766860ec429979df4
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs596078
milestone2.2a1pre
Bug 596078: Remove old 4.x plugin directory scan. Patch by Scott Greenlay and Josh Aas. r=bsmedberg
modules/libpref/src/init/all.js
modules/plugin/base/src/nsPluginDirServiceProvider.cpp
modules/plugin/base/src/nsPluginDirServiceProvider.h
modules/plugin/base/src/nsPluginHost.cpp
modules/plugin/base/src/nsPluginHost.h
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -1765,22 +1765,16 @@ pref("plugin.scan.Quicktime", "5.0");
 
 // Locate and scan the Window Media Player installation directory for plugins with a minimum version
 pref("plugin.scan.WindowsMediaPlayer", "7.0");
 
 // Locate plugins by the directories specified in the Windows registry for PLIDs
 // Which is currently HKLM\Software\MozillaPlugins\xxxPLIDxxx\Path
 pref("plugin.scan.plid.all", true);
 
-// Controls the scanning of the Navigator 4.x directory for plugins
-// When pref is missing, the default is to pickup popular plugins such as
-// Flash, Shockwave, Acrobat, and Quicktime. If set to true, ALL plugins
-// will be picked up and if set to false the scan will not happen at all
-//pref("plugin.scan.4xPluginFolder", false);
-
 // Help Windows NT, 2000, and XP dialup a RAS connection
 // when a network address is unreachable.
 pref("network.autodial-helper.enabled", true);
 
 // Pref to control whether we set ddeexec subkeys for the http
 // Internet shortcut protocol if we are handling it.  These
 // subkeys will be set only while we are running (to avoid the
 // problem of Windows showing an alert when it tries to use DDE
--- a/modules/plugin/base/src/nsPluginDirServiceProvider.cpp
+++ b/modules/plugin/base/src/nsPluginDirServiceProvider.cpp
@@ -239,54 +239,17 @@ nsPluginDirServiceProvider::GetFile(cons
   nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
   if (!prefs)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIWindowsRegKey> regKey =
     do_CreateInstance("@mozilla.org/windows-registry-key;1");
   NS_ENSURE_TRUE(regKey, NS_ERROR_FAILURE);
 
-  if (nsCRT::strcmp(charProp, NS_WIN_4DOTX_SCAN_KEY) == 0) {
-    // Check our prefs to see if scanning the 4.x folder has been
-    // explictly overriden failure to get the pref is okay, we'll do
-    // what we've been doing -- a filtered scan
-    PRBool bScan4x;
-    if (NS_SUCCEEDED(prefs->GetBoolPref(NS_WIN_4DOTX_SCAN_KEY, &bScan4x)) &&
-        !bScan4x) {
-      return NS_ERROR_FAILURE;
-    }
-
-    // Look for the plugin folder that the user has in their
-    // Communicator 4x install
-    rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
-                      NS_LITERAL_STRING("Software\\Netscape\\Netscape Navigator"),
-                      nsIWindowsRegKey::ACCESS_READ);
-    if (NS_SUCCEEDED(rv)) {
-      nsAutoString currentVersion;
-      rv = regKey->ReadStringValue(NS_LITERAL_STRING("CurrentVersion"),
-                                   currentVersion);
-      if (NS_SUCCEEDED(rv)) {
-        nsAutoString childName = currentVersion;
-        childName.Append(NS_LITERAL_STRING("\\Main"));
-        nsCOMPtr<nsIWindowsRegKey> childKey;
-
-        rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_READ,
-                               getter_AddRefs(childKey));
-        if (NS_SUCCEEDED(rv) && childKey) {
-          nsAutoString pluginsDirectory;
-          rv = childKey->ReadStringValue(NS_LITERAL_STRING("Plugins Directory"),
-                                         pluginsDirectory);
-          if (NS_SUCCEEDED(rv)) {
-            rv = NS_NewLocalFile(pluginsDirectory, PR_TRUE,
-                                 getter_AddRefs(localFile));
-          }
-        }
-      }
-    }
-  } else if (nsCRT::strcmp(charProp, NS_WIN_JRE_SCAN_KEY) == 0) {
+  if (nsCRT::strcmp(charProp, NS_WIN_JRE_SCAN_KEY) == 0) {
     nsXPIDLCString strVer;
     if (NS_FAILED(prefs->GetCharPref(charProp, getter_Copies(strVer))))
       return NS_ERROR_FAILURE;
     verBlock minVer;
     TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
 
     rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
                       NS_LITERAL_STRING("Software\\JavaSoft\\Java Runtime Environment"),
--- a/modules/plugin/base/src/nsPluginDirServiceProvider.h
+++ b/modules/plugin/base/src/nsPluginDirServiceProvider.h
@@ -48,17 +48,16 @@
 class nsISimpleEnumerator;
 
 // Note: Our directory service provider scan keys are prefs which are check
 //       for minimum versions compatibility
 #define NS_WIN_JRE_SCAN_KEY            "plugin.scan.SunJRE"
 #define NS_WIN_ACROBAT_SCAN_KEY        "plugin.scan.Acrobat"
 #define NS_WIN_QUICKTIME_SCAN_KEY      "plugin.scan.Quicktime"
 #define NS_WIN_WMP_SCAN_KEY            "plugin.scan.WindowsMediaPlayer"
-#define NS_WIN_4DOTX_SCAN_KEY          "plugin.scan.4xPluginFolder"
 
 //*****************************************************************************
 // class nsPluginDirServiceProvider
 //*****************************************************************************   
 
 class nsPluginDirServiceProvider : public nsIDirectoryServiceProvider
 {
 public:
--- a/modules/plugin/base/src/nsPluginHost.cpp
+++ b/modules/plugin/base/src/nsPluginHost.cpp
@@ -2054,43 +2054,16 @@ nsPluginHost::SiteHasData(nsIPluginTag* 
   InfallibleTArray<nsCString> matches;
   rv = EnumerateSiteData(domain, sites, matches, true);
   NS_ENSURE_SUCCESS(rv, rv);
 
   *result = !matches.IsEmpty();
   return NS_OK;
 }
 
-// XXX called from ScanPluginsDirectory only when told to filter
-// currently 'unwanted' plugins are Java, and all other plugins except
-// Acrobat, Flash, Quicktime and Shockwave
-static PRBool isUnwantedPlugin(nsPluginTag * tag)
-{
-  if (tag->mFileName.IsEmpty())
-    return PR_TRUE;
-
-  for (PRInt32 i = 0; i < tag->mVariants; ++i) {
-    if (!PL_strcasecmp(tag->mMimeTypeArray[i], "application/pdf"))
-      return PR_FALSE;
-
-    if (tag->mIsFlashPlugin)
-      return PR_FALSE;
-
-    if (!PL_strcasecmp(tag->mMimeTypeArray[i], "application/x-director"))
-      return PR_FALSE;
-  }
-
-  // On Windows, we also want to include the Quicktime plugin from the 4.x directory
-  // But because it spans several DLL's, the best check for now is by filename
-  if (tag->mFileName.Find("npqtplugin", PR_TRUE, 0, -1) != kNotFound)
-    return PR_FALSE;
-
-  return PR_TRUE;
-}
-
 PRBool nsPluginHost::IsJavaMIMEType(const char* aType)
 {
   return aType &&
     ((0 == PL_strncasecmp(aType, "application/x-java-vm",
                           sizeof("application/x-java-vm") - 1)) ||
      (0 == PL_strncasecmp(aType, "application/x-java-applet",
                           sizeof("application/x-java-applet") - 1)) ||
      (0 == PL_strncasecmp(aType, "application/x-java-bean",
@@ -2178,21 +2151,19 @@ class nsDefaultComparator<pluginFileinDi
                      nsCaseInsensitiveStringComparator()) < 0;
     else
       return PR_FALSE;
   }
 };
 
 typedef NS_NPAPIPLUGIN_CALLBACK(char *, NP_GETMIMEDESCRIPTION)(void);
 
-nsresult nsPluginHost::ScanPluginsDirectory(nsIFile * pluginsDir,
-                                            nsIComponentManager * compManager,
+nsresult nsPluginHost::ScanPluginsDirectory(nsIFile *pluginsDir,
                                             PRBool aCreatePluginList,
-                                            PRBool * aPluginsChanged,
-                                            PRBool checkForUnwantedPlugins)
+                                            PRBool *aPluginsChanged)
 {
   NS_ENSURE_ARG_POINTER(aPluginsChanged);
   nsresult rv;
 
   *aPluginsChanged = PR_FALSE;
 
 #ifdef PLUGIN_LOGGING
   nsCAutoString dirPath;
@@ -2273,18 +2244,17 @@ nsresult nsPluginHost::ScanPluginsDirect
         pluginTag = nsnull;
 
         // plugin file changed, flag this fact
         *aPluginsChanged = PR_TRUE;
       }
       else {
         // if it is unwanted plugin we are checking for, get it back to the cache info list
         // if this is a duplicate plugin, too place it back in the cache info list marking unwantedness
-        if ((checkForUnwantedPlugins && isUnwantedPlugin(pluginTag)) ||
-           IsDuplicatePlugin(pluginTag)) {
+        if (IsDuplicatePlugin(pluginTag)) {
           if (!pluginTag->HasFlag(NS_PLUGIN_FLAG_UNWANTED)) {
             // Plugin switched from wanted to unwanted
             *aPluginsChanged = PR_TRUE;
           }
           pluginTag->Mark(NS_PLUGIN_FLAG_UNWANTED);
           pluginTag->mNext = mCachedPlugins;
           mCachedPlugins = pluginTag;
         } else if (pluginTag->HasFlag(NS_PLUGIN_FLAG_UNWANTED)) {
@@ -2379,48 +2349,39 @@ nsresult nsPluginHost::ScanPluginsDirect
       if (!enabled)
         pluginTag->UnMark(NS_PLUGIN_FLAG_ENABLED);
 
       // 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
       NS_ASSERTION(!pluginTag->HasFlag(NS_PLUGIN_FLAG_UNWANTED),
                    "Brand-new tags should not be unwanted");
-      if ((checkForUnwantedPlugins && isUnwantedPlugin(pluginTag)) ||
-         IsDuplicatePlugin(pluginTag)) {
+      if (IsDuplicatePlugin(pluginTag)) {
         pluginTag->Mark(NS_PLUGIN_FLAG_UNWANTED);
         pluginTag->mNext = mCachedPlugins;
         mCachedPlugins = pluginTag;
       }
 
       // Plugin unloading is tag-based. If we created a new tag and loaded
       // the library in the process then we want to attempt to unload it here.
       // Only do this if the pref is set for aggressive unloading.
       if (UnloadPluginsASAP()) {
         pluginTag->TryUnloadPlugin();
       }
     }
 
     // set the flag that we want to add this plugin to the list for now
     // and see if it remains after we check several reasons not to do so
     PRBool bAddIt = PR_TRUE;
-
-    // check if this is a specific plugin we don't want
-    if (checkForUnwantedPlugins && isUnwantedPlugin(pluginTag))
+    
+    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;
       bAddIt = PR_FALSE;
-
-    // check if we already have this plugin in the list which
-    // is possible if we do refresh
-    if (bAddIt) {
-      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;
-        bAddIt = PR_FALSE;
-      }
     }
 
     // do it if we still want it
     if (bAddIt) {
       if (!seenBefore) {
         // We have a valid new plugin so report that plugins have changed.
         *aPluginsChanged = PR_TRUE;
       }
@@ -2441,35 +2402,33 @@ nsresult nsPluginHost::ScanPluginsDirect
   }
   
   if (warnOutdated)
     mPrefService->SetBoolPref("plugins.update.notifyUser", PR_TRUE);
 
   return NS_OK;
 }
 
-nsresult nsPluginHost::ScanPluginsDirectoryList(nsISimpleEnumerator * dirEnum,
-                                                nsIComponentManager * compManager,
+nsresult nsPluginHost::ScanPluginsDirectoryList(nsISimpleEnumerator *dirEnum,
                                                 PRBool aCreatePluginList,
-                                                PRBool * aPluginsChanged,
-                                                PRBool checkForUnwantedPlugins)
+                                                PRBool *aPluginsChanged)
 {
     PRBool hasMore;
     while (NS_SUCCEEDED(dirEnum->HasMoreElements(&hasMore)) && hasMore) {
       nsCOMPtr<nsISupports> supports;
       nsresult rv = dirEnum->GetNext(getter_AddRefs(supports));
       if (NS_FAILED(rv))
         continue;
       nsCOMPtr<nsIFile> nextDir(do_QueryInterface(supports, &rv));
       if (NS_FAILED(rv))
         continue;
 
       // don't pass aPluginsChanged directly to prevent it from been reset
       PRBool pluginschanged = PR_FALSE;
-      ScanPluginsDirectory(nextDir, compManager, aCreatePluginList, &pluginschanged, checkForUnwantedPlugins);
+      ScanPluginsDirectory(nextDir, aCreatePluginList, &pluginschanged);
 
       if (pluginschanged)
         *aPluginsChanged = PR_TRUE;
 
       // if changes are detected and we are not creating the list, do not proceed
       if (!aCreatePluginList && *aPluginsChanged)
         break;
     }
@@ -2524,19 +2483,16 @@ nsresult nsPluginHost::FindPlugins(PRBoo
   *aPluginsChanged = PR_FALSE;
   nsresult rv;
 
   // Read cached plugins info. If the profile isn't yet available then don't
   // scan for plugins
   if (ReadPluginInfo() == NS_ERROR_NOT_AVAILABLE)
     return NS_OK;
 
-  nsCOMPtr<nsIComponentManager> compManager;
-  NS_GetComponentManager(getter_AddRefs(compManager));
-
 #ifdef XP_WIN
   // Failure here is not a show-stopper so just warn.
   rv = EnsurePrivateDirServiceProvider();
   NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to register dir service provider.");
 #endif /* XP_WIN */
 
   nsCOMPtr<nsIProperties> dirService(do_GetService(kDirectoryServiceContractID, &rv));
   if (NS_FAILED(rv))
@@ -2547,17 +2503,17 @@ nsresult nsPluginHost::FindPlugins(PRBoo
   // Scan plugins directories;
   // don't pass aPluginsChanged directly, to prevent its
   // possible reset in subsequent ScanPluginsDirectory calls
   PRBool pluginschanged = PR_FALSE;
 
   // Scan the app-defined list of plugin dirs.
   rv = dirService->Get(NS_APP_PLUGINS_DIR_LIST, NS_GET_IID(nsISimpleEnumerator), getter_AddRefs(dirList));
   if (NS_SUCCEEDED(rv)) {
-    ScanPluginsDirectoryList(dirList, compManager, aCreatePluginList, &pluginschanged);
+    ScanPluginsDirectoryList(dirList, aCreatePluginList, &pluginschanged);
 
     if (pluginschanged)
       *aPluginsChanged = PR_TRUE;
 
     // if we are just looking for possible changes,
     // no need to proceed if changes are detected
     if (!aCreatePluginList && *aPluginsChanged) {
       NS_ITERATIVE_UNREF_LIST(nsRefPtr<nsPluginTag>, mCachedPlugins, mNext);
@@ -2574,17 +2530,17 @@ nsresult nsPluginHost::FindPlugins(PRBoo
 
   if (mPrefService)
     mPrefService->GetBoolPref("plugin.scan.plid.all", &bScanPLIDs);
 
     // Now lets scan any PLID directories
   if (bScanPLIDs && mPrivateDirServiceProvider) {
     rv = mPrivateDirServiceProvider->GetPLIDDirectories(getter_AddRefs(dirList));
     if (NS_SUCCEEDED(rv)) {
-      ScanPluginsDirectoryList(dirList, compManager, aCreatePluginList, &pluginschanged);
+      ScanPluginsDirectoryList(dirList, aCreatePluginList, &pluginschanged);
 
       if (pluginschanged)
         *aPluginsChanged = PR_TRUE;
 
       // if we are just looking for possible changes,
       // no need to proceed if changes are detected
       if (!aCreatePluginList && *aPluginsChanged) {
         NS_ITERATIVE_UNREF_LIST(nsRefPtr<nsPluginTag>, mCachedPlugins, mNext);
@@ -2593,47 +2549,32 @@ nsresult nsPluginHost::FindPlugins(PRBoo
       }
     }
   }
 
 
   // Scan the installation paths of our popular plugins if the prefs are enabled
 
   // This table controls the order of scanning
-  const char* const prefs[] = {NS_WIN_JRE_SCAN_KEY,         nsnull,
-                               NS_WIN_ACROBAT_SCAN_KEY,     nsnull,
-                               NS_WIN_QUICKTIME_SCAN_KEY,   nsnull,
-                               NS_WIN_WMP_SCAN_KEY,         nsnull,
-                               NS_WIN_4DOTX_SCAN_KEY,       "1"  /*  second column is flag for 4.x folder */ };
+  const char* const prefs[] = {NS_WIN_JRE_SCAN_KEY,
+                               NS_WIN_ACROBAT_SCAN_KEY,
+                               NS_WIN_QUICKTIME_SCAN_KEY,
+                               NS_WIN_WMP_SCAN_KEY};
 
   PRUint32 size = sizeof(prefs) / sizeof(prefs[0]);
 
-  for (PRUint32 i = 0; i < size; i+=2) {
+  for (PRUint32 i = 0; i < size; i+=1) {
     nsCOMPtr<nsIFile> dirToScan;
     PRBool bExists;
     if (NS_SUCCEEDED(dirService->Get(prefs[i], NS_GET_IID(nsIFile), getter_AddRefs(dirToScan))) &&
         dirToScan &&
         NS_SUCCEEDED(dirToScan->Exists(&bExists)) &&
         bExists) {
-
-      PRBool bFilterUnwanted = PR_FALSE;
-
-      // 4.x plugins folder stuff:
-      // Normally we "filter" the 4.x folder through |IsUnwantedPlugin|
-      // Check for a pref to see if we want to scan the entire 4.x plugins folder
-      if (prefs[i+1]) {
-        PRBool bScanEverything;
-        bFilterUnwanted = PR_TRUE;  // default to filter 4.x folder
-        if (mPrefService &&
-            NS_SUCCEEDED(mPrefService->GetBoolPref(prefs[i], &bScanEverything)) &&
-            bScanEverything)
-          bFilterUnwanted = PR_FALSE;
-
-      }
-      ScanPluginsDirectory(dirToScan, compManager, aCreatePluginList, &pluginschanged, bFilterUnwanted);
+      
+      ScanPluginsDirectory(dirToScan, aCreatePluginList, &pluginschanged);
 
       if (pluginschanged)
         *aPluginsChanged = PR_TRUE;
 
       // if we are just looking for possible changes,
       // no need to proceed if changes are detected
       if (!aCreatePluginList && *aPluginsChanged) {
         NS_ITERATIVE_UNREF_LIST(nsRefPtr<nsPluginTag>, mCachedPlugins, mNext);
--- a/modules/plugin/base/src/nsPluginHost.h
+++ b/modules/plugin/base/src/nsPluginHost.h
@@ -231,28 +231,24 @@ private:
 
   nsresult
   FindStoppedPluginForURL(nsIURI* aURL, nsIPluginInstanceOwner *aOwner);
 
   nsresult
   FindPlugins(PRBool aCreatePluginList, PRBool * aPluginsChanged);
 
   nsresult
-  ScanPluginsDirectory(nsIFile * pluginsDir, 
-                       nsIComponentManager * compManager, 
+  ScanPluginsDirectory(nsIFile *pluginsDir,
                        PRBool aCreatePluginList,
-                       PRBool * aPluginsChanged,
-                       PRBool checkForUnwantedPlugins = PR_FALSE);
-                       
+                       PRBool *aPluginsChanged);
+
   nsresult
-  ScanPluginsDirectoryList(nsISimpleEnumerator * dirEnum,
-                           nsIComponentManager * compManager, 
+  ScanPluginsDirectoryList(nsISimpleEnumerator *dirEnum,
                            PRBool aCreatePluginList,
-                           PRBool * aPluginsChanged,
-                           PRBool checkForUnwantedPlugins = PR_FALSE);
+                           PRBool *aPluginsChanged);
 
   nsresult EnsurePluginLoaded(nsPluginTag* plugin);
 
   PRBool IsRunningPlugin(nsPluginTag * plugin);
 
   // Stores all plugins info into the registry
   nsresult WritePluginInfo();