OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 * Copyright 2013 The Chromium Authors. All rights reserved. Use of this |
| 3 * source code is governed by a BSD-style license that can be found in the |
| 4 * LICENSE file. |
| 5 --> |
| 6 <html> |
| 7 <head> |
| 8 <script type="text/javascript"> |
| 9 // A guest that monitors focus. |
| 10 // Notifies the embedder about changes in focus via postMessage. |
| 11 // Note that the embedder has to initiate a postMessage first so that |
| 12 // the guest has a reference to the embedder's window. |
| 13 |
| 14 // The window reference of the embedder to send post message reply. |
| 15 var embedderWindowChannel = null; |
| 16 var embedderTestName = ''; |
| 17 |
| 18 var notifyEmbedder = function(msg_array) { |
| 19 embedderWindowChannel.postMessage(JSON.stringify(msg_array), '*'); |
| 20 }; |
| 21 |
| 22 var onPostMessageReceived = function(e) { |
| 23 embedderWindowChannel = e.source; |
| 24 var data = JSON.parse(e.data); |
| 25 if (data[0] == 'create-channel') { |
| 26 embedderTestName = data[1]; |
| 27 notifyEmbedder(['channel-created']); |
| 28 } |
| 29 }; |
| 30 window.addEventListener('message', onPostMessageReceived, false); |
| 31 |
| 32 window.addEventListener('focus', function(e) { |
| 33 notifyEmbedder(['focused', embedderTestName]); |
| 34 }); |
| 35 |
| 36 window.addEventListener('blur', function(e) { |
| 37 notifyEmbedder(['blurred', embedderTestName]); |
| 38 }); |
| 39 </script> |
| 40 </head> |
| 41 <body> |
| 42 <div>This is a guest that monitors focus.</div> |
| 43 </body> |
| 44 </html> |
OLD | NEW |