1 // Copyright 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 chrome
.app
.runtime
.onLaunched
.addListener(function() {
6 chrome
.app
.window
.create('main.html', {}, function(win
) {
7 // The following key events handler will prevent the default behavior for
8 // the ESC key, thus will prevent the ESC key to leave fullscreen.
9 win
.contentWindow
.document
.addEventListener('keydown', function(e
) {
12 win
.contentWindow
.document
.addEventListener('keyup', function(e
) {
16 chrome
.test
.sendMessage('Launched', function(reply
) {
17 var doc
= win
.contentWindow
.document
;
18 doc
.addEventListener('keydown', function(e
) {
19 if (e
.keyCode
!= 90) // 'z'
21 chrome
.test
.sendMessage('KeyReceived');
26 doc
.addEventListener('keydown', function(e
) {
27 if (e
.keyCode
!= 66) // 'b'
29 doc
.removeEventListener('keydown', arguments
.callee
);
30 // We do one trip to the event loop to increase the chances that
31 // fullscreen could have been left before the message is received.
32 setTimeout(function() {
33 chrome
.test
.sendMessage('B_KEY_RECEIVED');
40 doc
.addEventListener('keydown', function() {
41 doc
.removeEventListener('keydown', arguments
.callee
);
43 doc
.addEventListener('keydown', function(e
) {
44 if (e
.keyCode
!= 66) // 'b'
46 doc
.removeEventListener('keydown', arguments
.callee
);
47 // We do one trip to the event loop to increase the chances that
48 // fullscreen could have been left before the message is received.
49 setTimeout(function() {
50 chrome
.test
.sendMessage('B_KEY_RECEIVED');
54 doc
.body
.webkitRequestFullscreen();