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. |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 callback(); | 278 callback(); |
279 }); | 279 }); |
280 } | 280 } |
281 | 281 |
282 /** | 282 /** |
283 * Requests notification cards from the server. | 283 * Requests notification cards from the server. |
284 * @param {string} requestParameters Query string for the request. | 284 * @param {string} requestParameters Query string for the request. |
285 * @param {function()} callback Completion callback. | 285 * @param {function()} callback Completion callback. |
286 */ | 286 */ |
287 function requestNotificationCards(requestParameters, callback) { | 287 function requestNotificationCards(requestParameters, callback) { |
288 console.log('requestNotificationCards ' + requestParameters); | 288 console.log('requestNotificationCards ' + requestParameters + ' from ' + |
| 289 NOTIFICATION_CARDS_URL); |
289 recordEvent(DiagnosticEvent.REQUEST_FOR_CARDS_TOTAL); | 290 recordEvent(DiagnosticEvent.REQUEST_FOR_CARDS_TOTAL); |
290 // TODO(vadimt): Figure out how to send user's identity to the server. | 291 // TODO(vadimt): Figure out how to send user's identity to the server. |
291 var request = new XMLHttpRequest(); | 292 var request = new XMLHttpRequest(); |
292 | 293 |
293 request.responseType = 'text'; | 294 request.responseType = 'text'; |
294 request.onloadend = function(event) { | 295 request.onloadend = function(event) { |
295 console.log('requestNotificationCards-onloadend ' + request.status); | 296 console.log('requestNotificationCards-onloadend ' + request.status); |
296 if (request.status == HTTP_OK) { | 297 if (request.status == HTTP_OK) { |
297 recordEvent(DiagnosticEvent.REQUEST_FOR_CARDS_SUCCESS); | 298 recordEvent(DiagnosticEvent.REQUEST_FOR_CARDS_SUCCESS); |
298 parseAndShowNotificationCards(request.response, callback); | 299 parseAndShowNotificationCards(request.response, callback); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 }); | 370 }); |
370 } | 371 } |
371 | 372 |
372 /** | 373 /** |
373 * Sends a server request to dismiss a card. | 374 * Sends a server request to dismiss a card. |
374 * @param {string} notificationId Unique identifier of the card. | 375 * @param {string} notificationId Unique identifier of the card. |
375 * @param {function(boolean)} callbackBoolean Completion callback with 'success' | 376 * @param {function(boolean)} callbackBoolean Completion callback with 'success' |
376 * parameter. | 377 * parameter. |
377 */ | 378 */ |
378 function requestCardDismissal(notificationId, callbackBoolean) { | 379 function requestCardDismissal(notificationId, callbackBoolean) { |
379 console.log('requestDismissingCard ' + notificationId); | 380 console.log('requestDismissingCard ' + notificationId + ' from ' + |
| 381 NOTIFICATION_CARDS_URL); |
380 recordEvent(DiagnosticEvent.DISMISS_REQUEST_TOTAL); | 382 recordEvent(DiagnosticEvent.DISMISS_REQUEST_TOTAL); |
381 // Send a dismiss request to the server. | 383 // Send a dismiss request to the server. |
382 var requestParameters = 'id=' + notificationId; | 384 var requestParameters = 'id=' + notificationId; |
383 var request = new XMLHttpRequest(); | 385 var request = new XMLHttpRequest(); |
384 request.responseType = 'text'; | 386 request.responseType = 'text'; |
385 request.onloadend = function(event) { | 387 request.onloadend = function(event) { |
386 console.log('requestDismissingCard-onloadend ' + request.status); | 388 console.log('requestDismissingCard-onloadend ' + request.status); |
387 if (request.status == HTTP_OK) | 389 if (request.status == HTTP_OK) |
388 recordEvent(DiagnosticEvent.DISMISS_REQUEST_SUCCESS); | 390 recordEvent(DiagnosticEvent.DISMISS_REQUEST_SUCCESS); |
389 | 391 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 'GoogleNow.ButtonClicked' + buttonIndex); | 591 'GoogleNow.ButtonClicked' + buttonIndex); |
590 onNotificationClicked(notificationId, function(actionUrls) { | 592 onNotificationClicked(notificationId, function(actionUrls) { |
591 if (!Array.isArray(actionUrls.buttonUrls)) | 593 if (!Array.isArray(actionUrls.buttonUrls)) |
592 return undefined; | 594 return undefined; |
593 | 595 |
594 return actionUrls.buttonUrls[buttonIndex]; | 596 return actionUrls.buttonUrls[buttonIndex]; |
595 }); | 597 }); |
596 }); | 598 }); |
597 | 599 |
598 chrome.notifications.onClosed.addListener(onNotificationClosed); | 600 chrome.notifications.onClosed.addListener(onNotificationClosed); |
OLD | NEW |