Bug 800018 - Part 1 - Remove binding events from nsObjectLoadingContent. r=josh, a=akeybl
authorJohn Schoenick <jschoenick@mozilla.com>
Wed, 07 Nov 2012 13:59:15 -0800
changeset 117053 46430f63e85b8195bdf6794ec0db2ed6e400eace
parent 117052 ce4d9f008712cd8c3be9131469e36258d6e8934c
child 117054 fb81a128125dc807f5ba2e10dd50a30964d0f7a1
push id1730
push userryanvm@gmail.com
push dateWed, 21 Nov 2012 23:19:47 +0000
treeherdermozilla-beta@9b66328a0d4e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh, akeybl
bugs800018
milestone18.0
Bug 800018 - Part 1 - Remove binding events from nsObjectLoadingContent. r=josh, a=akeybl
content/base/src/nsObjectLoadingContent.cpp
content/base/src/nsObjectLoadingContent.h
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -153,69 +153,35 @@ InDocCheckEvent::Run()
     objLC->UnloadObject();
   }
   return NS_OK;
 }
 
 /**
  * A task for firing PluginNotFound and PluginBlocklisted DOM Events.
  */
-class nsPluginErrorEvent : public nsRunnable {
+class nsPluginOutdatedEvent : public nsRunnable {
 public:
-  nsPluginErrorEvent(nsIContent* aContent,
-                     nsObjectLoadingContent::FallbackType aFallbackType)
-    : mContent(aContent),
-      mFallbackType(aFallbackType) {}
+  nsPluginOutdatedEvent(nsIContent* aContent) : mContent(aContent) {}
 
-  ~nsPluginErrorEvent() {}
+  ~nsPluginOutdatedEvent() {}
 
   NS_IMETHOD Run();
 
 private:
   nsCOMPtr<nsIContent> mContent;
-  nsObjectLoadingContent::FallbackType mFallbackType;
 };
 
 NS_IMETHODIMP
-nsPluginErrorEvent::Run()
+nsPluginOutdatedEvent::Run()
 {
-  nsString type;
-  switch (mFallbackType) {
-    case nsObjectLoadingContent::eFallbackVulnerableUpdatable:
-      type = NS_LITERAL_STRING("PluginVulnerableUpdatable");
-      break;
-    case nsObjectLoadingContent::eFallbackVulnerableNoUpdate:
-      type = NS_LITERAL_STRING("PluginVulnerableNoUpdate");
-      break;
-    case nsObjectLoadingContent::eFallbackClickToPlay:
-      type = NS_LITERAL_STRING("PluginClickToPlay");
-      break;
-    case nsObjectLoadingContent::eFallbackPlayPreview:
-      type = NS_LITERAL_STRING("PluginPlayPreview");
-      break;
-    case nsObjectLoadingContent::eFallbackUnsupported:
-      type = NS_LITERAL_STRING("PluginNotFound");
-      break;
-    case nsObjectLoadingContent::eFallbackDisabled:
-      type = NS_LITERAL_STRING("PluginDisabled");
-      break;
-    case nsObjectLoadingContent::eFallbackBlocklisted:
-      type = NS_LITERAL_STRING("PluginBlocklisted");
-      break;
-    case nsObjectLoadingContent::eFallbackOutdated:
-      type = NS_LITERAL_STRING("PluginOutdated");
-      break;
-    default:
-      return NS_OK;
-  }
-  LOG(("OBJLC [%p]: nsPluginErrorEvent firing '%s'",
-       mContent.get(), NS_ConvertUTF16toUTF8(type).get()));
+  LOG(("OBJLC [%p]: nsPluginOutdatedEvent firing", mContent.get()));
   nsContentUtils::DispatchTrustedEvent(mContent->GetDocument(), mContent,
-                                       type, true, true);
-
+                                       NS_LITERAL_STRING("PluginOutdated"),
+                                       true, true);
   return NS_OK;
 }
 
 /**
  * A task for firing PluginCrashed DOM Events.
  */
 class nsPluginCrashedEvent : public nsRunnable {
 public:
@@ -768,18 +734,26 @@ nsObjectLoadingContent::InstantiatePlugi
                                         getter_AddRefs(pluginTag));
 
     nsCOMPtr<nsIBlocklistService> blocklist =
       do_GetService("@mozilla.org/extensions/blocklist;1");
     if (blocklist) {
       uint32_t blockState = nsIBlocklistService::STATE_NOT_BLOCKED;
       blocklist->GetPluginBlocklistState(pluginTag, EmptyString(),
                                          EmptyString(), &blockState);
-      if (blockState == nsIBlocklistService::STATE_OUTDATED)
-        FirePluginError(eFallbackOutdated);
+      if (blockState == nsIBlocklistService::STATE_OUTDATED) {
+        // Fire plugin outdated event if necessary
+        LOG(("OBJLC [%p]: Dispatching nsPluginOutdatedEvent for content %p\n",
+             this));
+        nsCOMPtr<nsIRunnable> ev = new nsPluginOutdatedEvent(thisContent);
+        nsresult rv = NS_DispatchToCurrentThread(ev);
+        if (NS_FAILED(rv)) {
+          NS_WARNING("failed to dispatch nsPluginOutdatedEvent");
+        }
+      }
     }
   }
 
   return NS_OK;
 }
 
 void
 nsObjectLoadingContent::NotifyOwnerDocumentActivityChanged()
