From c3cae8d37ebe3b173a5b9a9912af9f966e48441f Mon Sep 17 00:00:00 2001 From: Krzysztof Mioduszewski Date: Fri, 23 May 2014 09:11:38 +0200 Subject: [PATCH] Bug 933595 - Part 1: Gecko code changes to pass error messages to gaia. r=allstars.chh --- dom/system/gonk/Nfc.js | 40 ++++++++----- dom/system/gonk/NfcContentHelper.js | 22 +++---- dom/system/gonk/nfc_consts.js | 80 ++++++++++++++++++++++++- dom/system/gonk/nfc_worker.js | 21 +++---- dom/system/gonk/nsINfcContentHelper.idl | 1 - 5 files changed, 119 insertions(+), 45 deletions(-) diff --git a/dom/system/gonk/Nfc.js b/dom/system/gonk/Nfc.js index ba38f722486..9d00caecb7a 100644 --- a/dom/system/gonk/Nfc.js +++ b/dom/system/gonk/Nfc.js @@ -315,14 +315,13 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () { NFC.NFC_PEER_EVENT_READY); // Remember the current AppId if registered. this.currentPeerAppId = (isValid) ? msg.json.appId : null; - let status = (isValid) ? NFC.GECKO_NFC_ERROR_SUCCESS : - NFC.GECKO_NFC_ERROR_GENERIC_FAILURE; + let respMsg = { requestId: msg.json.requestId }; + if(!isValid) { + respMsg.errorMsg = this.nfc.getErrorMessage(NFC.NFC_GECKO_ERROR_P2P_REG_INVALID); + } // Notify the content process immediately of the status - msg.target.sendAsyncMessage(msg.name + "Response", { - status: status, - requestId: msg.json.requestId - }); + msg.target.sendAsyncMessage(msg.name + "Response", respMsg); }, /** @@ -461,22 +460,26 @@ Nfc.prototype = { }, /** - * Send Error response to content. + * Send Error response to content. This is used only + * in case of discovering an error in message received from + * content process. * * @param message * An nsIMessageListener's message parameter. */ - sendNfcErrorResponse: function sendNfcErrorResponse(message) { + sendNfcErrorResponse: function sendNfcErrorResponse(message, errorCode) { if (!message.target) { return; } let nfcMsgType = message.name + "Response"; - message.target.sendAsyncMessage(nfcMsgType, { - sessionId: message.json.sessionToken, - requestId: message.json.requestId, - status: NFC.GECKO_NFC_ERROR_GENERIC_FAILURE - }); + message.json.errorMsg = this.getErrorMessage(errorCode); + message.target.sendAsyncMessage(nfcMsgType, message.json); + }, + + getErrorMessage: function getErrorMessage(errorCode) { + return NFC.NFC_ERROR_MSG[errorCode] || + NFC.NFC_ERROR_MSG[NFC.NFC_GECKO_ERROR_GENERIC_FAILURE]; }, /** @@ -486,6 +489,11 @@ Nfc.prototype = { let message = event.data; debug("Received message from NFC worker: " + JSON.stringify(message)); + // mapping error code to error message + if(message.status !== NFC.NFC_SUCCESS) { + message.errorMsg = this.getErrorMessage(message.status); + } + switch (message.type) { case "techDiscovered": this._currentSessionId = message.sessionId; @@ -525,7 +533,7 @@ Nfc.prototype = { } delete this.targetsByRequestId[message.requestId]; - if (message.status == NFC.GECKO_NFC_ERROR_SUCCESS) { + if (message.status === NFC.NFC_SUCCESS) { this.powerLevel = message.powerLevel; } @@ -580,7 +588,7 @@ Nfc.prototype = { if (this.powerLevel != NFC.NFC_POWER_LEVEL_ENABLED) { debug("NFC is not enabled. current powerLevel:" + this.powerLevel); - this.sendNfcErrorResponse(message); + this.sendNfcErrorResponse(message, NFC.NFC_GECKO_ERROR_NOT_ENABLED); return null; } @@ -588,7 +596,7 @@ Nfc.prototype = { if (message.json.sessionToken !== this.sessionTokenMap[this._currentSessionId]) { debug("Invalid Session Token: " + message.json.sessionToken + " Expected Session Token: " + this.sessionTokenMap[this._currentSessionId]); - this.sendNfcErrorResponse(message); + this.sendNfcErrorResponse(message, NFC.NFC_ERROR_BAD_SESSION_ID); return null; } diff --git a/dom/system/gonk/NfcContentHelper.js b/dom/system/gonk/NfcContentHelper.js index ac4724d91c3..395d2884f54 100644 --- a/dom/system/gonk/NfcContentHelper.js +++ b/dom/system/gonk/NfcContentHelper.js @@ -383,17 +383,17 @@ NfcContentHelper.prototype = { Services.DOMRequest.fireSuccess(request, result); }, - fireRequestError: function fireRequestError(requestId, error) { + fireRequestError: function fireRequestError(requestId, errorMsg) { let request = this.takeRequest(requestId); if (!request) { debug("not firing error for id: " + requestId + - ", error: " + JSON.stringify(error)); + ", errormsg: " + errorMsg); return; } debug("fire request error, id: " + requestId + - ", result: " + JSON.stringify(error)); - Services.DOMRequest.fireError(request, error); + ", errormsg: " + errorMsg); + Services.DOMRequest.fireError(request, errorMsg); }, receiveMessage: function receiveMessage(message) { @@ -416,8 +416,8 @@ NfcContentHelper.prototype = { case "NFC:MakeReadOnlyNDEFResponse": case "NFC:NotifySendFileStatusResponse": case "NFC:ConfigResponse": - if (result.status !== NFC.GECKO_NFC_ERROR_SUCCESS) { - this.fireRequestError(atob(result.requestId), result.status); + if (result.errorMsg) { + this.fireRequestError(atob(result.requestId), result.errorMsg); } else { this.fireRequestSuccess(atob(result.requestId), result); } @@ -442,8 +442,8 @@ NfcContentHelper.prototype = { } delete this._requestMap[result.requestId]; - if (result.status !== NFC.GECKO_NFC_ERROR_SUCCESS) { - this.fireRequestError(atob(result.requestId), result.status); + if (result.errorMsg) { + this.fireRequestError(atob(result.requestId), result.errorMsg); return; } @@ -461,8 +461,8 @@ NfcContentHelper.prototype = { }, handleGetDetailsNDEFResponse: function handleGetDetailsNDEFResponse(result) { - if (result.status !== NFC.GECKO_NFC_ERROR_SUCCESS) { - this.fireRequestError(atob(result.requestId), result.status); + if (result.errorMsg) { + this.fireRequestError(atob(result.requestId), result.errorMsg); return; } @@ -475,7 +475,7 @@ NfcContentHelper.prototype = { // 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); - this.fireRequestSuccess(requestId, result.status == NFC.GECKO_NFC_ERROR_SUCCESS); + this.fireRequestSuccess(requestId, !result.errorMsg); }, }; diff --git a/dom/system/gonk/nfc_consts.js b/dom/system/gonk/nfc_consts.js index 1db9768fe4b..b44e6422fa4 100644 --- a/dom/system/gonk/nfc_consts.js +++ b/dom/system/gonk/nfc_consts.js @@ -56,9 +56,83 @@ this.NFC_TECHS = { 8:"NFC_ISO_DEP" }; -// TODO: Bug 933595. Fill-in all error codes for Gonk/nfcd protocol -this.GECKO_NFC_ERROR_SUCCESS = 0; -this.GECKO_NFC_ERROR_GENERIC_FAILURE = 1; +// nfcd error codes +this.NFC_SUCCESS = 0; +this.NFC_ERROR_IO = -1; +this.NFC_ERROR_CANCELLED = -2; +this.NFC_ERROR_TIMEOUT = -3; +this.NFC_ERROR_BUSY = -4; +this.NFC_ERROR_CONNECT = -5; +this.NFC_ERROR_DISCONNECT = -6; +this.NFC_ERROR_READ = -7; +this.NFC_ERROR_WRITE = -8; +this.NFC_ERROR_INVALID_PARAM = -9; +this.NFC_ERROR_INSUFFICIENT_RESOURCES = -10; +this.NFC_ERROR_SOCKET_CREATION = -11; +this.NFC_ERROR_SOCKET_NOT_CONNECTED = -12; +this.NFC_ERROR_BUFFER_TOO_SMALL = -13; +this.NFC_ERROR_SAP_USED = -14; +this.NFC_ERROR_SERVICE_NAME_USED = -15; +this.NFC_ERROR_SOCKET_OPTIONS = -16; +this.NFC_ERROR_NFC_ALREADY_ON = -17; +this.NFC_ERROR_NFC_ALREADY_OFF = -18; +this.NFC_ERROR_ALREADY_DISCOVERY_ON = -19; +this.NFC_ERROR_ALREADY_DISCOVERY_OFF = -20; +this.NFC_ERROR_FAIL_ENABLE_DISCOVERY = -21; +this.NFC_ERROR_FAIL_DISABLE_DISCOVERY = -22; +this.NFC_ERROR_NOT_INITIALIZED = -23; +this.NFC_ERROR_INITIALIZE_FAIL = -24; +this.NFC_ERROR_DEINITIALIZE_FAIL = -25; +this.NFC_ERROR_SE_ALREADY_SELECTED = -26; +this.NFC_ERROR_SE_CONNECTED = -27; +this.NFC_ERROR_NO_SE_CONNECTED = -28; +this.NFC_ERROR_NOT_SUPPORTED = -29; +this.NFC_ERROR_BAD_SESSION_ID = -30; +this.NFC_ERROR_LOST_TECH = -31; +this.NFC_ERROR_BAD_TECH_TYPE = -32; + +// Gecko specific error codes +this.NFC_GECKO_ERROR_GENERIC_FAILURE = 1; +this.NFC_GECKO_ERROR_P2P_REG_INVALID = 2; +this.NFC_GECKO_ERROR_NOT_ENABLED = 3; + +this.NFC_ERROR_MSG = {}; +this.NFC_ERROR_MSG[this.NFC_ERROR_IO] = "NfcIoError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_CANCELLED] = "NfcCancelledError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_TIMEOUT] = "NfcTimeoutError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_BUSY] = "NfcBusyError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_CONNECT] = "NfcConnectError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_DISCONNECT] = "NfcDisconnectError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_READ] = "NfcReadError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_WRITE] = "NfcWriteError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_INVALID_PARAM] = "NfcInvalidParamError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_INSUFFICIENT_RESOURCES] = "NfcInsufficentResourcesError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_SOCKET_CREATION] = "NfcSocketCreationError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_SOCKET_NOT_CONNECTED] = "NfcSocketNotConntectedError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_BUFFER_TOO_SMALL] = "NfcBufferTooSmallError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_SAP_USED] = "NfcSapUsedError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_SERVICE_NAME_USED] = "NfcServiceNameUsedError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_SOCKET_OPTIONS] = "NfcSocketOptionsError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_NFC_ALREADY_ON] = "NfcAlreadOnError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_NFC_ALREADY_OFF] = "NfcAlreadyOffError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_ALREADY_DISCOVERY_ON] = "NfcDiscoveryOnError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_ALREADY_DISCOVERY_OFF] = "NfcDiscoveryOffError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_FAIL_ENABLE_DISCOVERY] = "NfcFailEnableDiscoveryError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_FAIL_DISABLE_DISCOVERY] = "NfcFailDisableDiscoveryError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_NOT_INITIALIZED] = "NfcNotInitializedError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_INITIALIZE_FAIL] = "NfcInitializeFailError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_DEINITIALIZE_FAIL] = "NfcDeinitializeFailError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_SE_ALREADY_SELECTED] = "NfcSeAlreadySelectedError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_SE_CONNECTED] = "NfcSeConnectedError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_NO_SE_CONNECTED] = "NfcNoSeConnectedError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_NOT_SUPPORTED] = "NfcNotSupportedError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_BAD_SESSION_ID] = "NfcBadSessionIdError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_LOST_TECH] = "NfcLostTechError"; +this.NFC_ERROR_MSG[this.NFC_ERROR_BAD_TECH_TYPE] = "NfcBadTechTypeError"; + +this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_GENERIC_FAILURE] = "NfcGenericFailureError"; +this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_P2P_REG_INVALID] = "NfcP2PRegistrationInvalid"; +this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_NOT_ENABLED] = "NfcNotEnabledError"; // NFC powerlevels must match config PDUs. this.NFC_POWER_LEVEL_UNKNOWN = -1; diff --git a/dom/system/gonk/nfc_worker.js b/dom/system/gonk/nfc_worker.js index 31304073850..192e93121a2 100644 --- a/dom/system/gonk/nfc_worker.js +++ b/dom/system/gonk/nfc_worker.js @@ -153,8 +153,7 @@ let NfcWorker = { message.type = "ReadNDEFResponse"; message.sessionId = sessionId; message.records = records; - message.status = (error === 0) ? GECKO_NFC_ERROR_SUCCESS : - GECKO_NFC_ERROR_GENERIC_FAILURE; + message.status = error; this.sendDOMMessage(message); } @@ -173,8 +172,7 @@ let NfcWorker = { message.type = "WriteNDEFResponse"; message.sessionId = sessionId; - message.status = (error === 0) ? GECKO_NFC_ERROR_SUCCESS : - GECKO_NFC_ERROR_GENERIC_FAILURE; + message.status = error; this.sendDOMMessage(message); }; @@ -231,8 +229,7 @@ let NfcWorker = { message.type = "MakeReadOnlyNDEFResponse"; message.sessionId = sessionId; - message.status = (error === 0) ? GECKO_NFC_ERROR_SUCCESS : - GECKO_NFC_ERROR_GENERIC_FAILURE; + message.status = error; this.sendDOMMessage(message); }; @@ -260,8 +257,7 @@ let NfcWorker = { message.isReadOnly = isReadOnly; message.canBeMadeReadOnly = canBeMadeReadOnly; message.maxSupportedLength = maxSupportedLength; - message.status = (error === 0) ? GECKO_NFC_ERROR_SUCCESS : - GECKO_NFC_ERROR_GENERIC_FAILURE; + message.status = error; this.sendDOMMessage(message); }; Buf.newParcel(NFC_REQUEST_GET_DETAILS, cb); @@ -280,8 +276,7 @@ let NfcWorker = { message.type = "ConnectResponse"; message.sessionId = sessionId; - message.status = (error === 0) ? GECKO_NFC_ERROR_SUCCESS : - GECKO_NFC_ERROR_GENERIC_FAILURE; + message.status = error; this.sendDOMMessage(message); }; @@ -299,8 +294,7 @@ let NfcWorker = { let error = Buf.readInt32(); message.type = "ConfigResponse"; - message.status = (error === 0) ? GECKO_NFC_ERROR_SUCCESS : - GECKO_NFC_ERROR_GENERIC_FAILURE; + message.status = error; this.sendDOMMessage(message); }; @@ -319,8 +313,7 @@ let NfcWorker = { message.type = "CloseResponse"; message.sessionId = sessionId; - message.status = (error === 0) ? GECKO_NFC_ERROR_SUCCESS : - GECKO_NFC_ERROR_GENERIC_FAILURE; + message.status = error; this.sendDOMMessage(message); }; diff --git a/dom/system/gonk/nsINfcContentHelper.idl b/dom/system/gonk/nsINfcContentHelper.idl index 91672408012..2ee946dcc10 100644 --- a/dom/system/gonk/nsINfcContentHelper.idl +++ b/dom/system/gonk/nsINfcContentHelper.idl @@ -127,7 +127,6 @@ interface nsINfcContentHelper : nsISupports * * @param status * Status of sendFile operation - * (GECKO_NFC_ERROR_SUCCESS, GECKO_NFC_ERROR_GENERIC_FAILURE) * * @param requestId * Request ID of SendFile DOM Request