OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
3 <title>Controlled frame for Cache API test with credentials</title> | 3 <title>Controlled frame for Cache API test with credentials</title> |
4 <script> | 4 <script> |
5 | 5 |
6 function xhr(url, username, password) { | 6 function xhr(url, username, password) { |
7 return new Promise(function(resolve, reject) { | 7 return new Promise(function(resolve, reject) { |
8 var xhr = new XMLHttpRequest(), async = true; | 8 var xhr = new XMLHttpRequest(), async = true; |
9 xhr.open('GET', url, async, username, password); | 9 xhr.open('GET', url, async, username, password); |
10 xhr.send(); | 10 xhr.send(); |
11 xhr.onreadystatechange = function() { | 11 xhr.onreadystatechange = function() { |
12 if (xhr.readyState !== XMLHttpRequest.DONE) | 12 if (xhr.readyState !== XMLHttpRequest.DONE) |
13 return; | 13 return; |
14 if (xhr.status === 200) { | 14 if (xhr.status === 200) { |
15 resolve(xhr.responseText); | 15 resolve(xhr.responseText); |
16 } else { | 16 } else { |
17 reject(new Error(xhr.statusText)); | 17 reject(new Error(xhr.statusText)); |
18 } | 18 } |
19 }; | 19 }; |
20 }); | 20 }); |
21 } | 21 } |
22 | 22 |
23 window.onmessage = function(e) { | |
24 Promise.all(e.data.map(function(item) { | |
25 return xhr(item.name, item.username, item.password); | |
26 })) | |
27 .then(function() { | |
28 navigator.serviceWorker.controller.postMessage('keys'); | |
29 navigator.serviceWorker.onmessage = function(e) { | |
30 window.parent.postMessage(e.data, '*'); | |
31 }; | |
32 }); | |
33 }; | |
34 | |
35 </script> | 23 </script> |
36 <body> | |
37 Hello? Yes, this is iframe. | |
38 </body> | |
OLD | NEW |