Bug 617152. Part 5: nsPluginHost::StopPluginInstance should skip plugin instances that are already destroyed (e.g. because the plugin was disabled). r=josh
authorRobert O'Callahan <robert@ocallahan.org>
Mon, 20 Dec 2010 14:37:43 +1300
changeset 59487 ade671d155143fda1d03114df6c69d148d3d9077
parent 59486 955ba94047fd81636bd9a45ed5ca602266f5d50d
child 59488 25aef953e3496f251a1b8f867a8fb1717b71212f
child 59645 7a2c4ae4b3e0dfdcf5b15c866f54632d5d654af8
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjosh
bugs617152
milestone2.0b9pre
Bug 617152. Part 5: nsPluginHost::StopPluginInstance should skip plugin instances that are already destroyed (e.g. because the plugin was disabled). r=josh
modules/plugin/base/src/nsNPAPIPluginInstance.h
modules/plugin/base/src/nsPluginHost.cpp
--- a/modules/plugin/base/src/nsNPAPIPluginInstance.h
+++ b/modules/plugin/base/src/nsNPAPIPluginInstance.h
@@ -104,16 +104,19 @@ public:
   // To be called when an instance becomes orphaned, when
   // it's plugin is no longer guaranteed to be around.
   void Destroy();
 
   // Indicates whether the plugin is running normally.
   bool IsRunning() {
     return RUNNING == mRunning;
   }
+  bool HasStartedDestroying() {
+    return mRunning >= DESTROYING;
+  }
 
   // Indicates whether the plugin is running normally or being shut down
   bool CanFireNotifications() {
     return mRunning == RUNNING || mRunning == DESTROYING;
   }
 
   // return is only valid when the plugin is not running
   mozilla::TimeStamp LastStopTime();
--- a/modules/plugin/base/src/nsPluginHost.cpp
+++ b/modules/plugin/base/src/nsPluginHost.cpp
@@ -1213,17 +1213,17 @@ nsPluginHost::TagForPlugin(nsNPAPIPlugin
 {
   nsPluginTag* pluginTag;
   for (pluginTag = mPlugins; pluginTag; pluginTag = pluginTag->mNext) {
     if (pluginTag->mEntryPoint == aPlugin) {
       return pluginTag;
     }
   }
   // a plugin should never exist without a corresponding tag
-  NS_ASSERTION(PR_FALSE, "TagForPlugin has failed");
+  NS_ERROR("TagForPlugin has failed");
   return nsnull;
 }
 
 nsresult nsPluginHost::FindStoppedPluginForURL(nsIURI* aURL,
                                                nsIPluginInstanceOwner *aOwner)
 {
   nsCAutoString url;
   if (!aURL)
@@ -3204,20 +3204,22 @@ nsPluginHost::StopPluginInstance(nsIPlug
 {
   if (PluginDestructionGuard::DelayDestroy(aInstance)) {
     return NS_OK;
   }
 
   PLUGIN_LOG(PLUGIN_LOG_NORMAL,
   ("nsPluginHost::StopPluginInstance called instance=%p\n",aInstance));
 
+  nsNPAPIPluginInstance* instance = static_cast<nsNPAPIPluginInstance*>(aInstance);
+  if (instance->HasStartedDestroying())
+    return NS_OK;
+
   aInstance->Stop();
 
-  nsNPAPIPluginInstance* instance = static_cast<nsNPAPIPluginInstance*>(aInstance);
-
   // if the plugin does not want to be 'cached' just remove it
   PRBool doCache = PR_TRUE;
   aInstance->ShouldCache(&doCache);
   if (doCache) {
     // try to get the max cached plugins from a pref or use default
     PRUint32 cachedPluginLimit;
     nsresult rv = NS_ERROR_FAILURE;
     if (mPrefService)