1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Called by the common.js module.
6 function attachListeners() {
7 document.getElementById('connectForm').addEventListener('submit', doConnect);
8 document.getElementById('sendForm').addEventListener('submit', doSend);
9 document.getElementById('listenForm').addEventListener('submit', doListen);
10 document.getElementById('closeButton').addEventListener('click', doClose);
13 // Called by the common.js module.
14 function moduleDidLoad() {
15 // The module is not hidden by default so we can easily see if the plugin
20 var msgTcpCreate = 't;'
21 var msgUdpCreate = 'u;'
26 function doConnect(event) {
27 // Send a request message. See also socket.cc for the request format.
28 event.preventDefault();
29 var hostname = document.getElementById('hostname').value;
30 var type = document.getElementById('connect_type').value;
31 common.logMessage(type);
33 common.naclModule.postMessage(msgTcpCreate + hostname);
35 common.naclModule.postMessage(msgUdpCreate + hostname);
39 function doSend(event) {
40 // Send a request message. See also socket.cc for the request format.
41 event.preventDefault();
42 var message = document.getElementById('message').value;
43 while (message.indexOf('\\n') > -1)
44 message = message.replace('\\n', '\n');
45 common.naclModule.postMessage(msgSend + message);
48 function doListen(event) {
49 // Listen a the given port.
50 event.preventDefault();
51 var port = document.getElementById('port').value;
52 var type = document.getElementById('listen_type').value;
53 common.naclModule.postMessage(msgListen + port);
57 // Send a request message. See also socket.cc for the request format.
58 common.naclModule.postMessage(msgClose);
61 function handleMessage(message) {
62 common.logMessage(message.data);