Bug 392125, Java plugin doesn't stay disabled on restart when disabled via plugin manager, r+sr=jst, a=blocking1.9
authorflamingice@sourmilk.net
Tue, 04 Sep 2007 11:19:31 -0700
changeset 5649 9e80cfa6867e8b5953ac32617a673ee064d359de
parent 5647 60b5828c26010a7cf0408080914c17749a469bd1
child 5650 25ac754f6b404712d375972a66f89584fcfe1559
push idunknown
push userunknown
push dateunknown
reviewersblocking1.9
bugs392125
milestone1.9a8pre
Bug 392125, Java plugin doesn't stay disabled on restart when disabled via plugin manager, r+sr=jst, a=blocking1.9
modules/plugin/base/src/nsPluginHostImpl.cpp
modules/plugin/base/src/nsPluginHostImpl.h
--- a/modules/plugin/base/src/nsPluginHostImpl.cpp
+++ b/modules/plugin/base/src/nsPluginHostImpl.cpp
@@ -763,16 +763,17 @@ nsPluginTag::nsPluginTag(nsPluginTag* aP
       mExtensionsArray[i] = new_str(aPluginTag->mExtensionsArray[i]);
   }
 
   mLibrary = nsnull;
   mCanUnloadLibrary = PR_TRUE;
   mEntryPoint = nsnull;
   mFlags = NS_PLUGIN_FLAG_ENABLED;
   mXPConnected = PR_FALSE;
