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 8var expandedDetails = false; 9 10function setupEvents() { 11 var overridable = loadTimeData.getBoolean('overridable'); 12 var ssl = loadTimeData.getBoolean('ssl'); 13 14 if (ssl) { 15 $('body').classList.add('ssl'); 16 } else { 17 $('body').classList.add('safe-browsing'); 18 setupMalwareFinchExperiment(); 19 } 20 21 $('primary-button').addEventListener('click', function() { 22 if (!ssl) 23 sendCommand(SB_CMD_TAKE_ME_BACK); 24 else if (overridable) 25 sendCommand(CMD_DONT_PROCEED); 26 else 27 sendCommand(CMD_RELOAD); 28 }); 29 30 if (overridable) { 31 $('proceed-link').addEventListener('click', function(event) { 32 sendCommand(ssl ? CMD_PROCEED : SB_CMD_PROCEED); 33 }); 34 } else if (!ssl) { 35 $('final-paragraph').classList.add('hidden'); 36 } 37 38 if (ssl && overridable) { 39 $('proceed-link').classList.add('small-link'); 40 } else { 41 // Overridable SSL page doesn't have this link. 42 $('help-link').addEventListener('click', function(event) { 43 if (ssl) 44 sendCommand(CMD_HELP); 45 else if (loadTimeData.getBoolean('phishing')) 46 sendCommand(SB_CMD_LEARN_MORE_2); 47 else 48 sendCommand(SB_CMD_SHOW_DIAGNOSTIC); 49 }); 50 } 51 52 if (ssl && !overridable) { 53 $('error-code').textContent = loadTimeData.getString('errorCode'); 54 $('error-code').classList.remove('hidden'); 55 } 56 57 $('details-button').addEventListener('click', function(event) { 58 var hiddenDetails = $('details').classList.toggle('hidden'); 59 $('details-button').innerText = hiddenDetails ? 60 loadTimeData.getString('openDetails') : 61 loadTimeData.getString('closeDetails'); 62 if (!expandedDetails) { 63 // Record a histogram entry only the first time that details is opened. 64 sendCommand(ssl ? CMD_MORE : SB_CMD_EXPANDED_SEE_MORE); 65 expandedDetails = true; 66 } 67 }); 68 69 preventDefaultOnPoundLinkClicks(); 70 setupCheckbox(); 71} 72 73document.addEventListener('DOMContentLoaded', setupEvents); 74