From 2872982e1b2a40651672f2f9d2f88651b587fb5e Mon Sep 17 00:00:00 2001 From: Shih-Chiang Chien Date: Mon, 19 Jan 2015 09:42:20 +0800 Subject: [PATCH] Bug 1091790 - Check active call via nsITelephonyService. r=fabrice --- b2g/components/ContentPermissionPrompt.js | 31 ++++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/b2g/components/ContentPermissionPrompt.js b/b2g/components/ContentPermissionPrompt.js index 4f4e7ea4426..95835f2bebb 100644 --- a/b2g/components/ContentPermissionPrompt.js +++ b/b2g/components/ContentPermissionPrompt.js @@ -35,9 +35,9 @@ var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptS let permissionSpecificChecker = {}; XPCOMUtils.defineLazyServiceGetter(this, - "AudioManager", - "@mozilla.org/telephony/audiomanager;1", - "nsIAudioManager"); + "TelephonyService", + "@mozilla.org/telephony/telephonyservice;1", + "nsITelephonyService"); XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy", "resource://gre/modules/SystemAppProxy.jsm"); @@ -455,12 +455,29 @@ ContentPermissionPrompt.prototype = { (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 { + let forbid = false; + + try { + // nsITelephonyService.enumerateCalls is synchronous. + TelephonyService.enumerateCalls({ + QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyListener]), + enumerateCallStateComplete: function() {}, + enumerateCallState: function(callInfo) { + if (callInfo.callState == Ci.nsITelephonyService.CALL_STATE_CONNECTED) { + forbid = true; + } + }, + }); + } catch (e) { + // No restriction if Telephony service doesn't exist. return false; } + + if (forbid) { + request.cancel(); + } + + return forbid; }; })();