Bug 638171 - FireFox does not read Java Plugin Info.plist correctly.; r=jst,joshmoz a=dveditz
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 24 Mar 2011 14:43:37 -0400
changeset 63371 7124cc6d660d52174328694b8f74447a9d71d938
parent 63370 f026ed05192127db1a1b6c3df5897310621742ca
child 63372 062e9361345ee66491c5dc29c23c8b5bec655f2b
push id32
push usereakhgari@mozilla.com
push dateFri, 01 Apr 2011 21:29:34 +0000
reviewersjst, joshmoz, dveditz
bugs638171
milestone2.0pre
Bug 638171 - FireFox does not read Java Plugin Info.plist correctly.; r=jst,joshmoz a=dveditz
modules/plugin/base/src/nsPluginHost.cpp
modules/plugin/base/src/nsPluginTags.cpp
modules/plugin/base/src/nsPluginTags.h
--- a/modules/plugin/base/src/nsPluginHost.cpp
+++ b/modules/plugin/base/src/nsPluginHost.cpp
@@ -189,18 +189,19 @@ using mozilla::TimeStamp;
 // 0.07 changed nsIRegistry to flat file support for caching plugins info
 // 0.08 mime entry point on MachO, bug 137535
 // 0.09 the file encoding is changed to UTF-8, bug 420285
 // 0.10 added plugin versions on appropriate platforms, bug 427743
 // 0.11 file name and full path fields now store expected values on all platforms, bug 488181
 // 0.12 force refresh due to quicktime pdf claim fix, bug 611197
 // 0.13 add architecture and list of invalid plugins, bug 616271
 // 0.14 force refresh due to locale comparison fix, bug 611296
+// 0.15 force refresh due to bug in reading Java plist MIME data, bug 638171
 // The current plugin registry version (and the maximum version we know how to read)
-static const char *kPluginRegistryVersion = "0.14";
+static const char *kPluginRegistryVersion = "0.15";
 // The minimum registry version we know how to read
 static const char *kMinimumRegistryVersion = "0.9";
 
 static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
 static const char kDirectoryServiceContractID[] = "@mozilla.org/file/directory_service;1";
 
 // Registry keys for caching plugin info
 static const char kPluginsRootKey[] = "software/plugins";
