From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- browser/fxr/content/prefs.js | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 browser/fxr/content/prefs.js (limited to 'browser/fxr/content/prefs.js') diff --git a/browser/fxr/content/prefs.js b/browser/fxr/content/prefs.js new file mode 100644 index 0000000000..a5a8c954d9 --- /dev/null +++ b/browser/fxr/content/prefs.js @@ -0,0 +1,118 @@ +/* -*- 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 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 from fxrui.html. In this +// scenario, some actions are propogated to the parent +function initParentDependencies() { + if (window.parent != window) { + // Close the instance that loaded this page + document.getElementById("eCloseSettings").addEventListener("click", () => { + window.parent.closeSettings(); + }); + + // Load the relevant URLs into the top UI's + document.getElementById("ePrivacyPolicy").addEventListener("click", () => { + window.parent.showPrivacyPolicy(); + }); + + document.getElementById("eLicenseInfo").addEventListener("click", () => { + window.parent.showLicenseInfo(); + }); + + document.getElementById("eReportIssue").addEventListener("click", () => { + window.parent.showReportIssue(); + }); + } +} -- cgit v1.2.3