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 // Empty service worker script. | 5 this.onmessage = function(event) { |
|
Peter Beverloo
2014/10/24 14:54:58
This doesn't seem to be used for anything other th
Michael van Ouwerkerk
2014/10/27 15:14:30
Deleted.
| |
| 6 console.log(event); | |
| 7 console.log(event.data); | |
| 8 sendMessageToClients('message', 'Message from service worker'); | |
| 9 }; | |
| 6 | 10 |
| 7 // TODO(mvanouwerkerk): Add test coverage for push event delivery. | 11 this.onpush = function(event) { |
| 12 console.log(event); | |
| 13 console.log(event.data); | |
|
Peter Beverloo
2014/10/24 14:54:58
nit: are the console.log() calls here necessary fo
Michael van Ouwerkerk
2014/10/27 15:14:30
Deleted.
| |
| 14 sendMessageToClients('push', event.data); | |
| 15 }; | |
| 16 | |
| 17 function sendMessageToClients(type, data) { | |
| 18 var message = JSON.stringify({ | |
| 19 'type': type, | |
| 20 'data': data | |
| 21 }); | |
| 22 this.clients.getAll().then(function(clients) { | |
|
Peter Beverloo
2014/10/24 14:54:58
|this| is a bit odd here -- normally |this| would
Michael van Ouwerkerk
2014/10/27 15:14:30
Done. I think it's perfectly normal for the execut
| |
| 23 clients.forEach(function(client) { | |
| 24 client.postMessage(message); | |
| 25 }); | |
| 26 }, function(error) { | |
| 27 console.log(error); | |
| 28 }); | |
| 29 } | |
| OLD | NEW |