summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/safe_browsing/malware_block_v2.js
blob: dba68fd20838fb3ea64ecfcd65bb1f6a0a478b3d (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2012 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.

/**
 * Sends a command message to SafeBrowsingBlockingPage::CommandReceived.
 * @param {string} cmd The command to send.
 */
function sendCommand(cmd) {
  window.domAutomationController.setAutomationId(1);
  window.domAutomationController.send(cmd);
}

/**
 * Records state of the reporting checkbox.
 */
function savePreference() {
  var checkBox = $('check-report');
  if (checkBox.checked)
    sendCommand('doReport');
  else
    sendCommand('dontReport');
}

/**
 * Expands or collapses the "see more" section of the page.
 */
function seeMore() {
  if ($('see-less-text').hidden) {
    $('see-more-text').hidden = true;
    $('see-less-text').hidden = false;
    $('see-more-contents').hidden = false;
    sendCommand('expandedSeeMore');
  } else {
    $('see-more-text').hidden = false;
    $('see-less-text').hidden = true;
    $('see-more-contents').hidden = true;
  }
}

/* This sets up 4 conditions for the Field Trial.
 * The 'NoBrand' conditions don't have the Chrome/Chromium logo at the top.
 * The 'OneStep' conditions don't hide the proceed button.
 */
function setupInterstitialExperiment() {
  var condition = templateData.trialType;
  if (condition == 'cond2MalwareNoBrand' ||
      condition == 'cond4PhishingNoBrand') {
    $('logo').style.display = 'none';
  } else if (condition == 'cond5MalwareOneStep' ||
             condition == 'cond6PhishingOneStep') {
    $('see-more-contents').hidden = false;
    $('see-less-text').hidden = true;
    $('see-more-text').hidden = true;
  }
}

/**
 * Onload listener to initialize javascript handlers.
 */
document.addEventListener('DOMContentLoaded', function() {
  $('proceed-span').hidden = templateData.proceedDisabled;

  $('back').onclick = function() {
    sendCommand('takeMeBack');
  };
  $('proceed').onclick = function(e) {
    sendCommand('proceed');
  };
  $('learn-more-link').onclick = function(e) {
    sendCommand('learnMore2');
  };
  $('show-diagnostic-link').onclick = function(e) {
    sendCommand('showDiagnostic');
  };
  $('report-error-link').onclick = function(e) {
    sendCommand('reportError');
  };
  $('see-more-link').onclick = function(e) {
    seeMore();
    // preventDefaultOnPoundLinkClicks doesn't work for this link since it
    // contains <span>s, which confuse preventDefaultOnPoundLinkClicks.
    e.preventDefault();
  };
  $('check-report').onclick = savePreference;

  // All the links are handled by javascript sending commands back to the C++
  // handler, we don't want the default actions.
  preventDefaultOnPoundLinkClicks();  // From webui/js/util.js.

  setupInterstitialExperiment();

  // Allow jsdisplay elements to be visible now.
  document.documentElement.classList.remove('loading');
});