Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: extensions/renderer/resources/serial_custom_bindings.js

Issue 423403002: Implement more of chrome.serial on the Mojo SerialConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@js-serial
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();

Powered by Google App Engine
This is Rietveld 408576698