From ec3cfdec9c51db4783a0db90c5e9b7e5df9907d0 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Mon, 10 Aug 2015 12:16:30 -0400 Subject: [PATCH] Bug 1191298 - don't fail on unknown audio constraints e.g. getUserMedia({ audio: {} }) (regression) r=jesup --- dom/media/MediaManager.cpp | 57 +++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index d88fe5d1cce7..84e51e1d1942 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1690,11 +1690,11 @@ MediaManager::GetUserMedia(nsPIDOMWindow* aWindow, } if (vc.mAdvanced.WasPassed() && videoType != dom::MediaSourceEnum::Camera) { - // iterate through advanced, forcing mediaSource to match "root" - const char *camera = EnumToASCII(dom::MediaSourceEnumValues::strings, - dom::MediaSourceEnum::Camera); + // iterate through advanced, forcing all unset mediaSources to match "root" + const char *unset = EnumToASCII(dom::MediaSourceEnumValues::strings, + dom::MediaSourceEnum::Camera); for (MediaTrackConstraintSet& cs : vc.mAdvanced.Value()) { - if (cs.mMediaSource.EqualsASCII(camera)) { + if (cs.mMediaSource.EqualsASCII(unset)) { cs.mMediaSource = vc.mMediaSource; } } @@ -1729,15 +1729,46 @@ MediaManager::GetUserMedia(nsPIDOMWindow* aWindow, 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; + // Work around WebIDL default since spec uses same dictionary w/audio & video. + if (audioType == dom::MediaSourceEnum::Camera) { + audioType = dom::MediaSourceEnum::Microphone; + ac.mMediaSource.AssignASCII(EnumToASCII(dom::MediaSourceEnumValues::strings, + audioType)); + } + + switch (audioType) { + case dom::MediaSourceEnum::Microphone: + break; + + case dom::MediaSourceEnum::AudioCapture: + // Only enable AudioCapture if the pref is enabled. If it's not, we can + // deny right away. + if (!Preferences::GetBool("media.getusermedia.audiocapture.enabled")) { + nsRefPtr error = + new MediaStreamError(aWindow, + NS_LITERAL_STRING("PermissionDeniedError")); + onFailure->OnError(error); + return NS_OK; + } + break; + + case dom::MediaSourceEnum::Other: + default: { + nsRefPtr error = + new MediaStreamError(aWindow, NS_LITERAL_STRING("NotFoundError")); + onFailure->OnError(error); + return NS_OK; + } + } + if (ac.mAdvanced.WasPassed()) { + // iterate through advanced, forcing all unset mediaSources to match "root" + const char *unset = EnumToASCII(dom::MediaSourceEnumValues::strings, + dom::MediaSourceEnum::Camera); + for (MediaTrackConstraintSet& cs : ac.mAdvanced.Value()) { + if (cs.mMediaSource.EqualsASCII(unset)) { + cs.mMediaSource = ac.mMediaSource; + } + } } } StreamListeners* listeners = AddWindowID(windowID);