Chromium Code Reviews| Index: chrome/test/data/push_messaging/service_worker.js |
| diff --git a/chrome/test/data/push_messaging/service_worker.js b/chrome/test/data/push_messaging/service_worker.js |
| index a338fdc12b67916945a433b11fde0aa64f25debb..fb30f61415d36721e620dca37777b8cfd1ef34ff 100644 |
| --- a/chrome/test/data/push_messaging/service_worker.js |
| +++ b/chrome/test/data/push_messaging/service_worker.js |
| @@ -2,6 +2,12 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +self.importScripts('push_constants.js'); |
| + |
| +var pushSubscriptionOptions = { |
| + userVisibleOnly: true |
| +}; |
| + |
| // The "onpush" event currently understands two values as message payload |
| // data coming from the test. Any other input is passed through to the |
| // document unchanged. |
| @@ -38,6 +44,31 @@ this.onpush = function(event) { |
| })); |
| }; |
| +self.addEventListener('message', function handler (event) { |
| + if (event.data.command == 'workerSubscribe') { |
| + pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; |
| + } else if (event.data.command == 'workerSubscribePermissionFail') { |
|
Michael van Ouwerkerk
2016/03/30 09:50:04
This case appears to be unused?
harkness
2016/03/30 10:51:49
Done.
|
| + pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; |
| + pushSubscriptionOptions.userVisibleOnly = false; |
| + } else if (event.data.command == 'workerSubscribeNoKey') { |
| + // Nothing to set up |
| + } else { |
| + sendMessageToClients('message', 'error - unknown message request'); |
| + return; |
| + } |
| + |
| + self.registration.pushManager.subscribe(pushSubscriptionOptions) |
| + .then(function(subscription) { |
| + sendMessageToClients('message', subscription.endpoint); |
| + }, function(error) { |
| + sendErrorToClients(error); |
| + }); |
| +}); |
| + |
| +function sendErrorToClients(error) { |
| + sendMessageToClients('error', error.name + ' - ' + error.message); |
| +} |
| + |
| function sendMessageToClients(type, data) { |
| var message = JSON.stringify({ |
| 'type': type, |