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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 sendResultToTest(subscription.endpoint); | 104 sendResultToTest(subscription.endpoint); |
105 }); | 105 }); |
106 }).catch(sendErrorToTest); | 106 }).catch(sendErrorToTest); |
107 } | 107 } |
108 | 108 |
109 function getCurve25519dh() { | 109 function getCurve25519dh() { |
110 navigator.serviceWorker.ready.then(function(swRegistration) { | 110 navigator.serviceWorker.ready.then(function(swRegistration) { |
111 return swRegistration.pushManager.getSubscription() | 111 return swRegistration.pushManager.getSubscription() |
112 .then(function(subscription) { | 112 .then(function(subscription) { |
113 sendResultToTest(btoa(String.fromCharCode.apply(null, | 113 sendResultToTest(btoa(String.fromCharCode.apply(null, |
114 new Uint8Array(subscription.curve25519dh)))); | 114 new Uint8Array(subscription.getKey('curve25519dh'))))); |
115 }); | 115 }); |
116 }).catch(sendErrorToTest); | 116 }).catch(sendErrorToTest); |
117 } | 117 } |
118 | 118 |
119 function permissionState() { | 119 function permissionState() { |
120 navigator.serviceWorker.ready.then(function(swRegistration) { | 120 navigator.serviceWorker.ready.then(function(swRegistration) { |
121 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) | 121 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) |
122 .then(function(permission) { | 122 .then(function(permission) { |
123 sendResultToTest('permission status - ' + permission); | 123 sendResultToTest('permission status - ' + permission); |
124 }); | 124 }); |
(...skipping 28 matching lines...) Expand all Loading... |
153 sendResultToTest(subscription ? 'true - subscribed' | 153 sendResultToTest(subscription ? 'true - subscribed' |
154 : 'false - not subscribed'); | 154 : 'false - not subscribed'); |
155 }).catch(sendErrorToTest); | 155 }).catch(sendErrorToTest); |
156 } | 156 } |
157 | 157 |
158 navigator.serviceWorker.addEventListener('message', function(event) { | 158 navigator.serviceWorker.addEventListener('message', function(event) { |
159 var message = JSON.parse(event.data); | 159 var message = JSON.parse(event.data); |
160 if (message.type == 'push') | 160 if (message.type == 'push') |
161 resultQueue.push(message.data); | 161 resultQueue.push(message.data); |
162 }, false); | 162 }, false); |
OLD | NEW |