| 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 = { | 9 var pushSubscriptionOptions = { |
| 10 userVisibleOnly: true | 10 userVisibleOnly: true |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 event.waitUntil(result.then(function() { | 42 event.waitUntil(result.then(function() { |
| 43 sendMessageToClients('push', data); | 43 sendMessageToClients('push', data); |
| 44 }, function(ex) { | 44 }, function(ex) { |
| 45 sendMessageToClients('push', String(ex)); | 45 sendMessageToClients('push', String(ex)); |
| 46 })); | 46 })); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 self.addEventListener('message', function handler (event) { | 49 self.addEventListener('message', function handler (event) { |
| 50 if (event.data.command == 'workerSubscribe') { | 50 if (event.data.command == 'workerSubscribe') { |
| 51 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; | 51 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; |
| 52 } else if (event.data.command == 'workerSubscribeWithNumericKey') { |
| 53 pushSubscriptionOptions.applicationServerKey = |
| 54 new TextEncoder().encode('1234567890'); |
| 52 } else if (event.data.command == 'workerSubscribeNoKey') { | 55 } else if (event.data.command == 'workerSubscribeNoKey') { |
| 53 // Nothing to set up | 56 // Nothing to set up |
| 54 } else { | 57 } else { |
| 55 sendMessageToClients('message', 'error - unknown message request'); | 58 sendMessageToClients('message', 'error - unknown message request'); |
| 56 return; | 59 return; |
| 57 } | 60 } |
| 58 | 61 |
| 59 self.registration.pushManager.subscribe(pushSubscriptionOptions) | 62 self.registration.pushManager.subscribe(pushSubscriptionOptions) |
| 60 .then(function(subscription) { | 63 .then(function(subscription) { |
| 61 sendMessageToClients('message', subscription.endpoint); | 64 sendMessageToClients('message', subscription.endpoint); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 74 'data': data | 77 'data': data |
| 75 }); | 78 }); |
| 76 clients.matchAll().then(function(clients) { | 79 clients.matchAll().then(function(clients) { |
| 77 clients.forEach(function(client) { | 80 clients.forEach(function(client) { |
| 78 client.postMessage(message); | 81 client.postMessage(message); |
| 79 }); | 82 }); |
| 80 }, function(error) { | 83 }, function(error) { |
| 81 console.log(error); | 84 console.log(error); |
| 82 }); | 85 }); |
| 83 } | 86 } |
| OLD | NEW |