Bug 1109458 - Let privilege App know if NFC is enabled or not. r=smaug, dimi

This commit is contained in:
Yoshi Huang 2014-12-12 15:13:40 +08:00
parent 6a07e31ef6
commit b15507d889
3 changed files with 20 additions and 11 deletions

View File

@ -397,7 +397,7 @@ Nfc.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsINfcGonkEventListener]),
rfState: null,
rfState: NFC.NFC_RF_STATE_IDLE,
nfcService: null,

View File

@ -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() {

View File

@ -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.