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

Side by Side Diff: chrome/browser/resources/usb_internals/usb_internals.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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.serial_number;
27 landingPage.textContent = device.landing_page.url; 27 landingPage.textContent = device.landing_page.url;
28 removeButton.addEventListener('click', function() { 28 removeButton.addEventListener('click', function() {
29 pageHandler.removeDeviceForTesting(device.guid) 29 pageHandler.removeDeviceForTesting(device.guid).then(refreshDeviceList);
30 .then(refreshDeviceList); 30 });
31 }); 31 removeButton.textContent = 'Remove';
32 removeButton.textContent = 'Remove'; 32 row.appendChild(name);
33 row.appendChild(name); 33 row.appendChild(serialNumber);
34 row.appendChild(serialNumber); 34 row.appendChild(landingPage);
35 row.appendChild(landingPage); 35 remove.appendChild(removeButton);
36 remove.appendChild(removeButton); 36 row.appendChild(remove);
37 row.appendChild(remove); 37 tableBody.appendChild(row);
38 tableBody.appendChild(row); 38 }
39 } 39 });
40 }); 40 }
41 }
42 41
43 function addTestDevice(event) { 42 function addTestDevice(event) {
44 pageHandler.addDeviceForTesting( 43 pageHandler
45 $('test-device-name').value, 44 .addDeviceForTesting(
46 $('test-device-serial').value, 45 $('test-device-name').value, $('test-device-serial').value,
47 $('test-device-landing-page').value).then(function(response) { 46 $('test-device-landing-page').value)
48 if (response.success) 47 .then(function(response) {
49 refreshDeviceList(); 48 if (response.success)
50 $('add-test-device-result').textContent = response.message; 49 refreshDeviceList();
51 $('add-test-device-result').className = 50 $('add-test-device-result').textContent = response.message;
52 response.success ? 'action-success' : 'action-failure'; 51 $('add-test-device-result').className =
53 }); 52 response.success ? 'action-success' : 'action-failure';
54 event.preventDefault(); 53 });
55 } 54 event.preventDefault();
55 }
56 56
57 function initializeProxies() { 57 function initializeProxies() {
58 return importModules([ 58 return importModules([
59 'chrome/browser/ui/webui/usb_internals/usb_internals.mojom', 59 'chrome/browser/ui/webui/usb_internals/usb_internals.mojom',
60 'content/public/renderer/frame_interfaces', 60 'content/public/renderer/frame_interfaces',
61 ]).then(function(modules) { 61 ])
62 let mojom = modules[0]; 62 .then(function(modules) {
63 let frameInterfaces = modules[1]; 63 let mojom = modules[0];
64 let frameInterfaces = modules[1];
64 65
65 pageHandler = new mojom.UsbInternalsPageHandlerPtr( 66 pageHandler = new mojom.UsbInternalsPageHandlerPtr(
66 frameInterfaces.getInterface(mojom.UsbInternalsPageHandler.name)); 67 frameInterfaces.getInterface(mojom.UsbInternalsPageHandler.name));
67 }); 68 });
68 } 69 }
69 70
70 document.addEventListener('DOMContentLoaded', function() { 71 document.addEventListener('DOMContentLoaded', function() {
71 initializeProxies().then(function() { 72 initializeProxies().then(function() {
72 $('add-test-device-form').addEventListener('submit', addTestDevice); 73 $('add-test-device-form').addEventListener('submit', addTestDevice);
73 refreshDeviceList(); 74 refreshDeviceList();
74 });
75 }); 75 });
76 });
76 })(); 77 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698