Bug 1308615 - Part 1: Use nsIArray in nsIMediaManagerService. r=jesup

This converts nsIMediaManagerService to use nsIArray rather than
nsISupportsArray. All usages of the interface are updated.

MozReview-Commit-ID: 1PLczEptf59
This commit is contained in:
Eric Rahm 2016-10-13 22:02:47 -07:00
parent 29c2ee2410
commit 441292eb71
4 changed files with 23 additions and 25 deletions

View File

@ -261,8 +261,8 @@ function forgetPendingListsEventually(aContentWindow) {
}
function updateIndicators() {
let contentWindowSupportsArray = MediaManagerService.activeMediaCaptureWindows;
let count = contentWindowSupportsArray.Count();
let contentWindowArray = MediaManagerService.activeMediaCaptureWindows;
let count = contentWindowArray.length;
let state = {
showGlobalIndicator: count > 0,
@ -280,7 +280,7 @@ function updateIndicators() {
// sending duplicate notifications.
let contentWindows = new Set();
for (let i = 0; i < count; ++i) {
contentWindows.add(contentWindowSupportsArray.GetElementAt(i).top);
contentWindows.add(contentWindowArray.queryElementAt(i, Ci.nsISupports).top);
}
for (let contentWindow of contentWindows) {

View File

@ -10,6 +10,7 @@
#include "mozilla/dom/MediaStreamTrack.h"
#include "GetUserMediaRequest.h"
#include "MediaStreamListener.h"
#include "nsArray.h"
#include "nsContentUtils.h"
#include "nsHashPropertyBag.h"
#ifdef MOZ_WIDGET_GONK
@ -3133,14 +3134,11 @@ MediaManager::Observe(nsISupports* aSubject, const char* aTopic,
}
nsresult
MediaManager::GetActiveMediaCaptureWindows(nsISupportsArray** aArray)
MediaManager::GetActiveMediaCaptureWindows(nsIArray** aArray)
{
MOZ_ASSERT(aArray);
nsISupportsArray* array;
nsresult rv = NS_NewISupportsArray(&array); // AddRefs
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIMutableArray> array = nsArray::Create();
for (auto iter = mActiveWindows.Iter(); !iter.Done(); iter.Next()) {
const uint64_t& id = iter.Key();
@ -3171,11 +3169,11 @@ MediaManager::GetActiveMediaCaptureWindows(nsISupportsArray** aArray)
}
}
if (capturing) {
array->AppendElement(window);
array->AppendElement(window, /*weak =*/ false);
}
}
*aArray = array;
array.forget(aArray);
return NS_OK;
}
@ -3334,14 +3332,14 @@ MediaManager::IterateWindowListeners(nsPIDOMWindowInner* aWindow,
void
MediaManager::StopMediaStreams()
{
nsCOMPtr<nsISupportsArray> array;
nsCOMPtr<nsIArray> array;
GetActiveMediaCaptureWindows(getter_AddRefs(array));
uint32_t len;
array->Count(&len);
array->GetLength(&len);
for (uint32_t i = 0; i < len; i++) {
nsCOMPtr<nsISupports> window;
array->GetElementAt(i, getter_AddRefs(window));
nsCOMPtr<nsPIDOMWindowInner> win(do_QueryInterface(window));
nsCOMPtr<nsPIDOMWindowInner> win;
array->QueryElementAt(i, NS_GET_IID(nsPIDOMWindowInner),
getter_AddRefs(win));
if (win) {
OnNavigation(win->WindowID());
}
@ -3353,14 +3351,14 @@ MediaManager::IsActivelyCapturingOrHasAPermission(uint64_t aWindowId)
{
// Does page currently have a gUM stream active?
nsCOMPtr<nsISupportsArray> array;
nsCOMPtr<nsIArray> array;
GetActiveMediaCaptureWindows(getter_AddRefs(array));
uint32_t len;
array->Count(&len);
array->GetLength(&len);
for (uint32_t i = 0; i < len; i++) {
nsCOMPtr<nsISupports> window;
array->GetElementAt(i, getter_AddRefs(window));
nsCOMPtr<nsPIDOMWindowInner> win(do_QueryInterface(window));
nsCOMPtr<nsPIDOMWindowInner> win;
array->QueryElementAt(i, NS_GET_IID(nsPIDOMWindowInner),
getter_AddRefs(win));
if (win && win->WindowID() == aWindowId) {
return true;
}

View File

@ -4,7 +4,7 @@
#include "nsISupports.idl"
interface nsISupportsArray;
interface nsIArray;
interface nsIDOMWindow;
%{C++
@ -16,7 +16,7 @@ interface nsIDOMWindow;
interface nsIMediaManagerService : nsISupports
{
/* return a array of inner windows that have active captures */
readonly attribute nsISupportsArray activeMediaCaptureWindows;
readonly attribute nsIArray activeMediaCaptureWindows;
/* Get the capture state for the given window and all descendant windows (iframes, etc) */
void mediaCaptureWindowState(in nsIDOMWindow aWindow, out boolean aVideo, out boolean aAudio,

View File

@ -58,7 +58,7 @@ var WebrtcUI = {
notify: function() {
let windows = MediaManagerService.activeMediaCaptureWindows;
let count = windows.Count();
let count = windows.length;
let msg = {};
if (count == 0) {
if (this._notificationId) {
@ -76,7 +76,7 @@ var WebrtcUI = {
let cameraActive = false;
let audioActive = false;
for (let i = 0; i < count; i++) {
let win = windows.GetElementAt(i);
let win = windows.queryElementAt(i, Ci.nsIDOMWindow);
let hasAudio = {};
let hasVideo = {};
MediaManagerService.mediaCaptureWindowState(win, hasVideo, hasAudio);