bug 825281 - remove nsISupportsArray from plugins r=bsmedberg
authorTrevor Saunders <trev.saunders@gmail.com>
Wed, 12 Dec 2012 02:56:25 -0500
changeset 126873 313fece4cf4a1cde75943a3bb9cd64d40960e375
parent 126872 a30a8521c16880fe67a34fd5e566123b45301716
child 126874 0d5717bc07bda78a7ece1de6280426317922ba5e
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs825281
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 825281 - remove nsISupportsArray from plugins r=bsmedberg
dom/plugins/base/nsPluginHost.cpp
dom/plugins/base/nsPluginHost.h
dom/plugins/base/nsPluginTags.h
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -24,16 +24,17 @@
 #include "nsIHttpChannel.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIUploadChannel.h"
 #include "nsIByteRangeRequest.h"
 #include "nsIStreamListener.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsIURL.h"
+#include "nsTArray.h"
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsIProtocolProxyService2.h"
 #include "nsIStreamConverterService.h"
 #include "nsIFile.h"
 #if defined(XP_MACOSX)
 #include "nsILocalFileMac.h"
 #endif
@@ -105,17 +106,16 @@
 #include "nsPluginManifestLineReader.h"
 
 #include "nsIWeakReferenceUtils.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMHTMLObjectElement.h"
 #include "nsIDOMHTMLEmbedElement.h"
 #include "nsIPresShell.h"
 #include "nsIWebNavigation.h"
-#include "nsISupportsArray.h"
 #include "nsIDocShell.h"
 #include "nsPluginNativeWindow.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIContentPolicy.h"
 #include "nsContentPolicyUtils.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Telemetry.h"
 #include "nsIImageLoadingContent.h"
