From 9ce3e8090ca604e45021041a6dfc08febdd4065b Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Tue, 28 Oct 2014 14:58:47 +0800 Subject: [PATCH] Bug 991970 - Part 3: add permission check. r=smaug From 6462cdf51f04b81479932f1b7b1d809970820620 Mon Sep 17 00:00:00 2001 --- dom/nfc/nsNfc.js | 23 +++++++++++++++++++++++ dom/webidl/MozNFC.webidl | 1 + 2 files changed, 24 insertions(+) --- dom/nfc/nsNfc.js | 23 +++++++++++++++++++++++ dom/webidl/MozNFC.webidl | 1 + 2 files changed, 24 insertions(+) diff --git a/dom/nfc/nsNfc.js b/dom/nfc/nsNfc.js index 7ed964db11f..216a6d61dba 100644 --- a/dom/nfc/nsNfc.js +++ b/dom/nfc/nsNfc.js @@ -224,6 +224,10 @@ mozNfc.prototype = { return; } + if (!this.checkPermissions(["nfc-read", "nfc-write"])) { + return; + } + let tag = new MozNFCTag(this._window, sessionToken); let tagContentObj = this._window.MozNFCTag._create(this._window, tag); @@ -253,6 +257,10 @@ mozNfc.prototype = { return; } + if (!this.checkPermissions(["nfc-read", "nfc-write"])) { + return; + } + debug("fire ontaglost " + sessionToken); let event = new this._window.Event("taglost"); this.__DOM_IMPL__.dispatchEvent(event); @@ -297,6 +305,21 @@ mozNfc.prototype = { this.__DOM_IMPL__.dispatchEvent(event); }, + checkPermissions: function checkPermissions(perms) { + let principal = this._window.document.nodePrincipal; + for (let perm of perms) { + let permValue = + Services.perms.testExactPermissionFromPrincipal(principal, perm); + if (permValue == Ci.nsIPermissionManager.ALLOW_ACTION) { + return true; + } else { + debug("doesn't have " + perm + " permission."); + } + } + + return false; + }, + hasDeadWrapper: function hasDeadWrapper() { return Cu.isDeadWrapper(this._window) || Cu.isDeadWrapper(this.__DOM_IMPL__); }, diff --git a/dom/webidl/MozNFC.webidl b/dom/webidl/MozNFC.webidl index 6317a9efd00..ca6c77a0a9a 100644 --- a/dom/webidl/MozNFC.webidl +++ b/dom/webidl/MozNFC.webidl @@ -82,6 +82,7 @@ interface MozNFC : EventTarget { /** * This event will be fired if the tag detected in ontagfound has been removed. */ + [CheckPermissions="nfc-read nfc-write"] attribute EventHandler ontaglost; };