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

Side by Side Diff: chrome/browser/resources/security_warnings/interstitial_v2.js

Issue 600153004: Refactor SafeBrowsing and SSL interstitials to have a type variable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/resources/security_warnings/safe_browsing.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 11 /**
12 * A convenience method for sending commands to the parent page. 12 * A convenience method for sending commands to the parent page.
13 * @param {string} cmd The command to send. 13 * @param {string} cmd The command to send.
14 */ 14 */
15 function sendCommand(cmd) { 15 function sendCommand(cmd) {
16 window.domAutomationController.setAutomationId(1); 16 window.domAutomationController.setAutomationId(1);
17 window.domAutomationController.send(cmd); 17 window.domAutomationController.send(cmd);
18 } 18 }
19 19
20 /** 20 /**
21 * This allows errors to be skippped by typing "danger" into the page. 21 * This allows errors to be skippped by typing "danger" into the page.
22 * @param {string} e The key that was just pressed. 22 * @param {string} e The key that was just pressed.
23 */ 23 */
24 function handleKeypress(e) { 24 function handleKeypress(e) {
25 var BYPASS_SEQUENCE = 'danger'; 25 var BYPASS_SEQUENCE = 'danger';
26 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) { 26 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) {
27 keyPressState++; 27 keyPressState++;
28 if (keyPressState == BYPASS_SEQUENCE.length) { 28 if (keyPressState == BYPASS_SEQUENCE.length) {
29 sendCommand(CMD_PROCEED); 29 sendCommand(SSL_CMD_PROCEED);
30 keyPressState = 0; 30 keyPressState = 0;
31 } 31 }
32 } else { 32 } else {
33 keyPressState = 0; 33 keyPressState = 0;
34 } 34 }
35 } 35 }
36 36
37 /** 37 /**
38 * This appends a piece of debugging information to the end of the warning. 38 * This appends a piece of debugging information to the end of the warning.
39 * When complete, the caller must also make the debugging div 39 * When complete, the caller must also make the debugging div
(...skipping 18 matching lines...) Expand all
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.getBoolean('ssl'); 68 var ssl = loadTimeData.getString('type') === 'SSL';
69 69
70 if (ssl) { 70 if (ssl) {
71 $('body').classList.add('ssl'); 71 $('body').classList.add('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');
74 } else { 74 } else {
75 $('body').classList.add('safe-browsing'); 75 $('body').classList.add('safe-browsing');
76 } 76 }
77 77
78 $('primary-button').addEventListener('click', function() { 78 $('primary-button').addEventListener('click', function() {
79 if (!ssl) 79 if (!ssl)
80 sendCommand(SB_CMD_TAKE_ME_BACK); 80 sendCommand(SB_CMD_TAKE_ME_BACK);
81 else if (overridable) 81 else if (overridable)
82 sendCommand(CMD_DONT_PROCEED); 82 sendCommand(SSL_CMD_DONT_PROCEED);
83 else 83 else
84 sendCommand(CMD_RELOAD); 84 sendCommand(SSL_CMD_RELOAD);
85 }); 85 });
86 86
87 if (overridable) { 87 if (overridable) {
88 $('proceed-link').addEventListener('click', function(event) { 88 $('proceed-link').addEventListener('click', function(event) {
89 sendCommand(ssl ? CMD_PROCEED : SB_CMD_PROCEED); 89 sendCommand(ssl ? SSL_CMD_PROCEED : SB_CMD_PROCEED);
90 }); 90 });
91 } else if (!ssl) { 91 } else if (!ssl) {
92 $('final-paragraph').classList.add('hidden'); 92 $('final-paragraph').classList.add('hidden');
93 } 93 }
94 94
95 if (ssl && overridable) { 95 if (ssl && overridable) {
96 $('proceed-link').classList.add('small-link'); 96 $('proceed-link').classList.add('small-link');
97 } else if ($('help-link')) { 97 } else if ($('help-link')) {
98 // Overridable SSL page doesn't have this link. 98 // Overridable SSL page doesn't have this link.
99 $('help-link').addEventListener('click', function(event) { 99 $('help-link').addEventListener('click', function(event) {
100 if (ssl) 100 if (ssl)
101 sendCommand(CMD_HELP); 101 sendCommand(SSL_CMD_HELP);
102 else if (loadTimeData.getBoolean('phishing')) 102 else if (loadTimeData.getBoolean('phishing'))
103 sendCommand(SB_CMD_LEARN_MORE_2); 103 sendCommand(SB_CMD_LEARN_MORE_2);
104 else 104 else
105 sendCommand(SB_CMD_SHOW_DIAGNOSTIC); 105 sendCommand(SB_CMD_SHOW_DIAGNOSTIC);
106 }); 106 });
107 } 107 }
108 108
109 if (ssl && $('clock-link')) { 109 if (ssl && $('clock-link')) {
110 $('clock-link').addEventListener('click', function(event) { 110 $('clock-link').addEventListener('click', function(event) {
111 sendCommand(CMD_CLOCK); 111 sendCommand(SSL_CMD_CLOCK);
112 }); 112 });
113 } 113 }
114 114
115 $('details-button').addEventListener('click', function(event) { 115 $('details-button').addEventListener('click', function(event) {
116 var hiddenDetails = $('details').classList.toggle('hidden'); 116 var hiddenDetails = $('details').classList.toggle('hidden');
117 $('details-button').innerText = hiddenDetails ? 117 $('details-button').innerText = hiddenDetails ?
118 loadTimeData.getString('openDetails') : 118 loadTimeData.getString('openDetails') :
119 loadTimeData.getString('closeDetails'); 119 loadTimeData.getString('closeDetails');
120 if (!expandedDetails) { 120 if (!expandedDetails) {
121 // Record a histogram entry only the first time that details is opened. 121 // Record a histogram entry only the first time that details is opened.
122 sendCommand(ssl ? CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); 122 sendCommand(ssl ? SSL_CMD_MORE : SB_CMD_EXPANDED_SEE_MORE);
123 expandedDetails = true; 123 expandedDetails = true;
124 } 124 }
125 }); 125 });
126 126
127 preventDefaultOnPoundLinkClicks(); 127 preventDefaultOnPoundLinkClicks();
128 setupCheckbox(); 128 setupCheckbox();
129 setupSSLDebuggingInfo(); 129 setupSSLDebuggingInfo();
130 document.addEventListener('keypress', handleKeypress); 130 document.addEventListener('keypress', handleKeypress);
131 } 131 }
132 132
133 document.addEventListener('DOMContentLoaded', setupEvents); 133 document.addEventListener('DOMContentLoaded', setupEvents);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/security_warnings/safe_browsing.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698