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