Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Allows a document to exercise the Push API within a service worker by sending commands. | 1 // Allows a document to exercise the Push API within a service worker by sending commands. |
| 2 | 2 |
| 3 // The port through which the document sends commands to the service worker. | 3 // The port through which the document sends commands to the service worker. |
| 4 var port = null; | 4 var port = null; |
| 5 | 5 |
| 6 // The most recently seen subscription. | 6 // The most recently seen subscription. |
| 7 var lastSeenSubscription = null; | 7 var lastSeenSubscription = null; |
| 8 | 8 |
| 9 self.addEventListener('message', function(workerEvent) { | 9 self.addEventListener('message', function(workerEvent) { |
| 10 port = workerEvent.data; | 10 port = workerEvent.data; |
| 11 | 11 |
| 12 // Listen to incoming commands on the message port. | 12 // Listen to incoming commands on the message port. |
| 13 port.onmessage = function(event) { | 13 port.onmessage = function(event) { |
| 14 if (typeof event.data != 'object' || !event.data.command) | 14 if (typeof event.data != 'object' || !event.data.command) |
| 15 return; | 15 return; |
| 16 | 16 var arguments = event.data.arg || {} |
|
Peter Beverloo
2015/05/07 15:28:21
Please also pass the |options| argument to subscri
Peter Beverloo
2015/05/07 15:28:21
s/(arguments|arg)/options/
Miguel Garcia
2015/05/07 19:40:46
Done.
Miguel Garcia
2015/05/07 19:40:46
Done.
| |
| 17 switch (event.data.command) { | 17 switch (event.data.command) { |
| 18 case 'permissionState': | 18 case 'permissionState': |
| 19 self.registration.pushManager.permissionState().then(function(pe rmissionStatus) { | 19 self.registration.pushManager.permissionState(arguments).then(fu nction(permissionStatus) { |
| 20 port.postMessage({ command: event.data.command, | 20 port.postMessage({ command: event.data.command, |
| 21 success: true, | 21 success: true, |
| 22 permission: permissionStatus }); | 22 permission: permissionStatus }); |
| 23 }).catch(makeErrorHandler(event.data.command)); | 23 }).catch(makeErrorHandler(event.data.command)); |
| 24 break; | 24 break; |
| 25 | 25 |
| 26 case 'subscribe': | 26 case 'subscribe': |
| 27 self.registration.pushManager.subscribe().then(function(subscrip tion) { | 27 self.registration.pushManager.subscribe().then(function(subscrip tion) { |
| 28 lastSeenSubscription = subscription; | 28 lastSeenSubscription = subscription; |
| 29 port.postMessage({ command: event.data.command, | 29 port.postMessage({ command: event.data.command, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 }); | 73 }); |
| 74 | 74 |
| 75 function makeErrorHandler(command) { | 75 function makeErrorHandler(command) { |
| 76 return function(error) { | 76 return function(error) { |
| 77 var errorMessage = error ? error.message : 'unknown error'; | 77 var errorMessage = error ? error.message : 'unknown error'; |
| 78 port.postMessage({ command: command, | 78 port.postMessage({ command: command, |
| 79 success: false, | 79 success: false, |
| 80 errorMessage: errorMessage }); | 80 errorMessage: errorMessage }); |
| 81 }; | 81 }; |
| 82 } | 82 } |
| OLD | NEW |