зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1692385 Add and use a helper method to create a GetUserMediaWindowListener on demand r=pehrsons
Differential Revision: https://phabricator.services.mozilla.com/D105250
This commit is contained in:
Родитель
01891fd90a
Коммит
4f3448549f
|
@ -2532,17 +2532,8 @@ RefPtr<MediaManager::StreamPromise> MediaManager::GetUserMedia(
|
|||
|
||||
// Create a window listener if it doesn't already exist.
|
||||
RefPtr<GetUserMediaWindowListener> windowListener =
|
||||
GetWindowListener(windowID);
|
||||
if (windowListener) {
|
||||
PrincipalHandle existingPrincipalHandle =
|
||||
windowListener->GetPrincipalHandle();
|
||||
MOZ_ASSERT(PrincipalHandleMatches(existingPrincipalHandle, principal));
|
||||
} else {
|
||||
windowListener = new GetUserMediaWindowListener(
|
||||
windowID, MakePrincipalHandle(principal));
|
||||
AddWindowID(windowID, windowListener);
|
||||
}
|
||||
|
||||
GetOrMakeWindowListener(aWindow);
|
||||
MOZ_ASSERT(windowListener);
|
||||
auto sourceListener = MakeRefPtr<SourceListener>();
|
||||
windowListener->Register(sourceListener);
|
||||
|
||||
|
@ -3026,21 +3017,9 @@ RefPtr<MediaManager::DevicesPromise> MediaManager::EnumerateDevices(
|
|||
uint64_t windowId = aWindow->WindowID();
|
||||
Document* doc = aWindow->GetExtantDoc();
|
||||
MOZ_ASSERT(doc);
|
||||
|
||||
nsIPrincipal* principal = doc->NodePrincipal();
|
||||
|
||||
RefPtr<GetUserMediaWindowListener> windowListener =
|
||||
GetWindowListener(windowId);
|
||||
if (windowListener) {
|
||||
PrincipalHandle existingPrincipalHandle =
|
||||
windowListener->GetPrincipalHandle();
|
||||
MOZ_ASSERT(PrincipalHandleMatches(existingPrincipalHandle, principal));
|
||||
} else {
|
||||
windowListener = new GetUserMediaWindowListener(
|
||||
windowId, MakePrincipalHandle(principal));
|
||||
AddWindowID(windowId, windowListener);
|
||||
}
|
||||
|
||||
GetOrMakeWindowListener(aWindow);
|
||||
MOZ_ASSERT(windowListener);
|
||||
// Create an inactive SourceListener to act as a placeholder, so the
|
||||
// window listener doesn't clean itself up until we're done.
|
||||
auto sourceListener = MakeRefPtr<SourceListener>();
|
||||
|
@ -3164,19 +3143,9 @@ RefPtr<SinkInfoPromise> MediaManager::GetSinkDevice(nsPIDOMWindowInner* aWindow,
|
|||
|
||||
// We have to add the window id here because enumerate methods
|
||||
// check for that and abort silently if it does not exist.
|
||||
uint64_t windowId = aWindow->WindowID();
|
||||
nsIPrincipal* principal = aWindow->GetExtantDoc()->NodePrincipal();
|
||||
RefPtr<GetUserMediaWindowListener> windowListener =
|
||||
GetWindowListener(windowId);
|
||||
if (windowListener) {
|
||||
PrincipalHandle existingPrincipalHandle =
|
||||
windowListener->GetPrincipalHandle();
|
||||
MOZ_ASSERT(PrincipalHandleMatches(existingPrincipalHandle, principal));
|
||||
} else {
|
||||
windowListener = new GetUserMediaWindowListener(
|
||||
windowId, MakePrincipalHandle(principal));
|
||||
AddWindowID(windowId, windowListener);
|
||||
}
|
||||
GetOrMakeWindowListener(aWindow);
|
||||
MOZ_ASSERT(windowListener);
|
||||
// Create an inactive SourceListener to act as a placeholder, so the
|
||||
// window listener doesn't clean itself up until we're done.
|
||||
auto sourceListener = MakeRefPtr<SourceListener>();
|
||||
|
@ -3321,6 +3290,28 @@ void MediaManager::OnMicrophoneMute(bool aMute) {
|
|||
}
|
||||
}
|
||||
|
||||
RefPtr<GetUserMediaWindowListener> MediaManager::GetOrMakeWindowListener(
|
||||
nsPIDOMWindowInner* aWindow) {
|
||||
Document* doc = aWindow->GetExtantDoc();
|
||||
if (!doc) {
|
||||
// The window has been destroyed. Destroyed windows don't have listeners.
|
||||
return nullptr;
|
||||
}
|
||||
nsIPrincipal* principal = doc->NodePrincipal();
|
||||
uint64_t windowId = aWindow->WindowID();
|
||||
RefPtr<GetUserMediaWindowListener> windowListener =
|
||||
GetWindowListener(windowId);
|
||||
if (windowListener) {
|
||||
MOZ_ASSERT(PrincipalHandleMatches(windowListener->GetPrincipalHandle(),
|
||||
principal));
|
||||
} else {
|
||||
windowListener = new GetUserMediaWindowListener(
|
||||
windowId, MakePrincipalHandle(principal));
|
||||
AddWindowID(windowId, windowListener);
|
||||
}
|
||||
return windowListener;
|
||||
}
|
||||
|
||||
void MediaManager::AddWindowID(uint64_t aWindowId,
|
||||
RefPtr<GetUserMediaWindowListener> aListener) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
|
|
@ -174,6 +174,11 @@ class MediaManager final : public nsIMediaManagerService, public nsIObserver {
|
|||
media::Parent<media::NonE10s>* GetNonE10sParent();
|
||||
MediaEngine* GetBackend();
|
||||
|
||||
// If the window has not been destroyed, then return the
|
||||
// GetUserMediaWindowListener for this window.
|
||||
// If the window has been destroyed, then return null.
|
||||
RefPtr<GetUserMediaWindowListener> GetOrMakeWindowListener(
|
||||
nsPIDOMWindowInner* aWindow);
|
||||
WindowTable* GetActiveWindows() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return &mActiveWindows;
|
||||
|
|
Загрузка…
Ссылка в новой задаче