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
3 // found in the LICENSE file.
5 // Called by the common.js module.
6 function domContentLoaded(name, tc, config, width, height) {
7 window.webkitStorageInfo.requestQuota(window.PERSISTENT, 1024*1024,
10 'Allocated '+bytes+' bytes of persistant storage.');
11 common.createNaClModule(name, tc, config, width, height);
12 common.attachDefaultListeners();
14 function(e) { alert('Failed to allocate space') });
17 // Called by the common.js module.
18 function attachListeners() {
19 document.getElementById('saveButton').addEventListener('click', saveFile);
20 document.getElementById('loadButton').addEventListener('click', loadFile);
21 document.getElementById('deleteButton').addEventListener('click', deleteFile);
25 if (common.naclModule) {
26 var fileName = document.getElementById('fileName').value;
28 // Package a message using a simple protocol containing:
29 // instruction file_name_length file_name
30 var msg = "ld " + fileName.length + " " + fileName;
31 common.naclModule.postMessage(msg);
36 if (common.naclModule) {
37 var fileName = document.getElementById('fileName').value;
38 var fileText = document.getElementById('fileEditor').value;
40 // Package a message using a simple protocol containing:
41 // instruction file_name_length file_name file_contents
42 var msg = "sv " + fileName.length + " " + fileName + " " + fileText;
43 common.naclModule.postMessage(msg);
47 function deleteFile() {
48 if (common.naclModule) {
49 var fileName = document.getElementById('fileName').value;
51 // Package a message using a simple protocol containing:
52 // instruction file_name_length file_name
53 var msg = "de " + fileName.length + " " + fileName;
54 common.naclModule.postMessage(msg);
58 // Called by the common.js module.
59 function handleMessage(message_event) {
60 var messageParts = message_event.data.split("|", 3);
62 if (messageParts[0] == "ERR") {
63 common.updateStatus(messageParts[1]);
64 document.getElementById('statusField').style.color = "red";
66 else if(messageParts[0] == "STAT") {
67 common.updateStatus(messageParts[1]);
69 else if (messageParts[0] == "DISP") {
70 // Display the message in the file edit box
71 document.getElementById('fileEditor').value = messageParts[1];
73 else if (messageParts[0] == "READY") {
74 var statusField = document.getElementById('statusField');
75 common.updateStatus(statusField.innerHTML + ' Ready!');