Backed out changeset 7cd22106e8d9. Simplify code for exposing plugin file names vs. full path. b=488181
authorJosh Aas <joshmoz@gmail.com>
Sat, 16 May 2009 21:09:48 -0400
changeset 28451 687daa472dd409cc7a175a7cf8fbe5b056296734
parent 28395 7cd22106e8d9784eed2acc3c063f716ffaf2605e
child 28452 01962a35aa902574e55a1dca0e75ed49f62834c0
push id7068
push userjosh@mozilla.com
push dateSun, 17 May 2009 01:11:47 +0000
treeherdermozilla-central@7ed22f21d95d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs488181
milestone1.9.2a1pre
backs out7cd22106e8d9784eed2acc3c063f716ffaf2605e
Backed out changeset 7cd22106e8d9. Simplify code for exposing plugin file names vs. full path. b=488181
dom/locales/en-US/chrome/plugins.properties
modules/plugin/base/src/nsPluginHostImpl.cpp
modules/plugin/base/src/nsPluginsDirBeOS.cpp
modules/plugin/base/src/nsPluginsDirOS2.cpp
modules/plugin/base/src/nsPluginsDirUnix.cpp
modules/plugin/base/src/nsPluginsDirWin.cpp
toolkit/content/plugins.html
--- a/dom/locales/en-US/chrome/plugins.properties
+++ b/dom/locales/en-US/chrome/plugins.properties
@@ -2,16 +2,16 @@
 #    Those strings are inserted into an HTML page, so you all HTML characters
 #    have to be escaped in a way that they show up correctly in HTML!
 
 title_label=About Plugins
 installedplugins_label=Installed plugins
 nopluginsareinstalled_label=No plugins are installed
 findmore_label=Find more information about browser plugins at
 installhelp_label=Help for installing plugins is available from
-file_label=File:
+filename_label=File name:
 version_label=Version:
 mimetype_label=MIME Type
 description_label=Description
 suffixes_label=Suffixes
 enabled_label=Enabled
 yes_label=Yes
 no_label=No
--- a/modules/plugin/base/src/nsPluginHostImpl.cpp
+++ b/modules/plugin/base/src/nsPluginHostImpl.cpp
@@ -3697,21 +3697,21 @@ nsPluginHostImpl::TrySetUpPluginInstance
     // if we don't have an extension or no plugin for this extension,
     // return failure as there is nothing more we can do
     if (fileExtension.IsEmpty() ||
         !(pluginTag = FindPluginEnabledForExtension(fileExtension.get(),
                                                     mimetype))) {
       return NS_ERROR_FAILURE;
     }
   }
-  else {
+  else
     mimetype = aMimeType;
-  }
 
   NS_ASSERTION(pluginTag, "Must have plugin tag here!");
+  PRBool isJavaPlugin = pluginTag->mIsJavaPlugin;
 
   nsCAutoString contractID(
           NS_LITERAL_CSTRING(NS_INLINE_PLUGIN_CONTRACTID_PREFIX) +
           nsDependentCString(mimetype));
 
   GetPluginFactory(mimetype, getter_AddRefs(plugin));
 
   instance = do_CreateInstance(contractID.get(), &result);
