| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Called by the common.js module. | 5 // Called by the common.js module. |
| 6 function moduleDidLoad() { | 6 function moduleDidLoad() { |
| 7 // The module is not hidden by default so we can easily see if the plugin | 7 // The module is not hidden by default so we can easily see if the plugin |
| 8 // failed to load. | 8 // failed to load. |
| 9 common.hideModule(); | 9 common.hideModule(); |
| 10 } | 10 } |
| 11 | 11 |
| 12 // Called by the common.js module. | 12 // Called by the common.js module. |
| 13 function attachListeners() { | 13 function attachListeners() { |
| 14 document.getElementById('fortyTwo').addEventListener('click', fortyTwo); | 14 document.getElementById('fortyTwo').addEventListener('click', fortyTwo); |
| 15 document.getElementById('reverseText').addEventListener('click', reverseText); | 15 document.getElementById('reverseText').addEventListener('click', reverseText); |
| 16 } | 16 } |
| 17 | 17 |
| 18 function fortyTwo() { | 18 function fortyTwo() { |
| 19 common.naclModule.postMessage('fortyTwo'); | 19 common.naclModule.postMessage('fortyTwo'); |
| 20 } | 20 } |
| 21 | 21 |
| 22 function reverseText() { | 22 function reverseText() { |
| 23 // Grab the text from the text box, pass it into reverseText() | 23 // Grab the text from the text box, pass it into reverseText() |
| 24 var inputBox = document.getElementById('inputBox'); | 24 var inputBox = document.getElementById('inputBox'); |
| 25 common.naclModule.postMessage('reverseText:' + inputBox.value); | 25 common.naclModule.postMessage('reverseText:' + inputBox.value); |
| 26 } | 26 } |
| 27 | 27 |
| 28 // Called by the common.js module. | 28 function handleMessage(e) { |
| 29 function handleMessage(message_event) { | 29 if (typeof e.data === 'string') { |
| 30 alert(message_event.data); | 30 // Received a reversed message. |
| 31 common.logMessage('Received "' + e.data + '"\n'); |
| 32 } else if (typeof e.data === 'number') { |
| 33 // Recived 42. |
| 34 common.logMessage('Received "' + e.data + '"\n'); |
| 35 } |
| 31 } | 36 } |
| OLD | NEW |