OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This is the shared code for the new (Chrome 37) security interstitials. It is | 5 // This is the shared code for the new (Chrome 37) security interstitials. It is |
6 // used for both SSL interstitials and Safe Browsing interstitials. | 6 // used for both SSL interstitials and Safe Browsing interstitials. |
7 | 7 |
8 var expandedDetails = false; | 8 var expandedDetails = false; |
9 var keyPressState = 0; | 9 var keyPressState = 0; |
10 | 10 |
11 /* | 11 /* |
12 * A convenience method for sending commands to the parent page. | 12 * A convenience method for sending commands to the parent page. |
13 * @param {string} cmd The command to send. | 13 * @param {string} cmd The command to send. |
14 */ | 14 */ |
15 function sendCommand(cmd) { | 15 function sendCommand(cmd) { |
16 window.domAutomationController.setAutomationId(1); | 16 window.domAutomationController.setAutomationId(1); |
17 window.domAutomationController.send(cmd); | 17 window.domAutomationController.send(cmd); |
18 } | 18 } |
19 | 19 |
20 /* | 20 /* |
21 * This allows errors to be skippped by typing "danger" into the page. | 21 * This allows errors to be skippped by typing "danger" into the page. |
22 * @param {string} e The key that was just pressed. | 22 * @param {string} e The key that was just pressed. |
23 */ | 23 */ |
24 function handleKeypress(e) { | 24 function handleKeypress(e) { |
25 var BYPASS_SEQUENCE = 'danger'; | 25 var BYPASS_SEQUENCE = 'danger'; |
26 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) { | 26 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) { |
27 keyPressState++; | 27 keyPressState++; |
28 if (keyPressState == BYPASS_SEQUENCE.length) { | 28 if (keyPressState == BYPASS_SEQUENCE.length) { |
29 sendCommand(CMD_PROCEED); | 29 sendCommand(SSL_CMD_PROCEED); |
30 keyPressState = 0; | 30 keyPressState = 0; |
31 } | 31 } |
32 } else { | 32 } else { |
33 keyPressState = 0; | 33 keyPressState = 0; |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 function setupEvents() { | 37 function setupEvents() { |
38 var overridable = loadTimeData.getBoolean('overridable'); | 38 var overridable = loadTimeData.getBoolean('overridable'); |
39 var ssl = loadTimeData.getBoolean('ssl'); | 39 var ssl = loadTimeData.getString('type') === 'ssl'; |
40 | 40 |
41 if (ssl) { | 41 if (ssl) { |
42 $('body').classList.add('ssl'); | 42 $('body').classList.add('ssl'); |
43 $('error-code').textContent = loadTimeData.getString('errorCode'); | 43 $('error-code').textContent = loadTimeData.getString('errorCode'); |
44 $('error-code').classList.remove('hidden'); | 44 $('error-code').classList.remove('hidden'); |
45 } else { | 45 } else { |
46 $('body').classList.add('safe-browsing'); | 46 $('body').classList.add('safe-browsing'); |
47 } | 47 } |
48 | 48 |
49 $('primary-button').addEventListener('click', function() { | 49 $('primary-button').addEventListener('click', function() { |
50 if (!ssl) | 50 if (!ssl) |
51 sendCommand(SB_CMD_TAKE_ME_BACK); | 51 sendCommand(SB_CMD_TAKE_ME_BACK); |
52 else if (overridable) | 52 else if (overridable) |
53 sendCommand(CMD_DONT_PROCEED); | 53 sendCommand(SSL_CMD_DONT_PROCEED); |
54 else | 54 else |
55 sendCommand(CMD_RELOAD); | 55 sendCommand(SSL_CMD_RELOAD); |
56 }); | 56 }); |
57 | 57 |
58 if (overridable) { | 58 if (overridable) { |
59 $('proceed-link').addEventListener('click', function(event) { | 59 $('proceed-link').addEventListener('click', function(event) { |
60 sendCommand(ssl ? CMD_PROCEED : SB_CMD_PROCEED); | 60 sendCommand(ssl ? SSL_CMD_PROCEED : SB_CMD_PROCEED); |
61 }); | 61 }); |
62 } else if (!ssl) { | 62 } else if (!ssl) { |
63 $('final-paragraph').classList.add('hidden'); | 63 $('final-paragraph').classList.add('hidden'); |
64 } | 64 } |
65 | 65 |
66 if (ssl && overridable) { | 66 if (ssl && overridable) { |
67 $('proceed-link').classList.add('small-link'); | 67 $('proceed-link').classList.add('small-link'); |
68 } else if ($('help-link')) { | 68 } else if ($('help-link')) { |
69 // Overridable SSL page doesn't have this link. | 69 // Overridable SSL page doesn't have this link. |
70 $('help-link').addEventListener('click', function(event) { | 70 $('help-link').addEventListener('click', function(event) { |
71 if (ssl) | 71 if (ssl) |
72 sendCommand(CMD_HELP); | 72 sendCommand(SSL_CMD_HELP); |
73 else if (loadTimeData.getBoolean('phishing')) | 73 else if (loadTimeData.getBoolean('phishing')) |
74 sendCommand(SB_CMD_LEARN_MORE_2); | 74 sendCommand(SB_CMD_LEARN_MORE_2); |
75 else | 75 else |
76 sendCommand(SB_CMD_SHOW_DIAGNOSTIC); | 76 sendCommand(SB_CMD_SHOW_DIAGNOSTIC); |
77 }); | 77 }); |
78 } | 78 } |
79 | 79 |
80 if (ssl && $('clock-link')) { | 80 if (ssl && $('clock-link')) { |
81 $('clock-link').addEventListener('click', function(event) { | 81 $('clock-link').addEventListener('click', function(event) { |
82 sendCommand(CMD_CLOCK); | 82 sendCommand(SSL_CMD_CLOCK); |
83 }); | 83 }); |
84 } | 84 } |
85 | 85 |
86 $('details-button').addEventListener('click', function(event) { | 86 $('details-button').addEventListener('click', function(event) { |
87 var hiddenDetails = $('details').classList.toggle('hidden'); | 87 var hiddenDetails = $('details').classList.toggle('hidden'); |
88 $('details-button').innerText = hiddenDetails ? | 88 $('details-button').innerText = hiddenDetails ? |
89 loadTimeData.getString('openDetails') : | 89 loadTimeData.getString('openDetails') : |
90 loadTimeData.getString('closeDetails'); | 90 loadTimeData.getString('closeDetails'); |
91 if (!expandedDetails) { | 91 if (!expandedDetails) { |
92 // Record a histogram entry only the first time that details is opened. | 92 // Record a histogram entry only the first time that details is opened. |
93 sendCommand(ssl ? CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); | 93 sendCommand(ssl ? SSL_CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); |
94 expandedDetails = true; | 94 expandedDetails = true; |
95 } | 95 } |
96 }); | 96 }); |
97 | 97 |
98 preventDefaultOnPoundLinkClicks(); | 98 preventDefaultOnPoundLinkClicks(); |
99 setupCheckbox(); | 99 setupCheckbox(); |
100 document.addEventListener('keypress', handleKeypress); | 100 document.addEventListener('keypress', handleKeypress); |
101 } | 101 } |
102 | 102 |
103 document.addEventListener('DOMContentLoaded', setupEvents); | 103 document.addEventListener('DOMContentLoaded', setupEvents); |
OLD | NEW |