Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/resources/google_now/background.js

Issue 12313115: Take notification API out of experimental. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflict. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 }; 73 };
74 74
75 // TODO(vadimt): Reorganize server response to avoid deleting fields. 75 // TODO(vadimt): Reorganize server response to avoid deleting fields.
76 delete card.notificationId; 76 delete card.notificationId;
77 delete card.messageUrl; 77 delete card.messageUrl;
78 delete card.buttonOneUrl; 78 delete card.buttonOneUrl;
79 delete card.buttonTwoUrl; 79 delete card.buttonTwoUrl;
80 80
81 // Create a notification or quietly update if it already exists. 81 // Create a notification or quietly update if it already exists.
82 // TODO(vadimt): Implement non-quiet updates. 82 // TODO(vadimt): Implement non-quiet updates.
83 chrome.experimental.notification.create( 83 chrome.notifications.create(
84 notificationId, 84 notificationId,
85 card, 85 card,
86 function(assignedNotificationId) {}); 86 function(assignedNotificationId) {});
87 87
88 notificationsUrlInfo[notificationId] = actionUrls; 88 notificationsUrlInfo[notificationId] = actionUrls;
89 } 89 }
90 90
91 /** 91 /**
92 * Parse JSON response from the notification server, show notifications and 92 * Parse JSON response from the notification server, show notifications and
93 * schedule next update. 93 * schedule next update.
(...skipping 24 matching lines...) Expand all
118 // response. 118 // response.
119 for (var i = 0; i < cards.length; ++i) { 119 for (var i = 0; i < cards.length; ++i) {
120 var notificationId = cards[i].notificationId; 120 var notificationId = cards[i].notificationId;
121 if (notificationId in items.activeNotifications) 121 if (notificationId in items.activeNotifications)
122 items.activeNotifications[notificationId].hasUpdate = true; 122 items.activeNotifications[notificationId].hasUpdate = true;
123 } 123 }
124 124
125 // Delete notifications that didn't receive an update. 125 // Delete notifications that didn't receive an update.
126 for (var notificationId in items.activeNotifications) 126 for (var notificationId in items.activeNotifications)
127 if (!items.activeNotifications[notificationId].hasUpdate) { 127 if (!items.activeNotifications[notificationId].hasUpdate) {
128 chrome.experimental.notification.delete( 128 chrome.notifications.delete(
129 notificationId, 129 notificationId,
130 function(wasDeleted) {}); 130 function(wasDeleted) {});
131 } 131 }
132 132
133 // Create/update notifications and store their new properties. 133 // Create/update notifications and store their new properties.
134 var notificationsUrlInfo = {}; 134 var notificationsUrlInfo = {};
135 135
136 for (var i = 0; i < cards.length; ++i) { 136 for (var i = 0; i < cards.length; ++i) {
137 try { 137 try {
138 createNotification(cards[i], notificationsUrlInfo); 138 createNotification(cards[i], notificationsUrlInfo);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 var notificationActions = items.activeNotifications[notificationId] || {}; 229 var notificationActions = items.activeNotifications[notificationId] || {};
230 if (area in notificationActions) { 230 if (area in notificationActions) {
231 // Open URL specified for the clicked area. 231 // Open URL specified for the clicked area.
232 // TODO(vadimt): Figure out whether to open link in a new tab etc. 232 // TODO(vadimt): Figure out whether to open link in a new tab etc.
233 chrome.windows.create({url: notificationActions[area]}); 233 chrome.windows.create({url: notificationActions[area]});
234 } 234 }
235 }); 235 });
236 } 236 }
237 237
238 /** 238 /**
239 * Callback for chrome.experimental.notification.onClosed event. 239 * Callback for chrome.notifications.onClosed event.
240 * @param {string} notificationId Unique identifier of the notification. 240 * @param {string} notificationId Unique identifier of the notification.
241 * @param {boolean} byUser Whether the notification was closed by the user. 241 * @param {boolean} byUser Whether the notification was closed by the user.
242 */ 242 */
243 function onNotificationClosed(notificationId, byUser) { 243 function onNotificationClosed(notificationId, byUser) {
244 if (byUser) { 244 if (byUser) {
245 // TODO(vadimt): Analyze possible race conditions between request for cards 245 // TODO(vadimt): Analyze possible race conditions between request for cards
246 // and dismissal. 246 // and dismissal.
247 // Send a dismiss request to the server. 247 // Send a dismiss request to the server.
248 var requestParameters = '?id=' + notificationId; 248 var requestParameters = '?id=' + notificationId;
249 var request = new XMLHttpRequest(); 249 var request = new XMLHttpRequest();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 }); 289 });
290 290
291 chrome.runtime.onStartup.addListener(function() { 291 chrome.runtime.onStartup.addListener(function() {
292 initialize(); 292 initialize();
293 }); 293 });
294 294
295 chrome.alarms.onAlarm.addListener(function(alarm) { 295 chrome.alarms.onAlarm.addListener(function(alarm) {
296 updateNotificationsCards(); 296 updateNotificationsCards();
297 }); 297 });
298 298
299 chrome.experimental.notification.onClicked.addListener( 299 chrome.notifications.onClicked.addListener(
300 function(notificationId) { 300 function(notificationId) {
301 onNotificationClicked(notificationId, 'message'); 301 onNotificationClicked(notificationId, 'message');
302 }); 302 });
303 303
304 chrome.experimental.notification.onButtonClicked.addListener( 304 chrome.notifications.onButtonClicked.addListener(
305 function(notificationId, buttonIndex) { 305 function(notificationId, buttonIndex) {
306 onNotificationClicked(notificationId, 'button' + buttonIndex); 306 onNotificationClicked(notificationId, 'button' + buttonIndex);
307 }); 307 });
308 308
309 chrome.experimental.notification.onClosed.addListener(onNotificationClosed); 309 chrome.notifications.onClosed.addListener(onNotificationClosed);
OLDNEW
« no previous file with comments | « chrome/browser/notifications/message_center_settings_controller.cc ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698