+  mIsJavaPlugin = aPluginTag->mIsJavaPlugin;
   mFileName = new_str(aPluginTag->mFileName);
   mFullPath = new_str(aPluginTag->mFullPath);
 }
 
 
 ////////////////////////////////////////////////////////////////////////
 nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo)
 {
@@ -780,22 +781,26 @@ nsPluginTag::nsPluginTag(nsPluginInfo* a
   mNext = nsnull;
   mName = new_str(aPluginInfo->fName);
   mDescription = new_str(aPluginInfo->fDescription);
   mVariants = aPluginInfo->fVariantCount;
 
   mMimeTypeArray = nsnull;
   mMimeDescriptionArray = nsnull;
   mExtensionsArray = nsnull;
+  mIsJavaPlugin = PR_FALSE;
 
   if(aPluginInfo->fMimeTypeArray != nsnull)
   {
     mMimeTypeArray = new char*[mVariants];
-    for (int i = 0; i < mVariants; i++)
+    for (int i = 0; i < mVariants; i++) {
       mMimeTypeArray[i] = new_str(aPluginInfo->fMimeTypeArray[i]);
+      if (nsPluginHostImpl::IsJavaMIMEType(mMimeTypeArray[i]))
+        mIsJavaPlugin = PR_TRUE;
+    }
   }
 
   if(aPluginInfo->fMimeDescriptionArray != nsnull)
   {
     mMimeDescriptionArray = new char*[mVariants];
     for (int i = 0; i < mVariants; i++) {
       // we should cut off the list of suffixes which the mime
       // description string may have, see bug 53895
@@ -868,26 +873,29 @@ nsPluginTag::nsPluginTag(const char* aNa
     mLastModifiedTime(aLastModifiedTime),
     mFlags(0) // Caller will read in our flags from cache
 {
   mPluginHost = nsnull;
   mName            = new_str(aName);
   mDescription     = new_str(aDescription);
   mFileName        = new_str(aFileName);
   mFullPath        = new_str(aFullPath);
+  mIsJavaPlugin    = PR_FALSE;
 
   if (mVariants) {
     mMimeTypeArray        = new char*[mVariants];
     mMimeDescriptionArray = new char*[mVariants];
     mExtensionsArray      = new char*[mVariants];
 
     for (PRInt32 i = 0; i < aVariants; ++i) {
       mMimeTypeArray[i]        = new_str(aMimeTypes[i]);
       mMimeDescriptionArray[i] = new_str(aMimeDescriptions[i]);
       mExtensionsArray[i]      = new_str(aExtensions[i]);
+      if (nsPluginHostImpl::IsJavaMIMEType(mMimeTypeArray[i]))
+        mIsJavaPlugin = PR_TRUE;
     }
   }
 }
 
 nsPluginTag::~nsPluginTag()
 {
   TryUnloadPlugin(PR_TRUE);
 
@@ -987,16 +995,29 @@ nsPluginTag::GetDisabled(PRBool* aDisabl
 }
 
 NS_IMETHODIMP
 nsPluginTag::SetDisabled(PRBool aDisabled)
 {
   if (HasFlag(NS_PLUGIN_FLAG_ENABLED) == !aDisabled)
     return NS_OK;
 
+  if (mIsJavaPlugin) {
+    nsresult rv;
+    nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    PRBool javaEnabled;
+    rv = pref->GetBoolPref("security.enable_java", &javaEnabled);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (javaEnabled == aDisabled)
+      return pref->SetBoolPref("security.enable_java", !aDisabled);
+  }
+
   if (aDisabled)
     UnMark(NS_PLUGIN_FLAG_ENABLED);
   else
     Mark(NS_PLUGIN_FLAG_ENABLED);
 
   mPluginHost->UpdatePluginInfo(this);
   return NS_OK;
 }
@@ -3476,17 +3497,17 @@ NS_IMETHODIMP nsPluginHostImpl::Instanti
   } else if (!mJavaEnabled && IsJavaMIMEType(aMimeType)) {
     // Even if we had no Java plugin, if mJavaEnabled is false we should throw
     // here for Java types.  Note that we only need to do this for the case
     // when pluginTag is null; if we had a pluginTag, it would have its
     // NS_PLUGIN_FLAG_ENABLED set the right way.
     return NS_ERROR_NOT_AVAILABLE;
   }
     
-  PRBool isJava = pluginTag && IsJavaPluginTag(pluginTag);
+  PRBool isJava = pluginTag && pluginTag->mIsJavaPlugin;
 
   // Determine if the scheme of this URL is one we can handle internaly because we should
   // only open the initial stream if it's one that we can handle internally. Otherwise
   // |NS_OpenURI| in |InstantiateEmbeddedPlugin| may open up a OS protocal registered helper app
   PRBool bCanHandleInternally = PR_FALSE;
   nsCAutoString scheme;
   if (aURL && NS_SUCCEEDED(aURL->GetScheme(scheme))) {
       nsCAutoString contractID(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX);
@@ -3640,17 +3661,17 @@ NS_IMETHODIMP nsPluginHostImpl::Instanti
 
   if(FindStoppedPluginForURL(aURI, aOwner) == NS_OK) {
     PLUGIN_LOG(PLUGIN_LOG_NOISY,
     ("nsPluginHostImpl::InstantiateFullPagePlugin FoundStopped mime=%s\n",aMimeType));
 
     nsIPluginInstance* instance;
     aOwner->GetInstance(instance);
     nsPluginTag* pluginTag = FindPluginForType(aMimeType, PR_TRUE);
-    if(!pluginTag || !IsJavaPluginTag(pluginTag))
+    if(!pluginTag || !pluginTag->mIsJavaPlugin)
       NewFullPagePluginStream(aStreamListener, instance);
     NS_IF_RELEASE(instance);
     return NS_OK;
   }
 
   nsresult rv = SetUpPluginInstance(aMimeType, aURI, aOwner);
 
   if (NS_OK == rv)
@@ -3920,17 +3941,17 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUp
                                                     mimetype))) {
       return NS_ERROR_FAILURE;
     }
   }
   else
     mimetype = aMimeType;
 
   NS_ASSERTION(pluginTag, "Must have plugin tag here!");
-  PRBool isJavaPlugin = IsJavaPluginTag(pluginTag);
+  PRBool isJavaPlugin = pluginTag->mIsJavaPlugin;
 
 #if defined(OJI) && ((defined(XP_UNIX) && !defined(XP_MACOSX)) || defined(XP_OS2))
   // This is a work-around on Unix for a LiveConnect problem (bug 83698).
   // The problem:
   // The proxy JNI needs to be created by the browser. If it is created by
   // someone else (e.g., a plugin) on a different thread, the proxy JNI will
   // not work, and break LiveConnect.
   // Currently, on Unix, when instantiating a Java plugin instance (by calling
@@ -4828,33 +4849,22 @@ static PRBool isUnwantedPlugin(nsPluginT
 
   return PR_TRUE;
 }
 
 ////////////////////////////////////////////////////////////////////////
 PRBool nsPluginHostImpl::IsUnwantedJavaPlugin(nsPluginTag * tag)
 {
 #ifndef OJI
-  return IsJavaPluginTag(tag);
+  return tag->mIsJavaPlugin;
 #else
   return PR_FALSE;
 #endif /* OJI */
 }
 
-PRBool nsPluginHostImpl::IsJavaPluginTag(nsPluginTag * tag)
-{
-  for (PRInt32 i = 0; i < tag->mVariants; ++i) {
-    if (IsJavaMIMEType(tag->mMimeTypeArray[i])) {
-      return PR_TRUE;
-    }
-  }
-
-  return PR_FALSE;
-}
-
 PRBool nsPluginHostImpl::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",
@@ -5145,17 +5155,17 @@ nsresult nsPluginHostImpl::ScanPluginsDi
       pluginFile.FreePluginInfo(info);
 
       if(pluginTag == nsnull)
         return NS_ERROR_OUT_OF_MEMORY;
 
       pluginTag->mLibrary = pluginLibrary;
       pluginTag->mLastModifiedTime = fileModTime;
       if (!(oldFlags & NS_PLUGIN_FLAG_ENABLED) ||
-          (IsJavaPluginTag(pluginTag) && !mJavaEnabled))
+          (pluginTag->mIsJavaPlugin && !mJavaEnabled))
         pluginTag->UnMark(NS_PLUGIN_FLAG_ENABLED);
 
       if (oldFlags & NS_PLUGIN_FLAG_BLOCKLISTED)
         pluginTag->Mark(NS_PLUGIN_FLAG_BLOCKLISTED);
 
       // 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
@@ -5785,17 +5795,17 @@ nsPluginHostImpl::ReadPluginInfo()
     }
 
     if (!tag) {
       continue;
     }
 
     // Mark plugin as loaded from cache
     tag->Mark(tagflag | NS_PLUGIN_FLAG_FROMCACHE);
