| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Service Worker to be used with the platform_notification_service.html page. | 5 // Service Worker to be used with the platform_notification_service.html page. |
| 6 var messagePort = null; | 6 var messagePort = null; |
| 7 | 7 |
| 8 addEventListener('message', function (event) { | 8 addEventListener('message', function (event) { |
| 9 messagePort = event.data; | 9 messagePort = event.data; |
| 10 messagePort.postMessage('ready'); | 10 messagePort.postMessage('ready'); |
| 11 }); | 11 }); |
| 12 | 12 |
| 13 // The notificationclick event will be invoked when a persistent notification | 13 // The notificationclick event will be invoked when a persistent notification |
| 14 // has been clicked on. When this happens, the title determines whether this | 14 // has been clicked on. When this happens, the title determines whether this |
| 15 // Service Worker has to act upon this. | 15 // Service Worker has to act upon this. |
| 16 addEventListener('notificationclick', function (event) { | 16 addEventListener('notificationclick', function (event) { |
| 17 if (event.notification.title == 'action_close') | 17 if (event.notification.title == 'action_close') |
| 18 event.notification.close(); | 18 event.notification.close(); |
| 19 | 19 |
| 20 var message = event.notification.title; | 20 var message = event.notification.title; |
| 21 | 21 |
| 22 if (message == 'action_button_click') | 22 if (message == 'action_button_click') |
| 23 message += ' ' + event.action; | 23 message += ' ' + event.action; |
| 24 | 24 if (event.reply) |
| 25 message += ' ' + event.reply; |
| 25 messagePort.postMessage(message); | 26 messagePort.postMessage(message); |
| 26 }); | 27 }); |
| 27 | 28 |
| 28 // The notificationclose event will be invoked when a persistent notification | 29 // The notificationclose event will be invoked when a persistent notification |
| 29 // has been closed by the user. | 30 // has been closed by the user. |
| 30 addEventListener('notificationclose', function (event) { | 31 addEventListener('notificationclose', function (event) { |
| 31 messagePort.postMessage('closing notification: ' + event.notification.title); | 32 messagePort.postMessage('closing notification: ' + event.notification.title); |
| 32 }); | 33 }); |
| OLD | NEW |