Bug 1308615 - Part 2: Stop using nsISupportsArray for observer messages. r?jesup draft
authorEric Rahm <erahm@mozilla.com>
Fri, 07 Oct 2016 14:52:52 -0700
changeset 422578 29861f299bb972e2ff0c378b386273d58128a0fd
parent 422577 d0ff29c25e3d4e24d28e7e2bfa7e9dbe77a3a8f4
child 533314 bed5543897a1c286de8cfcc9b88636c13b5fef41
push id31749
push usererahm@mozilla.com
push dateFri, 07 Oct 2016 21:53:14 +0000
reviewersjesup
bugs1308615
milestone52.0a1
Bug 1308615 - Part 2: Stop using nsISupportsArray for observer messages. r?jesup This removes the rest of the usage of nsISupportsArray in MediaManager. MozReview-Commit-ID: EqXTRNyKiva
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -16,17 +16,16 @@
 #ifdef MOZ_WIDGET_GONK
 #include "nsIAudioManager.h"
 #endif
 #include "nsIEventTarget.h"
 #include "nsIUUIDGenerator.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIPermissionManager.h"
 #include "nsIPopupWindowManager.h"
-#include "nsISupportsArray.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIIDNService.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsPrincipal.h"
@@ -2428,24 +2427,20 @@ MediaManager::GetUserMedia(nsPIDOMWindow
       }
       if (!(*devices)->Length()) {
         RefPtr<MediaStreamError> error =
             new MediaStreamError(window, NS_LITERAL_STRING("NotFoundError"));
         onFailure->OnError(error);
         return;
       }
 
-      nsCOMPtr<nsISupportsArray> devicesCopy; // before we give up devices below
+      nsCOMPtr<nsIMutableArray> devicesCopy = nsArray::Create(); // before we give up devices below
       if (!askPermission) {
-        nsresult rv = NS_NewISupportsArray(getter_AddRefs(devicesCopy));
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          return;
-        }
         for (auto& device : **devices) {
-          rv = devicesCopy->AppendElement(device);
+          nsresult rv = devicesCopy->AppendElement(device, /*weak =*/ false);
           if (NS_WARN_IF(NS_FAILED(rv))) {
             return;
           }
         }
       }
 
       // Pass callbacks and MediaStreamListener along to GetUserMediaTask.
       RefPtr<GetUserMediaTask> task (new GetUserMediaTask(c, onSuccess.forget(),
@@ -3053,25 +3048,25 @@ MediaManager::Observe(nsISupports* aSubj
     mActiveCallbacks.Remove(key, getter_AddRefs(task));
     if (!task) {
       return NS_OK;
     }
 
     if (aSubject) {
       // A particular device or devices were chosen by the user.
       // NOTE: does not allow setting a device to null; assumes nullptr
-      nsCOMPtr<nsISupportsArray> array(do_QueryInterface(aSubject));
+      nsCOMPtr<nsIArray> array(do_QueryInterface(aSubject));
       MOZ_ASSERT(array);
       uint32_t len = 0;
-      array->Count(&len);
+      array->GetLength(&len);
       bool videoFound = false, audioFound = false;
       for (uint32_t i = 0; i < len; i++) {
-        nsCOMPtr<nsISupports> supports;
-        array->GetElementAt(i,getter_AddRefs(supports));
-        nsCOMPtr<nsIMediaDevice> device(do_QueryInterface(supports));
+        nsCOMPtr<nsIMediaDevice> device;
+        array->QueryElementAt(i, NS_GET_IID(nsIMediaDevice),
+                              getter_AddRefs(device));
         MOZ_ASSERT(device); // shouldn't be returning anything else...
         if (device) {
           nsString type;
           device->GetType(type);
           if (type.EqualsLiteral("video")) {
             if (!videoFound) {
               task->SetVideoDevice(static_cast<VideoDevice*>(device.get()));
               videoFound = true;