diff options
author | sammc@chromium.org <sammc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-29 08:11:44 +0000 |
---|---|---|
committer | sammc@chromium.org <sammc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-29 08:11:44 +0000 |
commit | afac7312f4245e61a940e0a307f34b8bde8a2ddf (patch) | |
tree | 384f3cc037872d6d4bea37ec728fc730b0ddf326 /extensions/renderer/resources/serial_service.js | |
parent | e5dd2e068095b0e60fe94c5cb31d0fd45a0f51f2 (diff) | |
download | chromium_src-afac7312f4245e61a940e0a307f34b8bde8a2ddf.zip chromium_src-afac7312f4245e61a940e0a307f34b8bde8a2ddf.tar.gz chromium_src-afac7312f4245e61a940e0a307f34b8bde8a2ddf.tar.bz2 |
Implement chrome.serial.getDevices() on top of the Mojo serial service.
This does not change Chrome to use the new implementation.
BUG=389016
Review URL: https://codereview.chromium.org/391413005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286122 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/renderer/resources/serial_service.js')
-rw-r--r-- | extensions/renderer/resources/serial_service.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/extensions/renderer/resources/serial_service.js b/extensions/renderer/resources/serial_service.js new file mode 100644 index 0000000..92e17d0 --- /dev/null +++ b/extensions/renderer/resources/serial_service.js @@ -0,0 +1,42 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +define('serial_service', [ + 'content/public/renderer/service_provider', + 'device/serial/serial.mojom', + 'mojo/public/js/bindings/router', +], function(serviceProvider, serialMojom, routerModule) { + + function defineService(proxy, handle) { + if (!handle) + handle = serviceProvider.connectToService(proxy.NAME_); + var router = new routerModule.Router(handle); + var service = new proxy(router); + return { + service: service, + router: router, + }; + } + + var service = defineService(serialMojom.SerialServiceProxy).service; + + function getDevices() { + return service.getDevices().then(function(response) { + return $Array.map(response.devices, function(device) { + var result = {path: device.path || ''}; + if (device.has_vendor_id) + result.vendorId = device.vendor_id; + if (device.has_product_id) + result.productId = device.product_id; + if (device.display_name) + result.displayName = device.display_name; + return result; + }); + }); + } + + return { + getDevices: getDevices, + }; +}); |