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
3 // found in the LICENSE file.
6 * @fileoverview Provides a "bottom half" helper to assist with raw requests.
7 * This fills the same role as the Authenticator-Specific Module component of
8 * U2F documents, although the API is different.
23 * code: (number|undefined)
29 * A helper to process requests.
32 function RequestHelper() {}
35 * Gets a handler for a request.
36 * @param {HelperRequest} request The request to handle.
37 * @return {RequestHandler} A handler for the request.
39 RequestHelper.prototype.getHandler = function(request) {};
42 * A handler to track an outstanding request.
43 * @extends {Closeable}
46 function RequestHandler() {}
48 /** @typedef {function(HelperReply, string=)} */
49 var RequestHandlerCallback;
52 * @param {RequestHandlerCallback} cb Called with the result of the request,
53 * and an optional source for the result.
54 * @return {boolean} Whether this handler could be run.
56 RequestHandler.prototype.run = function(cb) {};
58 /** Closes this handler. */
59 RequestHandler.prototype.close = function() {};
62 * Makes a response to a helper request with an error code.
63 * @param {HelperRequest} request The request to make a response to.
64 * @param {DeviceStatusCodes} code The error code to return.
65 * @param {string=} opt_defaultType The default response type, if none is
66 * present in the request.
67 * @return {HelperReply} The helper error response.
69 function makeHelperErrorResponse(request, code, opt_defaultType) {
71 if (request && request.type) {
72 type = request.type.replace(/_request$/, '_reply');
74 type = opt_defaultType || 'unknown_type_reply';
78 'code': /** @type {number} */ (code)