diff options
author | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-02 20:40:13 +0000 |
---|---|---|
committer | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-02 20:40:13 +0000 |
commit | 22bc912e8ead4576e8fff27d49da8d75fd6802eb (patch) | |
tree | f33e9cff7bd7581a3f31969cf2bfcb832cb7a057 /chrome/browser/resources/sync_internals/notifications.js | |
parent | 2758c793c149246eda44f4843d4b3d72b00de434 (diff) | |
download | chromium_src-22bc912e8ead4576e8fff27d49da8d75fd6802eb.zip chromium_src-22bc912e8ead4576e8fff27d49da8d75fd6802eb.tar.gz chromium_src-22bc912e8ead4576e8fff27d49da8d75fd6802eb.tar.bz2 |
Add content-security-policy directive to chrome://sync-internals
Review URL: http://codereview.chromium.org/7529012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/sync_internals/notifications.js')
-rw-r--r-- | chrome/browser/resources/sync_internals/notifications.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/chrome/browser/resources/sync_internals/notifications.js b/chrome/browser/resources/sync_internals/notifications.js new file mode 100644 index 0000000..b6e651e --- /dev/null +++ b/chrome/browser/resources/sync_internals/notifications.js @@ -0,0 +1,99 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +(function () { + +// TODO(akalin): Use table.js. + +function updateNotificationsEnabledInfo(notificationsEnabled) { + var notificationsEnabledInfo = + document.getElementById('notificationsEnabledInfo'); + jstProcess( + new JsEvalContext({ 'notificationsEnabled': notificationsEnabled }), + notificationsEnabledInfo); +} + +// Contains all notification data. The keys are sync types (as strings) and +// the value is a dictionary with: +// +// type: the sync type again (for convenience when using JsTemplate) +// totalCount: Number of notifications received since browser start. +// sessionCount: Number of notifications received this +// chrome://sync-internals session. +// payload: The last received payload. +// +chrome.sync.notifications = {}; + +/** + * Merges d1 and d2 (with d2 taking precedence) and returns the result. + */ +function mergeDictionaries(d1, d2) { + var d = {}; + for (var k in d1) { + d[k] = d1[k]; + } + for (var k in d2) { + d[k] = d2[k]; + } + return d; +} + +/** + * Merge notificationInfo into chrome.sync.notifications. + */ +function updateNotificationsFromNotificationInfo(notificationInfo) { + for (var k in notificationInfo) { + chrome.sync.notifications[k] = + mergeDictionaries(chrome.sync.notifications[k] || {}, + notificationInfo[k]); + // notificationInfo[k] has values for the totalCount and payload keys, + // so fill in the rest (if necessary). + chrome.sync.notifications[k].type = k; + chrome.sync.notifications[k].sessionCount = + chrome.sync.notifications[k].sessionCount || 0; + } +} + +function incrementSessionNotificationCount(changedType) { + chrome.sync.notifications[changedType].sessionCount = + chrome.sync.notifications[changedType].sessionCount || 0; + ++chrome.sync.notifications[changedType].sessionCount; +} + +function updateNotificationInfoTable() { + var notificationInfoTable = + document.getElementById('notificationInfo'); + var infos = []; + for (var k in chrome.sync.notifications) { + infos.push(chrome.sync.notifications[k]); + } + jstProcess(new JsEvalContext({ 'notifications': infos }), + notificationInfoTable); +} + +function updateNotificationInfo(notificationInfo) { + updateNotificationsFromNotificationInfo(notificationInfo); + updateNotificationInfoTable(); +} + +function onLoad() { + chrome.sync.getNotificationState(updateNotificationsEnabledInfo); + chrome.sync.getNotificationInfo(updateNotificationInfo); + chrome.sync.onNotificationStateChange.addListener( + function(details) { updateNotificationsEnabledInfo(details.enabled); }); + + chrome.sync.onIncomingNotification.addListener(function(details) { + var changedTypes = details.changedTypes; + for (var i = 0; i < changedTypes.length; ++i) { + incrementSessionNotificationCount(changedTypes[i]); + } + updateNotificationInfoTable(); + + // Also update total counts. + chrome.sync.getNotificationInfo(updateNotificationInfo); + }); +} + +document.addEventListener("DOMContentLoaded", onLoad, false); +})(); |