2
Copyright 2008, Google Inc.
4
Redistribution and use in source and binary forms, with or without
5
modification, are permitted provided that the following conditions are met:
7
1. Redistributions of source code must retain the above copyright notice,
8
this list of conditions and the following disclaimer.
9
2. Redistributions in binary form must reproduce the above copyright notice,
10
this list of conditions and the following disclaimer in the documentation
11
and/or other materials provided with the distribution.
12
3. Neither the name of Google Inc. nor the names of its contributors may be
13
used to endorse or promote products derived from this software without
14
specific prior written permission.
16
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
<title>Gears Console Test Page</title>
38
<h1>Gears Console Test Page</h1>
42
<textarea id="message" rows="6" cols="80"></textarea>
43
<p>Message Arguments:<br />
44
(Comma separated list of values, will be interpolated into message
45
replacing instances of %s.)</p>
46
[ <input id="arguments" /> ]
48
<button onclick="log('debug',
49
document.getElementById('message').value);" disabled="disabled">
52
<button onclick="log('info',
53
document.getElementById('message').value);" disabled="disabled">
56
<button onclick="log('warn',
57
document.getElementById('message').value);" disabled="disabled">
60
<button onclick="log('error',
61
document.getElementById('message').value);" disabled="disabled">
64
<input id="other-type" value="Custom type..."
65
onfocus="if(this.value == 'Custom type...') this.value = '';" />
67
document.getElementById('other-type').value,
68
document.getElementById('message').value);" disabled="disabled">
73
<input type="checkbox" id="wp" />
74
<label for="wp">Send the log message from a WorkerPool process</label>
77
<button onclick="document.getElementById('status').innerHTML = '';">
83
<!-- ====================================== -->
84
<!-- JavaScript code -->
86
<script type="text/javascript" src="../../sdk/gears_init.js"></script>
87
<script type="text/javascript">
92
function addStatus(msg) {
93
document.getElementById('status').insertBefore(
94
document.createElement('br'),
95
document.getElementById('status').firstChild);
96
document.getElementById('status').insertBefore(
97
document.createTextNode(msg),
98
document.getElementById('status').firstChild);
101
function onlogHandler(log_event) {
102
// TODO(aa): We could just call addStatus here to avoid duplication,
103
// but the handler throws an exception about addStatus not being
104
// defined if we log events too early for some reason. The exception stops
105
// being thrown after a few seconds. Need to investigate the cause, but
106
// this works ok for now.
107
document.getElementById('status').insertBefore(
108
document.createElement('br'),
109
document.getElementById('status').firstChild);
110
document.getElementById('status').insertBefore(
111
document.createTextNode(
112
"(" + log_event.type + "): " + log_event.message +
113
" (" + log_event.sourceUrl + ") (" +
114
// TODO(aa): Change this when log_event.date actually returns a
115
// JavaScript Date object.
116
Date(log_event.date) +
118
document.getElementById('status').firstChild);
121
function log(type, msg) {
124
if (document.getElementById('arguments').value != '') {
125
args = "[" + document.getElementById('arguments').value + "]";
127
if (document.getElementById('wp').checked) {
128
addStatus('Logging message from WorkerPool process...');
129
workerPool.sendMessage(type + ":_:_:" + msg + ":_:_:" + args,
132
console.log(type, msg, eval(args));
135
addStatus(e.message);
139
function childInit() {
141
wp = google.gears.workerPool;
142
wp.onmessage = childHandler;
143
wp.onerror = function(e) {
144
wp.sendMessage(e.message, parentId);
147
console = google.gears.factory.create('beta.console');
150
function childHandler(message, sender) {
152
var split_message = message.split(":_:_:", 3);
153
var type = split_message[0];
154
var msg = split_message[1];
155
var args = eval(split_message[2]);
156
console.log(type, msg, args);
160
if (!window.google || !google.gears) {
161
addStatus('Google Gears is not installed', 'error');
165
console = google.gears.factory.create('beta.console');
166
console.onlog = onlogHandler;
168
workerPool = google.gears.factory.create('beta.workerpool');
169
workerPool.onmessage = function(message, sender) { addStatus(message); };
171
loggerWorkerId = workerPool.createWorker(
173
String(childHandler) +
182
addStatus('Messages logged here can also be viewed' +
183
' in the Log Viewer Tool.');
184
addStatus('Open two copies of this page side by side' +
185
' to log between them.');
187
var buttons = document.getElementsByTagName('button');
188
for (var i = 0, el; el = buttons[i]; i++) {