Bug 976402 - Part 2 - Throw an error when sessionToken is incorrect while using the interfaces getNFCTag() and getNFCPeer(). r=smaug

This commit is contained in:
Siddartha Pothapragada 2014-05-27 15:12:00 +02:00
Родитель 2486b27106
Коммит f1c5d13747
4 изменённых файлов: 12 добавлений и 34 удалений

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

@ -55,15 +55,7 @@ MozNFCTag.prototype = {
initialize: function(aWindow, aSessionToken) { initialize: function(aWindow, aSessionToken) {
this._window = aWindow; this._window = aWindow;
this.setSessionToken(aSessionToken);
},
// ChromeOnly interface
setSessionToken: function setSessionToken(aSessionToken) {
debug("Setting session token.");
this.session = aSessionToken; this.session = aSessionToken;
// report to NFC worker:
this._nfcContentHelper.setSessionToken(aSessionToken);
}, },
_techTypesMap: null, _techTypesMap: null,
@ -110,15 +102,7 @@ MozNFCPeer.prototype = {
initialize: function(aWindow, aSessionToken) { initialize: function(aWindow, aSessionToken) {
this._window = aWindow; this._window = aWindow;
this.setSessionToken(aSessionToken);
},
// ChromeOnly interface
setSessionToken: function setSessionToken(aSessionToken) {
debug("Setting session token.");
this.session = aSessionToken; this.session = aSessionToken;
// report to NFC worker:
return this._nfcContentHelper.setSessionToken(aSessionToken);
}, },
// NFCPeer interface: // NFCPeer interface:
@ -200,26 +184,22 @@ mozNfc.prototype = {
getNFCTag: function getNFCTag(sessionToken) { getNFCTag: function getNFCTag(sessionToken) {
let obj = new MozNFCTag(); let obj = new MozNFCTag();
let nfcTag = this._window.MozNFCTag._create(this._window, obj); obj.initialize(this._window, sessionToken);
if (nfcTag) { if (this._nfcContentHelper.setSessionToken(sessionToken)) {
obj.initialize(this._window, sessionToken); return this._window.MozNFCTag._create(this._window, obj);
return nfcTag;
} else {
debug("Error: Unable to create NFCTag");
return null;
} }
throw new Error("Unable to create NFCTag object, Reason: Bad SessionToken " +
sessionToken);
}, },
getNFCPeer: function getNFCPeer(sessionToken) { getNFCPeer: function getNFCPeer(sessionToken) {
let obj = new MozNFCPeer(); let obj = new MozNFCPeer();
let nfcPeer = this._window.MozNFCPeer._create(this._window, obj); obj.initialize(this._window, sessionToken);
if (nfcPeer) { if (this._nfcContentHelper.setSessionToken(sessionToken)) {
obj.initialize(this._window, sessionToken); return this._window.MozNFCPeer._create(this._window, obj);
return nfcPeer;
} else {
debug("Error: Unable to create NFCPeer");
return null;
} }
throw new Error("Unable to create NFCPeer object, Reason: Bad SessionToken " +
sessionToken);
}, },
// get/set onpeerready // get/set onpeerready

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

@ -46,7 +46,9 @@ interface MozNFCManager {
NavigatorProperty="mozNfc", NavigatorProperty="mozNfc",
Func="Navigator::HasNFCSupport"] Func="Navigator::HasNFCSupport"]
interface MozNFC : EventTarget { interface MozNFC : EventTarget {
[Throws]
MozNFCTag getNFCTag(DOMString sessionId); MozNFCTag getNFCTag(DOMString sessionId);
[Throws]
MozNFCPeer getNFCPeer(DOMString sessionId); MozNFCPeer getNFCPeer(DOMString sessionId);
[CheckPermissions="nfc-write"] [CheckPermissions="nfc-write"]

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

@ -18,6 +18,4 @@ interface MozNFCPeer {
partial interface MozNFCPeer { partial interface MozNFCPeer {
[ChromeOnly] [ChromeOnly]
attribute DOMString session; attribute DOMString session;
[ChromeOnly]
void setSessionToken(DOMString sessionToken);
}; };

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

@ -38,6 +38,4 @@ interface MozNFCTag {
partial interface MozNFCTag { partial interface MozNFCTag {
[ChromeOnly] [ChromeOnly]
attribute DOMString session; attribute DOMString session;
[ChromeOnly]
void setSessionToken(DOMString sessionToken);
}; };