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('gcm_internals', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
| 8 /** |
| 9 * If the info dictionary has property prop, then set the tex content of |
| 10 * element to the value of this property. |
| 11 * @param {!Object} info A dictionary of device infos to be displayed. |
| 12 * @param {string} prop Name of the property. |
| 13 * @param {HTMLElement} element An HTML element. |
| 14 */ |
| 15 function setIfExists(info, prop, element) { |
| 16 if (info.hasOwnProperty(prop)) { |
| 17 $(element).textContent = info[prop]; |
| 18 } |
| 19 } |
| 20 |
| 21 /** |
| 22 * Display device informations. |
| 23 * @param {!Object} info A dictionary of device infos to be displayed. |
| 24 */ |
| 25 function displayDeviceInfo(info) { |
| 26 setIfExists(info, 'userProfileExists', 'profile-exists'); |
| 27 setIfExists(info, 'profileServiceCreated', 'profile-service-created'); |
| 28 setIfExists(info, 'gcmEnabled', 'gcm-enabled'); |
| 29 setIfExists(info, 'userSignedIn', 'user-signed-in'); |
| 30 setIfExists(info, 'gcmClientCreated', 'gcm-client-created'); |
| 31 setIfExists(info, 'gcmClientState', 'gcm-client-state'); |
| 32 setIfExists(info, 'gcmClientReady', 'gcm-client-ready'); |
| 33 setIfExists(info, 'connectionClientCreated', 'connection-client-created'); |
| 34 setIfExists(info, 'connectionState', 'connection-state'); |
| 35 } |
| 36 |
8 function initialize() { | 37 function initialize() { |
| 38 chrome.send('getGcmInternalsInfo'); |
| 39 } |
| 40 |
| 41 /** |
| 42 * Callback function accepting a dictionary of info items to be displayed. |
| 43 * @param {!Object} infos A dictionary of info items to be displayed. |
| 44 */ |
| 45 function setGcmInternalsInfo(infos) { |
| 46 if (infos.hasOwnProperty('deviceInfo')) { |
| 47 displayDeviceInfo(infos.deviceInfo); |
| 48 } |
9 } | 49 } |
10 | 50 |
11 // Return an object with all of the exports. | 51 // Return an object with all of the exports. |
12 return { | 52 return { |
13 initialize: initialize, | 53 initialize: initialize, |
| 54 setGcmInternalsInfo: setGcmInternalsInfo, |
14 }; | 55 }; |
15 }); | 56 }); |
16 | 57 |
17 document.addEventListener('DOMContentLoaded', gcminternals.initialize); | 58 document.addEventListener('DOMContentLoaded', gcm_internals.initialize); |
OLD | NEW |