-    if (IsJavaPluginTag(tag)) {
+    if (tag->mIsJavaPlugin) {
       if (mJavaEnabled)
         tag->Mark(NS_PLUGIN_FLAG_ENABLED);
       else
         tag->UnMark(NS_PLUGIN_FLAG_ENABLED);
     }
     PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_BASIC,
       ("LoadCachedPluginsInfo : Loading Cached plugininfo for %s\n", tag->mFileName));
     tag->mNext = mCachedPlugins;
@@ -6430,17 +6440,17 @@ NS_IMETHODIMP nsPluginHostImpl::Observe(
 
     if (enabled != mJavaEnabled) {
       mJavaEnabled = enabled;
       // We want to keep the java PluginTag around so we'll know that it's
       // actually disabled, not just not present.  So just manually mark it as
       // disabled so at least FindPluginForType/Extension doesn't return
       // anything.
       for (nsPluginTag* cur = mPlugins; cur; cur = cur->mNext) {
-        if (IsJavaPluginTag(cur))
+        if (cur->mIsJavaPlugin)
           cur->SetDisabled(!mJavaEnabled);
       }            
     }
   }
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////
--- a/modules/plugin/base/src/nsPluginHostImpl.h
+++ b/modules/plugin/base/src/nsPluginHostImpl.h
@@ -144,16 +144,17 @@ public:
   PRInt32       mVariants;
   char          **mMimeTypeArray;
   char          **mMimeDescriptionArray;
   char          **mExtensionsArray;
   PRLibrary     *mLibrary;
   nsIPlugin     *mEntryPoint;
   PRPackedBool  mCanUnloadLibrary;
   PRPackedBool  mXPConnected;
+  PRPackedBool  mIsJavaPlugin;
   char          *mFileName;
   char          *mFullPath;
   PRInt64       mLastModifiedTime;
 private:
   PRUint32      mFlags;
 };
 
 struct nsActivePlugin
@@ -319,16 +320,20 @@ public:
   AddUnusedLibrary(PRLibrary * aLibrary);
 
   static nsresult GetPluginTempDir(nsIFile **aDir);
 
   // Writes updated plugins settings to disk and unloads the plugin
   // if it is now disabled
   nsresult UpdatePluginInfo(nsPluginTag* aPluginTag);
 
+  // checks whether aTag is a "java" plugin tag (a tag for a plugin
+  // that does Java)
+  static PRBool IsJavaMIMEType(const char *aType);
+
 private:
   NS_IMETHOD
   TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsIPluginInstanceOwner *aOwner);
 
   nsresult
   LoadXPCOMPlugins(nsIComponentManager* aComponentManager);
 
   nsresult
@@ -398,24 +403,16 @@ private:
   // 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);
 
   // checks whether the given plugin is an unwanted Java plugin
   // (e.g. no OJI support is compiled in)
   PRBool IsUnwantedJavaPlugin(nsPluginTag * aPluginTag);
 
-  // checks whether aTag is a "java" plugin tag (a tag for a plugin
-  // that does Java)
-  PRBool IsJavaPluginTag(nsPluginTag * aPluginTag);
-
-  // checks whether aTag is a "java" plugin tag (a tag for a plugin
-  // that does Java)
-  PRBool IsJavaMIMEType(const char *aType);
-
   nsresult EnsurePrivateDirServiceProvider();
 
   nsresult GetPrompt(nsIPluginInstanceOwner *aOwner, nsIPrompt **aPrompt);
 
   // one-off hack to include nppl3260.dll from the components folder
   nsresult ScanForRealInComponentsFolder(nsIComponentManager * aCompManager);
 
   // calls PostPluginUnloadEvent for each library in mUnusedLibraries