| 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 // The "onpush" event currently understands two values as message payload | 5 // The "onpush" event currently understands two values as message payload |
| 6 // data coming from the test. Any other input is passed through to the | 6 // data coming from the test. Any other input is passed through to the |
| 7 // document unchanged. | 7 // document unchanged. |
| 8 // | 8 // |
| 9 // "shownotification" - Display a Web Notification with event.waitUntil(). | 9 // "shownotification" - Display a Web Notification with event.waitUntil(). |
| 10 // "shownotification-without-waituntil" | 10 // "shownotification-without-waituntil" |
| 11 // - Display a Web Notification without using event.waitUntil(). | 11 // - Display a Web Notification without using event.waitUntil(). |
| 12 this.onpush = function(event) { | 12 this.onpush = function(event) { |
| 13 if (event.data === null) { |
| 14 sendMessageToClients('push', '[NULL]'); |
| 15 return; |
| 16 } |
| 17 |
| 13 var data = event.data.text(); | 18 var data = event.data.text(); |
| 14 if (!data.startsWith('shownotification')) { | 19 if (!data.startsWith('shownotification')) { |
| 15 sendMessageToClients('push', data); | 20 sendMessageToClients('push', data); |
| 16 return; | 21 return; |
| 17 } | 22 } |
| 18 | 23 |
| 19 var result = registration.showNotification('Push test title', { | 24 var result = registration.showNotification('Push test title', { |
| 20 body: 'Push test body', | 25 body: 'Push test body', |
| 21 tag: 'push_test_tag' | 26 tag: 'push_test_tag' |
| 22 }); | 27 }); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 39 'data': data | 44 'data': data |
| 40 }); | 45 }); |
| 41 clients.matchAll().then(function(clients) { | 46 clients.matchAll().then(function(clients) { |
| 42 clients.forEach(function(client) { | 47 clients.forEach(function(client) { |
| 43 client.postMessage(message); | 48 client.postMessage(message); |
| 44 }); | 49 }); |
| 45 }, function(error) { | 50 }, function(error) { |
| 46 console.log(error); | 51 console.log(error); |
| 47 }); | 52 }); |
| 48 } | 53 } |
| OLD | NEW |