| 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 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 spanValue.innerText = value; | 49 spanValue.innerText = value; |
| 50 | 50 |
| 51 var pElem = document.createElement('p'); | 51 var pElem = document.createElement('p'); |
| 52 pElem.classList.add('debugging-content'); | 52 pElem.classList.add('debugging-content'); |
| 53 pElem.appendChild(spanTitle); | 53 pElem.appendChild(spanTitle); |
| 54 pElem.appendChild(spanValue); | 54 pElem.appendChild(spanValue); |
| 55 $('error-debugging-info').appendChild(pElem); | 55 $('error-debugging-info').appendChild(pElem); |
| 56 } | 56 } |
| 57 | 57 |
| 58 function toggleDebuggingInfo() { | 58 function toggleDebuggingInfo() { |
| 59 $('error-debugging-info').classList.toggle('hidden'); | 59 $('error-debugging-info').classList.toggle(HIDDEN_CLASS); |
| 60 } | 60 } |
| 61 | 61 |
| 62 function setupEvents() { | 62 function setupEvents() { |
| 63 var overridable = loadTimeData.getBoolean('overridable'); | 63 var overridable = loadTimeData.getBoolean('overridable'); |
| 64 var interstitialType = loadTimeData.getString('type'); | 64 var interstitialType = loadTimeData.getString('type'); |
| 65 var ssl = interstitialType == 'SSL'; | 65 var ssl = interstitialType == 'SSL'; |
| 66 var captivePortal = interstitialType == 'CAPTIVE_PORTAL'; | 66 var captivePortal = interstitialType == 'CAPTIVE_PORTAL'; |
| 67 var badClock = ssl && loadTimeData.getBoolean('bad_clock'); | 67 var badClock = ssl && loadTimeData.getBoolean('bad_clock'); |
| 68 var hidePrimaryButton = loadTimeData.getBoolean('hide_primary_button'); | 68 var hidePrimaryButton = loadTimeData.getBoolean('hide_primary_button'); |
| 69 | 69 |
| 70 if (ssl) { | 70 if (ssl) { |
| 71 $('body').classList.add(badClock ? 'bad-clock' : 'ssl'); | 71 $('body').classList.add(badClock ? 'bad-clock' : 'ssl'); |
| 72 $('error-code').textContent = loadTimeData.getString('errorCode'); | 72 $('error-code').textContent = loadTimeData.getString('errorCode'); |
| 73 $('error-code').classList.remove('hidden'); | 73 $('error-code').classList.remove(HIDDEN_CLASS); |
| 74 } else if (captivePortal) { | 74 } else if (captivePortal) { |
| 75 $('body').classList.add('captive-portal'); | 75 $('body').classList.add('captive-portal'); |
| 76 } else { | 76 } else { |
| 77 $('body').classList.add('safe-browsing'); | 77 $('body').classList.add('safe-browsing'); |
| 78 } | 78 } |
| 79 | 79 |
| 80 $('icon').classList.add('icon'); | 80 $('icon').classList.add('icon'); |
| 81 | 81 |
| 82 if (hidePrimaryButton) { | 82 if (hidePrimaryButton) { |
| 83 $('primary-button').classList.add('hidden'); | 83 $('primary-button').classList.add(HIDDEN_CLASS); |
| 84 } else { | 84 } else { |
| 85 $('primary-button').addEventListener('click', function() { | 85 $('primary-button').addEventListener('click', function() { |
| 86 switch (interstitialType) { | 86 switch (interstitialType) { |
| 87 case 'CAPTIVE_PORTAL': | 87 case 'CAPTIVE_PORTAL': |
| 88 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_LOGIN); | 88 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_LOGIN); |
| 89 break; | 89 break; |
| 90 | 90 |
| 91 case 'SSL': | 91 case 'SSL': |
| 92 if (badClock) | 92 if (badClock) |
| 93 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_DATE_SETTINGS); | 93 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_DATE_SETTINGS); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 } | 106 } |
| 107 }); | 107 }); |
| 108 } | 108 } |
| 109 | 109 |
| 110 if (overridable) { | 110 if (overridable) { |
| 111 // Captive portal page isn't overridable. | 111 // Captive portal page isn't overridable. |
| 112 $('proceed-link').addEventListener('click', function(event) { | 112 $('proceed-link').addEventListener('click', function(event) { |
| 113 sendCommand(SecurityInterstitialCommandId.CMD_PROCEED); | 113 sendCommand(SecurityInterstitialCommandId.CMD_PROCEED); |
| 114 }); | 114 }); |
| 115 } else if (!ssl) { | 115 } else if (!ssl) { |
| 116 $('final-paragraph').classList.add('hidden'); | 116 $('final-paragraph').classList.add(HIDDEN_CLASS); |
| 117 } | 117 } |
| 118 | 118 |
| 119 if (ssl && overridable) { | 119 if (ssl && overridable) { |
| 120 $('proceed-link').classList.add('small-link'); | 120 $('proceed-link').classList.add('small-link'); |
| 121 } | 121 } |
| 122 | 122 |
| 123 if ($('diagnostic-link')) { | 123 if ($('diagnostic-link')) { |
| 124 $('diagnostic-link').addEventListener('click', function(event) { | 124 $('diagnostic-link').addEventListener('click', function(event) { |
| 125 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_DIAGNOSTIC); | 125 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_DIAGNOSTIC); |
| 126 }); | 126 }); |
| 127 } | 127 } |
| 128 | 128 |
| 129 if ($('learn-more-link')) { | 129 if ($('learn-more-link')) { |
| 130 $('learn-more-link').addEventListener('click', function(event) { | 130 $('learn-more-link').addEventListener('click', function(event) { |
| 131 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_HELP_CENTER); | 131 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_HELP_CENTER); |
| 132 }); | 132 }); |
| 133 } | 133 } |
| 134 | 134 |
| 135 if (captivePortal) { | 135 if (captivePortal) { |
| 136 // Captive portal page doesn't have details button. | 136 // Captive portal page doesn't have details button. |
| 137 $('details-button').classList.add('hidden'); | 137 $('details-button').classList.add('hidden'); |
| 138 } else { | 138 } else { |
| 139 $('details-button').addEventListener('click', function(event) { | 139 $('details-button').addEventListener('click', function(event) { |
| 140 var hiddenDetails = $('details').classList.toggle('hidden'); | 140 var hiddenDetails = $('details').classList.toggle(HIDDEN_CLASS); |
| 141 | 141 |
| 142 if (mobileNav) { | 142 if (mobileNav) { |
| 143 // Details appear over the main content on small screens. | 143 // Details appear over the main content on small screens. |
| 144 $('main-content').classList.toggle('hidden', !hiddenDetails); | 144 $('main-content').classList.toggle(HIDDEN_CLASS, !hiddenDetails); |
| 145 } else { | 145 } else { |
| 146 $('main-content').classList.remove('hidden'); | 146 $('main-content').classList.remove(HIDDEN_CLASS); |
| 147 } | 147 } |
| 148 | 148 |
| 149 $('details-button').innerText = hiddenDetails ? | 149 $('details-button').innerText = hiddenDetails ? |
| 150 loadTimeData.getString('openDetails') : | 150 loadTimeData.getString('openDetails') : |
| 151 loadTimeData.getString('closeDetails'); | 151 loadTimeData.getString('closeDetails'); |
| 152 if (!expandedDetails) { | 152 if (!expandedDetails) { |
| 153 // Record a histogram entry only the first time that details is opened. | 153 // Record a histogram entry only the first time that details is opened. |
| 154 sendCommand(SecurityInterstitialCommandId.CMD_SHOW_MORE_SECTION); | 154 sendCommand(SecurityInterstitialCommandId.CMD_SHOW_MORE_SECTION); |
| 155 expandedDetails = true; | 155 expandedDetails = true; |
| 156 } | 156 } |
| 157 }); | 157 }); |
| 158 } | 158 } |
| 159 | 159 |
| 160 if ($('report-error-link')) { | 160 if ($('report-error-link')) { |
| 161 $('report-error-link').addEventListener('click', function(event) { | 161 $('report-error-link').addEventListener('click', function(event) { |
| 162 sendCommand(SecurityInterstitialCommandId.CMD_REPORT_PHISHING_ERROR); | 162 sendCommand(SecurityInterstitialCommandId.CMD_REPORT_PHISHING_ERROR); |
| 163 }); | 163 }); |
| 164 } | 164 } |
| 165 | 165 |
| 166 document.addEventListener('click', function(e) { | 166 preventDefaultOnPoundLinkClicks(); |
| 167 var anchor = findAncestor(/** @type {Node} */ (e.target), function(el) { | |
| 168 return el.tagName == 'A'; | |
| 169 }); | |
| 170 // Use getAttribute() to prevent URL normalization. | |
| 171 if (anchor && anchor.getAttribute('href') == '#') | |
| 172 e.preventDefault(); | |
| 173 }); | |
| 174 | |
| 175 setupExtendedReportingCheckbox(); | 167 setupExtendedReportingCheckbox(); |
| 176 setupSSLDebuggingInfo(); | 168 setupSSLDebuggingInfo(); |
| 177 document.addEventListener('keypress', handleKeypress); | 169 document.addEventListener('keypress', handleKeypress); |
| 178 } | 170 } |
| 179 | 171 |
| 180 document.addEventListener('DOMContentLoaded', setupEvents); | 172 document.addEventListener('DOMContentLoaded', setupEvents); |
| OLD | NEW |