| 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 |
| 11 // process. | 11 // process. |
| 12 let pageHandler = null; | 12 let pageHandler = null; |
| 13 | 13 |
| 14 function refreshDeviceList() { | 14 function refreshDeviceList() { |
| 15 pageHandler.getTestDevices().then(function(response) { | 15 pageHandler.getTestDevices().then(function(response) { |
| 16 let tableBody = $('test-device-list'); | 16 let tableBody = $('test-device-list'); |
| 17 tableBody.innerHTML = ''; | 17 tableBody.innerHTML = ''; |
| 18 for (let device of response.devices) { | 18 for (let device of response.devices) { |
| 19 let row = document.createElement('tr'); | 19 let row = document.createElement('tr'); |
| 20 let name = document.createElement('td'); | 20 let name = document.createElement('td'); |
| 21 let serialNumber = document.createElement('td'); | 21 let serialNumber = document.createElement('td'); |
| 22 let landingPage = document.createElement('td'); | 22 let landingPage = document.createElement('td'); |
| 23 let remove = document.createElement('td'); | 23 let remove = document.createElement('td'); |
| 24 let removeButton = document.createElement('button'); | 24 let removeButton = document.createElement('button'); |
| 25 name.textContent = device.name; | 25 name.textContent = device.name; |
| 26 serialNumber.textContent = device.serial_number; | 26 serialNumber.textContent = device.serialNumber; |
| 27 landingPage.textContent = device.landing_page.url; | 27 landingPage.textContent = device.landingPage.url; |
| 28 removeButton.addEventListener('click', function() { | 28 removeButton.addEventListener('click', function() { |
| 29 pageHandler.removeDeviceForTesting(device.guid).then(refreshDeviceList); | 29 pageHandler.removeDeviceForTesting(device.guid).then(refreshDeviceList); |
| 30 }); | 30 }); |
| 31 removeButton.textContent = 'Remove'; | 31 removeButton.textContent = 'Remove'; |
| 32 row.appendChild(name); | 32 row.appendChild(name); |
| 33 row.appendChild(serialNumber); | 33 row.appendChild(serialNumber); |
| 34 row.appendChild(landingPage); | 34 row.appendChild(landingPage); |
| 35 remove.appendChild(removeButton); | 35 remove.appendChild(removeButton); |
| 36 row.appendChild(remove); | 36 row.appendChild(remove); |
| 37 tableBody.appendChild(row); | 37 tableBody.appendChild(row); |
| 38 } | 38 } |
| 39 }); | 39 }); |
| 40 } | 40 } |
| 41 | 41 |
| 42 function addTestDevice(event) { | 42 function addTestDevice(event) { |
| 43 pageHandler | 43 pageHandler |
| 44 .addDeviceForTesting( | 44 .addDeviceForTesting( |
| 45 $('test-device-name').value, $('test-device-serial').value, | 45 $('test-device-name').value, $('test-device-serial').value, |
| 46 $('test-device-landing-page').value) | 46 $('test-device-landing-page').value) |
| 47 .then(function(response) { | 47 .then(function(response) { |
| 48 if (response.success) | 48 if (response.success) |
| 49 refreshDeviceList(); | 49 refreshDeviceList(); |
| 50 $('add-test-device-result').textContent = response.message; | 50 $('add-test-device-result').textContent = response.message; |
| 51 $('add-test-device-result').className = | 51 $('add-test-device-result').className = |
| 52 response.success ? 'action-success' : 'action-failure'; | 52 response.success ? 'action-success' : 'action-failure'; |
| 53 }); | 53 }); |
| 54 event.preventDefault(); | 54 event.preventDefault(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 function initializeProxies() { | 57 document.addEventListener('DOMContentLoaded', function() { |
| 58 return importModules([ | 58 pageHandler = new mojom.UsbInternalsPageHandlerPtr; |
| 59 'chrome/browser/ui/webui/usb_internals/usb_internals.mojom', | 59 Mojo.bindInterface( |
| 60 'content/public/renderer/frame_interfaces', | 60 mojom.UsbInternalsPageHandler.name, mojo.makeRequest(pageHandler).handle); |
| 61 ]) | |
| 62 .then(function(modules) { | |
| 63 let mojom = modules[0]; | |
| 64 let frameInterfaces = modules[1]; | |
| 65 | 61 |
| 66 pageHandler = new mojom.UsbInternalsPageHandlerPtr( | 62 $('add-test-device-form').addEventListener('submit', addTestDevice); |
| 67 frameInterfaces.getInterface(mojom.UsbInternalsPageHandler.name)); | 63 refreshDeviceList(); |
| 68 }); | |
| 69 } | |
| 70 | |
| 71 document.addEventListener('DOMContentLoaded', function() { | |
| 72 initializeProxies().then(function() { | |
| 73 $('add-test-device-form').addEventListener('submit', addTestDevice); | |
| 74 refreshDeviceList(); | |
| 75 }); | |
| 76 }); | 64 }); |
| 77 })(); | 65 })(); |
| OLD | NEW |