Bug 1439082 - ensure shield checkbox is disabled when about:preferences loads while FHR/Telemetry is preffed off, r?mythmon
MozReview-Commit-ID: 7mhuD7BS7xz
--- a/browser/extensions/shield-recipe-client/lib/ShieldPreferences.jsm
+++ b/browser/extensions/shield-recipe-client/lib/ShieldPreferences.jsm
@@ -113,37 +113,45 @@ this.ShieldPreferences = {
let allowedByPolicy = Services.policies.isAllowed("Shield");
if (allowedByPolicy) {
// If Shield is not allowed by policy, don't tie this checkbox to the preference,
// so that the checkbox remains unchecked.
// Otherwise, it would be grayed out but still checked, which looks confusing
// because it appears it's enabled with no way to disable it.
checkbox.setAttribute("preference", OPT_OUT_STUDIES_ENABLED_PREF);
}
- checkbox.setAttribute("disabled", Services.prefs.prefIsLocked(FHR_UPLOAD_ENABLED_PREF) ||
- !AppConstants.MOZ_TELEMETRY_REPORTING ||
- !allowedByPolicy);
hContainer.appendChild(checkbox);
const viewStudies = doc.createElementNS(XUL_NS, "label");
viewStudies.setAttribute("id", "viewShieldStudies");
viewStudies.setAttribute("href", "about:studies");
viewStudies.setAttribute("useoriginprincipal", true);
viewStudies.textContent = "View Firefox Studies";
viewStudies.classList.add("learnMore", "text-link");
hContainer.appendChild(viewStudies);
// Preference instances for prefs that we need to monitor while the page is open.
doc.defaultView.Preferences.add({ id: OPT_OUT_STUDIES_ENABLED_PREF, type: "bool" });
// Weirdly, FHR doesn't have a Preference instance on the page, so we create it.
const fhrPref = doc.defaultView.Preferences.add({ id: FHR_UPLOAD_ENABLED_PREF, type: "bool" });
- function onChangeFHRPref(event) {
- checkbox.disabled = !Services.prefs.getBoolPref(FHR_UPLOAD_ENABLED_PREF) || !allowedByPolicy;
+ function onChangeFHRPref() {
+ let isDisabled = Services.prefs.prefIsLocked(FHR_UPLOAD_ENABLED_PREF) ||
+ !AppConstants.MOZ_TELEMETRY_REPORTING ||
+ !Services.prefs.getBoolPref(FHR_UPLOAD_ENABLED_PREF) ||
+ !allowedByPolicy;
+ // We can't use checkbox.disabled here because the XBL binding may not be present,
+ // in which case setting the property won't work properly.
+ if (isDisabled) {
+ checkbox.setAttribute("disabled", "true");
+ } else {
+ checkbox.removeAttribute("disabled");
+ }
}
fhrPref.on("change", onChangeFHRPref);
+ onChangeFHRPref();
doc.defaultView.addEventListener("unload", () => fhrPref.off("change", onChangeFHRPref), { once: true });
// Actually inject the elements we've created.
const parent = doc.getElementById("submitHealthReportBox").closest("description");
parent.appendChild(container);
},
};