Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: components/security_interstitials/core/browser/resources/interstitial_v2.js

Issue 2854263003: Add quiet safe browsing interstitial for WebView (Closed)
Patch Set: Fix unit test Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 security_interstitials::SecurityInterstitialCommands
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 var CMD_OPEN_WHITEPAPER = 11;
27 // Report a phishing error.
28 var CMD_REPORT_PHISHING_ERROR = 12;
29
30 /**
31 * A convenience method for sending commands to the parent page.
32 * @param {string} cmd The command to send.
33 */
34 function sendCommand(cmd) {
35 // <if expr="not is_ios">
36 window.domAutomationController.setAutomationId(1);
37 window.domAutomationController.send(cmd);
38 // </if>
39 // <if expr="is_ios">
40 // TODO(crbug.com/565877): Revisit message passing for WKWebView.
41 var iframe = document.createElement('IFRAME');
42 iframe.setAttribute('src', 'js-command:' + cmd);
43 document.documentElement.appendChild(iframe);
44 iframe.parentNode.removeChild(iframe);
45 // </if>
46 }
47
48 /** 11 /**
49 * This allows errors to be skippped by typing a secret phrase into the page. 12 * This allows errors to be skippped by typing a secret phrase into the page.
50 * @param {string} e The key that was just pressed. 13 * @param {string} e The key that was just pressed.
51 */ 14 */
52 function handleKeypress(e) { 15 function handleKeypress(e) {
53 var BYPASS_SEQUENCE = 'badidea'; 16 var BYPASS_SEQUENCE = 'badidea';
54 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) { 17 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) {
55 keyPressState++; 18 keyPressState++;
56 if (keyPressState == BYPASS_SEQUENCE.length) { 19 if (keyPressState == BYPASS_SEQUENCE.length) {
57 sendCommand(CMD_PROCEED); 20 sendCommand(SecurityInterstitialCommandId.CMD_PROCEED);
58 keyPressState = 0; 21 keyPressState = 0;
59 } 22 }
60 } else { 23 } else {
61 keyPressState = 0; 24 keyPressState = 0;
62 } 25 }
63 } 26 }
64 27
65 /** 28 /**
66 * This appends a piece of debugging information to the end of the warning. 29 * This appends a piece of debugging information to the end of the warning.
67 * When complete, the caller must also make the debugging div 30 * When complete, the caller must also make the debugging div
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 78 }
116 79
117 $('icon').classList.add('icon'); 80 $('icon').classList.add('icon');
118 81
119 if (hidePrimaryButton) { 82 if (hidePrimaryButton) {
120 $('primary-button').classList.add('hidden'); 83 $('primary-button').classList.add('hidden');
121 } else { 84 } else {
122 $('primary-button').addEventListener('click', function() { 85 $('primary-button').addEventListener('click', function() {
123 switch (interstitialType) { 86 switch (interstitialType) {
124 case 'CAPTIVE_PORTAL': 87 case 'CAPTIVE_PORTAL':
125 sendCommand(CMD_OPEN_LOGIN); 88 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_LOGIN);
126 break; 89 break;
127 90
128 case 'SSL': 91 case 'SSL':
129 if (badClock) 92 if (badClock)
130 sendCommand(CMD_OPEN_DATE_SETTINGS); 93 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_DATE_SETTINGS);
131 else if (overridable) 94 else if (overridable)
132 sendCommand(CMD_DONT_PROCEED); 95 sendCommand(SecurityInterstitialCommandId.CMD_DONT_PROCEED);
133 else 96 else
134 sendCommand(CMD_RELOAD); 97 sendCommand(SecurityInterstitialCommandId.CMD_RELOAD);
135 break; 98 break;
136 99
137 case 'SAFEBROWSING': 100 case 'SAFEBROWSING':
138 sendCommand(CMD_DONT_PROCEED); 101 sendCommand(SecurityInterstitialCommandId.CMD_DONT_PROCEED);
139 break; 102 break;
140 103
141 default: 104 default:
142 throw 'Invalid interstitial type'; 105 throw 'Invalid interstitial type';
143 } 106 }
144 }); 107 });
145 } 108 }
146 109
147 if (overridable) { 110 if (overridable) {
148 // Captive portal page isn't overridable. 111 // Captive portal page isn't overridable.
149 $('proceed-link').addEventListener('click', function(event) { 112 $('proceed-link').addEventListener('click', function(event) {
150 sendCommand(CMD_PROCEED); 113 sendCommand(SecurityInterstitialCommandId.CMD_PROCEED);
151 }); 114 });
152 } else if (!ssl) { 115 } else if (!ssl) {
153 $('final-paragraph').classList.add('hidden'); 116 $('final-paragraph').classList.add('hidden');
154 } 117 }
155 118
156 if (ssl && overridable) { 119 if (ssl && overridable) {
157 $('proceed-link').classList.add('small-link'); 120 $('proceed-link').classList.add('small-link');
158 } 121 }
159 122
160 if ($('diagnostic-link')) { 123 if ($('diagnostic-link')) {
161 $('diagnostic-link').addEventListener('click', function(event) { 124 $('diagnostic-link').addEventListener('click', function(event) {
162 sendCommand(CMD_OPEN_DIAGNOSTIC); 125 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_DIAGNOSTIC);
163 }); 126 });
164 } 127 }
165 128
166 if ($('learn-more-link')) { 129 if ($('learn-more-link')) {
167 $('learn-more-link').addEventListener('click', function(event) { 130 $('learn-more-link').addEventListener('click', function(event) {
168 sendCommand(CMD_OPEN_HELP_CENTER); 131 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_HELP_CENTER);
169 }); 132 });
170 } 133 }
171 134
172 if (captivePortal) { 135 if (captivePortal) {
173 // Captive portal page doesn't have details button. 136 // Captive portal page doesn't have details button.
174 $('details-button').classList.add('hidden'); 137 $('details-button').classList.add('hidden');
175 } else { 138 } else {
176 $('details-button').addEventListener('click', function(event) { 139 $('details-button').addEventListener('click', function(event) {
177 var hiddenDetails = $('details').classList.toggle('hidden'); 140 var hiddenDetails = $('details').classList.toggle('hidden');
178 141
179 if (mobileNav) { 142 if (mobileNav) {
180 // Details appear over the main content on small screens. 143 // Details appear over the main content on small screens.
181 $('main-content').classList.toggle('hidden', !hiddenDetails); 144 $('main-content').classList.toggle('hidden', !hiddenDetails);
182 } else { 145 } else {
183 $('main-content').classList.remove('hidden'); 146 $('main-content').classList.remove('hidden');
184 } 147 }
185 148
186 $('details-button').innerText = hiddenDetails ? 149 $('details-button').innerText = hiddenDetails ?
187 loadTimeData.getString('openDetails') : 150 loadTimeData.getString('openDetails') :
188 loadTimeData.getString('closeDetails'); 151 loadTimeData.getString('closeDetails');
189 if (!expandedDetails) { 152 if (!expandedDetails) {
190 // 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.
191 sendCommand(CMD_SHOW_MORE_SECTION); 154 sendCommand(SecurityInterstitialCommandId.CMD_SHOW_MORE_SECTION);
192 expandedDetails = true; 155 expandedDetails = true;
193 } 156 }
194 }); 157 });
195 } 158 }
196 159
197 // TODO(felt): This should be simplified once the Finch trial is no longer 160 // TODO(felt): This should be simplified once the Finch trial is no longer
198 // needed. 161 // needed.
199 if (interstitialType == 'SAFEBROWSING' && 162 if (interstitialType == 'SAFEBROWSING' &&
200 loadTimeData.getBoolean('phishing') && $('report-error-link')) { 163 loadTimeData.getBoolean('phishing') && $('report-error-link')) {
201 $('report-error-link').addEventListener('click', function(event) { 164 $('report-error-link').addEventListener('click', function(event) {
202 sendCommand(CMD_REPORT_PHISHING_ERROR); 165 sendCommand(SecurityInterstitialCommandId.CMD_REPORT_PHISHING_ERROR);
203 }); 166 });
204 } 167 }
205 168
206 preventDefaultOnPoundLinkClicks(); 169 preventDefaultOnPoundLinkClicks();
207 setupExtendedReportingCheckbox(); 170 setupExtendedReportingCheckbox();
208 setupSSLDebuggingInfo(); 171 setupSSLDebuggingInfo();
209 document.addEventListener('keypress', handleKeypress); 172 document.addEventListener('keypress', handleKeypress);
210 } 173 }
211 174
212 document.addEventListener('DOMContentLoaded', setupEvents); 175 document.addEventListener('DOMContentLoaded', setupEvents);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698