Bug 918054 - Deny the GetUserMedia while in call. r=jesup, r=fabrice, a=koi+
authorShih-Chiang Chien <schien@mozilla.com>
Fri, 04 Oct 2013 12:41:57 -0400
changeset 160560 8b4152d366c3010d512b281f58661a5883283ac8
parent 160559 74e15e692c0de8a8df18ae2e39ec19e13e7f6971
child 160561 57e9a22e8eeb39ab1f3a3cb359b4f52afed55ab3
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, fabrice, koi
bugs918054
milestone26.0a2
Bug 918054 - Deny the GetUserMedia while in call. r=jesup, r=fabrice, a=koi+
b2g/components/ContentPermissionPrompt.js
--- a/b2g/components/ContentPermissionPrompt.js
+++ b/b2g/components/ContentPermissionPrompt.js
@@ -24,21 +24,28 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/Webapps.jsm");
 Cu.import("resource://gre/modules/AppsUtils.jsm");
 Cu.import("resource://gre/modules/PermissionsInstaller.jsm");
 Cu.import("resource://gre/modules/PermissionsTable.jsm");
 
 var permissionManager = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
 var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
 
+let permissionSpecificChecker = {};
+
 XPCOMUtils.defineLazyServiceGetter(this,
                                    "PermSettings",
                                    "@mozilla.org/permissionSettings;1",
                                    "nsIDOMPermissionSettings");
 
+XPCOMUtils.defineLazyServiceGetter(this,
+                                   "AudioManager",
+                                   "@mozilla.org/telephony/audiomanager;1",
+                                   "nsIAudioManager");
+
 function rememberPermission(aPermission, aPrincipal, aSession)
 {
   function convertPermToAllow(aPerm, aPrincipal)
   {
     let type =
       permissionManager.testExactPermissionFromPrincipal(aPrincipal, aPerm);
     if (type == Ci.nsIPermissionManager.PROMPT_ACTION ||
         (type == Ci.nsIPermissionManager.UNKNOWN_ACTION &&
@@ -110,25 +117,33 @@ ContentPermissionPrompt.prototype = {
         result == Ci.nsIPermissionManager.PROMPT_ACTION) {
       return false;
     }
 
     request.cancel();
     return true;
   },
 
+  handledByPermissionType: function handledByPermissionType(request) {
+    return permissionSpecificChecker.hasOwnProperty(request.type)
+             ? permissionSpecificChecker[request.type](request)
+             : false;
+  },
+
   _id: 0,
   prompt: function(request) {
     if (secMan.isSystemPrincipal(request.principal)) {
       request.allow();
       return true;
     }
 
-    if (this.handledByApp(request))
-        return;
+    if (this.handledByApp(request) ||
+        this.handledByPermissionType(request)) {
+      return;
+    }
 
     // returns true if the request was handled
     if (this.handleExistingPermission(request))
        return;
 
     let frame = request.element;
     let requestId = this._id++;
 
@@ -257,11 +272,23 @@ ContentPermissionPrompt.prototype = {
     browser.shell.sendChromeEvent(details);
   },
 
   classID: Components.ID("{8c719f03-afe0-4aac-91ff-6c215895d467}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt])
 };
 
+(function() {
+  // Do not allow GetUserMedia while in call.
+  permissionSpecificChecker["audio-capture"] = function(request) {
+    if (AudioManager.phoneState === Ci.nsIAudioManager.PHONE_STATE_IN_CALL) {
+      request.cancel();
+      return true;
+    } else {
+      return false;
+    }
+  };
+})();
+
 
 //module initialization
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentPermissionPrompt]);