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
This commit is contained in:
Jim Chen 2017-06-02 16:11:53 -04:00
Родитель 9798dcedbb
Коммит 858e777c78
4 изменённых файлов: 25 добавлений и 6 удалений

Просмотреть файл

@ -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();

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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",