summaryrefslogtreecommitdiffstats
path: root/browser/fxr/content/prefs.js
blob: 384e882dd26044958f038f254760968c3ac6c05c (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* import-globals-from common.js */

var { AppConstants } = ChromeUtils.importESModule(
  "resource://gre/modules/AppConstants.sys.mjs"
);

const PREF_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";

window.addEventListener(
  "DOMContentLoaded",
  () => {
    initAboutInfo();
    initClearAllData();
    initSubmitHealthReport();
    initParentDependencies();
  },
  { once: true }
);

function initAboutInfo() {
  // Bug 1586294 - Update FxR Desktop Settings to use Fluent
  document.getElementById("eFxrVersion").textContent = "version 0.9";
  document.getElementById("eFxrDate").textContent = "(2019-12-17)";
  document.getElementById("eFxVersion").textContent =
    "Firefox version " + Services.appinfo.version;
}

function initClearAllData() {
  let eClearPrompt = document.getElementById("eClearPrompt");

  let eClearTry = document.getElementById("eClearTry");
  eClearTry.addEventListener("click", () => {
    showModalContainer(eClearPrompt);
  });

  // Note: the calls to clearModalContainer below return eClearPrompt
  // back to <body> to be reused later, because it is moved into anothe
  // element in showModalContainer.

  let eClearCancel = document.getElementById("eClearCancel");
  eClearCancel.addEventListener("click", () => {
    document.body.appendChild(clearModalContainer());
  });

  // When the confirm option is visible, do the work to actually clear the data
  document.getElementById("eClearConfirm").addEventListener("click", () => {
    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, function(
      aFailedFlags
    ) {
      if (aFailedFlags == 0) {
        eClearTry.textContent = "Data cleared";
        eClearTry.disabled = true;
        document.body.appendChild(clearModalContainer());
      } else {
        eClearTry.textContent = "Error";
      }
    });
  });
}

// Based on https://searchfox.org/mozilla-central/source/browser/components/preferences/privacy.js
function initSubmitHealthReport() {
  let checkbox = document.getElementById("eCrashConfig");

  // Telemetry is only sending data if MOZ_TELEMETRY_REPORTING is defined.
  // We still want to display the preferences panel if that's not the case, but
  // we want it to be disabled and unchecked.
  if (
    Services.prefs.prefIsLocked(PREF_UPLOAD_ENABLED) ||
    !AppConstants.MOZ_TELEMETRY_REPORTING
  ) {
    checkbox.disabled = true;
  } else {
    checkbox.addEventListener("change", updateSubmitHealthReport);

    checkbox.checked =
      Services.prefs.getBoolPref(PREF_UPLOAD_ENABLED) &&
      AppConstants.MOZ_TELEMETRY_REPORTING;
  }
}

/**
 * Update the health report preference with state from checkbox.
 */
function updateSubmitHealthReport() {
  let checkbox = document.getElementById("eCrashConfig");
  Services.prefs.setBoolPref(PREF_UPLOAD_ENABLED, checkbox.checked);
}

// prefs.html can be loaded as another <browser> from fxrui.html. In this
// scenario, some actions are propogated to the parent
function initParentDependencies() {
  if (window.parent != window) {
    // Close the <browser> instance that loaded this page
    document.getElementById("eCloseSettings").addEventListener("click", () => {
      window.parent.closeSettings();
    });

    // Load the relevant URLs into the top UI's <browser>
    document.getElementById("ePrivacyPolicy").addEventListener("click", () => {
      window.parent.showPrivacyPolicy();
    });

    document.getElementById("eLicenseInfo").addEventListener("click", () => {
      window.parent.showLicenseInfo();
    });

    document.getElementById("eReportIssue").addEventListener("click", () => {
      window.parent.showReportIssue();
    });
  }
}