OLD | NEW |
---|---|
(Empty) | |
1 This page should be sandboxed. | |
2 | |
3 <script> | |
4 // We're not served with the extension default CSP, we can use inline script. | |
5 | |
6 // Loading status of frames, keyed by frame's url. | |
7 var frameLoadStatus = {}; | |
8 | |
9 var updateFrameLoadStatus = function(fileName, succeeded) { | |
10 if (frameLoadStatus[fileName].completed) | |
11 return; | |
12 frameLoadStatus[fileName].completed = true; | |
13 var mainWindow = window.opener || window.top; | |
14 mainWindow.postMessage(JSON.stringify(['loaded', url, succeeded]), '*'); | |
15 }; | |
16 | |
17 var loadIframe = function(url, fileName) { | |
18 var iframe = document.createElement('iframe'); | |
19 iframe.src = url; | |
20 frameLoadStatus[fileName] = {completed: false}; | |
21 document.body.appendChild(iframe); | |
22 // The frame load will fail for remote frames in this test because of CSP. | |
23 // I couldn't find a better way than setTimeout to detect that :(. | |
Devlin
2016/12/20 17:36:38
Can we verify this in the C++ instead?
Timeouts i
lazyboy
2016/12/22 03:07:29
I've changed to test a bit to not rely on timeouts
| |
24 setTimeout(function() { | |
25 updateFrameLoadStatus(fileName, false); | |
26 }, 2000); | |
27 }; | |
28 | |
29 onmessage = function(e) { | |
30 var command = JSON.parse(e.data); | |
31 switch (command[0]) { | |
32 case 'load': | |
33 // message from main app window. | |
34 url = command[1]; | |
35 fileName = command[2]; | |
36 loadIframe(url, fileName); | |
37 break; | |
38 case 'loaded': | |
39 // message from subframe. | |
40 fileName = command[1]; | |
41 updateFrameLoadStatus(fileName, true); | |
42 break; | |
43 } | |
44 }; | |
45 </script> | |
OLD | NEW |