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. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 ', ERROR=' + errorMessage); | 265 ', ERROR=' + errorMessage); |
| 266 } | 266 } |
| 267 }); | 267 }); |
| 268 } catch (error) { | 268 } catch (error) { |
| 269 console.error('Error in notifications.update: ' + error); | 269 console.error('Error in notifications.update: ' + error); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 notificationsData[card.notificationId] = { | 273 notificationsData[card.notificationId] = { |
| 274 actionUrls: card.actionUrls, | 274 actionUrls: card.actionUrls, |
| 275 version: card.version | 275 version: card.version, |
| 276 dismissalParameters: card.dismissal | |
| 276 }; | 277 }; |
| 277 } | 278 } |
| 278 | 279 |
| 279 /** | 280 /** |
| 280 * Parses JSON response from the notification server, show notifications and | 281 * Parses JSON response from the notification server, show notifications and |
| 281 * schedule next update. | 282 * schedule next update. |
| 282 * @param {string} response Server response. | 283 * @param {string} response Server response. |
| 283 * @param {function()} callback Completion callback. | 284 * @param {function()} callback Completion callback. |
| 284 */ | 285 */ |
| 285 function parseAndShowNotificationCards(response, callback) { | 286 function parseAndShowNotificationCards(response, callback) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 }); | 458 }); |
| 458 }); | 459 }); |
| 459 }); | 460 }); |
| 460 } | 461 } |
| 461 | 462 |
| 462 /** | 463 /** |
| 463 * Sends a server request to dismiss a card. | 464 * Sends a server request to dismiss a card. |
| 464 * @param {string} notificationId Unique identifier of the card. | 465 * @param {string} notificationId Unique identifier of the card. |
| 465 * @param {number} dismissalTimeMs Time of the user's dismissal of the card in | 466 * @param {number} dismissalTimeMs Time of the user's dismissal of the card in |
| 466 * milliseconds since epoch. | 467 * milliseconds since epoch. |
| 468 * @param {Object} dismissalParameters Dismissal parameters. | |
| 467 * @param {function(boolean)} callbackBoolean Completion callback with 'success' | 469 * @param {function(boolean)} callbackBoolean Completion callback with 'success' |
| 468 * parameter. | 470 * parameter. |
| 469 */ | 471 */ |
| 470 function requestCardDismissal( | 472 function requestCardDismissal( |
| 471 notificationId, dismissalTimeMs, callbackBoolean) { | 473 notificationId, dismissalTimeMs, dismissalParameters, callbackBoolean) { |
| 472 console.log('requestDismissingCard ' + notificationId + ' from ' + | 474 console.log('requestDismissingCard ' + notificationId + ' from ' + |
| 473 NOTIFICATION_CARDS_URL); | 475 NOTIFICATION_CARDS_URL); |
| 474 recordEvent(DiagnosticEvent.DISMISS_REQUEST_TOTAL); | 476 recordEvent(DiagnosticEvent.DISMISS_REQUEST_TOTAL); |
| 475 // Send a dismiss request to the server. | 477 // Send a dismiss request to the server. |
| 476 var requestParameters = 'id=' + notificationId + | 478 var requestParameters = |
|
rgustafson
2013/06/27 02:32:40
I wanted to just send a json object in the post bo
vadimt
2013/06/27 19:52:56
Done.
| |
| 477 '&dismissalAge=' + (Date.now() - dismissalTimeMs); | 479 'id=' + notificationId + |
| 480 '&age=' + (Date.now() - dismissalTimeMs) + | |
| 481 '&dismissal=' + escape(JSON.stringify(dismissalParameters)); | |
| 478 var request = buildServerRequest('dismiss'); | 482 var request = buildServerRequest('dismiss'); |
| 479 request.onloadend = function(event) { | 483 request.onloadend = function(event) { |
| 480 console.log('requestDismissingCard-onloadend ' + request.status); | 484 console.log('requestDismissingCard-onloadend ' + request.status); |
| 481 if (request.status == HTTP_OK) | 485 if (request.status == HTTP_OK) |
| 482 recordEvent(DiagnosticEvent.DISMISS_REQUEST_SUCCESS); | 486 recordEvent(DiagnosticEvent.DISMISS_REQUEST_SUCCESS); |
| 483 | 487 |
| 484 callbackBoolean(request.status == HTTP_OK); | 488 callbackBoolean(request.status == HTTP_OK); |
| 485 }; | 489 }; |
| 486 | 490 |
| 487 setAuthorization(request, function(success) { | 491 setAuthorization(request, function(success) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 function doProcessDismissals() { | 526 function doProcessDismissals() { |
| 523 if (items.pendingDismissals.length == 0) { | 527 if (items.pendingDismissals.length == 0) { |
| 524 dismissalAttempts.stop(); | 528 dismissalAttempts.stop(); |
| 525 onFinish(true); | 529 onFinish(true); |
| 526 return; | 530 return; |
| 527 } | 531 } |
| 528 | 532 |
| 529 // Send dismissal for the first card, and if successful, repeat | 533 // Send dismissal for the first card, and if successful, repeat |
| 530 // recursively with the rest. | 534 // recursively with the rest. |
| 531 var dismissal = items.pendingDismissals[0]; | 535 var dismissal = items.pendingDismissals[0]; |
| 532 requestCardDismissal( | 536 requestCardDismissal(dismissal.notificationId, |
| 533 dismissal.notificationId, dismissal.time, function(success) { | 537 dismissal.time, |
| 538 dismissal.parameters, | |
| 539 function(success) { | |
| 534 if (success) { | 540 if (success) { |
| 535 dismissalsChanged = true; | 541 dismissalsChanged = true; |
| 536 items.pendingDismissals.splice(0, 1); | 542 items.pendingDismissals.splice(0, 1); |
| 537 items.recentDismissals[dismissal.notificationId] = Date.now(); | 543 items.recentDismissals[dismissal.notificationId] = Date.now(); |
| 538 doProcessDismissals(); | 544 doProcessDismissals(); |
| 539 } else { | 545 } else { |
| 540 onFinish(false); | 546 onFinish(false); |
| 541 } | 547 } |
| 542 }); | 548 }); |
| 543 } | 549 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 | 642 |
| 637 tasks.add(DISMISS_CARD_TASK_NAME, function(callback) { | 643 tasks.add(DISMISS_CARD_TASK_NAME, function(callback) { |
| 638 dismissalAttempts.start(); | 644 dismissalAttempts.start(); |
| 639 | 645 |
| 640 // Deleting the notification in case it was re-added while this task was | 646 // Deleting the notification in case it was re-added while this task was |
| 641 // scheduled, waiting for execution. | 647 // scheduled, waiting for execution. |
| 642 chrome.notifications.clear( | 648 chrome.notifications.clear( |
| 643 notificationId, | 649 notificationId, |
| 644 function() {}); | 650 function() {}); |
| 645 | 651 |
| 646 tasks.debugSetStepName('onNotificationClosed-get-pendingDismissals'); | 652 tasks.debugSetStepName('onNotificationClosed-storage-get'); |
| 647 storage.get('pendingDismissals', function(items) { | 653 storage.get(['pendingDismissals', 'notificationsData'], function(items) { |
| 648 items.pendingDismissals = items.pendingDismissals || []; | 654 items.pendingDismissals = items.pendingDismissals || []; |
| 655 items.notificationsData = items.notificationsData || {}; | |
| 656 | |
| 657 var notificationData = items.notificationsData[notificationId]; | |
| 649 | 658 |
| 650 var dismissal = { | 659 var dismissal = { |
| 651 notificationId: notificationId, | 660 notificationId: notificationId, |
| 652 time: Date.now() | 661 time: Date.now(), |
| 662 parameters: notificationData && notificationData.dismissalParameters | |
| 653 }; | 663 }; |
| 654 items.pendingDismissals.push(dismissal); | 664 items.pendingDismissals.push(dismissal); |
| 655 storage.set({pendingDismissals: items.pendingDismissals}); | 665 storage.set({pendingDismissals: items.pendingDismissals}); |
| 656 processPendingDismissals(function(success) { callback(); }); | 666 processPendingDismissals(function(success) { callback(); }); |
| 657 }); | 667 }); |
| 658 }); | 668 }); |
| 659 } | 669 } |
| 660 | 670 |
| 661 /** | 671 /** |
| 662 * Initializes the polling system to start monitoring location and fetching | 672 * Initializes the polling system to start monitoring location and fetching |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 | 759 |
| 750 chrome.location.onLocationUpdate.addListener(function(position) { | 760 chrome.location.onLocationUpdate.addListener(function(position) { |
| 751 recordEvent(DiagnosticEvent.LOCATION_UPDATE); | 761 recordEvent(DiagnosticEvent.LOCATION_UPDATE); |
| 752 updateNotificationsCards(position); | 762 updateNotificationsCards(position); |
| 753 }); | 763 }); |
| 754 | 764 |
| 755 chrome.omnibox.onInputEntered.addListener(function(text) { | 765 chrome.omnibox.onInputEntered.addListener(function(text) { |
| 756 localStorage['server_url'] = NOTIFICATION_CARDS_URL = text; | 766 localStorage['server_url'] = NOTIFICATION_CARDS_URL = text; |
| 757 initialize(); | 767 initialize(); |
| 758 }); | 768 }); |
| OLD | NEW |