| 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'); | |
| 55 } else if (event.data.command == 'workerSubscribeNoKey') { | 52 } else if (event.data.command == 'workerSubscribeNoKey') { |
| 56 // Nothing to set up | 53 // Nothing to set up |
| 57 } else { | 54 } else { |
| 58 sendMessageToClients('message', 'error - unknown message request'); | 55 sendMessageToClients('message', 'error - unknown message request'); |
| 59 return; | 56 return; |
| 60 } | 57 } |
| 61 | 58 |
| 62 self.registration.pushManager.subscribe(pushSubscriptionOptions) | 59 self.registration.pushManager.subscribe(pushSubscriptionOptions) |
| 63 .then(function(subscription) { | 60 .then(function(subscription) { |
| 64 sendMessageToClients('message', subscription.endpoint); | 61 sendMessageToClients('message', subscription.endpoint); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 'data': data | 74 'data': data |
| 78 }); | 75 }); |
| 79 clients.matchAll().then(function(clients) { | 76 clients.matchAll().then(function(clients) { |
| 80 clients.forEach(function(client) { | 77 clients.forEach(function(client) { |
| 81 client.postMessage(message); | 78 client.postMessage(message); |
| 82 }); | 79 }); |
| 83 }, function(error) { | 80 }, function(error) { |
| 84 console.log(error); | 81 console.log(error); |
| 85 }); | 82 }); |
| 86 } | 83 } |
| OLD | NEW |