@@ -3719,17 +3719,17 @@ nsPluginHostImpl::TrySetUpPluginInstance
   // couldn't create an XPCOM plugin, try to create wrapper for a
   // legacy plugin
   if (NS_FAILED(result)) {
     if (plugin) {
 #if defined(XP_WIN) && !defined(WINCE)
       static BOOL firstJavaPlugin = FALSE;
       BOOL restoreOrigDir = FALSE;
       char origDir[_MAX_PATH];
-      if (pluginTag->mIsJavaPlugin && !firstJavaPlugin) {
+      if (isJavaPlugin && !firstJavaPlugin) {
         DWORD dw = ::GetCurrentDirectory(_MAX_PATH, origDir);
         NS_ASSERTION(dw <= _MAX_PATH, "Falied to obtain the current directory, which may leads to incorrect class laoding");
         nsCOMPtr<nsIFile> binDirectory;
         result = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
                                         getter_AddRefs(binDirectory));
 
         if (NS_SUCCEEDED(result)) {
           nsCAutoString path;
@@ -3990,24 +3990,43 @@ public:
     return NS_OK;
   }
 
   NS_METHOD GetFilename(nsAString& aFilename)
   {
     PRBool bShowPath;
     nsCOMPtr<nsIPrefBranch> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
     if (prefService &&
-        NS_SUCCEEDED(prefService->GetBoolPref("plugin.expose_full_path", &bShowPath)) &&
+        NS_SUCCEEDED(prefService->GetBoolPref("plugin.expose_full_path",&bShowPath)) &&
         bShowPath) {
+      // only show the full path if people have set the pref,
+      // the default should not reveal path information (bug 88183)
+#if defined(XP_MACOSX)
       CopyUTF8toUTF16(mPluginTag.mFullPath, aFilename);
+#else
+      CopyUTF8toUTF16(mPluginTag.mFileName, aFilename);
+#endif
+      return NS_OK;
+    }
+
+    nsAutoString spec;
+    if (!mPluginTag.mFullPath.IsEmpty()) {
+#if !defined(XP_MACOSX)
+      NS_ERROR("Only MAC should be using nsPluginTag::mFullPath!");
+#endif
+      CopyUTF8toUTF16(mPluginTag.mFullPath, spec);
     } else {
-      CopyUTF8toUTF16(mPluginTag.mFileName, aFilename);
+      CopyUTF8toUTF16(mPluginTag.mFileName, spec);
     }
 
-    return NS_OK;
+    nsCString leafName;
+    nsCOMPtr<nsILocalFile> pluginPath;
+    NS_NewLocalFile(spec, PR_TRUE, getter_AddRefs(pluginPath));
+
+    return pluginPath->GetLeafName(aFilename);
   }
 
   NS_METHOD GetVersion(nsAString& aVersion)
   {
     CopyUTF8toUTF16(mPluginTag.mVersion, aVersion);
     return NS_OK;
   }
 
@@ -4347,20 +4366,24 @@ NS_IMETHODIMP nsPluginHostImpl::GetPlugi
     aMimeType, pluginTag->mFileName.get()));
 
 #ifdef NS_DEBUG
     if (aMimeType && !pluginTag->mFileName.IsEmpty())
       printf("For %s found plugin %s\n", aMimeType, pluginTag->mFileName.get());
 #endif
 
     if (!pluginTag->mLibrary) { // if we haven't done this yet
+     nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1");
+#if !defined(XP_MACOSX)
+      file->InitWithPath(NS_ConvertUTF8toUTF16(pluginTag->mFileName));
+#else
       if (pluginTag->mFullPath.IsEmpty())
         return NS_ERROR_FAILURE;
-      nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1");
       file->InitWithPath(NS_ConvertUTF8toUTF16(pluginTag->mFullPath));
+#endif
       nsPluginFile pluginFile(file);
       PRLibrary* pluginLibrary = NULL;
 
       if (pluginFile.LoadPlugin(pluginLibrary) != NS_OK || pluginLibrary == NULL)
         return NS_ERROR_FAILURE;
 
       // remove from unused lib list, if it is there
       if (mUnusedLibraries.Contains(pluginLibrary))
--- a/modules/plugin/base/src/nsPluginsDirBeOS.cpp
+++ b/modules/plugin/base/src/nsPluginsDirBeOS.cpp
@@ -159,26 +159,22 @@ typedef char* (*BeOS_Plugin_GetMIMEDescr
 
 
 /**
  * Obtains all of the information currently available for this plugin.
  */
 nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
 {
     info.fVersion = nsnull;
-
-    nsCAutoString fullPath;
-    if (NS_FAILED(rv = mPlugin->GetNativePath(path)))
+    nsCAutoString fpath;
+    nsresult rv = mPlugin->GetNativePath(fpath);
+    if (NS_OK != rv) {
         return rv;
-
-    nsCAutoString fileName;
-    if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName)))
-        return rv;
-
-    const char *path = fullPath.get();
+    }
+    const char *path = fpath.get();
     int i;
 
 #ifdef NS_PLUGIN_BEOS_DEBUG
     printf("nsPluginFile::GetPluginInfo() an attempt to load MIME String\n");
     printf("path = <%s>\n", path);
 #endif
 
     // get supported mime types
@@ -242,18 +238,18 @@ nsresult nsPluginFile::GetPluginInfo(nsP
         info.fDescription = ToNewCString(NS_ConvertUTF8toUTF16(vinfo.long_info));
     } else {
         // use filename as its name
         info.fName = GetFileName(path);
         info.fDescription = PL_strdup("");
     }
 
     info.fVariantCount = types_num;
-    info.fFullPath = PL_strdup(fullPath.get());
-    info.fFileName = PL_strdup(fileName.get());
+    info.fFileName = PL_strdup(path);
+
 
 #ifdef NS_PLUGIN_BEOS_DEBUG
     printf("info.fFileName = %s\n", info.fFileName);
     printf("info.fName = %s\n", info.fName);
     printf("info.fDescription = %s\n", info.fDescription);
 #endif
 
     return NS_OK;
@@ -277,19 +273,16 @@ nsresult nsPluginFile::FreePluginInfo(ns
         if (info.fExtensionArray[i])
             PL_strfree(info.fExtensionArray[i]);
     }
 
     PR_FREEIF(info.fMimeTypeArray);
     PR_FREEIF(info.fMimeDescriptionArray);
     PR_FREEIF(info.fExtensionArray);
 
-    if (info.fFullPath)
-        PL_strfree(info.fFullPath);
-
     if (info.fFileName)
         PL_strfree(info.fFileName);
 
     if (info.fVersion)
         PL_strfree(info.fVersion);
 
     return NS_OK;
 }
