OLD | NEW |
1 <script type="text/javascript"> | 1 <script type="text/javascript"> |
2 function loadAbort(evt) { | 2 function loadAbort(evt) { |
3 document.title = evt.type; | 3 document.title = evt.type; |
4 } | 4 } |
5 function loadStart(evt) { | 5 function loadStart(evt) { |
6 document.title = evt.url; | 6 document.title = evt.url; |
7 } | 7 } |
8 var redirectOldUrl; | 8 var redirectOldUrl; |
9 var redirectNewUrl; | 9 var redirectNewUrl; |
10 function loadRedirect(event) { | 10 function loadRedirect(event) { |
11 document.title = "redirected"; | 11 document.title = "redirected"; |
12 if (event.isTopLevel) { | 12 if (event.isTopLevel) { |
13 redirectOldUrl = event.oldUrl; | 13 redirectOldUrl = event.oldUrl; |
14 redirectNewUrl = event.newUrl; | 14 redirectNewUrl = event.newUrl; |
15 } | 15 } |
16 } | 16 } |
17 function SetSrc(src) { | 17 function SetSrc(src) { |
18 var plugin = document.getElementById('plugin'); | 18 var plugin = document.getElementById('plugin'); |
19 plugin.src = src; | 19 plugin.src = src; |
20 } | 20 } |
21 function SetSize(w, h) { | 21 function SetSize(w, h) { |
22 var plugin = document.getElementById('plugin'); | 22 var plugin = document.getElementById('plugin'); |
23 plugin.width = w; | 23 plugin.width = w; |
24 plugin.height = h; | 24 plugin.height = h; |
25 } | 25 } |
| 26 function PostMessage(data, shouldTargetIframe) { |
| 27 plugin = document.getElementById('plugin'); |
| 28 // TODO(fsamuel): contentWindow can be accessed directly once |
| 29 // http://wkbug.com/85679 lands. |
| 30 if (shouldTargetIframe) { |
| 31 plugin.contentWindow.frames[0].postMessage('testing123', '*'); |
| 32 } else { |
| 33 plugin.contentWindow.frames.postMessage('testing123', '*'); |
| 34 } |
| 35 } |
26 function Back() { | 36 function Back() { |
27 var plugin = document.getElementById('plugin'); | 37 var plugin = document.getElementById('plugin'); |
28 plugin.back(); | 38 plugin.back(); |
29 } | 39 } |
30 function CanGoBack() { | 40 function CanGoBack() { |
31 var plugin = document.getElementById('plugin'); | 41 var plugin = document.getElementById('plugin'); |
32 return plugin.canGoBack(); | 42 return plugin.canGoBack(); |
33 } | 43 } |
34 function CanGoForward() { | 44 function CanGoForward() { |
35 var plugin = document.getElementById('plugin'); | 45 var plugin = document.getElementById('plugin'); |
(...skipping 12 matching lines...) Expand all Loading... |
48 } | 58 } |
49 document.title = 'embedder'; | 59 document.title = 'embedder'; |
50 </script> | 60 </script> |
51 | 61 |
52 <object id="plugin" | 62 <object id="plugin" |
53 tabindex="0" | 63 tabindex="0" |
54 type="application/browser-plugin" | 64 type="application/browser-plugin" |
55 width="640" | 65 width="640" |
56 height="480" | 66 height="480" |
57 border="0px"></object> | 67 border="0px"></object> |
58 | 68 <script type="text/javascript"> |
59 <script> | 69 var msg; |
| 70 function receiveMessage(event) { |
| 71 msg = event.data; |
| 72 if (msg == 'ready') { |
| 73 document.title = 'ready'; |
| 74 return; |
| 75 } |
| 76 if (msg.indexOf('stop_ack') == -1) { |
| 77 event.source.postMessage('stop', '*'); |
| 78 } else { |
| 79 var name = msg.replace("stop_ack", "").trim(); |
| 80 if (name !== '') { |
| 81 window.document.title = name; |
| 82 } else { |
| 83 window.document.title = 'main guest'; |
| 84 } |
| 85 } |
| 86 } |
60 var plugin = document.getElementById('plugin'); | 87 var plugin = document.getElementById('plugin'); |
61 plugin.addEventListener('loadStart', loadStart); | 88 plugin.addEventListener('loadStart', loadStart); |
62 plugin.addEventListener('loadAbort', loadAbort); | 89 plugin.addEventListener('loadAbort', loadAbort); |
63 plugin.addEventListener('loadRedirect', loadRedirect); | 90 plugin.addEventListener('loadRedirect', loadRedirect); |
| 91 window.addEventListener('message', receiveMessage, false); |
64 </script> | 92 </script> |
OLD | NEW |