summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/ssl/interstitial_v2.js
blob: 31ea103fe684ac62fdbeb9fa68472b415232b061 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is the shared code for the new (Chrome 37) security interstitials. It is
// used for both SSL interstitials and Safe Browsing interstitials.

var expandedDetails = false;

function setupEvents() {
  var overridable = loadTimeData.getBoolean('overridable');
  var ssl = loadTimeData.getBoolean('ssl');

  if (ssl) {
    $('body').classList.add('ssl');
    setupSSLFinchTrial();  /* From ssl_errors_common.js. */
    $('error-code').textContent = loadTimeData.getString('errorCode');
    $('error-code').classList.remove('hidden');
  } else {
    $('body').classList.add('safe-browsing');
    setupMalwareFinchExperiment();  /* From safe_browsing_v3.js. */
  }

  $('primary-button').addEventListener('click', function() {
    if (!ssl)
      sendCommand(SB_CMD_TAKE_ME_BACK);
    else if (overridable)
      sendCommand(CMD_DONT_PROCEED);
    else
      sendCommand(CMD_RELOAD);
  });

  if (overridable) {
    $('proceed-link').addEventListener('click', function(event) {
      sendCommand(ssl ? CMD_PROCEED : SB_CMD_PROCEED);
    });
  } else if (!ssl) {
    $('final-paragraph').classList.add('hidden');
  }

  if (ssl && overridable) {
    $('proceed-link').classList.add('small-link');
  } else if ($('help-link')) {
    // Overridable SSL page doesn't have this link.
    $('help-link').addEventListener('click', function(event) {
      if (ssl)
        sendCommand(CMD_HELP);
      else if (loadTimeData.getBoolean('phishing'))
        sendCommand(SB_CMD_LEARN_MORE_2);
      else
        sendCommand(SB_CMD_SHOW_DIAGNOSTIC);
    });
  }

  if (ssl && $('clock-link')) {
    $('clock-link').addEventListener('click', function(event) {
      sendCommand(CMD_CLOCK);
    });
  }

  $('details-button').addEventListener('click', function(event) {
    var hiddenDetails = $('details').classList.toggle('hidden');
    $('details-button').innerText = hiddenDetails ?
        loadTimeData.getString('openDetails') :
        loadTimeData.getString('closeDetails');
    if (!expandedDetails) {
      // Record a histogram entry only the first time that details is opened.
      sendCommand(ssl ? CMD_MORE : SB_CMD_EXPANDED_SEE_MORE);
      expandedDetails = true;
    }
  });

  preventDefaultOnPoundLinkClicks();
  setupCheckbox();
}

document.addEventListener('DOMContentLoaded', setupEvents);