diff --git a/dom/media/MediaDevices.cpp b/dom/media/MediaDevices.cpp index d2f679902f47..21cedc3cf439 100644 --- a/dom/media/MediaDevices.cpp +++ b/dom/media/MediaDevices.cpp @@ -200,15 +200,18 @@ void MediaDevices::MaybeResumeDeviceExposure() { return; } } + bool shouldResistFingerprinting = + window->AsGlobal()->ShouldResistFingerprinting(RFPTarget::MediaDevices); MediaManager::Get()->GetPhysicalDevices()->Then( GetCurrentSerialEventTarget(), __func__, [self = RefPtr(this), this, haveDeviceListChange = mHaveUnprocessedDeviceListChange, - enumerateDevicesPromises = std::move(mPendingEnumerateDevicesPromises)]( + enumerateDevicesPromises = std::move(mPendingEnumerateDevicesPromises), + shouldResistFingerprinting]( RefPtr aAllDevices) mutable { RefPtr exposedDevices = FilterExposedDevices(*aAllDevices); - if (haveDeviceListChange) { + if (haveDeviceListChange && !shouldResistFingerprinting) { if (ShouldQueueDeviceChange(*exposedDevices)) { NS_DispatchToCurrentThread(NS_NewRunnableFunction( "devicechange", [self = RefPtr(this), this] { @@ -762,28 +765,6 @@ void MediaDevices::OnDeviceChange() { return; } - // Do not fire event to content script when - // privacy.resistFingerprinting is true. - - if (nsContentUtils::ShouldResistFingerprinting( - "Guarding the more expensive RFP check with a simple one", - RFPTarget::MediaDevices)) { - nsCOMPtr window = GetOwnerWindow(); - auto* wrapper = GetWrapper(); - if (!window && wrapper) { - nsCOMPtr global = xpc::NativeGlobal(wrapper); - window = do_QueryInterface(global); - } - if (!window) { - return; - } - - if (nsGlobalWindowInner::Cast(window)->ShouldResistFingerprinting( - RFPTarget::MediaDevices)) { - return; - } - } - mHaveUnprocessedDeviceListChange = true; MaybeResumeDeviceExposure(); } diff --git a/dom/media/webrtc/tests/mochitests/mochitest.toml b/dom/media/webrtc/tests/mochitests/mochitest.toml index cf6381c63c26..7f7a68495f9c 100644 --- a/dom/media/webrtc/tests/mochitests/mochitest.toml +++ b/dom/media/webrtc/tests/mochitests/mochitest.toml @@ -83,3 +83,6 @@ skip-if = ["os != 'linux'"] # the only platform with real devices ["test_setSinkId_preMutedElement.html"] ["test_unfocused_pref.html"] + +["test_ondevicechange_resistfingerprinting.html"] +run-sequentially = "sets prefs that may disrupt other tests" diff --git a/dom/media/webrtc/tests/mochitests/test_ondevicechange_resistfingerprinting.html b/dom/media/webrtc/tests/mochitests/test_ondevicechange_resistfingerprinting.html new file mode 100644 index 000000000000..a9cec3b74a5e --- /dev/null +++ b/dom/media/webrtc/tests/mochitests/test_ondevicechange_resistfingerprinting.html @@ -0,0 +1,98 @@ + + + + + + + + + +