| 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..f32068849a8fb2b3995e84fd895d82133efc97a0 100644
|
| --- a/chrome/test/data/push_messaging/service_worker.js
|
| +++ b/chrome/test/data/push_messaging/service_worker.js
|
| @@ -2,6 +2,14 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +// Use an absolute path since this could be loaded from a different scope,
|
| +// which would affect the scope of the importScripts call here.
|
| +self.importScripts('/push_messaging/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 +46,28 @@ this.onpush = function(event) {
|
| }));
|
| };
|
|
|
| +self.addEventListener('message', function handler (event) {
|
| + if (event.data.command == 'workerSubscribe') {
|
| + pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer;
|
| + } 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,
|
|
|