Chromium Code Reviews| Index: extensions/renderer/resources/serial_custom_bindings.js |
| diff --git a/extensions/renderer/resources/serial_custom_bindings.js b/extensions/renderer/resources/serial_custom_bindings.js |
| index 3d15acff1c7fca3f4a1e9420bc53a5fd8162414e..4298d75a377b3bce006178afb55a2f1d1e623957 100644 |
| --- a/extensions/renderer/resources/serial_custom_bindings.js |
| +++ b/extensions/renderer/resources/serial_custom_bindings.js |
| @@ -19,12 +19,57 @@ function createAsyncProxy(targetPromise, functionNames) { |
| var serialService = createAsyncProxy(requireAsync('serial_service'), [ |
| 'getDevices', |
| + 'createConnection', |
| + 'getConnection', |
| + 'getConnections', |
| ]); |
| +function forwardToConnection(methodName) { |
| + return function(connectionId) { |
| + var args = $Array.slice(arguments, 1); |
| + return serialService.getConnection(connectionId).then(function(connection) { |
| + return $Function.apply(connection[methodName], connection, args); |
| + }); |
| + } |
|
Ken Rockot(use gerrit already)
2014/07/31 16:28:33
nit: missing ;
Sam McNally
2014/08/01 01:10:13
Done.
|
| +} |
| + |
| binding.registerCustomHook(function(bindingsAPI) { |
| var apiFunctions = bindingsAPI.apiFunctions; |
| apiFunctions.setHandleRequestWithPromise('getDevices', |
| serialService.getDevices); |
| + |
| + apiFunctions.setHandleRequestWithPromise('connect', function(path, options) { |
| + return serialService.createConnection(path, options).then(function(result) { |
| + return result.info; |
| + }).catch(function(e) { |
| + throw new Error('Failed to connect to the port.'); |
| + }); |
| + }); |
| + |
| + apiFunctions.setHandleRequestWithPromise( |
| + 'disconnect', forwardToConnection('close')); |
| + apiFunctions.setHandleRequestWithPromise( |
| + 'getInfo', forwardToConnection('getInfo')); |
| + apiFunctions.setHandleRequestWithPromise( |
| + 'update', forwardToConnection('setOptions')); |
| + apiFunctions.setHandleRequestWithPromise( |
| + 'getControlSignals', forwardToConnection('getControlSignals')); |
| + apiFunctions.setHandleRequestWithPromise( |
| + 'setControlSignals', forwardToConnection('setControlSignals')); |
| + apiFunctions.setHandleRequestWithPromise( |
| + 'flush', forwardToConnection('flush')); |
| + apiFunctions.setHandleRequestWithPromise( |
| + 'setPaused', forwardToConnection('setPaused')); |
| + |
| + apiFunctions.setHandleRequestWithPromise('getConnections', function() { |
| + return serialService.getConnections().then(function(connections) { |
| + var promises = []; |
| + for (var id in connections) { |
| + promises.push(connections[id].getInfo()); |
| + } |
| + return Promise.all(promises); |
| + }); |
| + }); |
| }); |
| exports.binding = binding.generate(); |