2013-11-05 14:18:56 -08:00
|
|
|
/* Copyright 2012 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Copyright © 2013, Deutsche Telekom, Inc. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
|
|
|
|
2014-05-07 15:53:16 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "NFC", function () {
|
|
|
|
let obj = {};
|
|
|
|
Cu.import("resource://gre/modules/nfc_consts.js", obj);
|
|
|
|
return obj;
|
|
|
|
});
|
2013-11-05 14:18:56 -08:00
|
|
|
|
2013-12-10 22:04:27 -08:00
|
|
|
Cu.import("resource://gre/modules/systemlibs.js");
|
|
|
|
const NFC_ENABLED = libcutils.property_get("ro.moz.nfc.enabled", "false") === "true";
|
|
|
|
|
2013-11-05 14:18:56 -08:00
|
|
|
// set to true to in nfc_consts.js to see debug messages
|
|
|
|
let DEBUG = NFC.DEBUG_CONTENT_HELPER;
|
|
|
|
|
|
|
|
let debug;
|
2014-10-14 01:37:50 -07:00
|
|
|
function updateDebug() {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug = function (s) {
|
|
|
|
dump("-*- NfcContentHelper: " + s + "\n");
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
debug = function (s) {};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updateDebug();
|
2013-11-05 14:18:56 -08:00
|
|
|
|
|
|
|
const NFCCONTENTHELPER_CID =
|
|
|
|
Components.ID("{4d72c120-da5f-11e1-9b23-0800200c9a66}");
|
|
|
|
|
|
|
|
const NFC_IPC_MSG_NAMES = [
|
|
|
|
"NFC:ReadNDEFResponse",
|
|
|
|
"NFC:WriteNDEFResponse",
|
|
|
|
"NFC:MakeReadOnlyNDEFResponse",
|
|
|
|
"NFC:ConnectResponse",
|
2013-12-03 13:22:21 -08:00
|
|
|
"NFC:CloseResponse",
|
|
|
|
"NFC:CheckP2PRegistrationResponse",
|
2014-09-23 23:52:04 -07:00
|
|
|
"NFC:DOMEvent",
|
2014-01-15 15:42:49 -08:00
|
|
|
"NFC:NotifySendFileStatusResponse",
|
2014-04-14 23:47:42 -07:00
|
|
|
"NFC:ConfigResponse"
|
2013-11-05 14:18:56 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsISyncMessageSender");
|
|
|
|
|
|
|
|
function NfcContentHelper() {
|
2014-10-14 01:37:50 -07:00
|
|
|
Services.obs.addObserver(this, NFC.TOPIC_MOZSETTINGS_CHANGED, false);
|
2013-11-05 14:18:56 -08:00
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
|
|
|
|
|
|
|
this._requestMap = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
NfcContentHelper.prototype = {
|
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsINfcContentHelper,
|
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsIObserver]),
|
|
|
|
classID: NFCCONTENTHELPER_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: NFCCONTENTHELPER_CID,
|
|
|
|
classDescription: "NfcContentHelper",
|
|
|
|
interfaces: [Ci.nsINfcContentHelper]
|
|
|
|
}),
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
_window: null,
|
2013-11-05 14:18:56 -08:00
|
|
|
_requestMap: null,
|
2014-09-23 23:52:04 -07:00
|
|
|
eventTarget: null,
|
2013-11-05 14:18:56 -08:00
|
|
|
|
2014-10-14 01:37:50 -07:00
|
|
|
init: function init(aWindow) {
|
2014-10-30 03:46:41 -07:00
|
|
|
if (aWindow == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
this._window = aWindow;
|
|
|
|
this.initDOMRequestHelper(this._window, NFC_IPC_MSG_NAMES);
|
|
|
|
|
|
|
|
if (this._window.navigator.mozSettings) {
|
|
|
|
let lock = this._window.navigator.mozSettings.createLock();
|
2014-10-14 01:37:50 -07:00
|
|
|
var nfcDebug = lock.get(NFC.SETTING_NFC_DEBUG);
|
|
|
|
nfcDebug.onsuccess = function _nfcDebug() {
|
|
|
|
DEBUG = nfcDebug.result[NFC.SETTING_NFC_DEBUG];
|
|
|
|
updateDebug();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
encodeNDEFRecords: function encodeNDEFRecords(records) {
|
2013-11-05 14:18:56 -08:00
|
|
|
let encodedRecords = [];
|
|
|
|
for (let i = 0; i < records.length; i++) {
|
|
|
|
let record = records[i];
|
|
|
|
encodedRecords.push({
|
|
|
|
tnf: record.tnf,
|
2014-08-18 02:31:18 -07:00
|
|
|
type: record.type || undefined,
|
|
|
|
id: record.id || undefined,
|
|
|
|
payload: record.payload || undefined,
|
2013-11-05 14:18:56 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return encodedRecords;
|
|
|
|
},
|
|
|
|
|
|
|
|
// NFC interface:
|
2014-08-18 02:43:28 -07:00
|
|
|
checkSessionToken: function checkSessionToken(sessionToken) {
|
2013-11-05 14:18:56 -08:00
|
|
|
if (sessionToken == null) {
|
|
|
|
throw Components.Exception("No session token!",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
2014-05-27 01:19:00 -07:00
|
|
|
return false;
|
2013-11-05 14:18:56 -08:00
|
|
|
}
|
|
|
|
// Report session to Nfc.js only.
|
2014-08-18 02:43:28 -07:00
|
|
|
let val = cpmm.sendSyncMessage("NFC:CheckSessionToken", {
|
2014-05-27 01:19:00 -07:00
|
|
|
sessionToken: sessionToken
|
2013-11-05 14:18:56 -08:00
|
|
|
});
|
2014-11-03 03:38:33 -08:00
|
|
|
return (val[0] === NFC.NFC_GECKO_SUCCESS);
|
2013-11-05 14:18:56 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// NFCTag interface
|
2014-10-30 03:46:41 -07:00
|
|
|
readNDEF: function readNDEF(sessionToken) {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2013-11-05 14:18:56 -08:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2013-11-05 14:18:56 -08:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:ReadNDEF", {
|
|
|
|
requestId: requestId,
|
|
|
|
sessionToken: sessionToken
|
|
|
|
});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
writeNDEF: function writeNDEF(records, sessionToken) {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2013-11-05 14:18:56 -08:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2013-11-05 14:18:56 -08:00
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
let encodedRecords = this.encodeNDEFRecords(records);
|
2013-11-05 14:18:56 -08:00
|
|
|
cpmm.sendAsyncMessage("NFC:WriteNDEF", {
|
|
|
|
requestId: requestId,
|
|
|
|
sessionToken: sessionToken,
|
|
|
|
records: encodedRecords
|
|
|
|
});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
makeReadOnlyNDEF: function makeReadOnlyNDEF(sessionToken) {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2013-11-05 14:18:56 -08:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2013-11-05 14:18:56 -08:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:MakeReadOnlyNDEF", {
|
|
|
|
requestId: requestId,
|
|
|
|
sessionToken: sessionToken
|
|
|
|
});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
connect: function connect(techType, sessionToken) {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2013-11-05 14:18:56 -08:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2013-11-05 14:18:56 -08:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:Connect", {
|
|
|
|
requestId: requestId,
|
|
|
|
sessionToken: sessionToken,
|
|
|
|
techType: techType
|
|
|
|
});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
close: function close(sessionToken) {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2013-11-05 14:18:56 -08:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2013-11-05 14:18:56 -08:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:Close", {
|
|
|
|
requestId: requestId,
|
|
|
|
sessionToken: sessionToken
|
|
|
|
});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
sendFile: function sendFile(data, sessionToken) {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2013-12-14 00:57:11 -08:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2013-12-14 00:57:11 -08:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:SendFile", {
|
|
|
|
requestId: requestId,
|
|
|
|
sessionToken: sessionToken,
|
|
|
|
blob: data.blob
|
|
|
|
});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
notifySendFileStatus: function notifySendFileStatus(status, requestId) {
|
2014-01-15 15:42:49 -08:00
|
|
|
cpmm.sendAsyncMessage("NFC:NotifySendFileStatus", {
|
|
|
|
status: status,
|
|
|
|
requestId: requestId
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-09-23 23:52:04 -07:00
|
|
|
registerEventTarget: function registerEventTarget(target) {
|
|
|
|
this.eventTarget = target;
|
|
|
|
cpmm.sendAsyncMessage("NFC:AddEventTarget");
|
2014-07-23 21:16:02 -07:00
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
registerTargetForPeerReady: function registerTargetForPeerReady(appId) {
|
2014-07-24 03:11:42 -07:00
|
|
|
cpmm.sendAsyncMessage("NFC:RegisterPeerReadyTarget", { appId: appId });
|
2013-12-03 13:22:21 -08:00
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
unregisterTargetForPeerReady: function unregisterTargetForPeerReady(appId) {
|
2014-07-24 03:11:42 -07:00
|
|
|
cpmm.sendAsyncMessage("NFC:UnregisterPeerReadyTarget", { appId: appId });
|
2013-12-03 13:22:21 -08:00
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
checkP2PRegistration: function checkP2PRegistration(appId) {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2013-12-03 13:22:21 -08:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2013-12-03 13:22:21 -08:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:CheckP2PRegistration", {
|
|
|
|
appId: appId,
|
|
|
|
requestId: requestId
|
|
|
|
});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
notifyUserAcceptedP2P: function notifyUserAcceptedP2P(appId) {
|
2013-12-03 13:22:21 -08:00
|
|
|
cpmm.sendAsyncMessage("NFC:NotifyUserAcceptedP2P", {
|
|
|
|
appId: appId
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
startPoll: function startPoll() {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2014-04-14 23:47:42 -07:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2014-04-14 23:47:42 -07:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:StartPoll",
|
|
|
|
{requestId: requestId});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
stopPoll: function stopPoll() {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2014-04-14 23:47:42 -07:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2014-04-14 23:47:42 -07:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:StopPoll",
|
|
|
|
{requestId: requestId});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-30 03:46:41 -07:00
|
|
|
powerOff: function powerOff() {
|
|
|
|
let request = Services.DOMRequest.createRequest(this._window);
|
2014-04-14 23:47:42 -07:00
|
|
|
let requestId = btoa(this.getRequestId(request));
|
2014-10-30 03:46:41 -07:00
|
|
|
this._requestMap[requestId] = this._window;
|
2014-04-14 23:47:42 -07:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("NFC:PowerOff",
|
|
|
|
{requestId: requestId});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2013-11-05 14:18:56 -08:00
|
|
|
// nsIObserver
|
|
|
|
observe: function observe(subject, topic, data) {
|
|
|
|
if (topic == "xpcom-shutdown") {
|
2014-04-23 20:14:58 -07:00
|
|
|
this.destroyDOMRequestHelper();
|
2014-10-14 01:37:50 -07:00
|
|
|
Services.obs.removeObserver(this, NFC.TOPIC_MOZSETTINGS_CHANGED);
|
2013-11-05 14:18:56 -08:00
|
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
|
|
|
cpmm = null;
|
2014-10-14 01:37:50 -07:00
|
|
|
} else if (topic == NFC.TOPIC_MOZSETTINGS_CHANGED) {
|
|
|
|
if ("wrappedJSObject" in subject) {
|
|
|
|
subject = subject.wrappedJSObject;
|
|
|
|
}
|
|
|
|
if (subject) {
|
|
|
|
this.handle(subject.key, subject.value);
|
|
|
|
}
|
2013-11-05 14:18:56 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// nsIMessageListener
|
|
|
|
|
|
|
|
fireRequestSuccess: function fireRequestSuccess(requestId, result) {
|
|
|
|
let request = this.takeRequest(requestId);
|
|
|
|
if (!request) {
|
2014-09-04 21:21:00 -07:00
|
|
|
debug("not firing success for id: " + requestId);
|
2013-11-05 14:18:56 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-04 21:21:00 -07:00
|
|
|
debug("fire request success, id: " + requestId);
|
2013-11-05 14:18:56 -08:00
|
|
|
Services.DOMRequest.fireSuccess(request, result);
|
|
|
|
},
|
|
|
|
|
2014-05-23 00:11:38 -07:00
|
|
|
fireRequestError: function fireRequestError(requestId, errorMsg) {
|
2013-11-05 14:18:56 -08:00
|
|
|
let request = this.takeRequest(requestId);
|
|
|
|
if (!request) {
|
|
|
|
debug("not firing error for id: " + requestId +
|
2014-05-23 00:11:38 -07:00
|
|
|
", errormsg: " + errorMsg);
|
2013-11-05 14:18:56 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("fire request error, id: " + requestId +
|
2014-05-23 00:11:38 -07:00
|
|
|
", errormsg: " + errorMsg);
|
|
|
|
Services.DOMRequest.fireError(request, errorMsg);
|
2013-11-05 14:18:56 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function receiveMessage(message) {
|
2014-09-04 21:21:00 -07:00
|
|
|
DEBUG && debug("Message received: " + JSON.stringify(message));
|
2014-02-20 02:13:40 -08:00
|
|
|
let result = message.json;
|
|
|
|
|
2013-11-05 14:18:56 -08:00
|
|
|
switch (message.name) {
|
|
|
|
case "NFC:ReadNDEFResponse":
|
2014-03-25 04:14:41 -07:00
|
|
|
this.handleReadNDEFResponse(result);
|
2014-02-20 02:13:40 -08:00
|
|
|
break;
|
2014-04-30 01:18:00 -07:00
|
|
|
case "NFC:CheckP2PRegistrationResponse":
|
|
|
|
this.handleCheckP2PRegistrationResponse(result);
|
|
|
|
break;
|
2013-11-05 14:18:56 -08:00
|
|
|
case "NFC:ConnectResponse": // Fall through.
|
|
|
|
case "NFC:CloseResponse":
|
|
|
|
case "NFC:WriteNDEFResponse":
|
|
|
|
case "NFC:MakeReadOnlyNDEFResponse":
|
2014-01-15 15:42:49 -08:00
|
|
|
case "NFC:NotifySendFileStatusResponse":
|
2014-04-14 23:47:42 -07:00
|
|
|
case "NFC:ConfigResponse":
|
2014-05-23 00:11:38 -07:00
|
|
|
if (result.errorMsg) {
|
|
|
|
this.fireRequestError(atob(result.requestId), result.errorMsg);
|
2014-04-08 23:17:53 -07:00
|
|
|
} else {
|
|
|
|
this.fireRequestSuccess(atob(result.requestId), result);
|
|
|
|
}
|
2013-11-05 14:18:56 -08:00
|
|
|
break;
|
2014-09-23 23:52:04 -07:00
|
|
|
case "NFC:DOMEvent":
|
2014-07-23 21:16:02 -07:00
|
|
|
switch (result.event) {
|
2014-10-20 02:53:39 -07:00
|
|
|
case NFC.PEER_EVENT_READY:
|
2014-10-29 23:08:00 -07:00
|
|
|
this.eventTarget.notifyPeerFound(result.sessionToken, /* isPeerReady */ true);
|
|
|
|
break;
|
|
|
|
case NFC.PEER_EVENT_FOUND:
|
|
|
|
this.eventTarget.notifyPeerFound(result.sessionToken);
|
2014-07-23 21:16:02 -07:00
|
|
|
break;
|
2014-10-20 02:53:39 -07:00
|
|
|
case NFC.PEER_EVENT_LOST:
|
2014-09-23 23:52:04 -07:00
|
|
|
this.eventTarget.notifyPeerLost(result.sessionToken);
|
2014-07-23 21:16:02 -07:00
|
|
|
break;
|
2014-10-20 02:53:39 -07:00
|
|
|
case NFC.TAG_EVENT_FOUND:
|
|
|
|
let event = new NfcTagEvent(result.techList);
|
|
|
|
this.eventTarget.notifyTagFound(result.sessionToken, event, result.records);
|
|
|
|
break;
|
|
|
|
case NFC.TAG_EVENT_LOST:
|
|
|
|
this.eventTarget.notifyTagLost(result.sessionToken);
|
|
|
|
break;
|
2013-12-03 13:22:21 -08:00
|
|
|
}
|
|
|
|
break;
|
2013-11-05 14:18:56 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-10-14 01:37:50 -07:00
|
|
|
handle: function handle(name, result) {
|
|
|
|
switch (name) {
|
|
|
|
case NFC.SETTING_NFC_DEBUG:
|
|
|
|
DEBUG = result;
|
|
|
|
updateDebug();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-25 04:14:41 -07:00
|
|
|
handleReadNDEFResponse: function handleReadNDEFResponse(result) {
|
|
|
|
let requester = this._requestMap[result.requestId];
|
|
|
|
if (!requester) {
|
|
|
|
debug("Response Invalid requestId=" + result.requestId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
delete this._requestMap[result.requestId];
|
|
|
|
|
2014-05-23 00:11:38 -07:00
|
|
|
if (result.errorMsg) {
|
|
|
|
this.fireRequestError(atob(result.requestId), result.errorMsg);
|
2014-03-25 04:14:41 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-20 02:13:40 -08:00
|
|
|
let requestId = atob(result.requestId);
|
|
|
|
let ndefMsg = [];
|
|
|
|
let records = result.records;
|
|
|
|
for (let i = 0; i < records.length; i++) {
|
|
|
|
let record = records[i];
|
2014-08-19 02:40:07 -07:00
|
|
|
ndefMsg.push(new requester.MozNDEFRecord({tnf: record.tnf,
|
|
|
|
type: record.type,
|
|
|
|
id: record.id,
|
|
|
|
payload: record.payload}));
|
2013-11-05 14:18:56 -08:00
|
|
|
}
|
2014-02-20 02:13:40 -08:00
|
|
|
this.fireRequestSuccess(requestId, ndefMsg);
|
2013-11-05 14:18:56 -08:00
|
|
|
},
|
|
|
|
|
2014-04-30 01:18:00 -07:00
|
|
|
handleCheckP2PRegistrationResponse: function handleCheckP2PRegistrationResponse(result) {
|
|
|
|
// Privilaged status API. Always fire success to avoid using exposed props.
|
|
|
|
// The receiver must check the boolean mapped status code to handle.
|
|
|
|
let requestId = atob(result.requestId);
|
2014-05-23 00:11:38 -07:00
|
|
|
this.fireRequestSuccess(requestId, !result.errorMsg);
|
2014-04-30 01:18:00 -07:00
|
|
|
},
|
2013-11-05 14:18:56 -08:00
|
|
|
};
|
|
|
|
|
2014-10-20 02:53:39 -07:00
|
|
|
function NfcTagEvent(techList) {
|
|
|
|
this.techList = techList;
|
|
|
|
}
|
|
|
|
NfcTagEvent.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsINfcTagEvent]),
|
|
|
|
|
|
|
|
techList: null
|
|
|
|
};
|
|
|
|
|
2013-12-10 22:04:27 -08:00
|
|
|
if (NFC_ENABLED) {
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NfcContentHelper]);
|
|
|
|
}
|