Bug 1545736: about:profiles buttons should be initialised when the UI loads, not everytime the UI is refreshed. r=jaws
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 19 Apr 2019 06:43:49 -0700
changeset 470292 6ffe4f5a3c4744adce3f62255cf91351c39a33a0
parent 470291 3425e11a7a2d6c603912c7d747850e827edda748
child 470293 a092972b53f0e566a36770e7b03363036ff820ec
push id35892
push userrgurzau@mozilla.com
push dateSat, 20 Apr 2019 09:55:32 +0000
treeherdermozilla-central@a092972b53f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1545736
milestone68.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 1545736: about:profiles buttons should be initialised when the UI loads, not everytime the UI is refreshed. r=jaws 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});