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 /** | |
9 * If the info dictionary has property prop, then set the text 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 {string} element The id of a HTML element. | |
14 */ | |
15 function setIfExists(info, prop, element) { | |
16 if (info[prop] !== undefined) { | |
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, 'userProfileName', 'profile-name'); | |
27 setIfExists(info, 'profileServiceCreated', 'profile-service-created'); | |
28 setIfExists(info, 'gcmEnabledState', 'gcm-enabled-state'); | |
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['deviceInfo'] != undefined) { | |
arv (Not doing code reviews)
2014/03/05 19:44:14
you probably want !== to distinguish null from und
arv (Not doing code reviews)
2014/03/05 19:44:14
Why infos['deviceInfo'] here but infos.deviceInfo
juyik
2014/03/05 19:58:26
Done.
juyik
2014/03/05 19:58:26
Done.
| |
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', gcmInternals.initialize); |
OLD | NEW |