From d61ba41f34e9122d20137d232642cd16f9b84322 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Tue, 29 Apr 2025 17:54:12 +0000 Subject: [PATCH] Bug 1958963 Expose all speaker devices, irrespective of groupId, upon microphone access. r=karlt Relaxes exposure criteria for speakers in the navigator.mediaDevices.enumerateDevices() API, to match the recent spec change in w3c/mediacapture-output#150 and other implementations for web compatibility. The old behavior was to only expose speakers whose groupId is the same as that of any microphone, once the document is using a microphone. The new behavior is to expose all speakers once the document is using a microphone. The old behavior is retained for RFPTarget::MediaDevices, to avoid any new exposure there. Also fixes an assumption in WPT test MediaDevices-enumerateDevices-per-origin-ids.sub.https.html broken by this patch about the total number of devices exposed after gUM in an iframe vs the top frame. Differential Revision: https://phabricator.services.mozilla.com/D246001 --- dom/media/MediaDevices.cpp | 9 ++-- .../mochitests/testLegacyEnumerateDevices.js | 1 + .../mochitests/test_enumerateDevices.html | 1 + .../test_fingerprinting_resistance.html | 32 +++++++------- .../webrtc/tests/mochitests/test_groupId.html | 1 - ...ocontext-sinkid-constructor.https.html.ini | 25 +++++++++++ ...diocontext-sinkid-setsinkid.https.html.ini | 42 +++++++++++++++---- ...context-sinkid-state-change.https.html.ini | 11 ++++- .../tests/audio-output/setSinkId.https.html | 6 --- ...erateDevices-per-origin-ids.sub.https.html | 4 +- 10 files changed, 96 insertions(+), 36 deletions(-) diff --git a/dom/media/MediaDevices.cpp b/dom/media/MediaDevices.cpp index 067094cb6b70..165fa69da767 100644 --- a/dom/media/MediaDevices.cpp +++ b/dom/media/MediaDevices.cpp @@ -264,7 +264,8 @@ RefPtr MediaDevices::FilterExposedDevices( bool dropSpeakers = !Preferences::GetBool("media.setsinkid.enabled") || !FeaturePolicyUtils::IsFeatureAllowed(doc, u"speaker-selection"_ns); - + bool shouldResistFingerprinting = + window->AsGlobal()->ShouldResistFingerprinting(RFPTarget::MediaDevices); bool legacy = IsLegacyMode(window); bool outputIsDefault = true; // First output is the default. bool haveDefaultOutput = false; @@ -293,8 +294,10 @@ RefPtr MediaDevices::FilterExposedDevices( case MediaDeviceKind::Audiooutput: if (dropSpeakers || (!mExplicitlyGrantedAudioOutputRawIds.Contains(device->mRawID) && - // Assumes aDevices order has microphones before speakers. - !exposedMicrophoneGroupIds.Contains(device->mRawGroupID))) { + (!mCanExposeMicrophoneInfo || + (shouldResistFingerprinting && + // Assumes aDevices order has microphones before speakers. + !exposedMicrophoneGroupIds.Contains(device->mRawGroupID))))) { outputIsDefault = false; continue; } diff --git a/dom/media/webrtc/tests/mochitests/testLegacyEnumerateDevices.js b/dom/media/webrtc/tests/mochitests/testLegacyEnumerateDevices.js index de51fdea6a74..3143921b8bc8 100644 --- a/dom/media/webrtc/tests/mochitests/testLegacyEnumerateDevices.js +++ b/dom/media/webrtc/tests/mochitests/testLegacyEnumerateDevices.js @@ -161,5 +161,6 @@ async function testLegacyEnumerateDevices() { ["media.video_loopback_dev", "none"] ); devices = await navigator.mediaDevices.enumerateDevices(); + devices = devices.filter(({ kind }) => kind != "audiooutput"); is(devices.length, 0, "No devices"); } diff --git a/dom/media/webrtc/tests/mochitests/test_enumerateDevices.html b/dom/media/webrtc/tests/mochitests/test_enumerateDevices.html index 48bec0006a48..617fd2c403f4 100644 --- a/dom/media/webrtc/tests/mochitests/test_enumerateDevices.html +++ b/dom/media/webrtc/tests/mochitests/test_enumerateDevices.html @@ -133,6 +133,7 @@ runTest(async () => { ["media.audio_loopback_dev", "none"], ["media.video_loopback_dev", "none"]); devices = await navigator.mediaDevices.enumerateDevices(); + devices = devices.filter(({kind}) => kind != "audiooutput"); is(devices.length, 0, "No devices"); }); diff --git a/dom/media/webrtc/tests/mochitests/test_fingerprinting_resistance.html b/dom/media/webrtc/tests/mochitests/test_fingerprinting_resistance.html index 7e9cd5a21997..ebe27800697d 100644 --- a/dom/media/webrtc/tests/mochitests/test_fingerprinting_resistance.html +++ b/dom/media/webrtc/tests/mochitests/test_fingerprinting_resistance.html @@ -8,16 +8,20 @@ - - + +