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

--HG--
extra : rebase_source : afc25d91dfcabf6f8f5c9aca6828d41acac9e97e
This commit is contained in:
Eric Rahm 2016-10-10 13:14:38 -07:00
parent 62ae2ac79e
commit 06a26b0b8c
4 changed files with 16 additions and 23 deletions

View File

@ -73,10 +73,10 @@ this.ContentWebRTC = {
let devices = contentWindow.pendingGetUserMediaRequests.get(callID);
forgetGUMRequest(contentWindow, callID);
let allowedDevices = Cc["@mozilla.org/supports-array;1"]
.createInstance(Ci.nsISupportsArray);
let allowedDevices = Cc["@mozilla.org/array;1"]
.createInstance(Ci.nsIMutableArray);
for (let deviceIndex of aMessage.data.devices)
allowedDevices.AppendElement(devices[deviceIndex]);
allowedDevices.AppendElement(devices[deviceIndex], /*weak =*/ false);
Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow", callID);
break;

View File

@ -21,7 +21,6 @@
#include "nsIScriptGlobalObject.h"
#include "nsIPermissionManager.h"
#include "nsIPopupWindowManager.h"
#include "nsISupportsArray.h"
#include "nsIDocShell.h"
#include "nsIDocument.h"
#include "nsISupportsPrimitives.h"
@ -2407,14 +2406,10 @@ if (privileged) {
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;
}
@ -3032,15 +3027,15 @@ MediaManager::Observe(nsISupports* aSubject, const char* aTopic,
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;

View File

@ -5,12 +5,12 @@
#include "MediaManager.h"
#include "MediaPermissionGonk.h"
#include "nsArray.h"
#include "nsCOMPtr.h"
#include "nsIContentPermissionPrompt.h"
#include "nsIDocument.h"
#include "nsIDOMNavigatorUserMedia.h"
#include "nsIStringEnumerator.h"
#include "nsISupportsArray.h"
#include "nsJSUtils.h"
#include "nsQueryObject.h"
#include "nsPIDOMWindow.h"
@ -67,12 +67,10 @@ static nsresult
NotifyPermissionAllow(const nsAString &aCallID, nsTArray<nsCOMPtr<nsIMediaDevice> > &aDevices)
{
nsresult rv;
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMutableArray> array = nsArray::Create();
for (uint32_t i = 0; i < aDevices.Length(); ++i) {
rv = array->AppendElement(aDevices.ElementAt(i));
rv = array->AppendElement(aDevices.ElementAt(i), /*weak =*/ false);
NS_ENSURE_SUCCESS(rv, rv);
}

View File

@ -150,19 +150,19 @@ var WebrtcUI = {
{
label: Strings.browser.GetStringFromName("getUserMedia.shareRequest.label"),
callback: function(checked /* ignored */, inputs) {
let allowedDevices = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
let allowedDevices = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
let audioId = 0;
if (inputs && inputs.audioDevice != undefined)
audioId = inputs.audioDevice;
if (audioDevices[audioId])
allowedDevices.AppendElement(audioDevices[audioId]);
allowedDevices.AppendElement(audioDevices[audioId], /*weak =*/ false);
let videoId = 0;
if (inputs && inputs.videoSource != undefined)
videoId = inputs.videoSource;
if (videoDevices[videoId]) {
allowedDevices.AppendElement(videoDevices[videoId]);
allowedDevices.AppendElement(videoDevices[videoId], /*weak =*/ false);
let perms = Services.perms;
// Although the lifetime is "session" it will be removed upon
// use so it's more of a one-shot.