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

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

Issue 2894413003: Rename interstitial_v2 files (Closed)
Patch Set: Fix rebase error Created 3 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
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.
7
8 var expandedDetails = false;
9 var keyPressState = 0;
10
11 /**
12 * This allows errors to be skippped by typing a secret phrase into the page.
13 * @param {string} e The key that was just pressed.
14 */
15 function handleKeypress(e) {
16 var BYPASS_SEQUENCE = 'badidea';
17 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) {
18 keyPressState++;
19 if (keyPressState == BYPASS_SEQUENCE.length) {
20 sendCommand(SecurityInterstitialCommandId.CMD_PROCEED);
21 keyPressState = 0;
22 }
23 } else {
24 keyPressState = 0;
25 }
26 }
27
28 /**
29 * This appends a piece of debugging information to the end of the warning.
30 * When complete, the caller must also make the debugging div
31 * (error-debugging-info) visible.
32 * @param {string} title The name of this debugging field.
33 * @param {string} value The value of the debugging field.
34 * @param {boolean=} fixedWidth If true, the value field is displayed fixed
35 * width.
36 */
37 function appendDebuggingField(title, value, fixedWidth) {
38 // The values input here are not trusted. Never use innerHTML on these
39 // values!
40 var spanTitle = document.createElement('span');
41 spanTitle.classList.add('debugging-title');
42 spanTitle.innerText = title + ': ';
43
44 var spanValue = document.createElement('span');
45 spanValue.classList.add('debugging-content');
46 if (fixedWidth) {
47 spanValue.classList.add('debugging-content-fixed-width');
48 }
49 spanValue.innerText = value;
50
51 var pElem = document.createElement('p');
52 pElem.classList.add('debugging-content');
53 pElem.appendChild(spanTitle);
54 pElem.appendChild(spanValue);
55 $('error-debugging-info').appendChild(pElem);
56 }
57
58 function toggleDebuggingInfo() {
59 $('error-debugging-info').classList.toggle('hidden');
60 }
61
62 function setupEvents() {
63 var overridable = loadTimeData.getBoolean('overridable');
64 var interstitialType = loadTimeData.getString('type');
65 var ssl = interstitialType == 'SSL';
66 var captivePortal = interstitialType == 'CAPTIVE_PORTAL';
67 var badClock = ssl && loadTimeData.getBoolean('bad_clock');
68 var hidePrimaryButton = loadTimeData.getBoolean('hide_primary_button');
69
70 if (ssl) {
71 $('body').classList.add(badClock ? 'bad-clock' : 'ssl');
72 $('error-code').textContent = loadTimeData.getString('errorCode');
73 $('error-code').classList.remove('hidden');
74 } else if (captivePortal) {
75 $('body').classList.add('captive-portal');
76 } else {
77 $('body').classList.add('safe-browsing');
78 }
79
80 $('icon').classList.add('icon');
81
82 if (hidePrimaryButton) {
83 $('primary-button').classList.add('hidden');
84 } else {
85 $('primary-button').addEventListener('click', function() {
86 switch (interstitialType) {
87 case 'CAPTIVE_PORTAL':
88 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_LOGIN);
89 break;
90
91 case 'SSL':
92 if (badClock)
93 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_DATE_SETTINGS);
94 else if (overridable)
95 sendCommand(SecurityInterstitialCommandId.CMD_DONT_PROCEED);
96 else
97 sendCommand(SecurityInterstitialCommandId.CMD_RELOAD);
98 break;
99
100 case 'SAFEBROWSING':
101 sendCommand(SecurityInterstitialCommandId.CMD_DONT_PROCEED);
102 break;
103
104 default:
105 throw 'Invalid interstitial type';
106 }
107 });
108 }
109
110 if (overridable) {
111 // Captive portal page isn't overridable.
112 $('proceed-link').addEventListener('click', function(event) {
113 sendCommand(SecurityInterstitialCommandId.CMD_PROCEED);
114 });
115 } else if (!ssl) {
116 $('final-paragraph').classList.add('hidden');
117 }
118
119 if (ssl && overridable) {
120 $('proceed-link').classList.add('small-link');
121 }
122
123 if ($('diagnostic-link')) {
124 $('diagnostic-link').addEventListener('click', function(event) {
125 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_DIAGNOSTIC);
126 });
127 }
128
129 if ($('learn-more-link')) {
130 $('learn-more-link').addEventListener('click', function(event) {
131 sendCommand(SecurityInterstitialCommandId.CMD_OPEN_HELP_CENTER);
132 });
133 }
134
135 if (captivePortal) {
136 // Captive portal page doesn't have details button.
137 $('details-button').classList.add('hidden');
138 } else {
139 $('details-button').addEventListener('click', function(event) {
140 var hiddenDetails = $('details').classList.toggle('hidden');
141
142 if (mobileNav) {
143 // Details appear over the main content on small screens.
144 $('main-content').classList.toggle('hidden', !hiddenDetails);
145 } else {
146 $('main-content').classList.remove('hidden');
147 }
148
149 $('details-button').innerText = hiddenDetails ?
150 loadTimeData.getString('openDetails') :
151 loadTimeData.getString('closeDetails');
152 if (!expandedDetails) {
153 // Record a histogram entry only the first time that details is opened.
154 sendCommand(SecurityInterstitialCommandId.CMD_SHOW_MORE_SECTION);
155 expandedDetails = true;
156 }
157 });
158 }
159
160 if ($('report-error-link')) {
161 $('report-error-link').addEventListener('click', function(event) {
162 sendCommand(SecurityInterstitialCommandId.CMD_REPORT_PHISHING_ERROR);
163 });
164 }
165
166 document.addEventListener('click', function(e) {
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();
176 setupSSLDebuggingInfo();
177 document.addEventListener('keypress', handleKeypress);
178 }
179
180 document.addEventListener('DOMContentLoaded', setupEvents);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698