Bug 1191298 - don't fail on unknown audio constraints e.g. getUserMedia({ audio: {} }) (regression) r=jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 10 Aug 2015 12:16:30 -0400
changeset 289964 0a170e64625c2d06c62b829352f0eece1455a0a5
parent 289963 1ab28b01bb215c71c762644ca999f7d4c6cc7cba
child 289965 5d44c5c1195c8f8880f3d76e03576f35dc1b78d6
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1191298
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1191298 - don't fail on unknown audio constraints e.g. getUserMedia({ audio: {} }) (regression) r=jesup
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1685,21 +1685,21 @@ MediaManager::GetUserMedia(nsPIDOMWindow
         nsRefPtr<MediaStreamError> error =
             new MediaStreamError(aWindow, NS_LITERAL_STRING("NotFoundError"));
         onFailure->OnError(error);
         return NS_OK;
       }
     }
 
     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;
         }
       }
     }
     if (!privileged) {
       // only allow privileged content to set the window id
       if (vc.mBrowserWindow.WasPassed()) {
         vc.mBrowserWindow.Value() = -1;
@@ -1724,25 +1724,56 @@ MediaManager::GetUserMedia(nsPIDOMWindow
     }
   }
 
   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<MediaStreamError> 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<MediaStreamError> error =
+            new MediaStreamError(aWindow,
+                                 NS_LITERAL_STRING("PermissionDeniedError"));
+          onFailure->OnError(error);
+          return NS_OK;
+        }
+        break;
+
+      case dom::MediaSourceEnum::Other:
+      default: {
+        nsRefPtr<MediaStreamError> 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);
 
   // Create a disabled listener to act as a placeholder
   nsRefPtr<GetUserMediaCallbackMediaStreamListener> listener =
     new GetUserMediaCallbackMediaStreamListener(mMediaThread, windowID);