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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 pElem.appendChild(spanValue); | 58 pElem.appendChild(spanValue); |
59 $('error-debugging-info').appendChild(pElem); | 59 $('error-debugging-info').appendChild(pElem); |
60 } | 60 } |
61 | 61 |
62 function toggleDebuggingInfo() { | 62 function toggleDebuggingInfo() { |
63 $('error-debugging-info').classList.toggle('hidden'); | 63 $('error-debugging-info').classList.toggle('hidden'); |
64 } | 64 } |
65 | 65 |
66 function setupEvents() { | 66 function setupEvents() { |
67 var overridable = loadTimeData.getBoolean('overridable'); | 67 var overridable = loadTimeData.getBoolean('overridable'); |
68 var ssl = loadTimeData.getString('type') === 'SSL'; | 68 var interstitialType = loadTimeData.getString('type'); |
69 var ssl = interstitialType === 'SSL'; | |
Bernhard Bauer
2014/12/18 18:10:06
The === isn't really necessary here if you know th
meacer
2014/12/19 02:42:24
Done.
| |
70 var captivePortal = interstitialType === 'CAPTIVE_PORTAL'; | |
69 var badClock = ssl && loadTimeData.getBoolean('bad_clock'); | 71 var badClock = ssl && loadTimeData.getBoolean('bad_clock'); |
70 var hidePrimaryButton = badClock && loadTimeData.getBoolean( | 72 var hidePrimaryButton = badClock && loadTimeData.getBoolean( |
71 'hide_primary_button'); | 73 'hide_primary_button'); |
72 | 74 |
73 if (ssl) { | 75 if (ssl) { |
74 $('body').classList.add(badClock ? 'bad-clock' : 'ssl'); | 76 $('body').classList.add(badClock ? 'bad-clock' : 'ssl'); |
75 $('error-code').textContent = loadTimeData.getString('errorCode'); | 77 $('error-code').textContent = loadTimeData.getString('errorCode'); |
76 $('error-code').classList.remove('hidden'); | 78 $('error-code').classList.remove('hidden'); |
79 } else if (captivePortal) { | |
80 $('body').classList.add('captive-portal'); | |
77 } else { | 81 } else { |
78 $('body').classList.add('safe-browsing'); | 82 $('body').classList.add('safe-browsing'); |
79 } | 83 } |
80 | 84 |
81 if (hidePrimaryButton) { | 85 if (hidePrimaryButton) { |
82 $('primary-button').classList.add('hidden'); | 86 $('primary-button').classList.add('hidden'); |
83 } else { | 87 } else { |
84 $('primary-button').addEventListener('click', function() { | 88 $('primary-button').addEventListener('click', function() { |
85 if (!ssl) | 89 switch (interstitialType) { |
90 case 'CAPTIVE_PORTAL': | |
91 sendCommand(CAPTIVEPORTAL_CMD_OPEN_LOGIN_PAGE); | |
Bernhard Bauer
2014/12/18 18:10:06
This should be indented two more spaces.
meacer
2014/12/19 02:42:24
Done.
| |
92 break; | |
93 | |
94 case 'SSL': | |
95 if (badClock) | |
96 sendCommand(SSL_CMD_CLOCK); | |
97 else if (overridable) | |
98 sendCommand(SSL_CMD_DONT_PROCEED); | |
99 else | |
100 sendCommand(SSL_CMD_RELOAD); | |
101 break; | |
102 | |
103 case 'SAFEBROWSING': | |
86 sendCommand(SB_CMD_TAKE_ME_BACK); | 104 sendCommand(SB_CMD_TAKE_ME_BACK); |
87 else if (badClock) | 105 break; |
88 sendCommand(SSL_CMD_CLOCK); | 106 |
89 else if (overridable) | 107 default: |
90 sendCommand(SSL_CMD_DONT_PROCEED); | 108 throw 'Invalid interstitial type'; |
91 else | 109 } |
92 sendCommand(SSL_CMD_RELOAD); | |
93 }); | 110 }); |
94 } | 111 } |
95 | 112 |
96 if (overridable) { | 113 if (overridable) { |
114 // Captive portal page isn't overridable. | |
97 $('proceed-link').addEventListener('click', function(event) { | 115 $('proceed-link').addEventListener('click', function(event) { |
98 sendCommand(ssl ? SSL_CMD_PROCEED : SB_CMD_PROCEED); | 116 sendCommand(ssl ? SSL_CMD_PROCEED : SB_CMD_PROCEED); |
99 }); | 117 }); |
100 } else if (!ssl) { | 118 } else if (!ssl) { |
101 $('final-paragraph').classList.add('hidden'); | 119 $('final-paragraph').classList.add('hidden'); |
102 } | 120 } |
103 | 121 |
104 if (ssl && overridable) { | 122 if (ssl && overridable) { |
105 $('proceed-link').classList.add('small-link'); | 123 $('proceed-link').classList.add('small-link'); |
106 } else if ($('help-link')) { | 124 } else if ($('help-link')) { |
107 // Overridable SSL page doesn't have this link. | 125 // Overridable SSL page doesn't have this link. |
108 $('help-link').addEventListener('click', function(event) { | 126 $('help-link').addEventListener('click', function(event) { |
109 if (ssl) | 127 if (ssl) |
110 sendCommand(SSL_CMD_HELP); | 128 sendCommand(SSL_CMD_HELP); |
111 else if (loadTimeData.getBoolean('phishing')) | 129 else if (loadTimeData.getBoolean('phishing')) |
112 sendCommand(SB_CMD_LEARN_MORE_2); | 130 sendCommand(SB_CMD_LEARN_MORE_2); |
113 else | 131 else |
114 sendCommand(SB_CMD_SHOW_DIAGNOSTIC); | 132 sendCommand(SB_CMD_SHOW_DIAGNOSTIC); |
115 }); | 133 }); |
116 } | 134 } |
117 | 135 |
118 $('details-button').addEventListener('click', function(event) { | 136 if (captivePortal) { |
119 var hiddenDetails = $('details').classList.toggle('hidden'); | 137 // Captive portal page doesn't have details button. |
120 $('details-button').innerText = hiddenDetails ? | 138 $('details-button').classList.add('hidden'); |
121 loadTimeData.getString('openDetails') : | 139 } else { |
122 loadTimeData.getString('closeDetails'); | 140 $('details-button').addEventListener('click', function(event) { |
123 if (!expandedDetails) { | 141 var hiddenDetails = $('details').classList.toggle('hidden'); |
124 // Record a histogram entry only the first time that details is opened. | 142 $('details-button').innerText = hiddenDetails ? |
125 sendCommand(ssl ? SSL_CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); | 143 loadTimeData.getString('openDetails') : |
126 expandedDetails = true; | 144 loadTimeData.getString('closeDetails'); |
127 } | 145 if (!expandedDetails) { |
128 }); | 146 // Record a histogram entry only the first time that details is opened. |
147 sendCommand(ssl ? SSL_CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); | |
148 expandedDetails = true; | |
149 } | |
150 }); | |
151 } | |
129 | 152 |
130 preventDefaultOnPoundLinkClicks(); | 153 preventDefaultOnPoundLinkClicks(); |
131 setupCheckbox(); | 154 setupCheckbox(); |
132 setupSSLDebuggingInfo(); | 155 setupSSLDebuggingInfo(); |
133 document.addEventListener('keypress', handleKeypress); | 156 document.addEventListener('keypress', handleKeypress); |
134 } | 157 } |
135 | 158 |
136 document.addEventListener('DOMContentLoaded', setupEvents); | 159 document.addEventListener('DOMContentLoaded', setupEvents); |
OLD | NEW |