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 509813002: Implement the client side of Serial I/O on data pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serial-io
Patch Set: remove TimeoutManager.pause() Created 6 years, 3 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 1d107c0e016729098f2a0bffb4090eac6d8ceb20..f0af8dad3a51015dc33ed9ce872e6865bce8280d 100644
--- a/extensions/renderer/resources/serial_custom_bindings.js
+++ b/extensions/renderer/resources/serial_custom_bindings.js
@@ -13,6 +13,7 @@
var binding = require('binding').Binding.create('serial');
var context = requireNative('v8_context');
+var eventBindings = require('event_bindings');
var utils = require('utils');
var serialServicePromise = function() {
@@ -48,13 +49,22 @@ binding.registerCustomHook(function(bindingsAPI) {
apiFunctions.setHandleRequestWithPromise('getDevices', function() {
return serialServicePromise.then(function(serialService) {
return serialService.getDevices();
- })
+ });
});
apiFunctions.setHandleRequestWithPromise('connect', function(path, options) {
return serialServicePromise.then(function(serialService) {
return serialService.createConnection(path, options);
}).then(function(result) {
+ var id = result.info.connectionId;
+ result.connection.onData = function(data) {
+ eventBindings.dispatchEvent(
+ 'serial.onReceive', [{connectionId: id, data: data}]);
+ };
+ result.connection.onError = function(error) {
+ eventBindings.dispatchEvent(
+ 'serial.onReceiveError', [{connectionId: id, error: error}]);
+ };
return result.info;
}).catch (function(e) {
throw new Error('Failed to connect to the port.');
@@ -75,6 +85,8 @@ binding.registerCustomHook(function(bindingsAPI) {
'flush', forwardToConnection('flush'));
apiFunctions.setHandleRequestWithPromise(
'setPaused', forwardToConnection('setPaused'));
+ apiFunctions.setHandleRequestWithPromise(
+ 'send', forwardToConnection('send'));
apiFunctions.setHandleRequestWithPromise('getConnections', function() {
return serialServicePromise.then(function(serialService) {
« no previous file with comments | « extensions/renderer/api/serial/serial_api_unittest.cc ('k') | extensions/renderer/resources/serial_service.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698