Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <script> | 1 <script> |
| 2 (function () { | 2 (function () { |
| 3 // Contains all notifications received since the page was loaded as a | 3 |
| 4 // map from each data type to the number of notifications received for | 4 // TODO(akalin): Use table.js. |
| 5 // it. | |
| 6 chrome.sync.notifications = {}; | |
| 7 | 5 |
| 8 function updateNotificationsEnabledInfo(notificationsEnabled) { | 6 function updateNotificationsEnabledInfo(notificationsEnabled) { |
| 9 var notificationsEnabledInfo = | 7 var notificationsEnabledInfo = |
| 10 document.getElementById('notificationsEnabledInfo'); | 8 document.getElementById('notificationsEnabledInfo'); |
| 11 jstProcess( | 9 jstProcess( |
| 12 new JsEvalContext({ 'notificationsEnabled': notificationsEnabled }), | 10 new JsEvalContext({ 'notificationsEnabled': notificationsEnabled }), |
| 13 notificationsEnabledInfo); | 11 notificationsEnabledInfo); |
| 14 } | 12 } |
| 15 | 13 |
| 16 function updateNotificationInfo(notification) { | 14 // Contains all notifications received since the page was loaded as a |
| 17 var notificationInfo = document.getElementById('notificationInfo'); | 15 // map from each data type to the number of notifications received for |
| 18 jstProcess( | 16 // it. |
| 19 new JsEvalContext({ | 17 chrome.sync.notifications = {}; |
| 20 'notificationInfo': JSON.stringify(notification, null, 2) | 18 |
| 21 }), | 19 /** |
| 22 notificationInfo); | 20 * Merges d1 and d2 (with d2 taking precedence) and returns the result. |
| 21 */ | |
| 22 function mergeDictionaries(d1, d2) { | |
| 23 var d = {}; | |
| 24 for (var k in d1) { | |
| 25 d[k] = d1[k]; | |
| 26 } | |
| 27 for (var k in d2) { | |
| 28 d[k] = d2[k]; | |
| 29 } | |
| 30 return d; | |
| 31 } | |
| 32 | |
| 33 /** | |
| 34 * Merge notificationInfo into chrome.sync.notifications. | |
| 35 */ | |
| 36 function updateNotificationsFromNotificationInfo(notificationInfo) { | |
| 37 for (var k in notificationInfo) { | |
| 38 chrome.sync.notifications[k] = | |
| 39 mergeDictionaries(chrome.sync.notifications[k] || {}, | |
| 40 notificationInfo[k]); | |
| 41 chrome.sync.notifications[k].type = k; | |
|
Nicolas Zea
2011/05/12 23:38:09
Is this information not in the original notificati
akalin
2011/05/13 00:10:18
It is, but only as the key. I'm stuffing it into
| |
| 42 chrome.sync.notifications[k].sessionCount = | |
| 43 chrome.sync.notifications[k].sessionCount || 0; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 function incrementSessionNotificationCount(changedType) { | |
| 48 chrome.sync.notifications[changedType].sessionCount = | |
|
Nicolas Zea
2011/05/12 23:38:09
Is it possible this data will be overwritten when
akalin
2011/05/13 00:10:18
No, because we don't only the sessionCount in this
| |
| 49 chrome.sync.notifications[changedType].sessionCount || 0; | |
| 50 ++chrome.sync.notifications[changedType].sessionCount; | |
| 51 } | |
| 52 | |
| 53 function updateNotificationInfoTable() { | |
| 54 var notificationInfoTable = | |
| 55 document.getElementById('notificationInfo'); | |
| 56 var infos = []; | |
| 57 for (var k in chrome.sync.notifications) { | |
| 58 infos.push(chrome.sync.notifications[k]); | |
| 59 } | |
| 60 jstProcess(new JsEvalContext({ 'notifications': infos }), | |
| 61 notificationInfoTable); | |
| 62 } | |
| 63 | |
| 64 function updateNotificationInfo(notificationInfo) { | |
| 65 updateNotificationsFromNotificationInfo(notificationInfo); | |
| 66 updateNotificationInfoTable(); | |
| 23 } | 67 } |
| 24 | 68 |
| 25 function onLoad() { | 69 function onLoad() { |
| 26 chrome.sync.getNotificationState(updateNotificationsEnabledInfo); | 70 chrome.sync.getNotificationState(updateNotificationsEnabledInfo); |
| 27 chrome.sync.getNotificationInfo(updateNotificationInfo); | 71 chrome.sync.getNotificationInfo(updateNotificationInfo); |
| 28 chrome.sync.onNotificationStateChange.addListener( | 72 chrome.sync.onNotificationStateChange.addListener( |
| 29 function(details) { updateNotificationsEnabledInfo(details.enabled); }); | 73 function(details) { updateNotificationsEnabledInfo(details.enabled); }); |
| 30 | 74 |
| 31 chrome.sync.onIncomingNotification.addListener(function(details) { | 75 chrome.sync.onIncomingNotification.addListener(function(details) { |
| 32 var changedTypes = details.changedTypes; | 76 var changedTypes = details.changedTypes; |
| 33 for (var i = 0; i < changedTypes.length; ++i) { | 77 for (var i = 0; i < changedTypes.length; ++i) { |
| 34 var changedType = changedTypes[i]; | 78 incrementSessionNotificationCount(changedTypes[i]); |
| 35 chrome.sync.notifications[changedType] = | |
| 36 chrome.sync.notifications[changedType] || 0; | |
| 37 ++chrome.sync.notifications[changedType]; | |
| 38 } | 79 } |
| 80 updateNotificationInfoTable(); | |
| 39 | 81 |
| 40 var infos = []; | 82 // Also update total counts. |
| 41 for (var k in chrome.sync.notifications) { | |
| 42 var info = { | |
| 43 'modelType': k, | |
| 44 'notificationCount': chrome.sync.notifications[k] | |
| 45 }; | |
| 46 infos.push(info); | |
| 47 } | |
| 48 | |
| 49 var notificationsInfo = | |
| 50 document.getElementById('notificationsInfo'); | |
| 51 jstProcess(new JsEvalContext({ 'notifications': infos }), | |
| 52 notificationsInfo); | |
| 53 chrome.sync.getNotificationInfo(updateNotificationInfo); | 83 chrome.sync.getNotificationInfo(updateNotificationInfo); |
| 54 }); | 84 }); |
| 55 } | 85 } |
| 56 | 86 |
| 57 document.addEventListener("DOMContentLoaded", onLoad, false); | 87 document.addEventListener("DOMContentLoaded", onLoad, false); |
| 58 })(); | 88 })(); |
| 59 </script> | 89 </script> |
| 60 | 90 |
| 61 <style> | 91 <style> |
| 62 table#notificationsInfo tr:nth-child(odd) { | 92 table#notificationInfo tr:nth-child(odd) { |
| 63 background: #eff3ff; | 93 background: #eff3ff; |
| 64 } | 94 } |
| 65 </style> | 95 </style> |
| 66 | 96 |
| 67 <p id='notificationsEnabledInfo'> | 97 <p id='notificationsEnabledInfo'> |
| 68 Enabled: <span jscontent='notificationsEnabled'></span> | 98 Enabled: <span jscontent='notificationsEnabled'></span> |
| 69 </p> | 99 </p> |
| 70 <pre id='notificationInfo'><span jscontent='notificationInfo'></span></pre> | 100 <table id='notificationInfo'> |
| 71 <table id='notificationsInfo'> | 101 <tr> |
| 102 <th>Type</th> | |
| 103 <th>Total count</th> | |
| 104 <th>Session count</th> | |
| 105 <th>Payload</th> | |
| 106 </tr> | |
| 72 <tr jsselect='notifications'> | 107 <tr jsselect='notifications'> |
| 73 <td jscontent='modelType'/> | 108 <td jscontent='type'/> |
| 74 <td jscontent='notificationCount'/> | 109 <td jscontent='totalCount'/> |
| 110 <td jscontent='sessionCount'/> | |
| 111 <td jscontent='payload'/> | |
| 75 </tr> | 112 </tr> |
| 76 </table> | 113 </table> |
| OLD | NEW |