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.
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.
8 var expandedDetails = false;
12 * A convenience method for sending commands to the parent page.
13 * @param {string} cmd The command to send.
15 function sendCommand(cmd) {
16 window.domAutomationController.setAutomationId(1);
17 window.domAutomationController.send(cmd);
21 * This allows errors to be skippped by typing "danger" into the page.
22 * @param {string} e The key that was just pressed.
24 function handleKeypress(e) {
25 var BYPASS_SEQUENCE = 'danger';
26 if (BYPASS_SEQUENCE.charCodeAt(keyPressState) == e.keyCode) {
28 if (keyPressState == BYPASS_SEQUENCE.length) {
29 sendCommand(CMD_PROCEED);
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
40 * (error-debugging-info) visible.
41 * @param {string} title The name of this debugging field.
42 * @param {string} value The value of the debugging field.
44 function appendDebuggingField(title, value) {
45 // The values input here are not trusted. Never use innerHTML on these
47 var spanTitle = document.createElement('span');
48 spanTitle.classList.add('debugging-title');
49 spanTitle.innerText = title + ': ';
51 var spanValue = document.createElement('span');
52 spanValue.classList.add('debugging-value');
53 spanValue.innerText = value;
55 var pElem = document.createElement('p');
56 pElem.classList.add('debugging-content');
57 pElem.appendChild(spanTitle);
58 pElem.appendChild(spanValue);
59 $('error-debugging-info').appendChild(pElem);
62 function toggleDebuggingInfo() {
63 $('error-debugging-info').classList.toggle('hidden');
66 function setupEvents() {
67 var overridable = loadTimeData.getBoolean('overridable');
68 var ssl = loadTimeData.getBoolean('ssl');
71 $('body').classList.add('ssl');
72 $('error-code').textContent = loadTimeData.getString('errorCode');
73 $('error-code').classList.remove('hidden');
75 $('body').classList.add('safe-browsing');
78 $('primary-button').addEventListener('click', function() {
80 sendCommand(SB_CMD_TAKE_ME_BACK);
82 sendCommand(CMD_DONT_PROCEED);
84 sendCommand(CMD_RELOAD);
88 $('proceed-link').addEventListener('click', function(event) {
89 sendCommand(ssl ? CMD_PROCEED : SB_CMD_PROCEED);
92 $('final-paragraph').classList.add('hidden');
95 if (ssl && overridable) {
96 $('proceed-link').classList.add('small-link');
97 } else if ($('help-link')) {
98 // Overridable SSL page doesn't have this link.
99 $('help-link').addEventListener('click', function(event) {
101 sendCommand(CMD_HELP);
102 else if (loadTimeData.getBoolean('phishing'))
103 sendCommand(SB_CMD_LEARN_MORE_2);
105 sendCommand(SB_CMD_SHOW_DIAGNOSTIC);
109 if (ssl && $('clock-link')) {
110 $('clock-link').addEventListener('click', function(event) {
111 sendCommand(CMD_CLOCK);
115 $('details-button').addEventListener('click', function(event) {
116 var hiddenDetails = $('details').classList.toggle('hidden');
117 $('details-button').innerText = hiddenDetails ?
118 loadTimeData.getString('openDetails') :
119 loadTimeData.getString('closeDetails');
120 if (!expandedDetails) {
121 // Record a histogram entry only the first time that details is opened.
122 sendCommand(ssl ? CMD_MORE : SB_CMD_EXPANDED_SEE_MORE);
123 expandedDetails = true;
127 preventDefaultOnPoundLinkClicks();
129 setupSSLDebuggingInfo();
130 document.addEventListener('keypress', handleKeypress);
133 document.addEventListener('DOMContentLoaded', setupEvents);