diff --git a/dom/nfc/gonk/Nfc.js b/dom/nfc/gonk/Nfc.js index 71a7123bc00..64cf0095ade 100644 --- a/dom/nfc/gonk/Nfc.js +++ b/dom/nfc/gonk/Nfc.js @@ -397,7 +397,7 @@ Nfc.prototype = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsINfcGonkEventListener]), - rfState: null, + rfState: NFC.NFC_RF_STATE_IDLE, nfcService: null, diff --git a/dom/nfc/nsNfc.js b/dom/nfc/nsNfc.js index 8d1b53e57bc..530bf9fa1d4 100644 --- a/dom/nfc/nsNfc.js +++ b/dom/nfc/nsNfc.js @@ -246,6 +246,13 @@ MozNFCPeerImpl.prototype = { Ci.nsIDOMGlobalPropertyInitializer]), }; +// Should be mapped to the RFState defined in WebIDL. +let RFState = { + IDLE: "idle", + LISTEN: "listen", + DISCOVERY: "discovery" +}; + /** * Implementation of navigator NFC object. */ @@ -270,13 +277,6 @@ MozNFCImpl.prototype = { nfcTag: null, eventService: null, - // Should be mapped to the RFState defined in WebIDL. - rfState: { - IDLE: "idle", - LISTEN: "listen", - DISCOVERY: "discovery" - }, - init: function init(aWindow) { debug("MozNFCImpl init called"); this._window = aWindow; @@ -316,22 +316,26 @@ MozNFCImpl.prototype = { startPoll: function startPoll() { let callback = new NfcCallback(this._window); - this._nfcContentHelper.changeRFState(this.rfState.DISCOVERY, callback); + this._nfcContentHelper.changeRFState(RFState.DISCOVERY, callback); return callback.promise; }, stopPoll: function stopPoll() { let callback = new NfcCallback(this._window); - this._nfcContentHelper.changeRFState(this.rfState.LISTEN, callback); + this._nfcContentHelper.changeRFState(RFState.LISTEN, callback); return callback.promise; }, powerOff: function powerOff() { let callback = new NfcCallback(this._window); - this._nfcContentHelper.changeRFState(this.rfState.IDLE, callback); + this._nfcContentHelper.changeRFState(RFState.IDLE, callback); return callback.promise; }, + get enabled() { + return this._rfState != RFState.IDLE; + }, + defineEventHandlerGetterSetter: function defineEventHandlerGetterSetter(name) { Object.defineProperty(this, name, { get: function get() { diff --git a/dom/webidl/MozNFC.webidl b/dom/webidl/MozNFC.webidl index 26a9882060a..5db6ef8c65a 100644 --- a/dom/webidl/MozNFC.webidl +++ b/dom/webidl/MozNFC.webidl @@ -75,6 +75,11 @@ interface MozNFCManager { CheckPermissions="nfc nfc-share", AvailableIn="PrivilegedApps"] interface MozNFC : EventTarget { + /** + * Indicate if NFC is enabled. + */ + readonly attribute boolean enabled; + /** * This event will be fired when another NFCPeer is detected, and user confirms * to share data to the NFCPeer object by calling mozNFC.notifyUserAcceptedP2P.