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 // Should match SecurityInterstitialCommands in security_interstitial_page.h |
| 12 var CMD_DONT_PROCEED = 0; |
| 13 var CMD_PROCEED = 1; |
| 14 // Ways for user to get more information |
| 15 var CMD_SHOW_MORE_SECTION = 2; |
| 16 var CMD_OPEN_HELP_CENTER = 3; |
| 17 var CMD_OPEN_DIAGNOSTIC = 4; |
| 18 // Primary button actions |
| 19 var CMD_RELOAD = 5; |
| 20 var CMD_OPEN_DATE_SETTINGS = 6; |
| 21 var CMD_OPEN_LOGIN = 7; |
| 22 // Safe Browsing Extended Reporting |
| 23 var CMD_DO_REPORT = 8; |
| 24 var CMD_DONT_REPORT = 9; |
| 25 var CMD_OPEN_REPORTING_PRIVACY = 10; |
| 26 |
11 /** | 27 /** |
12 * A convenience method for sending commands to the parent page. | 28 * A convenience method for sending commands to the parent page. |
13 * @param {string} cmd The command to send. | 29 * @param {string} cmd The command to send. |
14 */ | 30 */ |
15 function sendCommand(cmd) { | 31 function sendCommand(cmd) { |
16 window.domAutomationController.setAutomationId(1); | 32 window.domAutomationController.setAutomationId(1); |
17 window.domAutomationController.send(cmd); | 33 window.domAutomationController.send(cmd); |
18 } | 34 } |
19 | 35 |
20 /** | 36 /** |
21 * This allows errors to be skippped by typing "danger" into the page. | 37 * This allows errors to be skippped by typing "danger" into the page. |
22 * @param {string} e The key that was just pressed. | 38 * @param {string} e The key that was just pressed. |
23 */ | 39 */ |
24 function handleKeypress(e) { | 40 function handleKeypress(e) { |
25 var BYPASS_SEQUENCE = 'danger'; | 41 var BYPASS_SEQUENCE = 'danger'; |
26 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) { | 42 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) { |
27 keyPressState++; | 43 keyPressState++; |
28 if (keyPressState == BYPASS_SEQUENCE.length) { | 44 if (keyPressState == BYPASS_SEQUENCE.length) { |
29 sendCommand(SSL_CMD_PROCEED); | 45 sendCommand(CMD_PROCEED); |
30 keyPressState = 0; | 46 keyPressState = 0; |
31 } | 47 } |
32 } else { | 48 } else { |
33 keyPressState = 0; | 49 keyPressState = 0; |
34 } | 50 } |
35 } | 51 } |
36 | 52 |
37 /** | 53 /** |
38 * This appends a piece of debugging information to the end of the warning. | 54 * This appends a piece of debugging information to the end of the warning. |
39 * When complete, the caller must also make the debugging div | 55 * When complete, the caller must also make the debugging div |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } else { | 97 } else { |
82 $('body').classList.add('safe-browsing'); | 98 $('body').classList.add('safe-browsing'); |
83 } | 99 } |
84 | 100 |
85 if (hidePrimaryButton) { | 101 if (hidePrimaryButton) { |
86 $('primary-button').classList.add('hidden'); | 102 $('primary-button').classList.add('hidden'); |
87 } else { | 103 } else { |
88 $('primary-button').addEventListener('click', function() { | 104 $('primary-button').addEventListener('click', function() { |
89 switch (interstitialType) { | 105 switch (interstitialType) { |
90 case 'CAPTIVE_PORTAL': | 106 case 'CAPTIVE_PORTAL': |
91 sendCommand(CAPTIVEPORTAL_CMD_OPEN_LOGIN_PAGE); | 107 sendCommand(CMD_OPEN_LOGIN); |
92 break; | 108 break; |
93 | 109 |
94 case 'SSL': | 110 case 'SSL': |
95 if (badClock) | 111 if (badClock) |
96 sendCommand(SSL_CMD_CLOCK); | 112 sendCommand(CMD_OPEN_DATE_SETTINGS); |
97 else if (overridable) | 113 else if (overridable) |
98 sendCommand(SSL_CMD_DONT_PROCEED); | 114 sendCommand(CMD_DONT_PROCEED); |
99 else | 115 else |
100 sendCommand(SSL_CMD_RELOAD); | 116 sendCommand(CMD_RELOAD); |
101 break; | 117 break; |
102 | 118 |
103 case 'SAFEBROWSING': | 119 case 'SAFEBROWSING': |
104 sendCommand(SB_CMD_TAKE_ME_BACK); | 120 sendCommand(CMD_DONT_PROCEED); |
105 break; | 121 break; |
106 | 122 |
107 default: | 123 default: |
108 throw 'Invalid interstitial type'; | 124 throw 'Invalid interstitial type'; |
109 } | 125 } |
110 }); | 126 }); |
111 } | 127 } |
112 | 128 |
113 if (overridable) { | 129 if (overridable) { |
114 // Captive portal page isn't overridable. | 130 // Captive portal page isn't overridable. |
115 $('proceed-link').addEventListener('click', function(event) { | 131 $('proceed-link').addEventListener('click', function(event) { |
116 sendCommand(ssl ? SSL_CMD_PROCEED : SB_CMD_PROCEED); | 132 sendCommand(CMD_PROCEED); |
117 }); | 133 }); |
118 } else if (!ssl) { | 134 } else if (!ssl) { |
119 $('final-paragraph').classList.add('hidden'); | 135 $('final-paragraph').classList.add('hidden'); |
120 } | 136 } |
121 | 137 |
122 if (ssl && overridable) { | 138 if (ssl && overridable) { |
123 $('proceed-link').classList.add('small-link'); | 139 $('proceed-link').classList.add('small-link'); |
124 } else if ($('help-link')) { | 140 } else if ($('help-link')) { |
125 // Overridable SSL page doesn't have this link. | 141 // Overridable SSL page doesn't have this link. |
126 $('help-link').addEventListener('click', function(event) { | 142 $('help-link').addEventListener('click', function(event) { |
127 if (ssl) | 143 if (ssl || loadTimeData.getBoolean('phishing')) |
128 sendCommand(SSL_CMD_HELP); | 144 sendCommand(CMD_OPEN_HELP_CENTER); |
129 else if (loadTimeData.getBoolean('phishing')) | |
130 sendCommand(SB_CMD_LEARN_MORE_2); | |
131 else | 145 else |
132 sendCommand(SB_CMD_SHOW_DIAGNOSTIC); | 146 sendCommand(CMD_OPEN_DIAGNOSTIC); |
133 }); | 147 }); |
134 } | 148 } |
135 | 149 |
136 if (captivePortal) { | 150 if (captivePortal) { |
137 // Captive portal page doesn't have details button. | 151 // Captive portal page doesn't have details button. |
138 $('details-button').classList.add('hidden'); | 152 $('details-button').classList.add('hidden'); |
139 } else { | 153 } else { |
140 $('details-button').addEventListener('click', function(event) { | 154 $('details-button').addEventListener('click', function(event) { |
141 var hiddenDetails = $('details').classList.toggle('hidden'); | 155 var hiddenDetails = $('details').classList.toggle('hidden'); |
142 | 156 |
143 if (mobileNav) { | 157 if (mobileNav) { |
144 // Details appear over the main content on small screens. | 158 // Details appear over the main content on small screens. |
145 $('main-content').classList.toggle('hidden', !hiddenDetails); | 159 $('main-content').classList.toggle('hidden', !hiddenDetails); |
146 } else { | 160 } else { |
147 $('main-content').classList.remove('hidden'); | 161 $('main-content').classList.remove('hidden'); |
148 } | 162 } |
149 | 163 |
150 $('details-button').innerText = hiddenDetails ? | 164 $('details-button').innerText = hiddenDetails ? |
151 loadTimeData.getString('openDetails') : | 165 loadTimeData.getString('openDetails') : |
152 loadTimeData.getString('closeDetails'); | 166 loadTimeData.getString('closeDetails'); |
153 if (!expandedDetails) { | 167 if (!expandedDetails) { |
154 // Record a histogram entry only the first time that details is opened. | 168 // Record a histogram entry only the first time that details is opened. |
155 sendCommand(ssl ? SSL_CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); | 169 sendCommand(CMD_SHOW_MORE_SECTION); |
156 expandedDetails = true; | 170 expandedDetails = true; |
157 } | 171 } |
158 }); | 172 }); |
159 } | 173 } |
160 | 174 |
161 preventDefaultOnPoundLinkClicks(); | 175 preventDefaultOnPoundLinkClicks(); |
162 setupCheckbox(); | 176 setupCheckbox(); |
163 setupSSLDebuggingInfo(); | 177 setupSSLDebuggingInfo(); |
164 document.addEventListener('keypress', handleKeypress); | 178 document.addEventListener('keypress', handleKeypress); |
165 } | 179 } |
166 | 180 |
167 document.addEventListener('DOMContentLoaded', setupEvents); | 181 document.addEventListener('DOMContentLoaded', setupEvents); |
OLD | NEW |