| 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.getSubscription() | |
| 112 .then(function(subscription) { | |
| 113 sendResultToTest(btoa(String.fromCharCode.apply(null, | |
| 114 new Uint8Array(subscription.curve25519dh)))); | |
| 115 }); | |
| 116 }).catch(sendErrorToTest); | |
| 117 } | |
| 118 | |
| 119 function permissionState() { | 109 function permissionState() { |
| 120 navigator.serviceWorker.ready.then(function(swRegistration) { | 110 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 121 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) | 111 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) |
| 122 .then(function(permission) { | 112 .then(function(permission) { |
| 123 sendResultToTest('permission status - ' + permission); | 113 sendResultToTest('permission status - ' + permission); |
| 124 }); | 114 }); |
| 125 }).catch(sendErrorToTest); | 115 }).catch(sendErrorToTest); |
| 126 } | 116 } |
| 127 | 117 |
| 128 function isControlled() { | 118 function isControlled() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 153 sendResultToTest(subscription ? 'true - subscribed' | 143 sendResultToTest(subscription ? 'true - subscribed' |
| 154 : 'false - not subscribed'); | 144 : 'false - not subscribed'); |
| 155 }).catch(sendErrorToTest); | 145 }).catch(sendErrorToTest); |
| 156 } | 146 } |
| 157 | 147 |
| 158 navigator.serviceWorker.addEventListener('message', function(event) { | 148 navigator.serviceWorker.addEventListener('message', function(event) { |
| 159 var message = JSON.parse(event.data); | 149 var message = JSON.parse(event.data); |
| 160 if (message.type == 'push') | 150 if (message.type == 'push') |
| 161 resultQueue.push(message.data); | 151 resultQueue.push(message.data); |
| 162 }, false); | 152 }, false); |
| OLD | NEW |