OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Does common handling for requests coming from web pages and | 6 * @fileoverview Does common handling for requests coming from web pages and |
7 * routes them to the provided handler. | 7 * routes them to the provided handler. |
8 */ | 8 */ |
9 | 9 |
10 /** | 10 /** |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return forSign ? GnubbyCodeTypes.NONE_PLUGGED_ENROLLED : | 221 return forSign ? GnubbyCodeTypes.NONE_PLUGGED_ENROLLED : |
222 GnubbyCodeTypes.ALREADY_ENROLLED; | 222 GnubbyCodeTypes.ALREADY_ENROLLED; |
223 | 223 |
224 case ErrorCodes.TIMEOUT: | 224 case ErrorCodes.TIMEOUT: |
225 return GnubbyCodeTypes.WAIT_TOUCH; | 225 return GnubbyCodeTypes.WAIT_TOUCH; |
226 } | 226 } |
227 return GnubbyCodeTypes.UNKNOWN_ERROR; | 227 return GnubbyCodeTypes.UNKNOWN_ERROR; |
228 } | 228 } |
229 | 229 |
230 /** | 230 /** |
231 * Maps a helper's error code from the DeviceStatusCodes namespace to the | 231 * Maps a helper's error code from the DeviceStatusCodes namespace to a |
232 * ErrorCodes namespace. | 232 * U2fError. |
233 * @param {number} code Error code from DeviceStatusCodes namespace. | 233 * @param {number} code Error code from DeviceStatusCodes namespace. |
234 * @return {ErrorCodes} A ErrorCodes error code. | 234 * @return {U2fError} An error. |
235 */ | 235 */ |
236 function mapDeviceStatusCodeToErrorCode(code) { | 236 function mapDeviceStatusCodeToU2fError(code) { |
237 var reportedError = ErrorCodes.OTHER_ERROR; | |
238 switch (code) { | 237 switch (code) { |
239 case DeviceStatusCodes.WRONG_DATA_STATUS: | 238 case DeviceStatusCodes.WRONG_DATA_STATUS: |
240 reportedError = ErrorCodes.DEVICE_INELIGIBLE; | 239 return {errorCode: ErrorCodes.DEVICE_INELIGIBLE}; |
241 break; | |
242 | 240 |
243 case DeviceStatusCodes.TIMEOUT_STATUS: | 241 case DeviceStatusCodes.TIMEOUT_STATUS: |
244 case DeviceStatusCodes.WAIT_TOUCH_STATUS: | 242 case DeviceStatusCodes.WAIT_TOUCH_STATUS: |
245 reportedError = ErrorCodes.TIMEOUT; | 243 return {errorCode: ErrorCodes.TIMEOUT}; |
246 break; | 244 |
| 245 default: |
| 246 var reportedError = { |
| 247 errorCode: ErrorCodes.OTHER_ERROR, |
| 248 errorMessage: 'device status code: ' + code.toString(16) |
| 249 }; |
| 250 return reportedError; |
247 } | 251 } |
248 return reportedError; | |
249 } | 252 } |
250 | 253 |
251 /** | 254 /** |
252 * Sends a response, using the given sentinel to ensure at most one response is | 255 * Sends a response, using the given sentinel to ensure at most one response is |
253 * sent. Also closes the closeable, if it's given. | 256 * sent. Also closes the closeable, if it's given. |
254 * @param {boolean} sentResponse Whether a response has already been sent. | 257 * @param {boolean} sentResponse Whether a response has already been sent. |
255 * @param {?Closeable} closeable A thing to close. | 258 * @param {?Closeable} closeable A thing to close. |
256 * @param {*} response The response to send. | 259 * @param {*} response The response to send. |
257 * @param {Function} sendResponse A function to send the response. | 260 * @param {Function} sendResponse A function to send the response. |
258 */ | 261 */ |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 'type': 'sign_helper_request', | 421 'type': 'sign_helper_request', |
419 'signData': challenges, | 422 'signData': challenges, |
420 'timeout': opt_timeoutSeconds || 0, | 423 'timeout': opt_timeoutSeconds || 0, |
421 'timeoutSeconds': opt_timeoutSeconds || 0 | 424 'timeoutSeconds': opt_timeoutSeconds || 0 |
422 }; | 425 }; |
423 if (opt_logMsgUrl !== undefined) { | 426 if (opt_logMsgUrl !== undefined) { |
424 request.logMsgUrl = opt_logMsgUrl; | 427 request.logMsgUrl = opt_logMsgUrl; |
425 } | 428 } |
426 return request; | 429 return request; |
427 } | 430 } |
OLD | NEW |