OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 function sendResultToTest(data) { | |
6 clients.matchAll({includeUncontrolled: true}).then(clients => { | |
7 clients.forEach(client => { | |
8 if (client.url.indexOf('payment_app_invocation.html') != -1) { | |
9 client.postMessage(data); | |
10 } | |
11 }); | |
12 }); | |
13 } | |
14 | |
5 self.addEventListener('paymentrequest', e => { | 15 self.addEventListener('paymentrequest', e => { |
16 sendResultToTest(e.topLevelOrigin); | |
17 sendResultToTest(e.paymentRequestOrigin); | |
18 sendResultToTest(e.paymentRequestId); | |
19 sendResultToTest(JSON.stringify(e.methodData)); | |
20 sendResultToTest(JSON.stringify(e.total)); | |
21 sendResultToTest(JSON.stringify(e.modifiers)); | |
22 sendResultToTest(e.instrumentKey); | |
nhiroki
2017/05/21 23:41:40
sendResultToTest()s run async operations, so we ma
zino
2017/05/23 14:51:29
Done.
| |
23 | |
6 // SW -------------------- openWindow() ------------------> payment_app_window | 24 // SW -------------------- openWindow() ------------------> payment_app_window |
7 // SW <----- postMessage('payment_app_window_ready') ------ payment_app_window | 25 // SW <----- postMessage('payment_app_window_ready') ------ payment_app_window |
8 // SW -------- postMessage('payment_app_request') --------> payment_app_window | 26 // SW -------- postMessage('payment_app_request') --------> payment_app_window |
9 // SW <-- postMessage({methodName: 'test', details: {}}) -- payment_app_window | 27 // SW <-- postMessage({methodName: 'test', details: {}}) -- payment_app_window |
10 e.respondWith(new Promise(resolve => { | 28 e.respondWith(new Promise(resolve => { |
11 let payment_app_window = undefined; | 29 let payment_app_window = undefined; |
12 let window_ready = false; | 30 let window_ready = false; |
13 | 31 |
14 let maybeSendPaymentRequest = function() { | 32 let maybeSendPaymentRequest = function() { |
15 if (payment_app_window && window_ready) | 33 if (payment_app_window && window_ready) |
(...skipping 11 matching lines...) Expand all Loading... | |
27 resolve(e.data); | 45 resolve(e.data); |
28 return; | 46 return; |
29 } | 47 } |
30 }); | 48 }); |
31 | 49 |
32 // Open a window | 50 // Open a window |
33 clients.openWindow('payment_app_window.html') | 51 clients.openWindow('payment_app_window.html') |
34 .then(window_client => { | 52 .then(window_client => { |
35 payment_app_window = window_client; | 53 payment_app_window = window_client; |
36 maybeSendPaymentRequest(); | 54 maybeSendPaymentRequest(); |
37 }) | 55 }) |
nhiroki
2017/05/21 23:41:39
ditto. This needs to extend the lifetime of the ev
zino
2017/05/23 14:51:29
I think the lifetime will be extended by e.respond
| |
38 })); | 56 })); |
39 }); | 57 }); |
OLD | NEW |