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

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: Address dbeam comments 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 79 }
117 80
118 $('icon').classList.add('icon'); 81 $('icon').classList.add('icon');
119 82
120 if (hidePrimaryButton) { 83 if (hidePrimaryButton) {
121 $('primary-button').classList.add('hidden'); 84 $('primary-button').classList.add('hidden');
122 } else { 85 } else {
123 $('primary-button').addEventListener('click', function() { 86 $('primary-button').addEventListener('click', function() {
124 switch (interstitialType) { 87 switch (interstitialType) {
125 case 'CAPTIVE_PORTAL': 88 case 'CAPTIVE_PORTAL':
126 sendCommand(CMD_OPEN_LOGIN); 89 sendCommand(securityInterstitialCommandId.CMD_OPEN_LOGIN);
127 break; 90 break;
128 91
129 case 'SSL': 92 case 'SSL':
130 if (badClock) 93 if (badClock)
131 sendCommand(CMD_OPEN_DATE_SETTINGS); 94 sendCommand(securityInterstitialCommandId.CMD_OPEN_DATE_SETTINGS);
132 else if (overridable) 95 else if (overridable)
133 sendCommand(CMD_DONT_PROCEED); 96 sendCommand(securityInterstitialCommandId.CMD_DONT_PROCEED);
134 else 97 else
135 sendCommand(CMD_RELOAD); 98 sendCommand(securityInterstitialCommandId.CMD_RELOAD);
136 break; 99 break;
137 100
138 case 'SAFEBROWSING': 101 case 'SAFEBROWSING':
139 sendCommand(CMD_DONT_PROCEED); 102 sendCommand(securityInterstitialCommandId.CMD_DONT_PROCEED);
140 break; 103 break;
141 104
142 default: 105 default:
143 throw 'Invalid interstitial type'; 106 throw 'Invalid interstitial type';
144 } 107 }
145 }); 108 });
146 } 109 }
147 110
148 if (overridable) { 111 if (overridable) {
149 // Captive portal page isn't overridable. 112 // Captive portal page isn't overridable.
150 $('proceed-link').addEventListener('click', function(event) { 113 $('proceed-link').addEventListener('click', function(event) {
151 sendCommand(CMD_PROCEED); 114 sendCommand(securityInterstitialCommandId.CMD_PROCEED);
152 }); 115 });
153 } else if (!ssl) { 116 } else if (!ssl) {
154 $('final-paragraph').classList.add('hidden'); 117 $('final-paragraph').classList.add('hidden');
155 } 118 }
156 119
157 if (ssl && overridable) { 120 if (ssl && overridable) {
158 $('proceed-link').classList.add('small-link'); 121 $('proceed-link').classList.add('small-link');
159 } 122 }
160 123
161 if ($('diagnostic-link')) { 124 if ($('diagnostic-link')) {
162 $('diagnostic-link').addEventListener('click', function(event) { 125 $('diagnostic-link').addEventListener('click', function(event) {
163 sendCommand(CMD_OPEN_DIAGNOSTIC); 126 sendCommand(securityInterstitialCommandId.CMD_OPEN_DIAGNOSTIC);
164 }); 127 });
165 } 128 }
166 129
167 if ($('learn-more-link')) { 130 if ($('learn-more-link')) {
168 $('learn-more-link').addEventListener('click', function(event) { 131 $('learn-more-link').addEventListener('click', function(event) {
169 sendCommand(CMD_OPEN_HELP_CENTER); 132 sendCommand(securityInterstitialCommandId.CMD_OPEN_HELP_CENTER);
170 }); 133 });
171 } 134 }
172 135
173 if (captivePortal) { 136 if (captivePortal) {
174 // Captive portal page doesn't have details button. 137 // Captive portal page doesn't have details button.
175 $('details-button').classList.add('hidden'); 138 $('details-button').classList.add('hidden');
176 } else { 139 } else {
177 $('details-button').addEventListener('click', function(event) { 140 $('details-button').addEventListener('click', function(event) {
178 var hiddenDetails = $('details').classList.toggle('hidden'); 141 var hiddenDetails = $('details').classList.toggle('hidden');
179 142
180 if (mobileNav) { 143 if (mobileNav) {
181 // Details appear over the main content on small screens. 144 // Details appear over the main content on small screens.
182 $('main-content').classList.toggle('hidden', !hiddenDetails); 145 $('main-content').classList.toggle('hidden', !hiddenDetails);
183 } else { 146 } else {
184 $('main-content').classList.remove('hidden'); 147 $('main-content').classList.remove('hidden');
185 } 148 }
186 149
187 $('details-button').innerText = hiddenDetails ? 150 $('details-button').innerText = hiddenDetails ?
188 loadTimeData.getString('openDetails') : 151 loadTimeData.getString('openDetails') :
189 loadTimeData.getString('closeDetails'); 152 loadTimeData.getString('closeDetails');
190 if (!expandedDetails) { 153 if (!expandedDetails) {
191 // Record a histogram entry only the first time that details is opened. 154 // Record a histogram entry only the first time that details is opened.
192 sendCommand(CMD_SHOW_MORE_SECTION); 155 sendCommand(securityInterstitialCommandId.CMD_SHOW_MORE_SECTION);
193 expandedDetails = true; 156 expandedDetails = true;
194 } 157 }
195 }); 158 });
196 } 159 }
197 160
198 // TODO(felt): This should be simplified once the Finch trial is no longer 161 // TODO(felt): This should be simplified once the Finch trial is no longer
199 // needed. 162 // needed.
200 if (interstitialType == 'SAFEBROWSING' && 163 if (interstitialType == 'SAFEBROWSING' &&
201 loadTimeData.getBoolean('phishing') && $('report-error-link')) { 164 loadTimeData.getBoolean('phishing') && $('report-error-link')) {
202 $('report-error-link').addEventListener('click', function(event) { 165 $('report-error-link').addEventListener('click', function(event) {
203 sendCommand(CMD_REPORT_PHISHING_ERROR); 166 sendCommand(securityInterstitialCommandId.CMD_REPORT_PHISHING_ERROR);
204 }); 167 });
205 } 168 }
206 169
207 preventDefaultOnPoundLinkClicks(); 170 preventDefaultOnPoundLinkClicks();
208 setupExtendedReportingCheckbox(); 171 setupExtendedReportingCheckbox();
209 setupSSLDebuggingInfo(); 172 setupSSLDebuggingInfo();
210 document.addEventListener('keypress', handleKeypress); 173 document.addEventListener('keypress', handleKeypress);
211 } 174 }
212 175
213 document.addEventListener('DOMContentLoaded', setupEvents); 176 document.addEventListener('DOMContentLoaded', setupEvents);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698