mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 970251 - Part 2: Impl. r=dimi
From e1c730487df90a5edfe416be9b9219da02652be3 Mon Sep 17 00:00:00 2001 --- dom/nfc/nsNfc.js | 17 +++++++++-- dom/system/gonk/Nfc.js | 35 ++++++++++++++++++++-- dom/system/gonk/NfcContentHelper.js | 48 ++++++++++++++++++++++++++++++- dom/system/gonk/nsINfcContentHelper.idl | 17 ++++++++++- 4 files changed, 111 insertions(+), 6 deletions(-)
This commit is contained in:
parent
a1b71343ed
commit
4a955516e6
@ -166,8 +166,9 @@ mozNfc.prototype = {
|
||||
this._window = aWindow;
|
||||
},
|
||||
|
||||
// Only System Process can call the following interfaces
|
||||
// 'checkP2PRegistration' , 'notifyUserAcceptedP2P' , 'notifySendFileStatus'
|
||||
// Only apps which have nfc-manager permission can call the following interfaces
|
||||
// 'checkP2PRegistration' , 'notifyUserAcceptedP2P' , 'notifySendFileStatus',
|
||||
// 'startPoll', 'stopPoll', and 'powerOff'.
|
||||
checkP2PRegistration: function checkP2PRegistration(manifestUrl) {
|
||||
// Get the AppID and pass it to ContentHelper
|
||||
let appID = appsService.getAppLocalIdByManifestURL(manifestUrl);
|
||||
@ -185,6 +186,18 @@ mozNfc.prototype = {
|
||||
status, requestId);
|
||||
},
|
||||
|
||||
startPoll: function startPoll() {
|
||||
return this._nfcContentHelper.startPoll(this._window);
|
||||
},
|
||||
|
||||
stopPoll: function stopPoll() {
|
||||
return this._nfcContentHelper.stopPoll(this._window);
|
||||
},
|
||||
|
||||
powerOff: function powerOff() {
|
||||
return this._nfcContentHelper.powerOff(this._window);
|
||||
},
|
||||
|
||||
getNFCTag: function getNFCTag(sessionToken) {
|
||||
let obj = new MozNFCTag();
|
||||
let nfcTag = this._window.MozNFCTag._create(this._window, obj);
|
||||
|
@ -66,7 +66,10 @@ const NFC_IPC_WRITE_PERM_MSG_NAMES = [
|
||||
const NFC_IPC_MANAGER_PERM_MSG_NAMES = [
|
||||
"NFC:CheckP2PRegistration",
|
||||
"NFC:NotifyUserAcceptedP2P",
|
||||
"NFC:NotifySendFileStatus"
|
||||
"NFC:NotifySendFileStatus",
|
||||
"NFC:StartPoll",
|
||||
"NFC:StopPoll",
|
||||
"NFC:PowerOff"
|
||||
];
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
|
||||
@ -420,6 +423,7 @@ function Nfc() {
|
||||
lock.get(NFC.SETTING_NFC_ENABLED, this);
|
||||
// Maps sessionId (that are generated from nfcd) with a unique guid : 'SessionToken'
|
||||
this.sessionTokenMap = {};
|
||||
this.targetsByRequestId = {};
|
||||
|
||||
gSystemWorkerManager.registerNfcWorker(this.worker);
|
||||
}
|
||||
@ -516,7 +520,14 @@ Nfc.prototype = {
|
||||
this.currentPeerAppId = null;
|
||||
break;
|
||||
case "ConfigResponse":
|
||||
gSystemMessenger.broadcastMessage("nfc-powerlevel-change", message);
|
||||
let target = this.targetsByRequestId[message.requestId];
|
||||
if (!target) {
|
||||
debug("No target for requestId: " + message.requestId);
|
||||
return;
|
||||
}
|
||||
delete this.targetsByRequestId[message.requestId];
|
||||
|
||||
target.sendAsyncMessage("NFC:ConfigResponse", message);
|
||||
break;
|
||||
case "ConnectResponse": // Fall through.
|
||||
case "CloseResponse":
|
||||
@ -539,12 +550,32 @@ Nfc.prototype = {
|
||||
|
||||
sessionTokenMap: null,
|
||||
|
||||
targetsByRequestId: null,
|
||||
|
||||
/**
|
||||
* Process a message from the content process.
|
||||
*/
|
||||
receiveMessage: function receiveMessage(message) {
|
||||
debug("Received '" + JSON.stringify(message) + "' message from content process");
|
||||
|
||||
// Handle messages without sessionToken.
|
||||
if (message.name == "NFC:StartPoll") {
|
||||
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||
this.setConfig({powerLevel: NFC.NFC_POWER_LEVEL_ENABLED,
|
||||
requestId: message.json.requestId});
|
||||
return null;
|
||||
} else if (message.name == "NFC:StopPoll") {
|
||||
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||
this.setConfig({powerLevel: NFC.NFC_POWER_LEVEL_LOW,
|
||||
requestId: message.json.requestId});
|
||||
return null;
|
||||
} else if (message.name == "NFC:PowerOff") {
|
||||
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||
this.setConfig({powerLevel: NFC.NFC_POWER_LEVEL_DISABLED,
|
||||
requestId: message.json.requestId});
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this._enabled) {
|
||||
debug("NFC is not enabled.");
|
||||
this.sendNfcErrorResponse(message);
|
||||
|
@ -54,7 +54,7 @@ const NFC_IPC_MSG_NAMES = [
|
||||
"NFC:CheckP2PRegistrationResponse",
|
||||
"NFC:PeerEvent",
|
||||
"NFC:NotifySendFileStatusResponse",
|
||||
"NFC:SendFileResponse"
|
||||
"NFC:ConfigResponse"
|
||||
];
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
||||
@ -314,6 +314,51 @@ NfcContentHelper.prototype = {
|
||||
});
|
||||
},
|
||||
|
||||
startPoll: function startPoll(window) {
|
||||
if (window == null) {
|
||||
throw Components.Exception("Can't get window object",
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
||||
let request = Services.DOMRequest.createRequest(window);
|
||||
let requestId = btoa(this.getRequestId(request));
|
||||
this._requestMap[requestId] = window;
|
||||
|
||||
cpmm.sendAsyncMessage("NFC:StartPoll",
|
||||
{requestId: requestId});
|
||||
return request;
|
||||
},
|
||||
|
||||
stopPoll: function stopPoll(window) {
|
||||
if (window == null) {
|
||||
throw Components.Exception("Can't get window object",
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
||||
let request = Services.DOMRequest.createRequest(window);
|
||||
let requestId = btoa(this.getRequestId(request));
|
||||
this._requestMap[requestId] = window;
|
||||
|
||||
cpmm.sendAsyncMessage("NFC:StopPoll",
|
||||
{requestId: requestId});
|
||||
return request;
|
||||
},
|
||||
|
||||
powerOff: function powerOff(window) {
|
||||
if (window == null) {
|
||||
throw Components.Exception("Can't get window object",
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
||||
let request = Services.DOMRequest.createRequest(window);
|
||||
let requestId = btoa(this.getRequestId(request));
|
||||
this._requestMap[requestId] = window;
|
||||
|
||||
cpmm.sendAsyncMessage("NFC:PowerOff",
|
||||
{requestId: requestId});
|
||||
return request;
|
||||
},
|
||||
|
||||
// nsIObserver
|
||||
observe: function observe(subject, topic, data) {
|
||||
if (topic == "xpcom-shutdown") {
|
||||
@ -368,6 +413,7 @@ NfcContentHelper.prototype = {
|
||||
case "NFC:MakeReadOnlyNDEFResponse":
|
||||
case "NFC:CheckP2PRegistrationResponse":
|
||||
case "NFC:NotifySendFileStatusResponse":
|
||||
case "NFC:ConfigResponse":
|
||||
if (result.status !== NFC.GECKO_NFC_ERROR_SUCCESS) {
|
||||
this.fireRequestError(atob(result.requestId), result.status);
|
||||
} else {
|
||||
|
@ -24,7 +24,7 @@ interface nsINfcPeerCallback : nsISupports
|
||||
in DOMString sessionToken);
|
||||
};
|
||||
|
||||
[scriptable, uuid(70cac000-7e3c-11e3-baa7-0800200c9a66)]
|
||||
[scriptable, uuid(10b2eb1b-3fe0-4c98-9c67-9e4c2274cd78)]
|
||||
interface nsINfcContentHelper : nsISupports
|
||||
{
|
||||
const long NFC_EVENT_PEER_READY = 0x01;
|
||||
@ -135,4 +135,19 @@ interface nsINfcContentHelper : nsISupports
|
||||
void notifySendFileStatus(in nsIDOMWindow window,
|
||||
in octet status,
|
||||
in DOMString requestId);
|
||||
|
||||
/**
|
||||
* Power on the NFC hardware and start polling for NFC tags or devices.
|
||||
*/
|
||||
nsIDOMDOMRequest startPoll(in nsIDOMWindow window);
|
||||
|
||||
/**
|
||||
* Stop polling for NFC tags or devices. i.e. enter low power mode.
|
||||
*/
|
||||
nsIDOMDOMRequest stopPoll(in nsIDOMWindow window);
|
||||
|
||||
/**
|
||||
* Power off the NFC hardware.
|
||||
*/
|
||||
nsIDOMDOMRequest powerOff(in nsIDOMWindow window);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user