forked from yoshikiohshima/NaClSqueak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
squeak.html
155 lines (136 loc) · 4.44 KB
/
squeak.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!--
Copyright (c) 2010 The Native Client Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>Squeak!</title>
<script type="text/javascript">
var squeakModule = null;
var paintInterval = null;
var statusInterval = null;
_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function base64_encode(input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
_keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
_keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
}
function loadSqueakImage() {
var req = new XMLHttpRequest();
req.open('GET', 'Etoys.image', false);
req.overrideMimeType('octet/binary-stream');
req.send(null);
if (req.status == 200) {
alert('buf size ' + req.responseText.length);
squeakModule.setImageSize(req.responseText.length.toString());
current = 0;
while (current < req.responseText.length) {
squeakModule.loadImage(base64_encode(req.responseText.substring(current, current + 3000)));
current = Math.min(current + 3000, req.responseText.length);
}
}
}
function moduleDidLoad() {
squeakModule = document.getElementById('squeak');
paintInterval = setInterval("squeakModule.paint()", 50);
statusInterval = setInterval("testStatus()", 500);
loadSqueakImage();
getSqueakStatus();
}
function pageDidUnload() {
clearInterval(paintInterval);
clearInterval(statusInterval);
}
function updateStatus(opt_message) {
var statusText;
if (opt_message)
statusText = opt_message;
var statusField = document.getElementById('status_field');
if (statusField) {
statusField.innerHTML = statusText;
statusField.scrollTop = statusField.scrollHeight;
}
}
function getSqueakStatus() {
var statusText;
try {
statusText = squeakModule.getStatus();
} catch(e) {
alert(e.message);
}
updateStatus(statusText);
}
function getLoaderStatus() {
var statusText;
try {
statusText = squeakModule.getLoaderStatus();
} catch(e) {
alert(e.message);
}
updateStatus(statusText);
}
function testStatus() {
var statusBox = document.getElementById('status_checkbox');
if (statusBox.checked) {
getSqueakStatus();
}
}
</script>
</head>
<body id="bodyId" onunload="pageDidUnload()">
<h1>Squeak Test</h1>
<p>
A small graphics test.
</p>
<!-- Load the published .nexe. This includes the 'nacl' attribute which
shows how to load multi-architecture modules. Each entry in the "nexes"
object in the .nmf manifest file is a key-value pair: the key is the
runtime ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl
module. To load the debug versions of your .nexes, set the 'nacl'
attribute to the _dbg.nmf version of the manifest file.
Note: The 'dimensions' attribute indicates that the pi_generator .nexe will
use the 2D drawing device in the browser.
-->
<embed name="nacl_module"
id="squeak"
width=200 height=200
nacl="squeak.nmf"
type="application/x-nacl"
dimensions="2"
onload="moduleDidLoad();" />
</script>
<br />
<form name="squeak_form" action="" method="get">
<input type="button" value="Call getStatus()" onclick="getSqueakStatus()">
<input type="checkbox" id="status_checkbox"> Update status
</form>
<table>
<tr>
<td style="width: 600px; height: 300px;">
<pre id="status_field" style="width: 100%; height: 100%; overflow:scroll;">NO-STATUS</pre>
</td>
</tr>
</table>
</body>
</HTML>