From 5f190b63fffd941a8785b7830d28efe846032468 Mon Sep 17 00:00:00 2001 From: Coroiu Cristina Date: Thu, 5 Sep 2019 20:00:26 +0300 Subject: [PATCH] Backed out 2 changesets (bug 1548087) for wpt failures at audio-output/setSinkId.https.html on a CLOSED TREE Backed out changeset 6f9782261d63 (bug 1548087) Backed out changeset 044e224f7011 (bug 1548087) --- dom/media/MediaDevices.cpp | 7 +- dom/media/MediaManager.cpp | 65 ++++++------------- .../mochitest/test_enumerateDevices.html | 4 +- ...erateDevices-not-allowed-camera.https.html | 30 --------- ...ices-not-allowed-camera.https.html.headers | 1 - ...numerateDevices-not-allowed-mic.https.html | 30 --------- ...Devices-not-allowed-mic.https.html.headers | 1 - .../MediaDevices-enumerateDevices.https.html | 30 ++++----- 8 files changed, 39 insertions(+), 129 deletions(-) delete mode 100644 testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-camera.https.html delete mode 100644 testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-camera.https.html.headers delete mode 100644 testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-mic.https.html delete mode 100644 testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-mic.https.html.headers diff --git a/dom/media/MediaDevices.cpp b/dom/media/MediaDevices.cpp index 5dfeec0d431a..7ea89b3448f6 100644 --- a/dom/media/MediaDevices.cpp +++ b/dom/media/MediaDevices.cpp @@ -142,10 +142,6 @@ already_AddRefed MediaDevices::EnumerateDevices(CallerType aCallerType, } auto windowId = window->WindowID(); nsTArray> infos; - bool allowLabel = - aDevices->Length() == 0 || - MediaManager::Get()->IsActivelyCapturingOrHasAPermission( - windowId); for (auto& device : *aDevices) { MOZ_ASSERT(device->mKind == dom::MediaDeviceKind::Audioinput || device->mKind == dom::MediaDeviceKind::Videoinput || @@ -153,7 +149,8 @@ already_AddRefed MediaDevices::EnumerateDevices(CallerType aCallerType, // Include name only if page currently has a gUM stream active // or persistent permissions (audio or video) have been granted nsString label; - if (allowLabel || + if (MediaManager::Get()->IsActivelyCapturingOrHasAPermission( + windowId) || Preferences::GetBool("media.navigator.permission.disabled", false)) { label = device->mName; diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 8c54ab8100e6..226d776e79f8 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -3161,10 +3161,8 @@ RefPtr MediaManager::EnumerateDevices( __func__); } uint64_t windowId = aWindow->WindowID(); - Document* doc = aWindow->GetExtantDoc(); - MOZ_ASSERT(doc); - nsIPrincipal* principal = doc->NodePrincipal(); + nsIPrincipal* principal = aWindow->GetExtantDoc()->NodePrincipal(); RefPtr windowListener = GetWindowListener(windowId); @@ -3185,30 +3183,8 @@ RefPtr MediaManager::EnumerateDevices( DeviceEnumerationType videoEnumerationType = DeviceEnumerationType::Normal; DeviceEnumerationType audioEnumerationType = DeviceEnumerationType::Normal; - - // Only expose devices which are allowed to use: - // https://w3c.github.io/mediacapture-main/#dom-mediadevices-enumeratedevices - MediaSourceEnum videoType = dom::FeaturePolicyUtils::IsFeatureAllowed( - doc, NS_LITERAL_STRING("camera")) - ? MediaSourceEnum::Camera - : MediaSourceEnum::Other; - MediaSourceEnum audioType = dom::FeaturePolicyUtils::IsFeatureAllowed( - doc, NS_LITERAL_STRING("microphone")) - ? MediaSourceEnum::Microphone - : MediaSourceEnum::Other; - - auto devices = MakeRefPtr(); - MediaSinkEnum audioOutputType = MediaSinkEnum::Other; - // TODO bug Bug 1577199 we don't seem to support the "speaker" feature policy - // yet. - if (Preferences::GetBool("media.setsinkid.enabled")) { - audioOutputType = MediaSinkEnum::Speaker; - } else if (audioType == MediaSourceEnum::Other && - videoType == MediaSourceEnum::Other) { - return DevicesPromise::CreateAndResolve(devices, __func__); - } - bool resistFingerprinting = nsContentUtils::ResistFingerprinting(aCallerType); + // In order of precedence: resist fingerprinting > loopback > fake pref if (resistFingerprinting) { videoEnumerationType = DeviceEnumerationType::Fake; @@ -3218,29 +3194,30 @@ RefPtr MediaManager::EnumerateDevices( nsAutoCString videoLoopDev, audioLoopDev; bool wantFakes = Preferences::GetBool("media.navigator.streams.fake"); // Video - if (videoType == MediaSourceEnum::Camera) { - Preferences::GetCString("media.video_loopback_dev", videoLoopDev); - // Loopback prefs take precedence over fake prefs - if (!videoLoopDev.IsEmpty()) { - videoEnumerationType = DeviceEnumerationType::Loopback; - } else if (wantFakes) { - videoEnumerationType = DeviceEnumerationType::Fake; - } + Preferences::GetCString("media.video_loopback_dev", videoLoopDev); + // Loopback prefs take precedence over fake prefs + if (!videoLoopDev.IsEmpty()) { + videoEnumerationType = DeviceEnumerationType::Loopback; + } else if (wantFakes) { + videoEnumerationType = DeviceEnumerationType::Fake; } - // Audio - if (audioType == MediaSourceEnum::Microphone) { - Preferences::GetCString("media.audio_loopback_dev", audioLoopDev); - // Loopback prefs take precedence over fake prefs - if (!audioLoopDev.IsEmpty()) { - audioEnumerationType = DeviceEnumerationType::Loopback; - } else if (wantFakes) { - audioEnumerationType = DeviceEnumerationType::Fake; - } + Preferences::GetCString("media.audio_loopback_dev", audioLoopDev); + // Loopback prefs take precedence over fake prefs + if (!audioLoopDev.IsEmpty()) { + audioEnumerationType = DeviceEnumerationType::Loopback; + } else if (wantFakes) { + audioEnumerationType = DeviceEnumerationType::Fake; } } - return EnumerateDevicesImpl(windowId, videoType, audioType, audioOutputType, + MediaSinkEnum audioOutputType = MediaSinkEnum::Other; + if (Preferences::GetBool("media.setsinkid.enabled")) { + audioOutputType = MediaSinkEnum::Speaker; + } + auto devices = MakeRefPtr(); + return EnumerateDevicesImpl(windowId, MediaSourceEnum::Camera, + MediaSourceEnum::Microphone, audioOutputType, videoEnumerationType, audioEnumerationType, false, devices) ->Then( diff --git a/dom/media/tests/mochitest/test_enumerateDevices.html b/dom/media/tests/mochitest/test_enumerateDevices.html index b8d70ebbe102..9fc94d1aa3d5 100644 --- a/dom/media/tests/mochitest/test_enumerateDevices.html +++ b/dom/media/tests/mochitest/test_enumerateDevices.html @@ -106,9 +106,7 @@ runTest(async () => { let [sameOriginDevices, differentOriginDevices] = origins.map(o => devicesMap.get(o)); is(sameOriginDevices.length, devices.length); - // Camera and microphone are allowed for documents that are same-origin by - // default. - is(differentOriginDevices.length, 0); + is(differentOriginDevices.length, devices.length); [...sameOriginDevices, ...differentOriginDevices].forEach(d => validateDevice(d)); for (let device of sameOriginDevices) { diff --git a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-camera.https.html b/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-camera.https.html deleted file mode 100644 index 1bb086dadddd..000000000000 --- a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-camera.https.html +++ /dev/null @@ -1,30 +0,0 @@ - - - -enumerateDevices: test enumerateDevices should not expose camera devices if they are not allowed to use - - - - -

Description

-

This test checks for the presence of camera in -navigator.mediaDevices.enumerateDevices() method.

-
- - - - - diff --git a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-camera.https.html.headers b/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-camera.https.html.headers deleted file mode 100644 index 2adc5e237fce..000000000000 --- a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-camera.https.html.headers +++ /dev/null @@ -1 +0,0 @@ -Feature-Policy: camera 'none' diff --git a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-mic.https.html b/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-mic.https.html deleted file mode 100644 index 8d535ce551de..000000000000 --- a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-mic.https.html +++ /dev/null @@ -1,30 +0,0 @@ - - - -enumerateDevices: test enumerateDevices should not expose microphone devices if they are not allowed to use - - - - -

Description

-

This test checks for the presence of microphone in -navigator.mediaDevices.enumerateDevices() method.

-
- - - - - diff --git a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-mic.https.html.headers b/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-mic.https.html.headers deleted file mode 100644 index a86e0a077851..000000000000 --- a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices-not-allowed-mic.https.html.headers +++ /dev/null @@ -1 +0,0 @@ -Feature-Policy: microphone 'none' diff --git a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html b/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html index efb460731690..76ca435cf588 100644 --- a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html +++ b/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html @@ -17,26 +17,26 @@ "use strict"; //NOTE ALEX: for completion, a test for ondevicechange event is missing. promise_test(async () => { - assert_not_equals(navigator.mediaDevices.enumerateDevices, undefined, "navigator.mediaDevices.enumerateDevices exists"); - const deviceList = await navigator.mediaDevices.enumerateDevices(); - for (const mediaInfo of deviceList) { - assert_not_equals(mediaInfo.deviceId, undefined, "mediaInfo's deviceId should exist."); - assert_not_equals(mediaInfo.kind, undefined, "mediaInfo's kind should exist."); - assert_not_equals(mediaInfo.label, undefined, "mediaInfo's label should exist."); - assert_not_equals(mediaInfo.groupId, undefined, "mediaInfo's groupId should exist."); - assert_in_array(mediaInfo.kind, ["videoinput", "audioinput", "audiooutput"]); + assert_true(undefined !== navigator.mediaDevices.enumerateDevices, "navigator.mediaDevices.enumerateDevices exists"); + const device_list = await navigator.mediaDevices.enumerateDevices(); + for (const mediainfo of device_list) { + assert_true(undefined !== mediainfo.deviceId, "mediaInfo's deviceId should exist."); + assert_true(undefined !== mediainfo.kind, "mediaInfo's kind should exist."); + assert_in_array(mediainfo.kind, ["videoinput", "audioinput", "audiooutput"]); + assert_true(undefined !== mediainfo.label, "mediaInfo's label should exist."); + assert_true(undefined !== mediainfo.groupId, "mediaInfo's groupId should exist."); } }, "mediaDevices.enumerateDevices() is present and working"); promise_test(async () => { - const deviceList = await navigator.mediaDevices.enumerateDevices(); - for (const mediaInfo of deviceList) { - if (mediaInfo.kind == "audioinput" || mediaInfo.kind == "videoinput") { - assert_true(mediaInfo instanceof InputDeviceInfo); - } else if ( mediaInfo.kind == "audiooutput" ) { - assert_true(mediaInfo instanceof MediaDeviceInfo); + const device_list = await navigator.mediaDevices.enumerateDevices(); + for (const mediainfo of device_list) { + if (mediainfo.kind == "audioinput" || mediainfo.kind == "videoinput") { + assert_true(mediainfo instanceof InputDeviceInfo); + } else if ( mediainfo.kind == "audiooutput" ) { + assert_true(mediainfo instanceof MediaDeviceInfo); } else { - assert_unreached("mediaInfo.kind should be one of 'audioinput', 'videoinput', or 'audiooutput'.") + assert_unreached("mediainfo.kind should be one of 'audioinput', 'videoinput', or 'audiooutput'.") } } }, "InputDeviceInfo is supported");