Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / ssl / ssl_errors_common.js
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.
4
5 // Should match SSLBlockingPageCommands in ssl_blocking_page.cc.
6 var CMD_DONT_PROCEED = 0;
7 var CMD_PROCEED = 1;
8 var CMD_MORE = 2;
9 var CMD_RELOAD = 3;
10 var CMD_HELP = 4;
11 var CMD_CLOCK = 5;
12
13 var keyPressState = 0;
14
15 function $(o) {
16   return document.getElementById(o);
17 }
18
19 function sendCommand(cmd) {
20   window.domAutomationController.setAutomationId(1);
21   window.domAutomationController.send(cmd);
22 }
23
24 // This allows errors to be skippped by typing "danger" into the page.
25 function keyPressHandler(e) {
26   var sequence = 'danger';
27   if (sequence.charCodeAt(keyPressState) == e.keyCode) {
28     keyPressState++;
29     if (keyPressState == sequence.length) {
30       sendCommand(CMD_PROCEED);
31       keyPressState = 0;
32     }
33   } else {
34     keyPressState = 0;
35   }
36 }
37
38 function sharedSetup() {
39   document.addEventListener('contextmenu', function(e) {
40     e.preventDefault();
41   });
42   document.addEventListener('keypress', keyPressHandler);
43 }
44
45 document.addEventListener('DOMContentLoaded', sharedSetup);
46