| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Javascript for usb_internals.html, served from chrome://usb-internals/. | 6 * Javascript for usb_internals.html, served from chrome://usb-internals/. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 (function() { | 9 (function() { |
| 10 // Connection to the UsbInternalsPageHandler instance running in the browser | 10 // Connection to the UsbInternalsPageHandler instance running in the browser |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 $('test-device-allowed-origin').value).then(function(response) { | 52 $('test-device-allowed-origin').value).then(function(response) { |
| 53 if (response.success) | 53 if (response.success) |
| 54 refreshDeviceList(); | 54 refreshDeviceList(); |
| 55 $('add-test-device-result').textContent = response.message; | 55 $('add-test-device-result').textContent = response.message; |
| 56 $('add-test-device-result').className = | 56 $('add-test-device-result').className = |
| 57 response.success ? 'action-success' : 'action-failure'; | 57 response.success ? 'action-success' : 'action-failure'; |
| 58 }); | 58 }); |
| 59 event.preventDefault(); | 59 event.preventDefault(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 /** | |
| 63 * Helper to convert callback-based define() API to a promise-based API. | |
| 64 * @param {!Array<string>} moduleNames | |
| 65 * @return {!Promise} | |
| 66 */ | |
| 67 function importModules(moduleNames) { | |
| 68 return new Promise(function(resolve, reject) { | |
| 69 define(moduleNames, function(var_args) { | |
| 70 resolve(Array.prototype.slice.call(arguments, 0)); | |
| 71 }); | |
| 72 }); | |
| 73 } | |
| 74 | |
| 75 function initializeProxies() { | 62 function initializeProxies() { |
| 76 return importModules([ | 63 return importModules([ |
| 77 'mojo/public/js/connection', | 64 'mojo/public/js/connection', |
| 78 'chrome/browser/ui/webui/usb_internals/usb_internals.mojom', | 65 'chrome/browser/ui/webui/usb_internals/usb_internals.mojom', |
| 79 'content/public/renderer/frame_interfaces', | 66 'content/public/renderer/frame_interfaces', |
| 80 ]).then(function(modules) { | 67 ]).then(function(modules) { |
| 81 let connection = modules[0]; | 68 let connection = modules[0]; |
| 82 let mojom = modules[1]; | 69 let mojom = modules[1]; |
| 83 let frameInterfaces = modules[2]; | 70 let frameInterfaces = modules[2]; |
| 84 | 71 |
| 85 pageHandler = connection.bindHandleToProxy( | 72 pageHandler = connection.bindHandleToProxy( |
| 86 frameInterfaces.getInterface(mojom.UsbInternalsPageHandler.name), | 73 frameInterfaces.getInterface(mojom.UsbInternalsPageHandler.name), |
| 87 mojom.UsbInternalsPageHandler); | 74 mojom.UsbInternalsPageHandler); |
| 88 }); | 75 }); |
| 89 } | 76 } |
| 90 | 77 |
| 91 document.addEventListener('DOMContentLoaded', function() { | 78 document.addEventListener('DOMContentLoaded', function() { |
| 92 initializeProxies().then(function() { | 79 initializeProxies().then(function() { |
| 93 $('add-test-device-form').addEventListener('submit', addTestDevice); | 80 $('add-test-device-form').addEventListener('submit', addTestDevice); |
| 94 refreshDeviceList(); | 81 refreshDeviceList(); |
| 95 }); | 82 }); |
| 96 }); | 83 }); |
| 97 })(); | 84 })(); |
| OLD | NEW |