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
--- a/browser/modules/ContentWebRTC.jsm
+++ b/browser/modules/ContentWebRTC.jsm
@@ -256,18 +256,18 @@ function forgetPendingListsEventually(aC
return;
}
aContentWindow.pendingGetUserMediaRequests = null;
aContentWindow.pendingPeerConnectionRequests = null;
aContentWindow.removeEventListener("unload", ContentWebRTC);
}
function updateIndicators() {
- let contentWindowSupportsArray = MediaManagerService.activeMediaCaptureWindows;
- let count = contentWindowSupportsArray.Count();
+ let contentWindowArray = MediaManagerService.activeMediaCaptureWindows;
+ let count = contentWindowArray.length;
let state = {
showGlobalIndicator: count > 0,
showCameraIndicator: false,
showMicrophoneIndicator: false,
showScreenSharingIndicator: ""
};
@@ -275,17 +275,17 @@ function updateIndicators() {
.getService(Ci.nsIMessageSender);
cpmm.sendAsyncMessage("webrtc:UpdatingIndicators");
// If several iframes in the same page use media streams, it's possible to
// have the same top level window several times. We use a Set to avoid
// 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) {
let tabState = getTabStateForContentWindow(contentWindow);
if (tabState.camera)
state.showCameraIndicator = true;
if (tabState.microphone)
state.showMicrophoneIndicator = true;
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -5,16 +5,17 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaManager.h"
#include "MediaStreamGraph.h"
#include "mozilla/dom/MediaStreamTrack.h"
#include "GetUserMediaRequest.h"
#include "MediaStreamListener.h"
+#include "nsArray.h"
#include "nsContentUtils.h"
#include "nsHashPropertyBag.h"
#ifdef MOZ_WIDGET_GONK
#include "nsIAudioManager.h"
#endif
#include "nsIEventTarget.h"
#include "nsIUUIDGenerator.h"
#include "nsIScriptGlobalObject.h"
@@ -3154,24 +3155,21 @@ MediaManager::Observe(nsISupports* aSubj
return NS_OK;
}
#endif
return NS_OK;
}
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();
StreamListeners* listeners = iter.UserData();
nsPIDOMWindowInner* window =
nsGlobalWindow::GetInnerWindowWithId(id)->AsInner();
MOZ_ASSERT(window);
@@ -3192,21 +3190,21 @@ MediaManager::GetActiveMediaCaptureWindo
listener->CapturingScreen() || listener->CapturingWindow() ||
listener->CapturingApplication()) {
capturing = true;
break;
}
}
}
if (capturing) {
- array->AppendElement(window);
+ array->AppendElement(window, /*weak =*/ false);
}
}
- *aArray = array;
+ array.forget(aArray);
return NS_OK;
}
// XXX flags might be better...
struct CaptureWindowStateData {
bool *mVideo;
bool *mAudio;
bool *mScreenShare;
@@ -3355,43 +3353,43 @@ MediaManager::IterateWindowListeners(nsP
}
}
}
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());
}
}
}
bool
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;
}
}
// Or are persistent permissions (audio or video) granted?
auto* window = nsGlobalWindow::GetInnerWindowWithId(aWindowId);
--- a/dom/media/nsIMediaManager.idl
+++ b/dom/media/nsIMediaManager.idl
@@ -1,27 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
-interface nsISupportsArray;
+interface nsIArray;
interface nsIDOMWindow;
%{C++
#define NS_MEDIAMANAGERSERVICE_CID {0xabc622ea, 0x9655, 0x4123, {0x80, 0xd9, 0x22, 0x62, 0x1b, 0xdd, 0x54, 0x65}}
#define MEDIAMANAGERSERVICE_CONTRACTID "@mozilla.org/mediaManagerService;1"
%}
[scriptable, builtinclass, uuid(24b23e01-33fd-401f-ba25-6e52658750b0)]
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,
[optional] out boolean aScreenShare, [optional] out boolean aWindowShare,
[optional] out boolean aAppShare, [optional] out boolean aBrowserShare);
/* Clear per-orgin list of persistent DeviceIds stored for enumerateDevices
sinceTime is milliseconds since 1 January 1970 00:00:00 UTC. 0 = clear all */
--- a/mobile/android/chrome/content/WebrtcUI.js
+++ b/mobile/android/chrome/content/WebrtcUI.js
@@ -53,17 +53,17 @@ var WebrtcUI = {
}
} else if (aTopic === "VideoCapture:Resumed") {
this.notify();
}
},
notify: function() {
let windows = MediaManagerService.activeMediaCaptureWindows;
- let count = windows.Count();
+ let count = windows.length;
let msg = {};
if (count == 0) {
if (this._notificationId) {
Notifications.cancel(this._notificationId);
this._notificationId = null;
}
} else {
let notificationOptions = {
@@ -71,17 +71,17 @@ var WebrtcUI = {
when: null, // hide the date row
light: [0xFF9500FF, 1000, 1000],
ongoing: true
};
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);
if (hasVideo.value) cameraActive = true;
if (hasAudio.value) audioActive = true;
}
if (cameraActive && audioActive) {