OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 cr.define('gcmInternals', function() { | 5 cr.define('gcmInternals', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var isRecording = false; | |
9 | |
8 /** | 10 /** |
9 * If the info dictionary has property prop, then set the text content of | 11 * If the info dictionary has property prop, then set the text content of |
10 * element to the value of this property. | 12 * element to the value of this property. Otherwise clear the content. |
11 * @param {!Object} info A dictionary of device infos to be displayed. | 13 * @param {!Object} info A dictionary of device infos to be displayed. |
12 * @param {string} prop Name of the property. | 14 * @param {string} prop Name of the property. |
13 * @param {string} element The id of a HTML element. | 15 * @param {string} element The id of a HTML element. |
14 */ | 16 */ |
15 function setIfExists(info, prop, element) { | 17 function setIfExists(info, prop, element) { |
16 if (info[prop] !== undefined) { | 18 if (info[prop] !== undefined) { |
17 $(element).textContent = info[prop]; | 19 $(element).textContent = info[prop]; |
20 } else { | |
21 $(element).textContent = ''; | |
18 } | 22 } |
19 } | 23 } |
20 | 24 |
21 /** | 25 /** |
22 * Display device informations. | 26 * Display device informations. |
23 * @param {!Object} info A dictionary of device infos to be displayed. | 27 * @param {!Object} info A dictionary of device infos to be displayed. |
24 */ | 28 */ |
25 function displayDeviceInfo(info) { | 29 function displayDeviceInfo(info) { |
26 setIfExists(info, 'androidId', 'android-id'); | 30 setIfExists(info, 'androidId', 'android-id'); |
27 setIfExists(info, 'profileServiceCreated', 'profile-service-created'); | 31 setIfExists(info, 'profileServiceCreated', 'profile-service-created'); |
28 setIfExists(info, 'gcmEnabledState', 'gcm-enabled-state'); | 32 setIfExists(info, 'gcmEnabledState', 'gcm-enabled-state'); |
29 setIfExists(info, 'signedInUserName', 'signed-in-username'); | 33 setIfExists(info, 'signedInUserName', 'signed-in-username'); |
30 setIfExists(info, 'gcmClientCreated', 'gcm-client-created'); | 34 setIfExists(info, 'gcmClientCreated', 'gcm-client-created'); |
31 setIfExists(info, 'gcmClientState', 'gcm-client-state'); | 35 setIfExists(info, 'gcmClientState', 'gcm-client-state'); |
32 setIfExists(info, 'gcmClientReady', 'gcm-client-ready'); | 36 setIfExists(info, 'gcmClientReady', 'gcm-client-ready'); |
33 setIfExists(info, 'connectionClientCreated', 'connection-client-created'); | 37 setIfExists(info, 'connectionClientCreated', 'connection-client-created'); |
34 setIfExists(info, 'connectionState', 'connection-state'); | 38 setIfExists(info, 'connectionState', 'connection-state'); |
39 setIfExists(info, 'appIdsCached', 'app-ids-cached'); | |
40 setIfExists(info, 'sendQueueSize', 'send-queue-size'); | |
41 setIfExists(info, 'unackedQueueSize', 'unacked-queue-size'); | |
42 } | |
43 | |
44 /** | |
45 * Remove all the child nodes of the element. | |
46 * @param {HTMLElement} element A HTML element. | |
47 */ | |
48 function removeAllChildNodes(element) { | |
49 while (element.firstChild) { | |
arv (Not doing code reviews)
2014/03/24 18:47:05
element.textContent = '';
juyik
2014/03/26 04:06:03
Done.
| |
50 element.removeChild(element.firstChild); | |
51 } | |
52 } | |
53 | |
54 /** | |
55 * For each item in line, add a row to the table. Each item is actually a list | |
56 * of sub-items; each of which will have a corresponding cell created in that | |
57 * row, and the sub-item will be displayed in the cell. | |
58 * @param {HTMLElement} table A HTML tbody element. | |
59 * @param {!Object} list A list of list of item. | |
60 */ | |
61 function addRows(table, list) { | |
62 for (var i = 0; i < list.length; ++i) { | |
63 var row = document.createElement('tr'); | |
64 | |
65 // The first element is always a timestamp. | |
66 var cell = document.createElement('td'); | |
67 var d = new Date(list[i][0]); | |
68 cell.textContent = d.toString(); | |
69 row.appendChild(cell); | |
70 | |
71 for (var j = 1; j < list[i].length; ++j) { | |
72 var cell = document.createElement('td'); | |
73 cell.textContent = list[i][j]; | |
74 row.appendChild(cell); | |
75 } | |
76 if ((i % 2) == 0) | |
77 row.className = 'odd-number-row'; | |
78 table.appendChild(row); | |
79 } | |
80 } | |
81 | |
82 /** | |
83 * Refresh all displayed information. | |
84 */ | |
85 function refreshAll() { | |
86 chrome.send('getGcmInternalsInfo', [false]); | |
87 } | |
88 | |
89 /** | |
90 * Toggle the isRecording variable and send it to browser. | |
91 */ | |
92 function setRecording() { | |
93 isRecording = !isRecording; | |
94 chrome.send('setGcmInternalsRecording', [isRecording]); | |
95 } | |
96 | |
97 /** | |
98 * Clear all the activity logs. | |
99 */ | |
100 function clearLogs() { | |
101 chrome.send('getGcmInternalsInfo', [true]); | |
35 } | 102 } |
36 | 103 |
37 function initialize() { | 104 function initialize() { |
38 chrome.send('getGcmInternalsInfo'); | 105 $('recording').disabled = true; |
106 $('refresh').onclick = refreshAll; | |
107 $('recording').onclick = setRecording; | |
108 $('clear-logs').onclick = clearLogs; | |
109 chrome.send('getGcmInternalsInfo', [false]); | |
39 } | 110 } |
40 | 111 |
41 /** | 112 /** |
42 * Callback function accepting a dictionary of info items to be displayed. | 113 * Callback function accepting a dictionary of info items to be displayed. |
43 * @param {!Object} infos A dictionary of info items to be displayed. | 114 * @param {!Object} infos A dictionary of info items to be displayed. |
44 */ | 115 */ |
45 function setGcmInternalsInfo(infos) { | 116 function setGcmInternalsInfo(infos) { |
117 isRecording = infos.isRecording; | |
118 if (isRecording) | |
119 $('recording').textContent = 'Stop Recording'; | |
120 else | |
121 $('recording').textContent = 'Start Recording'; | |
122 $('recording').disabled = false; | |
46 if (infos.deviceInfo !== undefined) { | 123 if (infos.deviceInfo !== undefined) { |
47 displayDeviceInfo(infos.deviceInfo); | 124 displayDeviceInfo(infos.deviceInfo); |
48 } | 125 } |
126 | |
127 removeAllChildNodes($('send-info')); | |
128 if (infos.sendInfo !== undefined) { | |
129 addRows($('send-info'), infos.sendInfo); | |
130 } | |
49 } | 131 } |
50 | 132 |
51 // Return an object with all of the exports. | 133 // Return an object with all of the exports. |
52 return { | 134 return { |
53 initialize: initialize, | 135 initialize: initialize, |
54 setGcmInternalsInfo: setGcmInternalsInfo, | 136 setGcmInternalsInfo: setGcmInternalsInfo, |
55 }; | 137 }; |
56 }); | 138 }); |
57 | 139 |
58 document.addEventListener('DOMContentLoaded', gcmInternals.initialize); | 140 document.addEventListener('DOMContentLoaded', gcmInternals.initialize); |
OLD | NEW |