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(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 /** |
| 38 * This appends a piece of debugging information to the end of the warning. |
| 39 * When complete, the caller must also make the debugging div |
| 40 * (error-debugging-info) visible. |
| 41 * @param {string} title The name of this debugging field. |
| 42 * @param {string} value The value of the debugging field. |
| 43 */ |
| 44 function appendDebuggingField(title, value) { |
| 45 // The values input here are not trusted. Never use innerHTML on these |
| 46 // values! |
| 47 var spanTitle = document.createElement('span'); |
| 48 spanTitle.classList.add('debugging-title'); |
| 49 spanTitle.innerText = title + ': '; |
| 50 |
| 51 var spanValue = document.createElement('span'); |
| 52 spanValue.classList.add('debugging-value'); |
| 53 spanValue.innerText = value; |
| 54 |
| 55 var pElem = document.createElement('p'); |
| 56 pElem.classList.add('debugging-content'); |
| 57 pElem.appendChild(spanTitle); |
| 58 pElem.appendChild(spanValue); |
| 59 $('error-debugging-info').appendChild(pElem); |
| 60 } |
| 61 |
| 62 function toggleDebuggingInfo() { |
| 63 $('error-debugging-info').classList.toggle('hidden'); |
| 64 } |
| 65 |
37 function setupEvents() { | 66 function setupEvents() { |
38 var overridable = loadTimeData.getBoolean('overridable'); | 67 var overridable = loadTimeData.getBoolean('overridable'); |
39 var ssl = loadTimeData.getBoolean('ssl'); | 68 var ssl = loadTimeData.getBoolean('ssl'); |
40 | 69 |
41 if (ssl) { | 70 if (ssl) { |
42 $('body').classList.add('ssl'); | 71 $('body').classList.add('ssl'); |
43 $('error-code').textContent = loadTimeData.getString('errorCode'); | 72 $('error-code').textContent = loadTimeData.getString('errorCode'); |
44 $('error-code').classList.remove('hidden'); | 73 $('error-code').classList.remove('hidden'); |
45 } else { | 74 } else { |
46 $('body').classList.add('safe-browsing'); | 75 $('body').classList.add('safe-browsing'); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 loadTimeData.getString('closeDetails'); | 119 loadTimeData.getString('closeDetails'); |
91 if (!expandedDetails) { | 120 if (!expandedDetails) { |
92 // Record a histogram entry only the first time that details is opened. | 121 // Record a histogram entry only the first time that details is opened. |
93 sendCommand(ssl ? CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); | 122 sendCommand(ssl ? CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); |
94 expandedDetails = true; | 123 expandedDetails = true; |
95 } | 124 } |
96 }); | 125 }); |
97 | 126 |
98 preventDefaultOnPoundLinkClicks(); | 127 preventDefaultOnPoundLinkClicks(); |
99 setupCheckbox(); | 128 setupCheckbox(); |
| 129 setupSSLDebuggingInfo(); |
100 document.addEventListener('keypress', handleKeypress); | 130 document.addEventListener('keypress', handleKeypress); |
101 } | 131 } |
102 | 132 |
103 document.addEventListener('DOMContentLoaded', setupEvents); | 133 document.addEventListener('DOMContentLoaded', setupEvents); |
OLD | NEW |