tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

prefs.js (3937B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
      2 * This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /* import-globals-from common.js */
      7 
      8 var { AppConstants } = ChromeUtils.importESModule(
      9  "resource://gre/modules/AppConstants.sys.mjs"
     10 );
     11 
     12 const PREF_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
     13 
     14 window.addEventListener(
     15  "DOMContentLoaded",
     16  () => {
     17    initAboutInfo();
     18    initClearAllData();
     19    initSubmitHealthReport();
     20    initParentDependencies();
     21  },
     22  { once: true }
     23 );
     24 
     25 function initAboutInfo() {
     26  // Bug 1586294 - Update FxR Desktop Settings to use Fluent
     27  document.getElementById("eFxrVersion").textContent = "version 0.9";
     28  document.getElementById("eFxrDate").textContent = "(2019-12-17)";
     29  document.getElementById("eFxVersion").textContent =
     30    "Firefox version " + Services.appinfo.version;
     31 }
     32 
     33 function initClearAllData() {
     34  let eClearPrompt = document.getElementById("eClearPrompt");
     35 
     36  let eClearTry = document.getElementById("eClearTry");
     37  eClearTry.addEventListener("click", () => {
     38    showModalContainer(eClearPrompt);
     39  });
     40 
     41  // Note: the calls to clearModalContainer below return eClearPrompt
     42  // back to <body> to be reused later, because it is moved into anothe
     43  // element in showModalContainer.
     44 
     45  let eClearCancel = document.getElementById("eClearCancel");
     46  eClearCancel.addEventListener("click", () => {
     47    document.body.appendChild(clearModalContainer());
     48  });
     49 
     50  // When the confirm option is visible, do the work to actually clear the data
     51  document.getElementById("eClearConfirm").addEventListener("click", () => {
     52    Services.clearData.deleteData(
     53      Ci.nsIClearDataService.CLEAR_ALL,
     54      function (aFailedFlags) {
     55        if (aFailedFlags == 0) {
     56          eClearTry.textContent = "Data cleared";
     57          eClearTry.disabled = true;
     58          document.body.appendChild(clearModalContainer());
     59        } else {
     60          eClearTry.textContent = "Error";
     61        }
     62      }
     63    );
     64  });
     65 }
     66 
     67 // Based on https://searchfox.org/mozilla-central/source/browser/components/preferences/privacy.js
     68 function initSubmitHealthReport() {
     69  let checkbox = document.getElementById("eCrashConfig");
     70 
     71  // Telemetry is only sending data if MOZ_TELEMETRY_REPORTING is defined.
     72  // We still want to display the preferences panel if that's not the case, but
     73  // we want it to be disabled and unchecked.
     74  if (
     75    Services.prefs.prefIsLocked(PREF_UPLOAD_ENABLED) ||
     76    !AppConstants.MOZ_TELEMETRY_REPORTING
     77  ) {
     78    checkbox.disabled = true;
     79  } else {
     80    checkbox.addEventListener("change", updateSubmitHealthReport);
     81 
     82    checkbox.checked =
     83      Services.prefs.getBoolPref(PREF_UPLOAD_ENABLED) &&
     84      AppConstants.MOZ_TELEMETRY_REPORTING;
     85  }
     86 }
     87 
     88 /**
     89 * Update the health report preference with state from checkbox.
     90 */
     91 function updateSubmitHealthReport() {
     92  let checkbox = document.getElementById("eCrashConfig");
     93  Services.prefs.setBoolPref(PREF_UPLOAD_ENABLED, checkbox.checked);
     94 }
     95 
     96 // prefs.html can be loaded as another <browser> from fxrui.html. In this
     97 // scenario, some actions are propogated to the parent
     98 function initParentDependencies() {
     99  if (window.parent != window) {
    100    // Close the <browser> instance that loaded this page
    101    document.getElementById("eCloseSettings").addEventListener("click", () => {
    102      window.parent.closeSettings();
    103    });
    104 
    105    // Load the relevant URLs into the top UI's <browser>
    106    document.getElementById("ePrivacyPolicy").addEventListener("click", () => {
    107      window.parent.showPrivacyPolicy();
    108    });
    109 
    110    document.getElementById("eLicenseInfo").addEventListener("click", () => {
    111      window.parent.showLicenseInfo();
    112    });
    113 
    114    document.getElementById("eReportIssue").addEventListener("click", () => {
    115      window.parent.showReportIssue();
    116    });
    117  }
    118 }