backout 8ff6b2bf34cd (bug 989094) for regressions. r=backout
authorWes Johnston <wjohnston@mozilla.com>
Mon, 22 Sep 2014 09:22:06 -0700
changeset 206487 a3ae1a0cf65f30674b13d01d37554c303be07579
parent 206486 89abe3df46afc3616b032906f6208f9e5aa8b565
child 206488 f809f2ecc04709c5510161258e3a4ed5ba618c88
push id27528
push userryanvm@gmail.com
push dateMon, 22 Sep 2014 19:27:54 +0000
treeherdermozilla-central@d8688cafc752 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs989094
milestone35.0a1
backs out8ff6b2bf34cdeb158ed1e6132779a6f0bb4d657c
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
backout 8ff6b2bf34cd (bug 989094) for regressions. r=backout
mobile/android/chrome/content/WebrtcUI.js
--- a/mobile/android/chrome/content/WebrtcUI.js
+++ b/mobile/android/chrome/content/WebrtcUI.js
@@ -1,22 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 XPCOMUtils.defineLazyModuleGetter(this, "Notifications", "resource://gre/modules/Notifications.jsm");
-XPCOMUtils.defineLazyServiceGetter(this, "contentPrefs",
-                                   "@mozilla.org/content-pref/service;1",
-                                   "nsIContentPrefService2");
 
 var WebrtcUI = {
   _notificationId: null,
-  VIDEO_SOURCE: "videoSource",
-  AUDIO_SOURCE: "audioDevice",
 
   observe: function(aSubject, aTopic, aData) {
     if (aTopic === "getUserMedia:request") {
       this.handleRequest(aSubject, aTopic, aData);
     } else if (aTopic === "recording-device-events") {
       switch (aData) {
         case "shutdown":
         case "starting":
@@ -78,203 +73,144 @@ var WebrtcUI = {
   },
 
   handleRequest: function handleRequest(aSubject, aTopic, aData) {
     let constraints = aSubject.getConstraints();
     let contentWindow = Services.wm.getOuterWindowWithId(aSubject.windowID);
 
     contentWindow.navigator.mozGetUserMediaDevices(
       constraints,
-      function (aDevices) {
-        WebrtcUI.prompt(contentWindow, aSubject.callID, constraints.audio, constraints.video, aDevices);
+      function (devices) {
+        WebrtcUI.prompt(contentWindow, aSubject.callID, constraints.audio,
+                        constraints.video, devices);
       },
-      Cu.reportError, aSubject.innerWindowID);
+      function (error) {
+        Cu.reportError(error);
+      },
+      aSubject.innerWindowID);
   },
 
-  getDeviceButtons: function(aAudioDevices, aVideoDevices, aCallID, aHost) {
+  getDeviceButtons: function(audioDevices, videoDevices, aCallID) {
     return [{
       label: Strings.browser.GetStringFromName("getUserMedia.denyRequest.label"),
-      callback: () => {
+      callback: function() {
         Services.obs.notifyObservers(null, "getUserMedia:response:deny", aCallID);
       }
-    }, {
+    },
+    {
       label: Strings.browser.GetStringFromName("getUserMedia.shareRequest.label"),
-      callback: (checked /* ignored */, inputs) => {
+      callback: function(checked /* ignored */, inputs) {
         let allowedDevices = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
 
         let audioId = 0;
-        if (inputs && inputs[this.AUDIO_SOURCE] != undefined) {
-          audioId = inputs[this.AUDIO_SOURCE];
-        }
-
-        if (aAudioDevices[audioId]) {
-          allowedDevices.AppendElement(aAudioDevices[audioId]);
-          this.setDefaultDevice(this.AUDIO_SOURCE, aAudioDevices[audioId].name, aHost);
-        }
+        if (inputs && inputs.audioDevice != undefined)
+          audioId = inputs.audioDevice;
+        if (audioDevices[audioId])
+          allowedDevices.AppendElement(audioDevices[audioId]);
 
         let videoId = 0;
-        if (inputs && inputs[this.VIDEO_SOURCE] != undefined) {
-          videoId = inputs[this.VIDEO_SOURCE];
-        }
-
-        if (aVideoDevices[videoId]) {
-          allowedDevices.AppendElement(aVideoDevices[videoId]);
-          this.setDefaultDevice(this.VIDEO_SOURCE, aVideoDevices[videoId].name, aHost);
-        }
+        if (inputs && inputs.videoSource != undefined)
+          videoId = inputs.videoSource;
+        if (videoDevices[videoId])
+          allowedDevices.AppendElement(videoDevices[videoId]);
 
         Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow", aCallID);
       }
     }];
   },
 
   // Get a list of string names for devices. Ensures that none of the strings are blank
   _getList: function(aDevices, aType) {
     let defaultCount = 0;
     return aDevices.map(function(device) {
-      let name = device.name;
-      // if this is a Camera input, convert the name to something readable
-      let res = /Camera\ \d+,\ Facing (front|back)/.exec(name);
-      if (res) {
-        return Strings.browser.GetStringFromName("getUserMedia." + aType + "." + res[1] + "Camera");
-      }
+        // if this is a Camera input, convert the name to something readable
+        let res = /Camera\ \d+,\ Facing (front|back)/.exec(device.name);
+        if (res)
+          return Strings.browser.GetStringFromName("getUserMedia." + aType + "." + res[1] + "Camera");
 
-      if (name.startsWith("&") && name.endsWith(";")) {
-        return Strings.browser.GetStringFromName(name.substring(1, name.length -1));
-      }
+        if (device.name.startsWith("&") && device.name.endsWith(";"))
+          return Strings.browser.GetStringFromName(device.name.substring(1, device.name.length -1));
 
-      if (name.trim() == "") {
-        defaultCount++;
-        return Strings.browser.formatStringFromName("getUserMedia." + aType + ".default", [defaultCount], 1);
-      }
-
-      return name;
-    }, this);
+        if (device.name.trim() == "") {
+          defaultCount++;
+          return Strings.browser.formatStringFromName("getUserMedia." + aType + ".default", [defaultCount], 1);
+        }
+        return device.name
+      }, this);
   },
 
-  _addDevicesToOptions: function(aDevices, aType, aOptions, aHost, aContext) {
-    if (aDevices.length == 0) {
-      return Promise.resolve(aOptions);
-    }
+  _addDevicesToOptions: function(aDevices, aType, aOptions, extraOptions) {
+    if (aDevices.length) {
 
-    let updateOptions = () => {
       // Filter out empty items from the list
       let list = this._getList(aDevices, aType);
+      if (extraOptions)
+        list = list.concat(extraOptions);
+
       if (list.length > 0) {
         aOptions.inputs.push({
           id: aType,
           type: "menulist",
           label: Strings.browser.GetStringFromName("getUserMedia." + aType + ".prompt"),
           values: list
         });
+
       }
-
-      return aOptions;
-    }
-
-    return this.getDefaultDevice(aType, aHost, aContext).then((defaultDevice) => {
-      aDevices.sort((a, b) => {
-        if (b.name === defaultDevice) return 1;
-        return 0;
-      });
-      return updateOptions();
-    }).catch(updateOptions);
-  },
-
-  // Sets the default for a aHost. If no aHost is specified, sets the browser wide default.
-  // Saving is async, but this doesn't wait for a result.
-  setDefaultDevice: function(aType, aValue, aHost, aContext) {
-    if (aHost) {
-      contentPrefs.set(aHost, "webrtc." + aType, aValue, aContext);
-    } else {
-      contentPrefs.setGlobal("webrtc." + aType, aValue, aContext);
     }
   },
 
-  _checkContentPref(aHost, aType, aContext) {
-    return new Promise((resolve, reject) => {
-      let result = null;
-      let handler = {
-        handleResult: (aResult) => result = aResult,
-        handleCompletion: function(aReason) {
-          if (aReason == Components.interfaces.nsIContentPrefCallback2.COMPLETE_OK &&
-              result instanceof Components.interfaces.nsIContentPref) {
-            resolve(result.value);
-          } else {
-            reject(result);
-          }
-        }
-      };
-
-      if (aHost) {
-        contentPrefs.getByDomainAndName(aHost, "webrtc." + aType, aContext, handler);
-      } else {
-        contentPrefs.getGlobal("webrtc." + aType, aContext, handler);
-      }
-    });
-  },
-
-  // Returns the default device for this aHost. If no aHost is specified, returns a browser wide default
-  getDefaultDevice: function(aType, aHost, aContext) {
-    return this._checkContentPref(aHost, aType, aContext).catch(() => {
-      // If we found nothing for the initial pref, try looking for a global one
-      return this._checkContentPref(null, aType, aContext);
-    });
-  },
-
-  prompt: function (aWindow, aCallID, aAudioRequested, aVideoRequested, aDevices) {
+  prompt: function prompt(aContentWindow, aCallID, aAudioRequested,
+                          aVideoRequested, aDevices) {
     let audioDevices = [];
     let videoDevices = [];
-
-    // Split up all the available aDevices into audio and video categories
     for (let device of aDevices) {
       device = device.QueryInterface(Ci.nsIMediaDevice);
       switch (device.type) {
       case "audio":
-        if (aAudioRequested) {
+        if (aAudioRequested)
           audioDevices.push(device);
-        }
         break;
       case "video":
-        if (aVideoRequested) {
+        if (aVideoRequested)
           videoDevices.push(device);
-        }
         break;
       }
     }
 
-    // Bsaed on the aTypes available, setup the prompt and icon text
     let requestType;
-    if (audioDevices.length && videoDevices.length) {
+    if (audioDevices.length && videoDevices.length)
       requestType = "CameraAndMicrophone";
-    } else if (audioDevices.length) {
+    else if (audioDevices.length)
       requestType = "Microphone";
-    } else if (videoDevices.length) {
+    else if (videoDevices.length)
       requestType = "Camera";
-    } else {
+    else
       return;
-    }
 
-    let host = aWindow.document.documentURIObject.host;
-    // Show the app name if this is a WebRT app, otherwise show the host.
+    let host = aContentWindow.document.documentURIObject.host;
     let requestor = BrowserApp.manifest ? "'" + BrowserApp.manifest.name  + "'" : host;
     let message = Strings.browser.formatStringFromName("getUserMedia.share" + requestType + ".message", [ requestor ], 1);
 
     let options = { inputs: [] };
     // if the users only option would be to select "No Audio" or "No Video"
     // i.e. we're only showing audio or only video and there is only one device for that type
     // don't bother showing a menulist to select from
-    if (videoDevices.length > 0 && audioDevices.length > 0) {
-      videoDevices.push({ name: Strings.browser.GetStringFromName("getUserMedia.videoSource.none") });
-      audioDevices.push({ name: Strings.browser.GetStringFromName("getUserMedia.audioDevice.none") });
+    var extraItems = null;
+    if (videoDevices.length > 1 || audioDevices.length > 0) {
+      // Only show the No Video option if there are also Audio devices to choose from
+      if (audioDevices.length > 0)
+        extraItems = [ Strings.browser.GetStringFromName("getUserMedia.videoSource.none") ];
+      // videoSource is both the string used for l10n lookup and the object that will be returned
+      this._addDevicesToOptions(videoDevices, "videoSource", options, extraItems);
     }
 
-    let loadContext = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                             .getInterface(Ci.nsIWebNavigation)
-                             .QueryInterface(Ci.nsILoadContext);
-    // videoSource is both the string used for l10n lookup and the object that will be returned
-    this._addDevicesToOptions(videoDevices, this.VIDEO_SOURCE, options, host, loadContext).then((aOptions) => {
-      return this._addDevicesToOptions(audioDevices, this.AUDIO_SOURCE, aOptions, host, loadContext);
-    }).catch(Cu.reportError).then((aOptions) => {
-      let buttons = this.getDeviceButtons(audioDevices, videoDevices, aCallID, host);
-      NativeWindow.doorhanger.show(message, "webrtc-request", buttons, BrowserApp.selectedTab.id, aOptions);
-    });
+    if (audioDevices.length > 1 || videoDevices.length > 0) {
+      // Only show the No Audio option if there are also Video devices to choose from
+      if (videoDevices.length > 0)
+        extraItems = [ Strings.browser.GetStringFromName("getUserMedia.audioDevice.none") ];
+      this._addDevicesToOptions(audioDevices, "audioDevice", options, extraItems);
+    }
+
+    let buttons = this.getDeviceButtons(audioDevices, videoDevices, aCallID);
+
+    NativeWindow.doorhanger.show(message, "webrtc-request", buttons, BrowserApp.selectedTab.id, options);
   }
 }