diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index d989563b805..a3fefcfd2fa 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1257,7 +1257,9 @@ static auto& MediaManager_AnonymizeDevices = MediaManager::AnonymizeDevices; */ already_AddRefed -MediaManager::EnumerateRawDevices(uint64_t aWindowId, MediaSourceEnum aVideoType, +MediaManager::EnumerateRawDevices(uint64_t aWindowId, + MediaSourceEnum aVideoType, + MediaSourceEnum aAudioType, bool aFake, bool aFakeTracks) { MOZ_ASSERT(NS_IsMainThread()); @@ -1287,7 +1289,8 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId, MediaSourceEnum aVideoType MediaManager::PostTask(FROM_HERE, NewTaskFrom([id, aWindowId, audioLoopDev, videoLoopDev, aVideoType, - aFake, aFakeTracks]() mutable { + aAudioType, aFake, + aFakeTracks]() mutable { nsRefPtr backend; if (aFake) { backend = new MediaEngineDefault(aFakeTracks); @@ -1306,7 +1309,7 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId, MediaSourceEnum aVideoType } nsTArray> audios; - GetSources(backend, dom::MediaSourceEnum::Microphone, + GetSources(backend, aAudioType, &MediaEngine::EnumerateAudioDevices, audios, audioLoopDev); for (auto& source : audios) { result->AppendElement(source); @@ -1628,6 +1631,7 @@ MediaManager::GetUserMedia(nsPIDOMWindow* aWindow, } MediaSourceEnum videoType = dom::MediaSourceEnum::Camera; + MediaSourceEnum audioType = dom::MediaSourceEnum::Microphone; if (c.mVideo.IsMediaTrackConstraints()) { auto& vc = c.mVideo.GetAsMediaTrackConstraints(); @@ -1716,6 +1720,23 @@ MediaManager::GetUserMedia(nsPIDOMWindow* aWindow, privileged = false; } } + + if (c.mAudio.IsMediaTrackConstraints()) { + auto& ac = c.mAudio.GetAsMediaTrackConstraints(); + audioType = StringToEnum(dom::MediaSourceEnumValues::strings, + ac.mMediaSource, + audioType); + // Only enable AudioCapture if the pref is enabled. If it's not, we can deny + // right away. + if (audioType == dom::MediaSourceEnum::AudioCapture && + !Preferences::GetBool("media.getusermedia.audiocapture.enabled")) { + nsRefPtr error = + new MediaStreamError(aWindow, + NS_LITERAL_STRING("PermissionDeniedError")); + onFailure->OnError(error); + return NS_OK; + } + } StreamListeners* listeners = AddWindowID(windowID); // Create a disabled listener to act as a placeholder @@ -1778,7 +1799,8 @@ MediaManager::GetUserMedia(nsPIDOMWindow* aWindow, (!fake || Preferences::GetBool("media.navigator.permission.fake")); nsRefPtr p = EnumerateDevicesImpl(windowID, videoType, - fake, fakeTracks); + audioType, fake, + fakeTracks); p->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission, prefs, isHTTPS, callID, origin](SourceSet*& aDevices) mutable { ScopedDeletePtr devices(aDevices); // grab result @@ -1934,7 +1956,9 @@ MediaManager::ToJSArray(SourceSet& aDevices) } already_AddRefed -MediaManager::EnumerateDevicesImpl(uint64_t aWindowId, MediaSourceEnum aVideoType, +MediaManager::EnumerateDevicesImpl(uint64_t aWindowId, + MediaSourceEnum aVideoType, + MediaSourceEnum aAudioType, bool aFake, bool aFakeTracks) { MOZ_ASSERT(NS_IsMainThread()); @@ -1963,12 +1987,13 @@ MediaManager::EnumerateDevicesImpl(uint64_t aWindowId, MediaSourceEnum aVideoTyp nsRefPtr> p = media::GetOriginKey(origin, privateBrowsing, persist); - p->Then([id, aWindowId, aVideoType, + p->Then([id, aWindowId, aVideoType, aAudioType, aFake, aFakeTracks](const nsCString& aOriginKey) mutable { MOZ_ASSERT(NS_IsMainThread()); nsRefPtr mgr = MediaManager_GetInstance(); - nsRefPtr p = mgr->EnumerateRawDevices(aWindowId, aVideoType, + nsRefPtr p = mgr->EnumerateRawDevices(aWindowId, + aVideoType, aAudioType, aFake, aFakeTracks); p->Then([id, aWindowId, aOriginKey](SourceSet*& aDevices) mutable { ScopedDeletePtr devices(aDevices); // secondary result @@ -2007,6 +2032,7 @@ MediaManager::EnumerateDevices(nsPIDOMWindow* aWindow, nsRefPtr p = EnumerateDevicesImpl(windowId, dom::MediaSourceEnum::Camera, + dom::MediaSourceEnum::Microphone, fake); p->Then([onSuccess](SourceSet*& aDevices) mutable { ScopedDeletePtr devices(aDevices); // grab result diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index 68ab7426920..d35f4bf40ec 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -597,10 +597,14 @@ public: // TODO: make private once we upgrade to GCC 4.8+ on linux. static already_AddRefed ToJSArray(SourceSet& aDevices); private: already_AddRefed - EnumerateRawDevices(uint64_t aWindowId, dom::MediaSourceEnum aSrcType, + EnumerateRawDevices(uint64_t aWindowId, + dom::MediaSourceEnum aVideoType, + dom::MediaSourceEnum aAudioType, bool aFake, bool aFakeTracks); already_AddRefed - EnumerateDevicesImpl(uint64_t aWindowId, dom::MediaSourceEnum aSrcType, + EnumerateDevicesImpl(uint64_t aWindowId, + dom::MediaSourceEnum aVideoSrcType, + dom::MediaSourceEnum aAudioSrcType, bool aFake = false, bool aFakeTracks = false); StreamListeners* AddWindowID(uint64_t aWindowId); diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index 223a5acde76..c45beae4ce2 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -268,7 +268,7 @@ MediaEngineWebRTCMicrophoneSource::Config(bool aEchoOn, uint32_t aEcho, // Infinity = UINT32_MAX e.g. device cannot satisfy accumulated ConstraintSets. // A finite result may be used to calculate this device's ranking as a choice. -uint32_t MediaEngineWebRTCAudioSource::GetBestFitnessDistance( +uint32_t MediaEngineWebRTCMicrophoneSource::GetBestFitnessDistance( const nsTArray& aConstraintSets, const nsString& aDeviceId) { diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index fbbab15fb33..576b7680a6a 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -445,6 +445,8 @@ pref("media.getusermedia.screensharing.allowed_domains", "mozilla.github.io,webe // OS/X 10.6 and XP have screen/window sharing off by default due to various issues - Caveat emptor pref("media.getusermedia.screensharing.allow_on_old_platforms", false); +pref("media.getusermedia.audiocapture.enabled", false); + // TextTrack support pref("media.webvtt.enabled", true); pref("media.webvtt.regions.enabled", false);