--- a/modules/plugin/base/src/nsPluginsDirOS2.cpp
+++ b/modules/plugin/base/src/nsPluginsDirOS2.cpp
@@ -214,25 +214,21 @@ nsresult nsPluginFile::LoadPlugin( PRLib
 // Obtains all of the information currently available for this plugin.
 nsresult nsPluginFile::GetPluginInfo( nsPluginInfo &info)
 {
    nsresult   rc = NS_ERROR_FAILURE;
    HMODULE    hPlug = 0; // Need a HMODULE to query resource statements
    char       failure[ CCHMAXPATH] = "";
    APIRET     ret;
 
-   nsCAutoString path;
-   if (NS_FAILED(rv = mPlugin->GetNativePath(path)))
-     return rv;
-
-   nsCAutoString fileName;
-   if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName)))
-     return rv;
-
-   ret = DosLoadModule( failure, CCHMAXPATH, path.get(), &hPlug);
+   const char* path;
+   nsCAutoString temp;
+   mPlugin->GetNativePath(temp);
+   path = temp.get();
+   ret = DosLoadModule( failure, CCHMAXPATH, path, &hPlug);
    info.fVersion = nsnull;
 
    while( ret == NO_ERROR)
    {
       info.fName = LoadRCDATAString( hPlug, NS_INFO_ProductName);
 
       info.fVersion = LoadRCDATAVersion( hPlug, NS_INFO_ProductVersion);
 
@@ -254,37 +250,33 @@ nsresult nsPluginFile::GetPluginInfo( ns
       if( info.fMimeTypeArray == nsnull) break;
 
       info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, mimeDescription);
       if( nsnull == info.fMimeDescriptionArray) break;
 
       info.fExtensionArray = MakeStringArray(info.fVariantCount, extensions);
       if( nsnull == info.fExtensionArray) break;
 
-      info.fFullPath = PL_strdup(path.get());
-      info.fFileName = PL_strdup(fileName.get());
+      info.fFileName = PL_strdup(path);
 
       rc = NS_OK;
       break;
    }
 
    if( 0 != hPlug)
       DosFreeModule( hPlug);
 
    return rc;
 }
 
 nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
 {
    if(info.fName != nsnull)
      PL_strfree(info.fName);
-
-   if(info.fFullPath != nsnull)
-     PL_strfree(info.fFullPath);
-
+ 
    if(info.fFileName != nsnull)
      PL_strfree(info.fFileName);
  
    if(info.fVersion != nsnull)
      PL_strfree(info.fVersion);
  
    if(info.fDescription != nsnull)
      PL_strfree(info.fDescription);
--- a/modules/plugin/base/src/nsPluginsDirUnix.cpp
+++ b/modules/plugin/base/src/nsPluginsDirUnix.cpp
@@ -429,17 +429,17 @@ nsresult nsPluginFile::LoadPlugin(PRLibr
 }
 
 /**
  * Obtains all of the information currently available for this plugin.
  */
 nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
 {
     nsresult rv;
-    const char *mimedescr = NULL, *name = NULL, *description = NULL;
+    const char* mimedescr = 0, *name = 0, *description = 0;
 
     // No, this doesn't leak. GetGlobalServiceManager() doesn't addref
     // it's out pointer. Maybe it should.
     nsIServiceManagerObsolete* mgr;
     nsServiceManager::GetGlobalServiceManager((nsIServiceManager**)&mgr);
 
     nsFactoryProc nsGetFactory =
         (nsFactoryProc) PR_FindFunctionSymbol(pLibrary, "NSGetFactory");
@@ -483,30 +483,23 @@ nsresult nsPluginFile::GetPluginInfo(nsP
             info.fVersion = PL_strdup(npGetPluginVersion());
 
         plugin->GetMIMEDescription(&mimedescr);
 #ifdef NS_DEBUG
         printf("GetMIMEDescription() returned \"%s\"\n", mimedescr);
 #endif
         if (NS_FAILED(rv = ParsePluginMimeDescription(mimedescr, info)))
             return rv;
-
-        nsCAutoString path;
-        if (NS_FAILED(rv = mPlugin->GetNativePath(path)))
+        nsCAutoString filename;
+        if (NS_FAILED(rv = mPlugin->GetNativePath(filename)))
             return rv;
-        info.fFullPath = PL_strdup(path.get());
-
-        nsCAutoString fileName;
-        if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName)))
-          return rv;
-        info.fFileName = PL_strdup(fileName.get());
-
+        info.fFileName = PL_strdup(filename.get());
         plugin->GetValue(nsPluginVariable_NameString, &name);
         if (!name)
