diff --git 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 index 22a3dce98cfb..0719c47ae0de 100644 --- 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 @@ -75,8 +75,8 @@ public class VideoCaptureDeviceInfoAndroid { // 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(); diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index ffbe3caeb0e7..1457aba19830 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -924,3 +924,6 @@ 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); diff --git a/mobile/android/chrome/content/WebrtcUI.js b/mobile/android/chrome/content/WebrtcUI.js index 8bfe9da95227..499643d48321 100644 --- a/mobile/android/chrome/content/WebrtcUI.js +++ b/mobile/android/chrome/content/WebrtcUI.js @@ -28,9 +28,15 @@ var WebrtcUI = { // 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); @@ -178,7 +184,16 @@ var WebrtcUI = { _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); } diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 5040dd50c3c2..69e6c645f7a0 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -159,7 +159,8 @@ var lazilyLoadedObserverScripts = [ if (AppConstants.MOZ_WEBRTC) { lazilyLoadedObserverScripts.push( - ["WebrtcUI", ["getUserMedia:request", + ["WebrtcUI", ["getUserMedia:ask-device-permission", + "getUserMedia:request", "PeerConnection:request", "recording-device-events", "VideoCapture:Paused",