Bug 1545736: about:profiles buttons should be initialised when the UI loads, not everytime the UI is refreshed. r=jaws a=pascalc
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 19 Apr 2019 06:43:49 -0700
changeset 523299 3ca335918c716fff83dc6cc079f719f73dfa8651
parent 523298 a64500e3a18b4355db601dcdeda5b348e31bb523
child 523300 b73974383bce7dd7bddb7f59a371ff766a1f4369
push id11138
push userarchaeopteryx@coole-files.de
push dateTue, 23 Apr 2019 19:02:09 +0000
treeherdermozilla-beta@c53e3fd76964 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, pascalc
bugs1545736
milestone67.0
Bug 1545736: about:profiles buttons should be initialised when the UI loads, not everytime the UI is refreshed. r=jaws a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D28194
toolkit/content/aboutProfiles.js
--- a/toolkit/content/aboutProfiles.js
+++ b/toolkit/content/aboutProfiles.js
@@ -12,17 +12,17 @@ XPCOMUtils.defineLazyServiceGetter(
   "ProfileService",
   "@mozilla.org/toolkit/profile-service;1",
   "nsIToolkitProfileService"
 );
 
 async function flush() {
   try {
     ProfileService.flush();
-    refreshUI();
+    rebuildProfileList();
   } catch (e) {
     let [title, msg, button] = await document.l10n.formatValues([
       { id: "profiles-flush-fail-title" },
       { id: e.result == Cr.NS_ERROR_DATABASE_CHANGED ?
                         "profiles-flush-conflict" :
                         "profiles-flush-failed" },
       { id: "profiles-flush-restart-button" },
     ]);
@@ -33,17 +33,17 @@ async function flush() {
                                           (PS.BUTTON_POS_1 * PS.BUTTON_TITLE_IS_STRING),
                                           null, button, null, null, {});
     if (result == 1) {
       restart(false);
     }
   }
 }
 
-function refreshUI() {
+function rebuildProfileList() {
   let parent = document.getElementById("profiles");
   while (parent.firstChild) {
     parent.firstChild.remove();
   }
 
   let defaultProfile;
   try {
     defaultProfile = ProfileService.defaultProfile;
@@ -67,29 +67,16 @@ function refreshUI() {
     }
     display({
       profile,
       isDefault: profile == defaultProfile,
       isCurrentProfile,
       isInUse,
     });
   }
-
-  let createButton = document.getElementById("create-button");
-  createButton.onclick = createProfileWizard;
-
-  let restartSafeModeButton = document.getElementById("restart-in-safe-mode-button");
-  if (!Services.policies || Services.policies.isAllowed("safeMode")) {
-    restartSafeModeButton.onclick = function() { restart(true); };
-  } else {
-    restartSafeModeButton.setAttribute("disabled", "true");
-  }
-
-  let restartNormalModeButton = document.getElementById("restart-button");
-  restartNormalModeButton.onclick = function() { restart(false); };
 }
 
 function display(profileData) {
   let parent = document.getElementById("profiles");
 
   let div = document.createElement("div");
   parent.appendChild(div);
 
@@ -347,15 +334,28 @@ function restart(safeMode) {
   if (safeMode) {
     Services.startup.restartInSafeMode(flags);
   } else {
     Services.startup.quit(flags);
   }
 }
 
 window.addEventListener("DOMContentLoaded", function() {
+  let createButton = document.getElementById("create-button");
+  createButton.addEventListener("click", createProfileWizard);
+
+  let restartSafeModeButton = document.getElementById("restart-in-safe-mode-button");
+  if (!Services.policies || Services.policies.isAllowed("safeMode")) {
+    restartSafeModeButton.addEventListener("click", () => { restart(true); });
+  } else {
+    restartSafeModeButton.setAttribute("disabled", "true");
+  }
+
+  let restartNormalModeButton = document.getElementById("restart-button");
+  restartNormalModeButton.addEventListener("click", () => { restart(false); });
+
   if (ProfileService.isListOutdated) {
     document.getElementById("owned").hidden = true;
   } else {
     document.getElementById("conflict").hidden = true;
-    refreshUI();
+    rebuildProfileList();
   }
 }, {once: true});