Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script> | |
| 3 'use restrict'; | |
| 4 let device; | |
| 5 window.onmessage = messageEvent => { | |
| 6 if (messageEvent.data === 'Iframe1RequestAndConnect') { | |
| 7 navigator.bluetooth.requestDevice({ | |
| 8 filters: [{services: ['heart_rate']}] | |
| 9 }) | |
| 10 .then(device => device.gatt.connect()) | |
| 11 .then(gattServer => { | |
| 12 // iframe1 can access heart_rate service. | |
| 13 gattServer.getPrimaryService('heart_rate'); | |
| 14 parent.postMessage('Iframe1Connected', '*'); | |
| 15 }).catch(err => { | |
| 16 console.error(err); | |
| 17 parent.postMessage('FAIL: ' + err, '*'); | |
| 18 }); | |
| 19 } else if (messageEvent.data === 'Iframe2RequestAndConnect') { | |
| 20 navigator.bluetooth.requestDevice({ | |
| 21 filters: [{services: ['generic_access']}] | |
| 22 }) | |
| 23 .then(device => device.gatt.connect()) | |
| 24 .then(gattServer => { | |
| 25 gattServer.getPrimaryService('generic_access'); | |
| 26 // Since iframe1 can access heart_rate service, and iframe2 has the | |
| 27 // same origin as iframe1, iframe2 should also be able to access | |
| 28 // heart_rate service. | |
| 29 gattServer.getPrimaryService('heart_rate'); | |
|
ortuno
2017/02/14 02:52:28
Why are we calling getPrimaryService here? We are
juncai
2017/02/14 05:52:47
Thanks! I'll fix it in a separate CL.
| |
| 30 parent.postMessage('Iframe2Connected', '*'); | |
| 31 }).catch(err => { | |
| 32 console.error(err); | |
| 33 parent.postMessage('FAIL: ' + err, '*'); | |
| 34 }); | |
| 35 } else if (messageEvent.data === 'TestIframe1HasGenericAccessService') { | |
| 36 navigator.bluetooth.requestDevice({ | |
| 37 filters: [{services: ['heart_rate']}] | |
| 38 }) | |
| 39 .then(device => device.gatt.connect()) | |
| 40 .then(gattServer => { | |
| 41 // Since iframe2 can access generic_access service, and iframe1 has the | |
| 42 // same origin as iframe2, iframe1 should also be able to access | |
| 43 // generic_access service. | |
| 44 gattServer.getPrimaryService('generic_access'); | |
|
ortuno
2017/02/14 02:52:28
Same here. The promise could reject and we would s
juncai
2017/02/14 05:52:47
ditto.
| |
| 45 parent.postMessage('DoneTest', '*'); | |
| 46 }).catch(err => { | |
| 47 console.error(err); | |
| 48 parent.postMessage('FAIL: ' + err, '*'); | |
| 49 }); | |
| 50 } | |
| 51 }; | |
| 52 parent.postMessage("Ready", "*"); | |
| 53 </script> | |
| OLD | NEW |