OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 * Show/hide trigger in a card. | 8 * Show/hide trigger in a card. |
9 * | 9 * |
10 * @typedef {{ | 10 * @typedef {{ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 * Notification as sent by the server. | 53 * Notification as sent by the server. |
54 * | 54 * |
55 * @typedef {{ | 55 * @typedef {{ |
56 * notificationId: NotificationId, | 56 * notificationId: NotificationId, |
57 * chromeNotificationId: ChromeNotificationId, | 57 * chromeNotificationId: ChromeNotificationId, |
58 * trigger: Trigger, | 58 * trigger: Trigger, |
59 * chromeNotificationOptions: Object, | 59 * chromeNotificationOptions: Object, |
60 * actionUrls: (ActionUrls|undefined), | 60 * actionUrls: (ActionUrls|undefined), |
61 * dismissal: Object, | 61 * dismissal: Object, |
62 * locationBased: (boolean|undefined), | 62 * locationBased: (boolean|undefined), |
63 * groupName: string | 63 * groupName: string, |
| 64 * cardTypeId: (number|undefined) |
64 * }} | 65 * }} |
65 */ | 66 */ |
66 var ReceivedNotification; | 67 var ReceivedNotification; |
67 | 68 |
68 /** | 69 /** |
69 * Received notification in a self-sufficient form that doesn't require group's | 70 * Received notification in a self-sufficient form that doesn't require group's |
70 * timestamp to calculate show and hide times. | 71 * timestamp to calculate show and hide times. |
71 * | 72 * |
72 * @typedef {{ | 73 * @typedef {{ |
73 * receivedNotification: ReceivedNotification, | 74 * receivedNotification: ReceivedNotification, |
(...skipping 10 matching lines...) Expand all Loading... |
84 */ | 85 */ |
85 var CombinedCard; | 86 var CombinedCard; |
86 | 87 |
87 /** | 88 /** |
88 * Data entry that we store for every Chrome notification. | 89 * Data entry that we store for every Chrome notification. |
89 * |timestamp| is the time when corresponding Chrome notification was created or | 90 * |timestamp| is the time when corresponding Chrome notification was created or |
90 * updated last time by cardSet.update(). | 91 * updated last time by cardSet.update(). |
91 * | 92 * |
92 * @typedef {{ | 93 * @typedef {{ |
93 * actionUrls: (ActionUrls|undefined), | 94 * actionUrls: (ActionUrls|undefined), |
| 95 * cardTypeId: (number|undefined), |
94 * timestamp: number, | 96 * timestamp: number, |
95 * combinedCard: CombinedCard | 97 * combinedCard: CombinedCard |
96 * }} | 98 * }} |
97 * | 99 * |
98 */ | 100 */ |
99 var NotificationDataEntry; | 101 var NotificationDataEntry; |
100 | 102 |
101 /** | 103 /** |
102 * Names for tasks that can be created by the this file. | 104 * Names for tasks that can be created by the this file. |
103 */ | 105 */ |
104 var UPDATE_CARD_TASK_NAME = 'update-card'; | 106 var UPDATE_CARD_TASK_NAME = 'update-card'; |
105 | 107 |
106 /** | 108 /** |
107 * Builds an object to manage notification card set. | 109 * Builds an object to manage notification card set. |
108 * @return {Object} Card set interface. | 110 * @return {Object} Card set interface. |
109 */ | 111 */ |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // If we expect more events, create an alarm for the next one. | 241 // If we expect more events, create an alarm for the next one. |
240 chrome.alarms.create(alarmPrefix + cardId, {when: nextEventTime}); | 242 chrome.alarms.create(alarmPrefix + cardId, {when: nextEventTime}); |
241 | 243 |
242 // The trick with stringify/parse is to create a copy of action URLs, | 244 // The trick with stringify/parse is to create a copy of action URLs, |
243 // otherwise notifications data with 2 pointers to the same object won't | 245 // otherwise notifications data with 2 pointers to the same object won't |
244 // be stored correctly to chrome.storage. | 246 // be stored correctly to chrome.storage. |
245 var winningActionUrls = winningCard && | 247 var winningActionUrls = winningCard && |
246 winningCard.receivedNotification.actionUrls && | 248 winningCard.receivedNotification.actionUrls && |
247 JSON.parse(JSON.stringify( | 249 JSON.parse(JSON.stringify( |
248 winningCard.receivedNotification.actionUrls)); | 250 winningCard.receivedNotification.actionUrls)); |
249 | 251 var winningCardTypeId = winningCard && |
| 252 winningCard.receivedNotification.cardTypeId; |
250 return { | 253 return { |
251 actionUrls: winningActionUrls, | 254 actionUrls: winningActionUrls, |
| 255 cardTypeId: winningCardTypeId, |
252 timestamp: now, | 256 timestamp: now, |
253 combinedCard: combinedCard | 257 combinedCard: combinedCard |
254 }; | 258 }; |
255 } else { | 259 } else { |
256 // If there are no more events, we are done with this card. Note that all | 260 // If there are no more events, we are done with this card. Note that all |
257 // received notifications have hideTime. | 261 // received notifications have hideTime. |
258 verify(!winningCard, 'No events left, but card is shown.'); | 262 verify(!winningCard, 'No events left, but card is shown.'); |
259 clearCardFromGroups(cardId, notificationGroups); | 263 clearCardFromGroups(cardId, notificationGroups); |
260 return undefined; | 264 return undefined; |
261 } | 265 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 }); | 360 }); |
357 }); | 361 }); |
358 } | 362 } |
359 }); | 363 }); |
360 | 364 |
361 return { | 365 return { |
362 update: update, | 366 update: update, |
363 onDismissal: onDismissal | 367 onDismissal: onDismissal |
364 }; | 368 }; |
365 } | 369 } |
OLD | NEW |