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

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

Issue 2204713006: Add chrome://usb-internals page for adding and removing test devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * Javascript for usb_internals.html, served from chrome://usb-internals/.
7 */
8
9 (function() {
10 // Connection to the UsbInternalsPageHandler instance running in the browser
11 // process.
12 let pageHandler = null;
13
14 /**
15 * Register event handlers.
16 */
17 function initialize() {
18 $('add-test-device-form').addEventListener('submit', addTestDevice);
19 refreshDeviceList();
20 }
21
22 function refreshDeviceList() {
23 pageHandler.getTestDevices().then(function(response) {
24 let tableBody = $('test-device-list');
25 while (tableBody.firstChild)
26 tableBody.removeChild(tableBody.firstChild);
27 for (let device of response.devices) {
28 let row = document.createElement('tr');
29 let name = document.createElement('td');
30 let serialNumber = document.createElement('td');
31 let landingPage = document.createElement('td');
32 let allowedOrigin = document.createElement('td');
33 let remove = document.createElement('td');
34 let removeButton = document.createElement('button');
35 name.textContent = device.name;
36 serialNumber.textContent = device.serial_number;
37 landingPage.textContent = device.landing_page;
38 allowedOrigin.textContent = device.allowed_origin;
39 removeButton.addEventListener('click', function(e) {
40 pageHandler.removeDeviceForTesting(device.guid)
41 .then(refreshDeviceList);
42 });
43 removeButton.textContent = 'Remove';
44 row.appendChild(name);
45 row.appendChild(serialNumber);
46 row.appendChild(landingPage);
47 row.appendChild(allowedOrigin);
48 remove.appendChild(removeButton);
49 row.appendChild(remove);
50 tableBody.appendChild(row);
51 }
52 });
53 }
54
55 function addTestDevice(event) {
56 pageHandler.addDeviceForTesting(
57 $('test-device-name').value,
58 $('test-device-serial').value,
59 $('test-device-landing-page').value,
60 $('test-device-allowed-origin').value).then(function(response) {
61 if (response.success)
62 refreshDeviceList();
63 $('add-test-device-result').textContent = response.message;
64 $('add-test-device-result').className =
65 response.success ? 'action-success' : 'action-failure';
66 });
67 event.preventDefault();
68 }
69
70 /**
71 * Helper to convert callback-based define() API to a promise-based API.
72 * @param {!Array<string>} moduleNames
73 * @return {!Promise}
74 */
75 function importModules(moduleNames) {
76 return new Promise(function(resolve, reject) {
77 define(moduleNames, function(var_args) {
78 resolve(Array.prototype.slice.call(arguments, 0));
79 });
80 });
81 }
82
83 function initializeProxies() {
84 return importModules([
85 'mojo/public/js/connection',
86 'chrome/browser/ui/webui/usb_internals/usb_internals.mojom',
87 'content/public/renderer/frame_interfaces',
88 ]).then(function(modules) {
89 let connection = modules[0];
90 let mojom = modules[1];
91 let frameInterfaces = modules[2];
92
93 pageHandler = connection.bindHandleToProxy(
94 frameInterfaces.getInterface(mojom.UsbInternalsPageHandler.name),
95 mojom.UsbInternalsPageHandler);
96 });
97 }
98
99 document.addEventListener('DOMContentLoaded', function() {
100 initializeProxies().then(initialize);
dpapad 2016/08/04 20:55:34 The |initialize| method is too small, and only cal
Reilly Grant (use Gerrit) 2016/08/05 01:30:55 Inlined.
101 });
102 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698