OLD | NEW |
---|---|
(Empty) | |
1 <script> | |
2 function with_iframe(url) { | |
3 return new Promise(function(resolve) { | |
4 var frame = document.createElement('iframe'); | |
5 frame.src = url; | |
6 frame.onload = function() { resolve(frame); }; | |
7 document.body.appendChild(frame); | |
8 }); | |
9 } | |
10 | |
11 function with_sandboxed_iframe(url, sandbox) { | |
12 return new Promise(function(resolve) { | |
13 var frame = document.createElement('iframe'); | |
14 frame.sandbox = sandbox; | |
15 frame.src = url; | |
16 frame.onload = function() { resolve(frame); }; | |
17 document.body.appendChild(frame); | |
18 }); | |
19 } | |
20 | |
21 window.onmessage = function (e) { | |
22 var id = e.data['id']; | |
23 fetch(location.href + "_fetch", {mode: 'no-cors'}) | |
24 .then(function() { | |
25 return with_iframe(location.href + "_iframe"); | |
26 }) | |
27 .then(function() { | |
28 return with_sandboxed_iframe(location.href + "_script", | |
29 "allow-scripts"); | |
30 }) | |
31 .then(function() { | |
32 return with_sandboxed_iframe(location.href + "_script-origin", | |
33 "allow-scripts allow-same-origin"); | |
34 }) | |
35 .then(function() { | |
36 window.top.postMessage({id: id, result: 'done'}, '*'); | |
37 }, | |
38 function() { | |
nhiroki
2015/06/26 01:01:36
Why don't you use 'catch'?
horo
2015/06/26 03:59:10
Done.
| |
39 window.top.postMessage({id: id, result: 'error'}, '*'); | |
40 }); | |
41 }; | |
42 </script> | |
OLD | NEW |