Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!-- | 1 <!-- |
| 2 * Copyright 2013 The Chromium Authors. All rights reserved. Use of this | 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 | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 * LICENSE file. | 4 * LICENSE file. |
| 5 --> | 5 --> |
| 6 <html> | 6 <html> |
| 7 <head> | 7 <head> |
| 8 <script type="text/javascript"> | 8 <script type="text/javascript"> |
| 9 // A guest that monitors focus and edit commands. | 9 // A guest that monitors focus and edit commands. |
|
lazyboy
2013/06/22 04:29:15
Update.
Fady Samuel
2013/06/25 15:46:12
Removing file.
| |
| 10 // Notifies the embedder about changes in focus via postMessage. | 10 // Notifies the embedder about changes in focus via postMessage. |
| 11 // Note that the embedder has to initiate a postMessage first so that | 11 // Note that the embedder has to initiate a postMessage first so that |
| 12 // the guest has a reference to the embedder's window. | 12 // the guest has a reference to the embedder's window. |
| 13 | 13 |
| 14 // The window reference of the embedder to send post message reply. | 14 // The window reference of the embedder to send post message reply. |
| 15 var embedderWindowChannel = null; | 15 var embedderWindowChannel = null; |
| 16 var embedderTestName = ''; | 16 var embedderTestName = ''; |
| 17 | 17 |
| 18 var notifyEmbedder = function(msg_array) { | 18 var notifyEmbedder = function(msg_array) { |
| 19 embedderWindowChannel.postMessage(JSON.stringify(msg_array), '*'); | 19 embedderWindowChannel.postMessage(JSON.stringify(msg_array), '*'); |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 var onPostMessageReceived = function(e) { | 22 var onPostMessageReceived = function(e) { |
| 23 embedderWindowChannel = e.source; | 23 embedderWindowChannel = e.source; |
| 24 var data = JSON.parse(e.data); | 24 var data = JSON.parse(e.data); |
| 25 if (data[0] == 'create-channel') { | 25 if (data[0] == 'create-channel') { |
| 26 embedderTestName = data[1]; | 26 embedderTestName = data[1]; |
| 27 notifyEmbedder(['channel-created']); | 27 notifyEmbedder(['channel-created']); |
| 28 return; | 28 return; |
| 29 } | 29 } |
| 30 if (data[0] == 'select-all') { | 30 if (data[0] == 'select-all') { |
|
lazyboy
2013/06/22 04:29:15
Clean this and stuffs below.
Fady Samuel
2013/06/25 15:46:12
Removing file.
| |
| 31 var range = document.createRange(); | 31 var range = document.createRange(); |
| 32 range.selectNode(document.body); | 32 range.selectNode(document.body); |
| 33 window.getSelection().addRange(range); | 33 window.getSelection().addRange(range); |
| 34 notifyEmbedder(['selected-all']); | 34 notifyEmbedder(['selected-all']); |
| 35 } | 35 } |
| 36 }; | 36 }; |
| 37 window.addEventListener('message', onPostMessageReceived, false); | 37 window.addEventListener('message', onPostMessageReceived, false); |
| 38 | 38 |
| 39 window.addEventListener('focus', function(e) { | 39 window.addEventListener('focus', function(e) { |
| 40 notifyEmbedder(['focused', embedderTestName]); | 40 notifyEmbedder(['focused', embedderTestName]); |
| 41 }); | 41 }); |
| 42 | 42 |
| 43 window.addEventListener('blur', function(e) { | 43 window.addEventListener('blur', function(e) { |
| 44 notifyEmbedder(['blurred', embedderTestName]); | 44 notifyEmbedder(['blurred', embedderTestName]); |
| 45 }); | 45 }); |
| 46 | 46 |
| 47 window.addEventListener('copy', function(e) { | 47 window.addEventListener('copy', function(e) { |
| 48 notifyEmbedder(['copy', embedderTestName]); | 48 notifyEmbedder(['copy', embedderTestName]); |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 </script> | 51 </script> |
| 52 </head> | 52 </head> |
| 53 <body> | 53 <body> |
| 54 <div>This is a guest that monitors focus.</div> | 54 <div>This is a guest that monitors focus.</div> |
| 55 </body> | 55 </body> |
| 56 </html> | 56 </html> |
| OLD | NEW |