From d72a96de1f3a07cd2fc1767762f9e729747db8f7 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Wed, 2 Jan 2019 16:44:35 +0000 Subject: [PATCH] Bug 1450762 - Don't prompt for device permissions on Android in MediaDevices.enumerateDevices() r=achronop Differential Revision: https://phabricator.services.mozilla.com/D14575 --HG-- extra : moz-landing-system : lando --- dom/media/MediaManager.cpp | 21 ++++++++++--------- dom/media/MediaManager.h | 4 ++-- .../geckoview/test/PermissionDelegateTest.kt | 13 ------------ 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 7d201389013f..d904fe9a36c6 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1772,7 +1772,7 @@ RefPtr MediaManager::EnumerateRawDevices( uint64_t aWindowId, MediaSourceEnum aVideoInputType, MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType, DeviceEnumerationType aVideoInputEnumType, - DeviceEnumerationType aAudioInputEnumType, + DeviceEnumerationType aAudioInputEnumType, bool aForceNoPermRequest, const RefPtr& aOutDevices) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aVideoInputType != MediaSourceEnum::Other || @@ -1879,7 +1879,7 @@ RefPtr MediaManager::EnumerateRawDevices( holder->Resolve(false, __func__); }); - if (realDeviceRequested && + if (realDeviceRequested && aForceNoPermRequest && Preferences::GetBool("media.navigator.permission.device", false)) { // Need to ask permission to retrieve list of all devices; // notify frontend observer and wait for callback notification to post task. @@ -2198,7 +2198,7 @@ void MediaManager::OnDeviceChange() { self->EnumerateRawDevices( 0, MediaSourceEnum::Camera, MediaSourceEnum::Microphone, MediaSinkEnum::Speaker, DeviceEnumerationType::Normal, - DeviceEnumerationType::Normal, devices) + DeviceEnumerationType::Normal, false, devices) ->Then(GetCurrentThreadSerialEventTarget(), __func__, [self, devices](bool) { if (!MediaManager::GetIfExists()) { @@ -2741,7 +2741,7 @@ RefPtr MediaManager::GetUserMedia( auto devices = MakeRefPtr(); return EnumerateDevicesImpl(windowID, videoType, audioType, MediaSinkEnum::Other, videoEnumerationType, - audioEnumerationType, devices) + audioEnumerationType, true, devices) ->Then( GetCurrentThreadSerialEventTarget(), __func__, [self, windowID, c, windowListener, isChrome, devices](bool) { @@ -3059,7 +3059,7 @@ RefPtr MediaManager::EnumerateDevicesImpl( uint64_t aWindowId, MediaSourceEnum aVideoInputType, MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType, DeviceEnumerationType aVideoInputEnumType, - DeviceEnumerationType aAudioInputEnumType, + DeviceEnumerationType aAudioInputEnumType, bool aForceNoPermRequest, const RefPtr& aOutDevices) { MOZ_ASSERT(NS_IsMainThread()); @@ -3101,8 +3101,8 @@ RefPtr MediaManager::EnumerateDevicesImpl( ->Then( GetMainThreadSerialEventTarget(), __func__, [aWindowId, aVideoInputType, aAudioInputType, aAudioOutputType, - aVideoInputEnumType, aAudioInputEnumType, aOutDevices, - originKey](const nsCString& aOriginKey) { + aVideoInputEnumType, aAudioInputEnumType, aForceNoPermRequest, + aOutDevices, originKey](const nsCString& aOriginKey) { MOZ_ASSERT(NS_IsMainThread()); originKey->Assign(aOriginKey); MediaManager* mgr = MediaManager::GetIfExists(); @@ -3114,7 +3114,8 @@ RefPtr MediaManager::EnumerateDevicesImpl( } return mgr->EnumerateRawDevices( aWindowId, aVideoInputType, aAudioInputType, aAudioOutputType, - aVideoInputEnumType, aAudioInputEnumType, aOutDevices); + aVideoInputEnumType, aAudioInputEnumType, aForceNoPermRequest, + aOutDevices); }, [](nsresult rs) { NS_WARNING( @@ -3232,7 +3233,7 @@ RefPtr MediaManager::EnumerateDevices( auto devices = MakeRefPtr(); return EnumerateDevicesImpl(windowId, MediaSourceEnum::Camera, MediaSourceEnum::Microphone, audioOutputType, - videoEnumerationType, audioEnumerationType, + videoEnumerationType, audioEnumerationType, false, devices) ->Then(GetCurrentThreadSerialEventTarget(), __func__, [windowListener, sourceListener, devices](bool) { @@ -3281,7 +3282,7 @@ RefPtr MediaManager::GetSinkDevice(nsPIDOMWindowInner* aWindow, return EnumerateDevicesImpl(aWindow->WindowID(), MediaSourceEnum::Other, MediaSourceEnum::Other, MediaSinkEnum::Speaker, DeviceEnumerationType::Normal, - DeviceEnumerationType::Normal, devices) + DeviceEnumerationType::Normal, true, devices) ->Then(GetCurrentThreadSerialEventTarget(), __func__, [aDeviceId, isSecure, devices](bool) { for (RefPtr& device : *devices) { diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index fbca5a63285d..639f159ac11d 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -291,14 +291,14 @@ class MediaManager final : public nsIMediaManagerService, uint64_t aWindowId, dom::MediaSourceEnum aVideoInputType, dom::MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType, DeviceEnumerationType aVideoInputEnumType, - DeviceEnumerationType aAudioInputEnumType, + DeviceEnumerationType aAudioInputEnumType, bool aForceNoPermRequest, const RefPtr& aOutDevices); RefPtr EnumerateDevicesImpl( uint64_t aWindowId, dom::MediaSourceEnum aVideoInputType, dom::MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType, DeviceEnumerationType aVideoInputEnumType, - DeviceEnumerationType aAudioInputEnumType, + DeviceEnumerationType aAudioInputEnumType, bool aForceNoPermRequest, const RefPtr& aOutDevices); RefPtr SelectSettings( diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt index 16ae1073239b..6053e1433a2f 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt @@ -50,19 +50,6 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadTestPath(HELLO_HTML_PATH) mainSession.waitForPageStop() - - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { - @AssertCalled(count = 1) - override fun onAndroidPermissionsRequest( - session: GeckoSession, permissions: Array?, - callback: GeckoSession.PermissionDelegate.Callback) { - assertThat("Permissions list should be correct", - listOf(*permissions!!), hasItems(Manifest.permission.CAMERA, - Manifest.permission.RECORD_AUDIO)) - callback.grant() - } - }) - val devices = mainSession.waitForJS( "window.navigator.mediaDevices.enumerateDevices()")