-            name = "";
+            name = PL_strrchr(info.fFileName, '/') + 1;
         info.fName = PL_strdup(name);
 
         plugin->GetValue(nsPluginVariable_DescriptionString, &description);
         if (!description)
             description = "";
         info.fDescription = PL_strdup(description);
     }
     return NS_OK;
@@ -531,19 +524,16 @@ nsresult nsPluginFile::FreePluginInfo(ns
         if (info.fExtensionArray[i] != nsnull)
             PL_strfree(info.fExtensionArray[i]);
     }
 
     PR_FREEIF(info.fMimeTypeArray);
     PR_FREEIF(info.fMimeDescriptionArray);
     PR_FREEIF(info.fExtensionArray);
 
-    if (info.fFullPath != nsnull)
-        PL_strfree(info.fFullPath);
-
     if (info.fFileName != nsnull)
         PL_strfree(info.fFileName);
 
     if (info.fVersion != nsnull)
         PL_strfree(info.fVersion);
 
     return NS_OK;
 }
--- a/modules/plugin/base/src/nsPluginsDirWin.cpp
+++ b/modules/plugin/base/src/nsPluginsDirWin.cpp
@@ -254,39 +254,34 @@ nsresult nsPluginFile::LoadPlugin(PRLibr
   return NS_OK;
 }
 
 /**
  * Obtains all of the information currently available for this plugin.
  */
 nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
 {
-  nsresult rv = NS_OK;
+  nsresult res = NS_OK;
   DWORD zerome, versionsize;
   TCHAR* verbuf = nsnull;
 
   const TCHAR* path;
 
   if (!mPlugin)
     return NS_ERROR_NULL_POINTER;
 
-  nsCAutoString fullPath;
-  if (NS_FAILED(rv = mPlugin->GetNativePath(fullPath)))
-    return rv;
-
-  nsCAutoString fileName;
-  if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName)))
-    return rv;
+  nsCAutoString temp;
+  mPlugin->GetNativePath(temp);
 
 #ifdef UNICODE
