1 // Copyright 2013 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.
5 // Called by the common.js module.
6 function moduleDidLoad() {
7 // The module is not hidden by default so we can easily see if the plugin
12 // Called by the common.js module.
13 function handleMessage(message
) {
14 if (typeof message
.data
=== "string") {
15 // We got an error from the NaCl module.
16 common
.logMessage('Error: ' + message
.data
);
20 // We expect that the message looks like this:
22 // name: "...", displayName: "...", state: "...", type: "...", MTU: 1234,
23 // ipAddresses: ["...", "..."]},
27 // Append a <tr> to the <tbody> for each interface in the array.
28 // The order in the .html file is:
29 // index, display name, name, type, state, ip addresses, MTU.
30 var net_interfaces
= message
.data
;
32 var tbodyEl
= document
.querySelector('tbody');
33 // First, clear the tbody.
34 while (tbodyEl
.firstChild
) {
35 tbodyEl
.removeChild(tbodyEl
.firstChild
);
38 for (var i
= 0; i
< net_interfaces
.length
; ++i
) {
39 var net_interface
= net_interfaces
[i
];
40 var trEl
= document
.createElement('tr');
41 trEl
.appendChild(makeTd(i
));
42 trEl
.appendChild(makeTd(net_interface
.displayName
));
43 trEl
.appendChild(makeTd(net_interface
.name
));
44 trEl
.appendChild(makeTd(net_interface
.type
));
45 trEl
.appendChild(makeTd(net_interface
.state
));
46 // ipAddresses is an array of strings. Let's join them with a comma.
47 trEl
.appendChild(makeTd(net_interface
.ipAddresses
.join(', ')));
48 trEl
.appendChild(makeTd(net_interface
.MTU
));
49 tbodyEl
.appendChild(trEl
);
53 function makeTd(text
) {
54 var tdEl
= document
.createElement('td');
55 tdEl
.textContent
= text
;