Bug 1597451 - Remove IterateWindowListeners altogether. r=jib,geckoview-reviewers,agi

GeckoView is seemingly the last user depending on MediaManager iterating over
a all iframes of a window when queried for its capture state.

It is fine however, since GeckoViewMedia already iterates over all windows in
MediaManagerService.activeMediaCaptureWindows, which includes all subframes that
are actively captured.

This patch removes IterateWindowListeners altogether, and the last callsite is
simplified.

Differential Revision: https://phabricator.services.mozilla.com/D93079
This commit is contained in:
Andreas Pehrson 2020-10-19 09:56:56 +00:00
Родитель 86ef11ab0d
Коммит c11959ec0e
5 изменённых файлов: 14 добавлений и 80 удалений

Просмотреть файл

@ -537,8 +537,7 @@ function getTabStateForContentWindow(aContentWindow, aForRemove = false) {
screen,
window,
browser,
devices,
false
devices
);
if (

Просмотреть файл

@ -48,7 +48,6 @@
#include "nsGlobalWindow.h"
#include "nsHashPropertyBag.h"
#include "nsICryptoHMAC.h"
#include "nsIDocShell.h"
#include "nsIEventTarget.h"
#include "nsIKeyModule.h"
#include "nsIPermissionManager.h"
@ -3972,7 +3971,7 @@ NS_IMETHODIMP
MediaManager::MediaCaptureWindowState(
nsIDOMWindow* aCapturedWindow, uint16_t* aCamera, uint16_t* aMicrophone,
uint16_t* aScreen, uint16_t* aWindow, uint16_t* aBrowser,
nsTArray<RefPtr<nsIMediaDevice>>& aDevices, bool aIncludeDescendants) {
nsTArray<RefPtr<nsIMediaDevice>>& aDevices) {
MOZ_ASSERT(NS_IsMainThread());
CaptureState camera = CaptureState::Off;
@ -3984,33 +3983,14 @@ MediaManager::MediaCaptureWindowState(
nsCOMPtr<nsPIDOMWindowInner> piWin = do_QueryInterface(aCapturedWindow);
if (piWin) {
auto combineCaptureState =
[&camera, &microphone, &screen, &window, &browser,
&devices](const RefPtr<GetUserMediaWindowListener>& aListener) {
camera = CombineCaptureState(
camera, aListener->CapturingSource(MediaSourceEnum::Camera));
microphone = CombineCaptureState(
microphone,
aListener->CapturingSource(MediaSourceEnum::Microphone));
screen = CombineCaptureState(
screen, aListener->CapturingSource(MediaSourceEnum::Screen));
window = CombineCaptureState(
window, aListener->CapturingSource(MediaSourceEnum::Window));
browser = CombineCaptureState(
browser, aListener->CapturingSource(MediaSourceEnum::Browser));
aListener->GetDevices(devices);
};
if (aIncludeDescendants) {
IterateWindowListeners(piWin, combineCaptureState);
} else {
uint64_t windowID = piWin->WindowID();
RefPtr<GetUserMediaWindowListener> listener = GetWindowListener(windowID);
// listener might have been destroyed.
if (listener) {
combineCaptureState(listener);
}
if (RefPtr<GetUserMediaWindowListener> listener =
GetWindowListener(piWin->WindowID())) {
camera = listener->CapturingSource(MediaSourceEnum::Camera);
microphone = listener->CapturingSource(MediaSourceEnum::Microphone);
screen = listener->CapturingSource(MediaSourceEnum::Screen);
window = listener->CapturingSource(MediaSourceEnum::Window);
browser = listener->CapturingSource(MediaSourceEnum::Browser);
listener->GetDevices(devices);
}
}
@ -4059,40 +4039,6 @@ void MediaManager::StopScreensharing(uint64_t aWindowID) {
}
}
template <typename FunctionType>
void MediaManager::IterateWindowListeners(nsPIDOMWindowInner* aWindow,
const FunctionType& aCallback) {
// Iterate the docshell tree to find all the child windows, and for each
// invoke the callback
MOZ_DIAGNOSTIC_ASSERT(aWindow);
MOZ_DIAGNOSTIC_ASSERT(aWindow->IsCurrentInnerWindow());
{
uint64_t windowID = aWindow->WindowID();
RefPtr<GetUserMediaWindowListener> listener = GetWindowListener(windowID);
if (listener) {
aCallback(listener);
}
// NB: `listener` might have been destroyed.
}
// iterate any children of *this* window (iframes, etc)
nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
if (docShell) {
int32_t i, count;
docShell->GetInProcessChildCount(&count);
for (i = 0; i < count; ++i) {
nsCOMPtr<nsIDocShellTreeItem> item;
docShell->GetInProcessChildAt(i, getter_AddRefs(item));
nsCOMPtr<nsPIDOMWindowOuter> child = item ? item->GetWindow() : nullptr;
if (child) {
if (auto* innerChild = child->GetCurrentInnerWindow()) {
IterateWindowListeners(innerChild, aCallback);
}
}
}
}
}
bool MediaManager::IsActivelyCapturingOrHasAPermission(uint64_t aWindowId) {
// Does page currently have a gUM stream active?

Просмотреть файл

@ -328,14 +328,6 @@ class MediaManager final : public nsIMediaManagerService, public nsIObserver {
void StopScreensharing(uint64_t aWindowID);
/**
* Calls aCallback with a GetUserMediaWindowListener argument once for
* each window listener associated with aWindow and its child windows.
*/
template <typename FunctionType>
void IterateWindowListeners(nsPIDOMWindowInner* aWindow,
const FunctionType& aCallback);
void RemoveMediaDevicesCallback(uint64_t aWindowID);
void DeviceListChanged();

Просмотреть файл

@ -24,9 +24,8 @@ interface nsIMediaManagerService : nsISupports
const unsigned short STATE_CAPTURE_ENABLED = 1;
const unsigned short STATE_CAPTURE_DISABLED = 2;
/* Get the capture state for the given window and, optionally,
all descendant windows (iframes, etc). The aIncludeDescendants
flag can be removed once all callers are converted to non-recursive usage.
/* Get the capture state for the given window and, optionally, all descendant
* windows (iframes, etc).
*/
void mediaCaptureWindowState(in nsIDOMWindow aWindow,
out unsigned short aCamera,
@ -34,8 +33,7 @@ interface nsIMediaManagerService : nsISupports
out unsigned short aScreenShare,
out unsigned short aWindowShare,
out unsigned short aBrowserShare,
out Array<nsIMediaDevice> devices,
in boolean aIncludeDescendants);
out Array<nsIMediaDevice> devices);
/* Clear per-orgin list of persistent DeviceIds stored for enumerateDevices
sinceTime is milliseconds since 1 January 1970 00:00:00 UTC. 0 = clear all */

Просмотреть файл

@ -101,8 +101,7 @@ const GeckoViewRecordingMedia = {
screen,
window,
browser,
mediaDevices,
true
mediaDevices
);
var cameraStatus = getStatusString(hasCamera.value);
var microphoneStatus = getStatusString(hasMicrophone.value);