Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @fileoverview The event page for Google Now for Chrome implementation. | 8 * @fileoverview The event page for Google Now for Chrome implementation. |
| 9 * The Google Now event page gets Google Now cards from the server and shows | 9 * The Google Now event page gets Google Now cards from the server and shows |
| 10 * them as Chrome notifications. | 10 * them as Chrome notifications. |
| 11 * The service performs periodic updating of Google Now cards. | 11 * The service performs periodic updating of Google Now cards. |
| 12 * Each updating of the cards includes 3 steps: | 12 * Each updating of the cards includes 3 steps: |
| 13 * 1. Obtaining the location of the machine; | 13 * 1. Obtaining the location of the machine; |
| 14 * 2. Making a server request based on that location; | 14 * 2. Making a server request based on that location; |
| 15 * 3. Showing the received cards as notifications. | 15 * 3. Showing the received cards as notifications. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 // TODO(vadimt): Use background permission to show notifications even when all | 18 // TODO(vadimt): Use background permission to show notifications even when all |
| 19 // browser windows are closed. | 19 // browser windows are closed. |
| 20 // TODO(vadimt): Remove the C++ implementation. | 20 // TODO(vadimt): Remove the C++ implementation. |
| 21 // TODO(vadimt): Decide what to do in incognito mode. | 21 // TODO(vadimt): Decide what to do in incognito mode. |
| 22 // TODO(vadimt): Gather UMAs. | 22 // TODO(vadimt): Gather UMAs. |
| 23 // TODO(vadimt): Honor the flag the enables Google Now integration. | 23 // TODO(vadimt): Honor the flag the enables Google Now integration. |
| 24 // TODO(vadimt): Figure out the final values of the constants. | 24 // TODO(vadimt): Figure out the final values of the constants. |
| 25 // TODO(vadimt): Report internal and server errors. Collect UMAs on errors where | 25 // TODO(vadimt): Report internal and server errors. Collect UMAs on errors where |
| 26 // appropriate. Also consider logging errors or throwing exceptions. | 26 // appropriate. Also consider logging errors or throwing exceptions. |
| 27 | 27 |
| 28 // TODO(vadimt): Consider processing errors for all storage.set calls. | |
| 28 // TODO(vadimt): Figure out the server name. Use it in the manifest and for | 29 // TODO(vadimt): Figure out the server name. Use it in the manifest and for |
| 29 // TODO(vadimt): Consider processing errors for all storage.set calls. | |
| 30 // NOTIFICATION_CARDS_URL. Meanwhile, to use the feature, you need to manually | 30 // NOTIFICATION_CARDS_URL. Meanwhile, to use the feature, you need to manually |
| 31 // edit NOTIFICATION_CARDS_URL before building Chrome. | 31 // set the server name via local storage. |
| 32 /** | 32 /** |
| 33 * URL to retrieve notification cards. | 33 * URL to retrieve notification cards. |
| 34 */ | 34 */ |
| 35 var NOTIFICATION_CARDS_URL = ''; | 35 var NOTIFICATION_CARDS_URL = localStorage['server_url']; |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * Standard response code for successful HTTP requests. This is the only success | 38 * Standard response code for successful HTTP requests. This is the only success |
| 39 * code the server will send. | 39 * code the server will send. |
| 40 */ | 40 */ |
| 41 var HTTP_OK = 200; | 41 var HTTP_OK = 200; |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Initial period for polling for Google Now Notifications cards to use when the | 44 * Initial period for polling for Google Now Notifications cards to use when the |
| 45 * period from the server is not available. | 45 * period from the server is not available. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // Mark existing notifications that received an update in this server | 101 // Mark existing notifications that received an update in this server |
| 102 // response. | 102 // response. |
| 103 for (var i = 0; i < cards.length; ++i) { | 103 for (var i = 0; i < cards.length; ++i) { |
| 104 var notificationId = cards[i].notificationId; | 104 var notificationId = cards[i].notificationId; |
| 105 if (notificationId in items.activeNotifications) | 105 if (notificationId in items.activeNotifications) |
| 106 items.activeNotifications[notificationId].hasUpdate = true; | 106 items.activeNotifications[notificationId].hasUpdate = true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Delete notifications that didn't receive an update. | 109 // Delete notifications that didn't receive an update. |
| 110 for (var notificationId in items.activeNotifications) | 110 for (var notificationId in items.activeNotifications) |
| 111 if (!items.activeNotifications[notificationId].hasUpdate) { | 111 if (items.activeNotifications.hasOwnProperty(notificationId) && |
|
arv (Not doing code reviews)
2013/03/11 16:04:21
Does it matter if it is "own" or "in"?
if (notifi
vadimt
2013/03/11 16:51:03
OK, I'm removing this line.
It looks like I've ad
| |
| 112 !items.activeNotifications[notificationId].hasUpdate) { | |
| 112 chrome.notifications.clear( | 113 chrome.notifications.clear( |
| 113 notificationId, | 114 notificationId, |
| 114 function(wasDeleted) {}); | 115 function(wasDeleted) {}); |
| 115 } | 116 } |
| 116 | 117 |
| 117 // Create/update notifications and store their new properties. | 118 // Create/update notifications and store their new properties. |
| 118 var notificationsUrlInfo = {}; | 119 var notificationsUrlInfo = {}; |
| 119 | 120 |
| 120 for (var i = 0; i < cards.length; ++i) { | 121 for (var i = 0; i < cards.length; ++i) { |
| 121 try { | 122 try { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 function(notificationId, buttonIndex) { | 301 function(notificationId, buttonIndex) { |
| 301 onNotificationClicked(notificationId, function(actionUrls) { | 302 onNotificationClicked(notificationId, function(actionUrls) { |
| 302 if (!Array.isArray(actionUrls.buttonUrls)) | 303 if (!Array.isArray(actionUrls.buttonUrls)) |
| 303 return undefined; | 304 return undefined; |
| 304 | 305 |
| 305 return actionUrls.buttonUrls[buttonIndex]; | 306 return actionUrls.buttonUrls[buttonIndex]; |
| 306 }); | 307 }); |
| 307 }); | 308 }); |
| 308 | 309 |
| 309 chrome.notifications.onClosed.addListener(onNotificationClosed); | 310 chrome.notifications.onClosed.addListener(onNotificationClosed); |
| OLD | NEW |