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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 var resultQueue = new ResultQueue(); | 7 var resultQueue = new ResultQueue(); |
8 var pushSubscription = null; | 8 var pushSubscription = null; |
9 | 9 |
10 var pushSubscriptionOptions = { | 10 var pushSubscriptionOptions = { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 function subscribePush() { | 99 function subscribePush() { |
100 navigator.serviceWorker.ready.then(function(swRegistration) { | 100 navigator.serviceWorker.ready.then(function(swRegistration) { |
101 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) | 101 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) |
102 .then(function(subscription) { | 102 .then(function(subscription) { |
103 pushSubscription = subscription; | 103 pushSubscription = subscription; |
104 sendResultToTest(subscription.endpoint); | 104 sendResultToTest(subscription.endpoint); |
105 }); | 105 }); |
106 }).catch(sendErrorToTest); | 106 }).catch(sendErrorToTest); |
107 } | 107 } |
108 | 108 |
109 function getCurve25519dh() { | |
110 navigator.serviceWorker.ready.then(function(swRegistration) { | |
111 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) | |
johnme
2015/07/21 15:37:26
Nit: the intent would probably be clearer if you s
Peter Beverloo
2015/07/21 15:51:08
Done.
| |
112 .then(function(subscription) { | |
113 sendResultToTest(btoa(String.fromCharCode.apply(null, | |
114 new Uint8Array(subscription.curve25519dh)))); | |
115 }); | |
116 }).catch(sendErrorToTest); | |
117 } | |
118 | |
109 function permissionState() { | 119 function permissionState() { |
110 navigator.serviceWorker.ready.then(function(swRegistration) { | 120 navigator.serviceWorker.ready.then(function(swRegistration) { |
111 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) | 121 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) |
112 .then(function(permission) { | 122 .then(function(permission) { |
113 sendResultToTest('permission status - ' + permission); | 123 sendResultToTest('permission status - ' + permission); |
114 }); | 124 }); |
115 }).catch(sendErrorToTest); | 125 }).catch(sendErrorToTest); |
116 } | 126 } |
117 | 127 |
118 function isControlled() { | 128 function isControlled() { |
(...skipping 24 matching lines...) Expand all Loading... | |
143 sendResultToTest(subscription ? 'true - subscribed' | 153 sendResultToTest(subscription ? 'true - subscribed' |
144 : 'false - not subscribed'); | 154 : 'false - not subscribed'); |
145 }).catch(sendErrorToTest); | 155 }).catch(sendErrorToTest); |
146 } | 156 } |
147 | 157 |
148 navigator.serviceWorker.addEventListener('message', function(event) { | 158 navigator.serviceWorker.addEventListener('message', function(event) { |
149 var message = JSON.parse(event.data); | 159 var message = JSON.parse(event.data); |
150 if (message.type == 'push') | 160 if (message.type == 'push') |
151 resultQueue.push(message.data); | 161 resultQueue.push(message.data); |
152 }, false); | 162 }, false); |
OLD | NEW |