@@ -1824,31 +1798,23 @@ nsObjectLoadingContent::LoadObject(bool 
     NS_ASSERTION(!mFrameLoader && !mInstanceOwner,
                  "switched to type null but also loaded something");
 
     if (mChannel) {
       // If we were loading with a channel but then failed over, throw it away
       CloseChannel();
     }
 
-    // Don't notify or send events - we'll handle those ourselves
+    // Don't notify, as LoadFallback doesn't know of our previous state
     // (so really this is just setting mFallbackType)
     LoadFallback(fallbackType, false);
   }
 
-  // Notify of our final state if we haven't already
+  // Notify of our final state
   NotifyStateChanged(oldType, oldState, false, aNotify);
-  
-  if (mType == eType_Null && !mContentType.IsEmpty() &&
-      mFallbackType != eFallbackAlternate) {
-    // if we have a content type and are not showing alternate
-    // content, fire a pluginerror to trigger (we stopped LoadFallback
-    // from doing so above, it doesn't know of our old state)
-    FirePluginError(mFallbackType);
-  }
 
   //
   // Pass load on to finalListener if loading with a channel
   //
 
   // If we re-entered and loaded something else, that load will have cleaned up
   // our our listener.
   if (!mIsLoading) {
@@ -2073,33 +2039,16 @@ nsObjectLoadingContent::NotifyStateChang
     // Otherwise, need to do that here
     nsCOMPtr<nsIPresShell> shell = doc->GetShell();
     if (shell) {
       shell->RecreateFramesFor(thisContent);
     }
   }
 }
 
-void
-nsObjectLoadingContent::FirePluginError(FallbackType aFallbackType)
-{
-  nsCOMPtr<nsIContent> thisContent = 
-    do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
-  NS_ASSERTION(thisContent, "must be a content");
-
-  LOG(("OBJLC [%p]: Dispatching nsPluginErrorEvent for content %p\n",
-       this));
-
-  nsCOMPtr<nsIRunnable> ev = new nsPluginErrorEvent(thisContent, aFallbackType);
-  nsresult rv = NS_DispatchToCurrentThread(ev);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("failed to dispatch nsPluginErrorEvent");
-  }
-}
-
 nsObjectLoadingContent::ObjectType
 nsObjectLoadingContent::GetTypeOfContent(const nsCString& aMIMEType)
 {
   if (aMIMEType.IsEmpty()) {
     return eType_Null;
   }
 
   uint32_t caps = GetCapabilities();
@@ -2323,32 +2272,22 @@ nsObjectLoadingContent::LoadFallback(Fal
         break;
       }
     }
   }
 
   mType = eType_Null;
   mFallbackType = aType;
 
-  //
-  // Notify & send events
-  //
+  // Notify
   if (!aNotify) {
     return; // done
   }
 
   NotifyStateChanged(oldType, oldState, false, true);
-
-  if (mFallbackType != eFallbackCrashed &&
-      mFallbackType != eFallbackAlternate)
-  {
-    // Alternate content doesn't trigger a pluginError, and nsPluginCrashedEvent
-    // is only handled by ::PluginCrashed
-    FirePluginError(mFallbackType);
-  }
 }
 
 void
 nsObjectLoadingContent::DoStopPlugin(nsPluginInstanceOwner* aInstanceOwner,
                                      bool aDelayedStop,
                                      bool aForcedReentry)
 {
   // DoStopPlugin can process events and there may be pending InDocCheckEvent
--- a/content/base/src/nsObjectLoadingContent.h
+++ b/content/base/src/nsObjectLoadingContent.h
@@ -343,23 +343,16 @@ class nsObjectLoadingContent : public ns
      * @param aSync If a synchronous frame construction is required. If false,
      *              the construction may either be sync or async.
      * @param aNotify if false, only need to update the state of our element.
      */
     void NotifyStateChanged(ObjectType aOldType, nsEventStates aOldState,
                             bool aSync, bool aNotify);
 
     /**
-     * Fires the nsPluginErrorEvent. This function doesn't do any checks
-     * whether it should be fired, or whether the given state translates to a
-     * meaningful event
-     */
-    void FirePluginError(FallbackType aFallbackType);
-
-    /**
      * Returns a ObjectType value corresponding to the type of content we would
      * support the given MIME type as, taking capabilities and plugin state
      * into account
      * 
      * NOTE this does not consider whether the content would be suppressed by
      *      click-to-play or other content policy checks
      */
     ObjectType GetTypeOfContent(const nsCString& aMIMEType);