Bug 1488361 - Only initiate the updating of site data control buttons after we have moved the buttons in the UI; r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 05 Sep 2018 13:00:02 -0400
changeset 434954 a0e69b970c12659b9ae787db8018ceedded2af68
parent 434953 5cec15b748f6c51dba2dbb99880dddb508be48a8
child 434955 d3abd725b443c80f0d1316db156c446103b658f9
push id34583
push usertoros@mozilla.com
push dateWed, 05 Sep 2018 22:25:44 +0000
treeherdermozilla-central@c4c125ee2556 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1488361
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1488361 - Only initiate the updating of site data control buttons after we have moved the buttons in the UI; r=johannh Differential Revision: https://phabricator.services.mozilla.com/D5057
browser/components/preferences/in-content/privacy.js
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -395,25 +395,20 @@ var gPrivacyPane = {
       document.l10n.setAttributes(checkbox, "permissions-notification-pause");
       if (AlertsServiceDND.manualDoNotDisturb) {
         let notificationsDoNotDisturb =
           document.getElementById("notificationsDoNotDisturb");
         notificationsDoNotDisturb.setAttribute("checked", true);
       }
     }
 
-    Services.obs.addObserver(this, "sitedatamanager:sites-updated");
-    Services.obs.addObserver(this, "sitedatamanager:updating-sites");
-    let unload = () => {
-      window.removeEventListener("unload", unload);
-      Services.obs.removeObserver(this, "sitedatamanager:sites-updated");
-      Services.obs.removeObserver(this, "sitedatamanager:updating-sites");
-    };
-    window.addEventListener("unload", unload);
-    SiteDataManager.updateSites();
+    if (!contentBlockingUiEnabled) {
+      // If content blocking UI is enabled, this has been handled by initContentBlocking.
+      this.initSiteDataControls();
+    }
     setEventListener("clearSiteDataButton", "command",
       gPrivacyPane.clearSiteData);
     setEventListener("siteDataSettings", "command",
       gPrivacyPane.showSiteDataSettings);
     let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "storage-permissions";
     document.getElementById("siteDataLearnMoreLink").setAttribute("href", url);
 
     let notificationInfoURL =
@@ -461,16 +456,28 @@ var gPrivacyPane = {
       document.getElementById("privateBrowsingAutoStart").hidden = true;
       document.querySelector("menuitem[value='dontremember']").hidden = true;
     }
 
     // Notify observers that the UI is now ready
     Services.obs.notifyObservers(window, "privacy-pane-loaded");
   },
 
+  initSiteDataControls() {
+    Services.obs.addObserver(this, "sitedatamanager:sites-updated");
+    Services.obs.addObserver(this, "sitedatamanager:updating-sites");
+    let unload = () => {
+      window.removeEventListener("unload", unload);
+      Services.obs.removeObserver(this, "sitedatamanager:sites-updated");
+      Services.obs.removeObserver(this, "sitedatamanager:updating-sites");
+    };
+    window.addEventListener("unload", unload);
+    SiteDataManager.updateSites();
+  },
+
   // CONTENT BLOCKING
 
   /**
    * Initializes the content blocking section.
    */
   initContentBlocking() {
     let contentBlockingCheckbox = document.getElementById("contentBlockingCheckbox");
     setEventListener("contentBlockingToggle", "command",
@@ -533,16 +540,22 @@ var gPrivacyPane = {
     // If we do this without a timeout, trackingProtectionReadPrefs will set the checked
     // attribute on our checkbox element before the XBL binding has had a chance to have
     // been re-applied to it.
     setTimeout(() => {
       browserPrivacyCategory.parentNode.insertBefore(siteDataGroup,
                                                      browserPrivacyCategory.nextSibling);
       browserPrivacyCategory.parentNode.insertBefore(trackingGroup,
                                                      browserPrivacyCategory.nextSibling);
+
+      // We do this after having moved the elements in the DOM above, in order to avoid
+      // a race condition with this timeout handler reapplying the XBL bindings to the
+      // elements in this subtree and the observe() method attempting to set the disabled
+      // attribute on the site data controls.
+      this.initSiteDataControls();
     }, 0);
   },
 
   /**
    * Resets all user-exposed content blocking preferences to their default values.
    */
   async restoreContentBlockingPrefs() {
     function clearIfNotLocked(pref) {