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 '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 pushSubscriptionOptionsWithoutKey = { | |
| 11 userVisibleOnly: true | |
| 12 }; | |
| 13 | |
| 10 var pushSubscriptionOptions = { | 14 var pushSubscriptionOptions = { |
| 11 userVisibleOnly: true | 15 userVisibleOnly: true, |
| 16 // TODO(harkness) When the validity of the public key is actually checked, | |
| 17 // this value will need to be updated. | |
|
Peter Beverloo
2016/02/23 14:28:28
Which is now? :)
| |
| 18 appServicePublicKey: new ArrayBuffer("1234567890") | |
| 12 }; | 19 }; |
| 13 | 20 |
| 14 // Sends data back to the test. This must be in response to an earlier | 21 // Sends data back to the test. This must be in response to an earlier |
| 15 // request, but it's ok to respond asynchronously. The request blocks until | 22 // request, but it's ok to respond asynchronously. The request blocks until |
| 16 // the response is sent. | 23 // the response is sent. |
| 17 function sendResultToTest(result) { | 24 function sendResultToTest(result) { |
| 18 console.log('sendResultToTest: ' + result); | 25 console.log('sendResultToTest: ' + result); |
| 19 if (window.domAutomationController) { | 26 if (window.domAutomationController) { |
| 20 domAutomationController.send('' + result); | 27 domAutomationController.send('' + result); |
| 21 } | 28 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 function swapManifestNoSenderId() { | 106 function swapManifestNoSenderId() { |
| 100 var element = document.querySelector('link[rel="manifest"]'); | 107 var element = document.querySelector('link[rel="manifest"]'); |
| 101 if (element) { | 108 if (element) { |
| 102 element.href = 'manifest_no_sender_id.json'; | 109 element.href = 'manifest_no_sender_id.json'; |
| 103 sendResultToTest('sender id removed from manifest'); | 110 sendResultToTest('sender id removed from manifest'); |
| 104 } else { | 111 } else { |
| 105 sendResultToTest('unable to find manifest element'); | 112 sendResultToTest('unable to find manifest element'); |
| 106 } | 113 } |
| 107 } | 114 } |
| 108 | 115 |
| 116 // This is the old style of push subscriptions which we are phasing away | |
| 117 // from, where the subscription used a sender ID instead of public key. | |
| 118 function subscribePushWithoutKey() { | |
| 119 navigator.serviceWorker.ready.then(function(swRegistration) { | |
| 120 return swRegistration.pushManager.subscribe( | |
| 121 pushSubscriptionOptionsWithoutKey) | |
| 122 .then(function(subscription) { | |
| 123 pushSubscription = subscription; | |
| 124 sendResultToTest(subscription.endpoint); | |
| 125 }); | |
| 126 }).catch(sendErrorToTest); | |
| 127 } | |
| 128 | |
| 109 function subscribePush() { | 129 function subscribePush() { |
| 110 navigator.serviceWorker.ready.then(function(swRegistration) { | 130 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 111 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) | 131 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) |
| 112 .then(function(subscription) { | 132 .then(function(subscription) { |
| 113 pushSubscription = subscription; | 133 pushSubscription = subscription; |
| 114 sendResultToTest(subscription.endpoint); | 134 sendResultToTest(subscription.endpoint); |
| 115 }); | 135 }); |
| 116 }).catch(sendErrorToTest); | 136 }).catch(sendErrorToTest); |
| 117 } | 137 } |
| 118 | 138 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 sendResultToTest(subscription ? 'true - subscribed' | 183 sendResultToTest(subscription ? 'true - subscribed' |
| 164 : 'false - not subscribed'); | 184 : 'false - not subscribed'); |
| 165 }).catch(sendErrorToTest); | 185 }).catch(sendErrorToTest); |
| 166 } | 186 } |
| 167 | 187 |
| 168 navigator.serviceWorker.addEventListener('message', function(event) { | 188 navigator.serviceWorker.addEventListener('message', function(event) { |
| 169 var message = JSON.parse(event.data); | 189 var message = JSON.parse(event.data); |
| 170 if (message.type == 'push') | 190 if (message.type == 'push') |
| 171 resultQueue.push(message.data); | 191 resultQueue.push(message.data); |
| 172 }, false); | 192 }, false); |
| OLD | NEW |