Bug 1250122 - Record granting permissions for the Camera on Android. r=mfinkle
authorGian-Carlo Pascutto <gcp@mozilla.com>
Wed, 24 Feb 2016 13:39:32 +0100
changeset 321722 417bac059dab26a1283843a00a041aebdb2f2813
parent 321721 8a2c2d8fc91f7014c701db6ee7d15b2a1b461b01
child 321723 8842a853d8f3f8c8756544a233d3583243142688
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1250122
milestone47.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 1250122 - Record granting permissions for the Camera on Android. r=mfinkle
mobile/android/chrome/content/WebrtcUI.js
--- a/mobile/android/chrome/content/WebrtcUI.js
+++ b/mobile/android/chrome/content/WebrtcUI.js
@@ -128,17 +128,17 @@ var WebrtcUI = {
       },
       function (error) {
         Cu.reportError(error);
       },
       aSubject.innerWindowID,
       aSubject.callID);
   },
 
-  getDeviceButtons: function(audioDevices, videoDevices, aCallID) {
+  getDeviceButtons: function(audioDevices, videoDevices, aCallID, aUri) {
     return [{
       label: Strings.browser.GetStringFromName("getUserMedia.denyRequest.label"),
       callback: function() {
         Services.obs.notifyObservers(null, "getUserMedia:response:deny", aCallID);
       }
     },
     {
       label: Strings.browser.GetStringFromName("getUserMedia.shareRequest.label"),
@@ -149,18 +149,23 @@ var WebrtcUI = {
         if (inputs && inputs.audioDevice != undefined)
           audioId = inputs.audioDevice;
         if (audioDevices[audioId])
           allowedDevices.AppendElement(audioDevices[audioId]);
 
         let videoId = 0;
         if (inputs && inputs.videoSource != undefined)
           videoId = inputs.videoSource;
-        if (videoDevices[videoId])
+        if (videoDevices[videoId]) {
           allowedDevices.AppendElement(videoDevices[videoId]);
+          let perms = Services.perms;
+          // Although the lifetime is "session" it will be removed upon
+          // use so it's more of a one-shot.
+          perms.add(aUri, "camera", perms.EXPIRE_SESSION);
+        }
 
         Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow", aCallID);
       },
       positive: true
     }];
   },
 
   _determineNeededRuntimePermissions: function(aSubject) {
@@ -265,17 +270,18 @@ var WebrtcUI = {
       requestType = "CameraAndMicrophone";
     else if (audioDevices.length)
       requestType = "Microphone";
     else if (videoDevices.length)
       requestType = "Camera";
     else
       return;
 
-    let host = aContentWindow.document.documentURIObject.host;
+    let uri = aContentWindow.document.documentURIObject;
+    let host = uri.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
     var extraItems = null;
@@ -289,13 +295,13 @@ var WebrtcUI = {
 
     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);
+    let buttons = this.getDeviceButtons(audioDevices, videoDevices, aCallID, uri);
 
     NativeWindow.doorhanger.show(message, "webrtc-request", buttons, BrowserApp.selectedTab.id, options);
   }
 }