Chromium Code Reviews| 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 // Don't wait for clients of old SW to close before activating. | 9 // Don't wait for clients of old SW to close before activating. |
| 10 self.addEventListener('install', () => skipWaiting()); | 10 self.addEventListener('install', () => skipWaiting()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 sendMessageToClients('push', String(ex)); | 44 sendMessageToClients('push', String(ex)); |
| 45 })); | 45 })); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 self.addEventListener('message', function handler (event) { | 48 self.addEventListener('message', function handler (event) { |
| 49 let pushSubscriptionOptions = { | 49 let pushSubscriptionOptions = { |
| 50 userVisibleOnly: true | 50 userVisibleOnly: true |
| 51 }; | 51 }; |
| 52 if (event.data.command == 'workerSubscribe') { | 52 if (event.data.command == 'workerSubscribe') { |
| 53 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; | 53 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; |
| 54 } else if (event.data.command == 'workerSubscribePushWithNumber') { | |
|
harkness
2016/11/02 18:48:12
nit NumericKey?
awdf
2016/11/03 14:10:11
Oops, this actually isn't called, (since it's one
awdf
2016/11/07 16:54:30
Reinstated. Discussing with John we figured it's n
| |
| 55 pushSubscriptionOptions.applicationServerKey = | |
| 56 new TextEncoder().encode('1234567890'); | |
| 54 } else if (event.data.command == 'workerSubscribeNoKey') { | 57 } else if (event.data.command == 'workerSubscribeNoKey') { |
| 55 // Nothing to set up | 58 // Nothing to set up |
| 56 } else { | 59 } else { |
| 57 sendMessageToClients('message', 'error - unknown message request'); | 60 sendMessageToClients('message', 'error - unknown message request'); |
| 58 return; | 61 return; |
| 59 } | 62 } |
| 60 | 63 |
| 61 self.registration.pushManager.subscribe(pushSubscriptionOptions) | 64 self.registration.pushManager.subscribe(pushSubscriptionOptions) |
| 62 .then(function(subscription) { | 65 .then(function(subscription) { |
| 63 sendMessageToClients('message', subscription.endpoint); | 66 sendMessageToClients('message', subscription.endpoint); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 76 'data': data | 79 'data': data |
| 77 }); | 80 }); |
| 78 clients.matchAll().then(function(clients) { | 81 clients.matchAll().then(function(clients) { |
| 79 clients.forEach(function(client) { | 82 clients.forEach(function(client) { |
| 80 client.postMessage(message); | 83 client.postMessage(message); |
| 81 }); | 84 }); |
| 82 }, function(error) { | 85 }, function(error) { |
| 83 console.log(error); | 86 console.log(error); |
| 84 }); | 87 }); |
| 85 } | 88 } |
| OLD | NEW |