-  NS_ConvertASCIItoUTF16 utf16Path(fullPath);
-  path = utf16Path.get();
+  NS_ConvertASCIItoUTF16 temp2(temp);
+  path = temp2.get();
   versionsize = ::GetFileVersionInfoSizeW((TCHAR*)path, &zerome);
 #else
-  path = fullPath.get();
+  path = temp.get();
   versionsize = ::GetFileVersionInfoSize((TCHAR*)path, &zerome);
 #endif
 
   if (versionsize > 0)
     verbuf = (TCHAR*)PR_Malloc(versionsize);
   if (!verbuf)
     return NS_ERROR_OUT_OF_MEMORY;
 
@@ -302,31 +297,30 @@ nsresult nsPluginFile::GetPluginInfo(nsP
     char *mimeType = GetKeyValue(verbuf, TEXT("\\StringFileInfo\\040904E4\\MIMEType"));
     char *mimeDescription = GetKeyValue(verbuf, TEXT("\\StringFileInfo\\040904E4\\FileOpenName"));
     char *extensions = GetKeyValue(verbuf, TEXT("\\StringFileInfo\\040904E4\\FileExtents"));
 
     info.fVariantCount = CalculateVariantCount(mimeType);
     info.fMimeTypeArray = MakeStringArray(info.fVariantCount, mimeType);
     info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, mimeDescription);
     info.fExtensionArray = MakeStringArray(info.fVariantCount, extensions);
-    info.fFullPath = PL_strdup(fullPath.get());
-    info.fFileName = PL_strdup(fileName.get());
+    info.fFileName = PL_strdup(temp.get());
     info.fVersion = GetVersion(verbuf);
 
     PL_strfree(mimeType);
     PL_strfree(mimeDescription);
     PL_strfree(extensions);
   }
   else {
-    rv = NS_ERROR_FAILURE;
+    res = NS_ERROR_FAILURE;
   }
 
   PR_Free(verbuf);
 
-  return rv;
+  return res;
 }
 
 nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
 {
   if (info.fName)
     PL_strfree(info.fName);
 
   if (info.fDescription)
@@ -336,19 +330,16 @@ nsresult nsPluginFile::FreePluginInfo(ns
     FreeStringArray(info.fVariantCount, info.fMimeTypeArray);
 
   if (info.fMimeDescriptionArray)
     FreeStringArray(info.fVariantCount, info.fMimeDescriptionArray);
 
   if (info.fExtensionArray)
     FreeStringArray(info.fVariantCount, info.fExtensionArray);
 
-  if (info.fFullPath)
-    PL_strfree(info.fFullPath);
-
   if (info.fFileName)
     PL_strfree(info.fFileName);
 
   if (info.fVersion)
     PR_smprintf_free(info.fVersion);
 
   ZeroMemory((void *)&info, sizeof(info));
 
--- a/toolkit/content/plugins.html
+++ b/toolkit/content/plugins.html
@@ -111,17 +111,17 @@
     var plugin = navigator.plugins[i];
 
     if (plugin)
     {
       document.write("<h2 class=\"plugname\">");
       document.write(plugin.name);
       document.writeln("<\/h2>");
 
-      document.writeln("<dl><dd><span class=\"label\">" + pluginsbundle.GetStringFromName("file_label") + "<\/span> ");
+      document.writeln("<dl><dd><span class=\"label\">" + pluginsbundle.GetStringFromName("filename_label") + "<\/span> ");
       document.write(plugin.filename);
       document.writeln("<\/dd><dd><span class=\"label\">" + pluginsbundle.GetStringFromName("version_label") + "<\/span> ");
       document.write(plugin.version);
       document.writeln("<\/dd><dd>");
       document.write(plugin.description);
       document.writeln("<\/dd><\/dl>");
 
       document.writeln("<table border=\"1\" class=\"contenttable\">");