| 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; | 8 var isRecording = false; |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * 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 |
| 12 * element to the value of this property. Otherwise clear the content. | 12 * element to the value of this property. Otherwise clear the content. |
| 13 * @param {!Object} info A dictionary of device infos to be displayed. | 13 * @param {!Object} info A dictionary of device infos to be displayed. |
| 14 * @param {string} prop Name of the property. | 14 * @param {string} prop Name of the property. |
| 15 * @param {string} element The id of a HTML element. | 15 * @param {string} elementId The id of a HTML element. |
| 16 */ | 16 */ |
| 17 function setIfExists(info, prop, element) { | 17 function setIfExists(info, prop, elementId) { |
| 18 var element = $(elementId); |
| 19 if (!element) |
| 20 return; |
| 21 |
| 18 if (info[prop] !== undefined) { | 22 if (info[prop] !== undefined) { |
| 19 $(element).textContent = info[prop]; | 23 element.textContent = info[prop]; |
| 20 } else { | 24 } else { |
| 21 $(element).textContent = ''; | 25 element.textContent = ''; |
| 22 } | 26 } |
| 23 } | 27 } |
| 24 | 28 |
| 25 /** | 29 /** |
| 26 * Display device informations. | 30 * Display device informations. |
| 27 * @param {!Object} info A dictionary of device infos to be displayed. | 31 * @param {!Object} info A dictionary of device infos to be displayed. |
| 28 */ | 32 */ |
| 29 function displayDeviceInfo(info) { | 33 function displayDeviceInfo(info) { |
| 30 setIfExists(info, 'androidId', 'android-id'); | 34 setIfExists(info, 'androidId', 'android-id'); |
| 31 setIfExists(info, 'profileServiceCreated', 'profile-service-created'); | 35 setIfExists(info, 'profileServiceCreated', 'profile-service-created'); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 $('recording').disabled = true; | 103 $('recording').disabled = true; |
| 100 $('refresh').onclick = refreshAll; | 104 $('refresh').onclick = refreshAll; |
| 101 $('recording').onclick = setRecording; | 105 $('recording').onclick = setRecording; |
| 102 $('clear-logs').onclick = clearLogs; | 106 $('clear-logs').onclick = clearLogs; |
| 103 chrome.send('getGcmInternalsInfo', [false]); | 107 chrome.send('getGcmInternalsInfo', [false]); |
| 104 } | 108 } |
| 105 | 109 |
| 106 /** | 110 /** |
| 107 * Refresh the log html table by clearing it first. If data is not empty, then | 111 * Refresh the log html table by clearing it first. If data is not empty, then |
| 108 * it will be used to populate the table. | 112 * it will be used to populate the table. |
| 109 * @param {string} id ID of the log html table. | 113 * @param {string} tableId ID of the log html table. |
| 110 * @param {!Object} data A list of list of data items. | 114 * @param {!Object} data A list of list of data items. |
| 111 */ | 115 */ |
| 112 function refreshLogTable(id, data) { | 116 function refreshLogTable(tableId, data) { |
| 113 removeAllChildNodes($(id)); | 117 var element = $(tableId); |
| 114 if (data !== undefined) { | 118 if (!element) |
| 115 addRows($(id), data); | 119 return; |
| 116 } | 120 |
| 121 removeAllChildNodes(element); |
| 122 if (data !== undefined) |
| 123 addRows(element, data); |
| 117 } | 124 } |
| 118 | 125 |
| 119 /** | 126 /** |
| 120 * Callback function accepting a dictionary of info items to be displayed. | 127 * Callback function accepting a dictionary of info items to be displayed. |
| 121 * @param {!Object} infos A dictionary of info items to be displayed. | 128 * @param {!Object} infos A dictionary of info items to be displayed. |
| 122 */ | 129 */ |
| 123 function setGcmInternalsInfo(infos) { | 130 function setGcmInternalsInfo(infos) { |
| 124 isRecording = infos.isRecording; | 131 isRecording = infos.isRecording; |
| 125 if (isRecording) | 132 if (isRecording) |
| 126 $('recording').textContent = 'Stop Recording'; | 133 $('recording').textContent = 'Stop Recording'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 139 } | 146 } |
| 140 | 147 |
| 141 // Return an object with all of the exports. | 148 // Return an object with all of the exports. |
| 142 return { | 149 return { |
| 143 initialize: initialize, | 150 initialize: initialize, |
| 144 setGcmInternalsInfo: setGcmInternalsInfo, | 151 setGcmInternalsInfo: setGcmInternalsInfo, |
| 145 }; | 152 }; |
| 146 }); | 153 }); |
| 147 | 154 |
| 148 document.addEventListener('DOMContentLoaded', gcmInternals.initialize); | 155 document.addEventListener('DOMContentLoaded', gcmInternals.initialize); |
| OLD | NEW |