@@ -274,33 +274,30 @@ bool ReadSectionHeader(nsPluginManifestL
   return false;
 }
 
 // Little helper struct to asynchronously reframe any presentations (embedded)
 // or reload any documents (full-page), that contained plugins
 // which were shutdown as a result of a plugins.refresh(1)
 class nsPluginDocReframeEvent: public nsRunnable {
 public:
-  nsPluginDocReframeEvent(nsISupportsArray* aDocs) { mDocs = aDocs; }
+  nsPluginDocReframeEvent(nsTArray<nsCOMPtr<nsIDocument> >& aDocs) { mDocs.SwapElements(aDocs); }
 
   NS_DECL_NSIRUNNABLE
 
-  nsCOMPtr<nsISupportsArray> mDocs;
+  nsTArray<nsCOMPtr<nsIDocument> > mDocs;
 };
 
 NS_IMETHODIMP nsPluginDocReframeEvent::Run() {
-  NS_ENSURE_TRUE(mDocs, NS_ERROR_FAILURE);
-
-  uint32_t c;
-  mDocs->Count(&c);
+  uint32_t c = mDocs.Length();
 
   // for each document (which previously had a running instance), tell
   // the frame constructor to rebuild
   for (uint32_t i = 0; i < c; i++) {
-    nsCOMPtr<nsIDocument> doc (do_QueryElementAt(mDocs, i));
+    nsIDocument* doc = mDocs[i];
     if (doc) {
       nsIPresShell *shell = doc->GetShell();
 
       // if this document has a presentation shell, then it has frames and can be reframed
       if (shell) {
         /* A reframe will cause a fresh object frame, instance owner, and instance
          * to be created. Reframing of the entire document is necessary as we may have
          * recently found new plugins and we want a shot at trying to use them instead
@@ -314,17 +311,18 @@ NS_IMETHODIMP nsPluginDocReframeEvent::R
       } else {  // no pres shell --> full-page plugin
 
         NS_NOTREACHED("all plugins should have a pres shell!");
 
       }
     }
   }
 
-  return mDocs->Clear();
+  mDocs.Clear();
+  return NS_OK;
 }
 
 static bool UnloadPluginsASAP()
 {
   return Preferences::GetBool("dom.ipc.plugins.unloadASAP", false);
 }
 
 nsPluginHost::nsPluginHost()
@@ -435,23 +433,22 @@ nsresult nsPluginHost::ReloadPlugins(boo
   // look for possible changes
   bool pluginschanged = true;
   FindPlugins(false, &pluginschanged);
 
   // if no changed detected, return an appropriate error code
   if (!pluginschanged)
     return NS_ERROR_PLUGINS_PLUGINSNOTCHANGED;
 
-  nsCOMPtr<nsISupportsArray> instsToReload;
+  nsTArray<nsCOMPtr<nsIDocument> > instsToReload;
   if (reloadPages) {
-    NS_NewISupportsArray(getter_AddRefs(instsToReload));
 
     // Then stop any running plugin instances but hold on to the documents in the array
     // We are going to need to restart the instances in these documents later
-    DestroyRunningInstances(instsToReload, nullptr);
+    DestroyRunningInstances(&instsToReload, nullptr);
   }
 
   // shutdown plugins and kill the list if there are no running plugins
   nsRefPtr<nsPluginTag> prev;
   nsRefPtr<nsPluginTag> next;
 
   for (nsRefPtr<nsPluginTag> p = mPlugins; p != nullptr;) {
     next = p->mNext;
@@ -480,21 +477,17 @@ nsresult nsPluginHost::ReloadPlugins(boo
   mPluginsLoaded = false;
 
   // load them again
   rv = LoadPlugins();
 
   // If we have shut down any plugin instances, we've now got to restart them.
   // Post an event to do the rest as we are going to be destroying the frame tree and we also want
   // any posted unload events to finish
-  uint32_t c;
-  if (reloadPages &&
-      instsToReload &&
-      NS_SUCCEEDED(instsToReload->Count(&c)) &&
-      c > 0) {
+  if (reloadPages && !instsToReload.IsEmpty()){
     nsCOMPtr<nsIRunnable> ev = new nsPluginDocReframeEvent(instsToReload);
     if (ev)
       NS_DispatchToCurrentThread(ev);
   }
 
   PLUGIN_LOG(PLUGIN_LOG_NORMAL,
   ("nsPluginHost::ReloadPlugins End active_instance_count=%d\n",
   mInstances.Length()));
@@ -2388,22 +2381,20 @@ nsPluginHost::UpdatePluginInfo(nsPluginT
   if (obsService)
     obsService->NotifyObservers(nullptr, "plugin-info-updated", nullptr);
 
   // Reload instances if needed
   if (aPluginTag->IsEnabled()) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsISupportsArray> instsToReload;
-  NS_NewISupportsArray(getter_AddRefs(instsToReload));
-  DestroyRunningInstances(instsToReload, aPluginTag);
+  nsTArray<nsCOMPtr<nsIDocument> > instsToReload;
+  DestroyRunningInstances(&instsToReload, aPluginTag);
   
-  uint32_t c;
-  if (instsToReload && NS_SUCCEEDED(instsToReload->Count(&c)) && c > 0) {
+  if (!instsToReload.IsEmpty()) {
     nsCOMPtr<nsIRunnable> ev = new nsPluginDocReframeEvent(instsToReload);
     if (ev)
       NS_DispatchToCurrentThread(ev);
   }
 
   return NS_OK;
 }
 
@@ -3820,34 +3811,35 @@ nsPluginHost::StoppedInstanceCount()
 }
 
 nsTArray< nsRefPtr<nsNPAPIPluginInstance> >*
 nsPluginHost::InstanceArray()
 {
   return &mInstances;
 }
 
-void
-nsPluginHost::DestroyRunningInstances(nsISupportsArray* aReloadDocs, nsPluginTag* aPluginTag)
+void 
+nsPluginHost::DestroyRunningInstances(nsTArray<nsCOMPtr<nsIDocument> >* aReloadDocs,
+                                      nsPluginTag* aPluginTag)
 {
   for (int32_t i = mInstances.Length(); i > 0; i--) {
     nsNPAPIPluginInstance *instance = mInstances[i - 1];
     if (instance->IsRunning() && (!aPluginTag || aPluginTag == TagForPlugin(instance->GetPlugin()))) {
       instance->SetWindow(nullptr);
       instance->Stop();
 
       // If we've been passed an array to return, lets collect all our documents,
       // removing duplicates. These will be reframed (embedded) or reloaded (full-page) later
       // to kickstart our instances.
       if (aReloadDocs) {
         nsRefPtr<nsPluginInstanceOwner> owner = instance->GetOwner();
         if (owner) {
           nsCOMPtr<nsIDocument> doc;
           owner->GetDocument(getter_AddRefs(doc));
-          if (doc && aReloadDocs->IndexOf(doc) == -1)  // don't allow for duplicates
+          if (doc && !aReloadDocs->Contains(doc))  // don't allow for duplicates
             aReloadDocs->AppendElement(doc);
         }
       }
 
       // Get rid of all the instances without the possibility of caching.
       nsPluginTag* pluginTag = TagForPlugin(instance->GetPlugin());
       instance->SetWindow(nullptr);
       instance->Destroy();
--- a/dom/plugins/base/nsPluginHost.h
+++ b/dom/plugins/base/nsPluginHost.h
@@ -14,17 +14,16 @@
 #include "npapi.h"
 #include "nsNPAPIPluginInstance.h"
 #include "nsIPluginTag.h"
 #include "nsPluginsDir.h"
 #include "nsPluginDirServiceProvider.h"
 #include "nsAutoPtr.h"
 #include "nsWeakPtr.h"
 #include "nsIPrompt.h"
-#include "nsISupportsArray.h"
 #include "nsWeakReference.h"
 #include "nsThreadUtils.h"
 #include "nsTArray.h"
 #include "nsTObserverArray.h"
 #include "nsITimer.h"
 #include "nsPluginTags.h"
 #include "nsIEffectiveTLDService.h"
 #include "nsIIDNService.h"
@@ -172,17 +171,17 @@ public:
                      const nsAString& browserDumpID);
 
   nsNPAPIPluginInstance *FindInstance(const char *mimetype);
   nsNPAPIPluginInstance *FindOldestStoppedInstance();
   uint32_t StoppedInstanceCount();
 
   nsTArray< nsRefPtr<nsNPAPIPluginInstance> > *InstanceArray();
 
-  void DestroyRunningInstances(nsISupportsArray* aReloadDocs, nsPluginTag* aPluginTag);
+  void DestroyRunningInstances(nsTArray<nsCOMPtr<nsIDocument> >* aReloadDocs, nsPluginTag* aPluginTag);
 
   // Return the tag for |aLibrary| if found, nullptr if not.
   nsPluginTag* FindTagForLibrary(PRLibrary* aLibrary);
 
   // The last argument should be false if we already have an in-flight stream
   // and don't need to set up a new stream.
   nsresult InstantiatePluginInstance(const char *aMimeType, nsIURI* aURL,
                                      nsObjectLoadingContent *aContent,
--- a/dom/plugins/base/nsPluginTags.h
+++ b/dom/plugins/base/nsPluginTags.h
@@ -7,17 +7,16 @@
 #define nsPluginTags_h_
 
 #include "nscore.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "nsIPluginTag.h"
 #include "nsNPAPIPluginInstance.h"
-#include "nsISupportsArray.h"
 #include "nsITimer.h"
 #include "nsIDOMMimeType.h"
 
 class nsPluginHost;
 struct PRLibrary;
 struct nsPluginInfo;
 
 // Remember that flags are written out to pluginreg.dat, be careful