Bug 1439082 - ensure shield checkbox is disabled when about:preferences loads while FHR/Telemetry is preffed off, r=myk,mythmon,a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Sat, 17 Feb 2018 12:29:54 +0000
changeset 455071 4c21d43deece7f619ac673ffbc624c64437f43f1
parent 455070 a330f1d4d12a7c144797f3686f35a99c37b0755e
child 455072 5a21c2f52c784f7890a5f35f7854753a02e360c4
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmyk, mythmon, lizzard
bugs1439082
milestone59.0
Bug 1439082 - ensure shield checkbox is disabled when about:preferences loads while FHR/Telemetry is preffed off, r=myk,mythmon,a=lizzard MozReview-Commit-ID: 7mhuD7BS7xz
browser/extensions/shield-recipe-client/lib/ShieldPreferences.jsm
--- a/browser/extensions/shield-recipe-client/lib/ShieldPreferences.jsm
+++ b/browser/extensions/shield-recipe-client/lib/ShieldPreferences.jsm
@@ -104,36 +104,44 @@ this.ShieldPreferences = {
     hContainer.setAttribute("align", "center");
     container.appendChild(hContainer);
 
     const checkbox = doc.createElementNS(XUL_NS, "checkbox");
     checkbox.setAttribute("id", "optOutStudiesEnabled");
     checkbox.setAttribute("class", "tail-with-learn-more");
     checkbox.setAttribute("label", "Allow Firefox to install and run studies");
     checkbox.setAttribute("preference", OPT_OUT_STUDIES_ENABLED_PREF);
-    checkbox.setAttribute("disabled", Services.prefs.prefIsLocked(FHR_UPLOAD_ENABLED_PREF) ||
-      !AppConstants.MOZ_TELEMETRY_REPORTING);
     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);
+    function onChangeFHRPref() {
+      let isDisabled = Services.prefs.prefIsLocked(FHR_UPLOAD_ENABLED_PREF) ||
+                       !AppConstants.MOZ_TELEMETRY_REPORTING ||
+                       !Services.prefs.getBoolPref(FHR_UPLOAD_ENABLED_PREF);
+      // 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);
   },
 };