Bug 976402 - Part 1 - Do not register target if the sessionTokens do not match. r=allstars.chh

This commit is contained in:
Siddartha Pothapragada 2014-05-27 10:19:00 +02:00
Родитель 42f55c3cf4
Коммит 1a20585dbd
3 изменённых файлов: 11 добавлений и 6 удалений

Просмотреть файл

@ -366,10 +366,14 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
switch (msg.name) {
case "NFC:SetSessionToken":
if (msg.json.sessionToken !== this.nfc.sessionTokenMap[this.nfc._currentSessionId]) {
debug("Received invalid Session Token: " + msg.json.sessionToken + " - Do not register this target");
return NFC.NFC_ERROR_BAD_SESSION_ID;
}
this._registerMessageTarget(this.nfc.sessionTokenMap[this.nfc._currentSessionId], msg.target);
debug("Registering target for this SessionToken : " +
this.nfc.sessionTokenMap[this.nfc._currentSessionId]);
return null;
return NFC.NFC_SUCCESS;
case "NFC:RegisterPeerTarget":
this.registerPeerTarget(msg);
return null;

Просмотреть файл

@ -118,12 +118,13 @@ NfcContentHelper.prototype = {
if (sessionToken == null) {
throw Components.Exception("No session token!",
Cr.NS_ERROR_UNEXPECTED);
return;
return false;
}
// Report session to Nfc.js only.
cpmm.sendAsyncMessage("NFC:SetSessionToken", {
sessionToken: sessionToken,
let val = cpmm.sendSyncMessage("NFC:SetSessionToken", {
sessionToken: sessionToken
});
return (val[0] === NFC.NFC_SUCCESS);
},
// NFCTag interface

Просмотреть файл

@ -24,13 +24,13 @@ interface nsINfcPeerCallback : nsISupports
in DOMString sessionToken);
};
[scriptable, uuid(10b2eb1b-3fe0-4c98-9c67-9e4c2274cd78)]
[scriptable, uuid(26e8123f-ba00-4708-ac77-d1902457168c)]
interface nsINfcContentHelper : nsISupports
{
const long NFC_EVENT_PEER_READY = 0x01;
const long NFC_EVENT_PEER_LOST = 0x02;
void setSessionToken(in DOMString sessionToken);
boolean setSessionToken(in DOMString sessionToken);
nsIDOMDOMRequest getDetailsNDEF(in nsIDOMWindow window, in DOMString sessionToken);
nsIDOMDOMRequest readNDEF(in nsIDOMWindow window, in DOMString sessionToken);