| 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 // Use an absolute path since this could be loaded from a different scope, | 5 // Use an absolute path since this could be loaded from a different scope, |
| 6 // which would affect the scope of the importScripts call here. | 6 // which would affect the scope of the importScripts call here. |
| 7 self.importScripts('/push_messaging/push_constants.js'); | 7 self.importScripts('/push_messaging/push_constants.js'); |
| 8 | 8 |
| 9 var pushSubscriptionOptions = { | |
| 10 userVisibleOnly: true | |
| 11 }; | |
| 12 | |
| 13 // The "onpush" event currently understands two values as message payload | 9 // The "onpush" event currently understands two values as message payload |
| 14 // data coming from the test. Any other input is passed through to the | 10 // data coming from the test. Any other input is passed through to the |
| 15 // document unchanged. | 11 // document unchanged. |
| 16 // | 12 // |
| 17 // "shownotification" - Display a Web Notification with event.waitUntil(). | 13 // "shownotification" - Display a Web Notification with event.waitUntil(). |
| 18 // "shownotification-without-waituntil" | 14 // "shownotification-without-waituntil" |
| 19 // - Display a Web Notification without using event.waitUntil(). | 15 // - Display a Web Notification without using event.waitUntil(). |
| 20 this.onpush = function(event) { | 16 this.onpush = function(event) { |
| 21 if (event.data === null) { | 17 if (event.data === null) { |
| 22 sendMessageToClients('push', '[NULL]'); | 18 sendMessageToClients('push', '[NULL]'); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 } | 36 } |
| 41 | 37 |
| 42 event.waitUntil(result.then(function() { | 38 event.waitUntil(result.then(function() { |
| 43 sendMessageToClients('push', data); | 39 sendMessageToClients('push', data); |
| 44 }, function(ex) { | 40 }, function(ex) { |
| 45 sendMessageToClients('push', String(ex)); | 41 sendMessageToClients('push', String(ex)); |
| 46 })); | 42 })); |
| 47 }; | 43 }; |
| 48 | 44 |
| 49 self.addEventListener('message', function handler (event) { | 45 self.addEventListener('message', function handler (event) { |
| 46 let pushSubscriptionOptions = { |
| 47 userVisibleOnly: true |
| 48 }; |
| 50 if (event.data.command == 'workerSubscribe') { | 49 if (event.data.command == 'workerSubscribe') { |
| 51 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; | 50 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; |
| 52 } else if (event.data.command == 'workerSubscribeNoKey') { | 51 } else if (event.data.command == 'workerSubscribeNoKey') { |
| 53 // Nothing to set up | 52 // Nothing to set up |
| 54 } else { | 53 } else { |
| 55 sendMessageToClients('message', 'error - unknown message request'); | 54 sendMessageToClients('message', 'error - unknown message request'); |
| 56 return; | 55 return; |
| 57 } | 56 } |
| 58 | 57 |
| 59 self.registration.pushManager.subscribe(pushSubscriptionOptions) | 58 self.registration.pushManager.subscribe(pushSubscriptionOptions) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 'data': data | 73 'data': data |
| 75 }); | 74 }); |
| 76 clients.matchAll().then(function(clients) { | 75 clients.matchAll().then(function(clients) { |
| 77 clients.forEach(function(client) { | 76 clients.forEach(function(client) { |
| 78 client.postMessage(message); | 77 client.postMessage(message); |
| 79 }); | 78 }); |
| 80 }, function(error) { | 79 }, function(error) { |
| 81 console.log(error); | 80 console.log(error); |
| 82 }); | 81 }); |
| 83 } | 82 } |
| OLD | NEW |