Bug 835892 - Provide No Video & No Audio options when both camera and microphone access are requested. r=gavin
authorDão Gottwald <dao@mozilla.com>
Tue, 29 Jan 2013 23:16:04 +0100
changeset 130166 b8dcf873cfa15cb2e18e16c450256bea59f1c3e4
parent 130165 3eb633a97c1f5318eb4f402ab93368d30fac31d1
child 130167 08326e6cba1fdbab2b822c0f669661db69a7d97f
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs835892
milestone21.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 835892 - Provide No Video & No Audio options when both camera and microphone access are requested. r=gavin
browser/locales/en-US/chrome/browser/browser.properties
browser/modules/webrtcUI.jsm
--- a/browser/locales/en-US/chrome/browser/browser.properties
+++ b/browser/locales/en-US/chrome/browser/browser.properties
@@ -421,15 +421,17 @@ identity.loggedIn.signOut.accessKey = O
 # LOCALIZATION NOTE (getUserMedia.shareCamera.message, getUserMedia.shareMicrophone.message, getUserMedia.shareCameraAndMicrophone.message, getUserMedia.sharingCamera.message, getUserMedia.sharingMicrophone.message, getUserMedia.sharingCameraAndMicrophone.message): %S is the website origin (e.g. www.mozilla.org)
 # LOCALIZATION NOTE (getUserMedia.shareSelectedDevices.label):
 # Semi-colon list of plural forms. See:
 # http://developer.mozilla.org/en/docs/Localization_and_Plurals
 # The number of devices can be either one or two.
 getUserMedia.shareCamera.message = Would you like to share your camera with %S?
 getUserMedia.shareMicrophone.message = Would you like to share your microphone with %S?
 getUserMedia.shareCameraAndMicrophone.message = Would you like to share your camera and microphone with %S?
+getUserMedia.noVideo.label = No Video
+getUserMedia.noAudio.label = No Audio
 getUserMedia.shareSelectedDevices.label = Share Selected Device;Share Selected Devices
 getUserMedia.shareSelectedDevices.accesskey = S
 getUserMedia.denyRequest.label = Don't Share
 getUserMedia.denyRequest.accesskey = D
 getUserMedia.sharingCamera.message = You are currently sharing your camera with %S.
 getUserMedia.sharingMicrophone.message = You are currently sharing your microphone with %S.
 getUserMedia.sharingCameraAndMicrophone.message = You are currently sharing your camera and microphone with %S.
--- a/browser/modules/webrtcUI.jsm
+++ b/browser/modules/webrtcUI.jsm
@@ -113,45 +113,64 @@ function prompt(aBrowser, aCallID, aAudi
                                                 [ host ]);
 
   function listDevices(menupopup, devices) {
     while (menupopup.lastChild)
       menupopup.removeChild(menupopup.lastChild);
 
     let deviceIndex = 0;
     for (let device of devices) {
-      let menuitem = chromeDoc.createElement("menuitem");
-      menuitem.setAttribute("value", deviceIndex);
-      menuitem.setAttribute("label", device.name);
-      menuitem.setAttribute("tooltiptext", device.name);
-      menupopup.appendChild(menuitem);
+      addDeviceToList(menupopup, device.name, deviceIndex);
       deviceIndex++;
     }
   }
 
+  function addDeviceToList(menupopup, deviceName, deviceIndex) {
+    let menuitem = chromeDoc.createElement("menuitem");
+    menuitem.setAttribute("value", deviceIndex);
+    menuitem.setAttribute("label", deviceName);
+    menuitem.setAttribute("tooltiptext", deviceName);
+    menupopup.appendChild(menuitem);
+  }
+
   chromeDoc.getElementById("webRTC-selectCamera").hidden = !videoDevices.length;
   chromeDoc.getElementById("webRTC-selectMicrophone").hidden = !audioDevices.length;
-  listDevices(chromeDoc.getElementById("webRTC-selectCamera-menupopup"), videoDevices);
-  listDevices(chromeDoc.getElementById("webRTC-selectMicrophone-menupopup"), audioDevices);
+
+  let camMenupopup = chromeDoc.getElementById("webRTC-selectCamera-menupopup");
+  let micMenupopup = chromeDoc.getElementById("webRTC-selectMicrophone-menupopup");
+  listDevices(camMenupopup, videoDevices);
+  listDevices(micMenupopup, audioDevices);
+  if (requestType == "CameraAndMicrophone") {
+    addDeviceToList(camMenupopup, stringBundle.getString("getUserMedia.noVideo.label"), "-1");
+    addDeviceToList(micMenupopup, stringBundle.getString("getUserMedia.noAudio.label"), "-1");
+  }
 
   let mainAction = {
     label: PluralForm.get(requestType == "CameraAndMicrophone" ? 2 : 1,
                           stringBundle.getString("getUserMedia.shareSelectedDevices.label")),
     accessKey: stringBundle.getString("getUserMedia.shareSelectedDevices.accesskey"),
     callback: function () {
       let allowedDevices = Cc["@mozilla.org/supports-array;1"]
                              .createInstance(Ci.nsISupportsArray);
       if (videoDevices.length) {
         let videoDeviceIndex = chromeDoc.getElementById("webRTC-selectCamera-menulist").value;
-        allowedDevices.AppendElement(videoDevices[videoDeviceIndex]);
+        if (videoDeviceIndex != "-1")
+          allowedDevices.AppendElement(videoDevices[videoDeviceIndex]);
       }
       if (audioDevices.length) {
         let audioDeviceIndex = chromeDoc.getElementById("webRTC-selectMicrophone-menulist").value;
-        allowedDevices.AppendElement(audioDevices[audioDeviceIndex]);
+        if (audioDeviceIndex != "-1")
+          allowedDevices.AppendElement(audioDevices[audioDeviceIndex]);
       }
+
+      if (allowedDevices.Count() == 0) {
+        Services.obs.notifyObservers(null, "getUserMedia:response:deny", aCallID);
+        return;
+      }
+
       Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow", aCallID);
 
       // Show browser-specific indicator for the active camera/mic access.
       let message = stringBundle.getFormattedString("getUserMedia.sharing" + requestType + ".message",
                                                     [ host ]);
       let mainAction = null;
       let secondaryActions = null;
       let options = {