Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Side by Side Diff: chrome/test/data/push_messaging/service_worker.js

Issue 2469293002: Handle push resubscribes with no sender info (avoids DCHECK) (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698