Bug 1369108 - 3. Implement new device permission code path for Fennec; r=esawin
authorJim Chen <nchen@mozilla.com>
Fri, 02 Jun 2017 16:11:53 -0400
changeset 410274 0a58469c18011216c9f1d0e052f6a0d9bf799543
parent 410273 54c93d5eb3089ed12163a7308edc003cdb41cf7a
child 410275 b6337d9fa55e9c74a23ecb786f9afa91d21556a7
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1369108
milestone55.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 1369108 - 3. Implement new device permission code path for Fennec; r=esawin Instead of asking for permission in VideoCaptureDeviceInfoAndroid.java, we now merely check for permission there. The actual permission prompt now happens in WebrtcUI.js, using the new "getUserMedia:ask-device-permission" and "getUserMedia:got-device-permission" notifications. MozReview-Commit-ID: DSVPjjW2JNR
media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid.java
mobile/android/app/mobile.js
mobile/android/chrome/content/WebrtcUI.js
mobile/android/chrome/content/browser.js
--- a/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid.java
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid.java
@@ -70,18 +70,18 @@ public class VideoCaptureDeviceInfoAndro
   }
 
   // Returns information about all cameras on the device.
   // Since this reflects static information about the hardware present, there is
   // no need to call this function more than once in a single process.  It is
   // marked "private" as it is only called by native code.
   @WebRTCJNITarget
   private static CaptureCapabilityAndroid[] getDeviceInfo() {
-      final boolean hasPermissions = Permissions.waitFor(
-              (Activity) GeckoAppShell.getContext(), Manifest.permission.CAMERA);
+      final boolean hasPermissions = Permissions.has(
+              GeckoAppShell.getApplicationContext(), Manifest.permission.CAMERA);
 
       if (hasPermissions) {
           return createDeviceList();
       } else {
           return new CaptureCapabilityAndroid[0];
       }
   }
 
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -919,8 +919,11 @@ pref("webchannel.allowObject.urlWhitelis
 
 pref("media.openUnsupportedTypeWithExternalApp", true);
 
 pref("dom.keyboardevent.dispatch_during_composition", true);
 
 #if CPU_ARCH == aarch64
 pref("javascript.options.native_regexp", false);
 #endif
+
+// Ask for permission when enumerating WebRTC devices.
+pref("media.navigator.permission.device", true);
--- a/mobile/android/chrome/content/WebrtcUI.js
+++ b/mobile/android/chrome/content/WebrtcUI.js
@@ -23,19 +23,25 @@ var WebrtcUI = {
   //        break;
   //      ...
   //      default:
   //        return stockObserve.call(this, aSubject, aTopic, aData);
   //
   // See browser/modules/webrtcUI.jsm for details.
 
   observe: function(aSubject, aTopic, aData) {
-    if (aTopic === "getUserMedia:request") {
+    if (aTopic === "getUserMedia:ask-device-permission") {
       RuntimePermissions
-        .waitForPermissions(this._determineNeededRuntimePermissions(aSubject))
+        .waitForPermissions(this._determineNeededRuntimePermissions(aData))
+        .then(_ => {
+          Services.obs.notifyObservers(aSubject, "getUserMedia:got-device-permission");
+        });
+    } else if (aTopic === "getUserMedia:request") {
+      RuntimePermissions
+        .checkPermissions(this._determineNeededRuntimePermissions(aSubject))
         .then((permissionGranted) => {
           if (permissionGranted) {
             WebrtcUI.handleGumRequest(aSubject, aTopic, aData);
           } else {
             Services.obs.notifyObservers(null, "getUserMedia:response:deny", aSubject.callID);
           }});
     } else if (aTopic === "PeerConnection:request") {
       this.handlePCRequest(aSubject, aTopic, aData);
@@ -173,17 +179,26 @@ var WebrtcUI = {
       },
       positive: true
     }];
   },
 
   _determineNeededRuntimePermissions: function(aSubject) {
     let permissions = [];
 
-    let constraints = aSubject.getConstraints();
+    let constraints;
+    if (typeof aSubject === "string") {
+      constraints = {
+        video: aSubject === "video" || aSubject === "all",
+        audio: aSubject === "audio" || aSubject === "all",
+      };
+    } else {
+      constraints = aSubject.getConstraints();
+    }
+
     if (constraints.video) {
       permissions.push(RuntimePermissions.CAMERA);
     }
     if (constraints.audio) {
       permissions.push(RuntimePermissions.RECORD_AUDIO);
     }
 
     return permissions;
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -154,17 +154,18 @@ lazilyLoadedBrowserScripts.forEach(funct
 
 var lazilyLoadedObserverScripts = [
   ["MemoryObserver", ["memory-pressure", "Memory:Dump"], "chrome://browser/content/MemoryObserver.js"],
   ["ConsoleAPI", ["console-api-log-event"], "chrome://browser/content/ConsoleAPI.js"],
 ];
 
 if (AppConstants.MOZ_WEBRTC) {
   lazilyLoadedObserverScripts.push(
-    ["WebrtcUI", ["getUserMedia:request",
+    ["WebrtcUI", ["getUserMedia:ask-device-permission",
+                  "getUserMedia:request",
                   "PeerConnection:request",
                   "recording-device-events",
                   "VideoCapture:Paused",
                   "VideoCapture:Resumed"], "chrome://browser/content/WebrtcUI.js"])
 }
 
 lazilyLoadedObserverScripts.forEach(function (aScript) {
   let [name, notifications, script] = aScript;