--- a/modules/plugin/base/src/nsPluginTags.cpp
+++ b/modules/plugin/base/src/nsPluginTags.cpp
@@ -121,31 +121,33 @@ mIsJavaPlugin(PR_FALSE),
 mIsNPRuntimeEnabledJavaPlugin(PR_FALSE),
 mIsFlashPlugin(PR_FALSE),
 mFileName(aPluginInfo->fFileName),
 mFullPath(aPluginInfo->fFullPath),
 mVersion(aPluginInfo->fVersion),
 mLastModifiedTime(0),
 mFlags(NS_PLUGIN_FLAG_ENABLED)
 {
+  PRInt32 javaSentinelVariant = -1;
+
   if (aPluginInfo->fMimeTypeArray) {
     mMimeTypeArray = new char*[mVariants];
     for (int i = 0; i < mVariants; i++) {
       char* currentMIMEType = aPluginInfo->fMimeTypeArray[i];
       if (!currentMIMEType) {
         continue;
       }
 
       if (mIsJavaPlugin) {
         if (strcmp(currentMIMEType, "application/x-java-vm-npruntime") == 0) {
-          // Stop processing here, any mimetypes after the magic "I'm a
-          // NPRuntime enabled Java plugin" mimetype will be ignored.
+          // This "magic MIME type" should not be exposed, but is just a signal
+          // to the browser that this is new-style java.
+          // Remove it and its associated MIME description from our arrays.
           mIsNPRuntimeEnabledJavaPlugin = PR_TRUE;
-          mVariants = i;
-          break;
+          javaSentinelVariant = i;
         }
       }
 
       mMimeTypeArray[i] = new_str(currentMIMEType);
 
       if (nsPluginHost::IsJavaMIMEType(mMimeTypeArray[i])) {
         mIsJavaPlugin = PR_TRUE;
       }
@@ -187,16 +189,18 @@ mFlags(NS_PLUGIN_FLAG_ENABLED)
   }
   
   if (aPluginInfo->fExtensionArray != nsnull) {
     mExtensionsArray = new char*[mVariants];
     for (int i = 0; i < mVariants; i++)
       mExtensionsArray[i] = new_str(aPluginInfo->fExtensionArray[i]);
   }
   
+  RemoveJavaSentinel(javaSentinelVariant);
+
   EnsureMembersAreUTF8();
 }
 
 nsPluginTag::nsPluginTag(const char* aName,
                          const char* aDescription,
                          const char* aFileName,
                          const char* aFullPath,
                          const char* aVersion,
@@ -218,40 +222,39 @@ mCanUnloadLibrary(aCanUnload),
 mIsJavaPlugin(PR_FALSE),
 mIsNPRuntimeEnabledJavaPlugin(PR_FALSE),
 mFileName(aFileName),
 mFullPath(aFullPath),
 mVersion(aVersion),
 mLastModifiedTime(aLastModifiedTime),
 mFlags(0) // Caller will read in our flags from cache
 {
+  PRInt32 javaSentinelVariant = -1;
+
   if (aVariants) {
     mMimeTypeArray        = new char*[mVariants];
     mExtensionsArray      = new char*[mVariants];
     
     for (PRInt32 i = 0; i < aVariants; ++i) {
       if (mIsJavaPlugin && aMimeTypes[i] &&
           strcmp(aMimeTypes[i], "application/x-java-vm-npruntime") == 0) {
         mIsNPRuntimeEnabledJavaPlugin = PR_TRUE;
-        
-        // Stop processing here, any mimetypes after the magic "I'm a
-        // NPRuntime enabled Java plugin" mimetype will be ignored.
-        mVariants = i;
-        
-        break;
+        javaSentinelVariant = i;
       }
       
       mMimeTypeArray[i]        = new_str(aMimeTypes[i]);
       mMimeDescriptionArray.AppendElement(aMimeDescriptions[i]);
       mExtensionsArray[i]      = new_str(aExtensions[i]);
       if (nsPluginHost::IsJavaMIMEType(mMimeTypeArray[i]))
         mIsJavaPlugin = PR_TRUE;
     }
   }
-  
+
+  RemoveJavaSentinel(javaSentinelVariant);
+
   if (!aArgsAreUTF8)
     EnsureMembersAreUTF8();
 }
 
 nsPluginTag::~nsPluginTag()
 {
   NS_ASSERTION(!mNext, "Risk of exhausting the stack space, bug 486349");
   
@@ -578,8 +581,38 @@ void nsPluginTag::TryUnloadPlugin()
   mLibrary = nsnull;
   
   // Remove mime types added to the category manager
   // only if we were made 'active' by setting the host
   if (mPluginHost) {
     RegisterWithCategoryManager(PR_FALSE, nsPluginTag::ePluginUnregister);
   }
 }
+
+void
+nsPluginTag::RemoveJavaSentinel(PRInt32 sentinelIndex)
+{
+  if (sentinelIndex == -1)
+    return;
+
+  delete[] mMimeTypeArray[sentinelIndex];
+  mMimeDescriptionArray.RemoveElementAt(sentinelIndex);
+  if (mExtensionsArray)
+    delete[] mExtensionsArray[sentinelIndex];
+
+  // Move the subsequent entries in the arrays.
+  if (mVariants > sentinelIndex + 1) {
+    memmove(mMimeTypeArray + sentinelIndex,
+            mMimeTypeArray + sentinelIndex + 1,
+            (mVariants - sentinelIndex - 1) * sizeof(mMimeTypeArray[0]));
+
+    if (mExtensionsArray) {
+      memmove(mExtensionsArray + sentinelIndex,
+              mExtensionsArray + sentinelIndex + 1,
+              (mVariants - sentinelIndex - 1) * sizeof(mExtensionsArray[0]));
+    }
+  }
+  --mVariants;
+
+  mMimeTypeArray[mVariants] = NULL;
+  if (mExtensionsArray)
+    mExtensionsArray[mVariants] = NULL;
+}
--- a/modules/plugin/base/src/nsPluginTags.h
+++ b/modules/plugin/base/src/nsPluginTags.h
@@ -95,16 +95,21 @@ public:
   void Mark(PRUint32 mask);
   void UnMark(PRUint32 mask);
   PRBool HasFlag(PRUint32 flag);
   PRUint32 Flags();
   PRBool Equals(nsPluginTag* aPluginTag);
   PRBool IsEnabled();
   void RegisterWithCategoryManager(PRBool aOverrideInternalTypes,
                                    nsRegisterType aType = ePluginRegister);
+
+  // Remove the MIME/description/extension entry associated with the magic Java sentinel
+  // which informs us that the Java plugin is NPAPI-enabled. If sentinelIndex is -1, no
+  // action will be performed.
+  void RemoveJavaSentinel(PRInt32 sentinelIndex);
   
   nsRefPtr<nsPluginTag> mNext;
   nsPluginHost *mPluginHost;
   nsCString     mName; // UTF-8
   nsCString     mDescription; // UTF-8
   PRInt32       mVariants;
   char          **mMimeTypeArray;
   nsTArray<nsCString> mMimeDescriptionArray; // UTF-8