Bug 1285328: Part 2. Add an ability to change the revert/cancel label and/or show the restart later button to the confirmRestartPrompt dialog. r?jaws draft
authorMilan Sreckovic <milan@mozilla.com>
Thu, 14 Jul 2016 14:14:28 -0400
changeset 387709 4a62db0b531121fdfe2bd6a6e6eb494c21814258
parent 387707 65429d7359fd207e090b219d2244e4d155263b20
child 525429 80adab21142a164350b0379f8714108af5129a9b
push id23049
push usermsreckovic@mozilla.com
push dateThu, 14 Jul 2016 18:15:15 +0000
reviewersjaws
bugs1285328
milestone50.0a1
Bug 1285328: Part 2. Add an ability to change the revert/cancel label and/or show the restart later button to the confirmRestartPrompt dialog. r?jaws MozReview-Commit-ID: D7SDsHqghAS
browser/components/preferences/in-content/main.js
browser/components/preferences/in-content/preferences.js
browser/components/preferences/in-content/privacy.js
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -136,17 +136,18 @@ var gMainPane = {
     } else {
       // Disabling e10s autostart
       prefsToChange = [e10sPref];
       if (e10sTempPref.value) {
        prefsToChange.push(e10sTempPref);
       }
     }
 
-    let buttonIndex = confirmRestartPrompt(e10sCheckbox.checked, 0);
+    let buttonIndex = confirmRestartPrompt(e10sCheckbox.checked, 0,
+                                           true, false);
     if (buttonIndex == CONFIRM_RESTART_PROMPT_RESTART_NOW) {
       const Cc = Components.classes, Ci = Components.interfaces;
       let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
                          .createInstance(Ci.nsISupportsPRBool);
       Services.obs.notifyObservers(cancelQuit, "quit-application-requested",
                                    "restart");
       if (!cancelQuit.data) {
         for (let prefToChange of prefsToChange) {
@@ -180,58 +181,38 @@ var gMainPane = {
 
       if (separateProfileModeCheckbox.checked) {
         OS.File.remove(ignoreSeparateProfile).then(onSuccess, revertCheckbox);
       } else {
         OS.File.writeAtomic(ignoreSeparateProfile, new Uint8Array()).then(onSuccess, revertCheckbox);
       }
     }
 
-    const Cc = Components.classes, Ci = Components.interfaces;
     let separateProfileModeCheckbox = document.getElementById("separateProfileMode");
-    let brandName = document.getElementById("bundleBrand").getString("brandShortName");
-    let bundle = document.getElementById("bundlePreferences");
-    let msg = bundle.getFormattedString(separateProfileModeCheckbox.checked ?
-                                        "featureEnableRequiresRestart" : "featureDisableRequiresRestart",
-                                        [brandName]);
-    let title = bundle.getFormattedString("shouldRestartTitle", [brandName]);
-    let check = {value: false};
-    let prompts = Services.prompt;
-    let flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_IS_STRING +
-                  prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_CANCEL  +
-                  prompts.BUTTON_POS_2 * prompts.BUTTON_TITLE_IS_STRING;
-    let button0Title = bundle.getString("restartNowButton");
-    let button2Title = bundle.getString("restartLaterButton");
-    let button_index = prompts.confirmEx(window, title, msg, flags,
-                         button0Title, null, button2Title, null, check)
-    let RESTART_NOW_BUTTON_INDEX = 0;
-    let CANCEL_BUTTON_INDEX = 1;
-    let RESTART_LATER_BUTTON_INDEX = 2;
-
+    let button_index = confirmRestartPrompt(separateProfileModeCheckbox.checked,
+                                            0, false, true);
     switch (button_index) {
-      case CANCEL_BUTTON_INDEX:
+      case CONFIRM_RESTART_PROMPT_CANCEL:
         revertCheckbox();
         return;
-      case RESTART_NOW_BUTTON_INDEX:
-        let shouldProceed = false;
+      case CONFIRM_RESTART_PROMPT_RESTART_NOW:
+        const Cc = Components.classes, Ci = Components.interfaces;
         let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
                            .createInstance(Ci.nsISupportsPRBool);
         Services.obs.notifyObservers(cancelQuit, "quit-application-requested",
                                       "restart");
-        shouldProceed = !cancelQuit.data;
-
-        if (shouldProceed) {
+        if (!cancelQuit.data) {
           createOrRemoveSpecialDevEditionFile(quitApp);
           return;
         }
 
         // Revert the checkbox in case we didn't quit
         revertCheckbox();
         return;
-      case RESTART_LATER_BUTTON_INDEX:
+      case CONFIRM_RESTART_PROMPT_RESTART_LATER:
         createOrRemoveSpecialDevEditionFile();
         return;
     }
   },
 
   onGetStarted: function (aEvent) {
     const Cc = Components.classes, Ci = Components.interfaces;
     let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
--- a/browser/components/preferences/in-content/preferences.js
+++ b/browser/components/preferences/in-content/preferences.js
@@ -170,51 +170,73 @@ function friendlyPrefCategoryNameToInter
   return "pane" + aName.substring(0,1).toUpperCase() + aName.substr(1);
 }
 
 // This function is duplicated inside of utilityOverlay.js's openPreferences.
 function internalPrefCategoryNameToFriendlyName(aName) {
   return (aName || "").replace(/^pane./, function(toReplace) { return toReplace[4].toLowerCase(); });
 }
 
-// Put up a confirm dialog with "ok to restart" and "revert without restarting"
-// buttons and returns the index of the button chosen.
+// Put up a confirm dialog with "ok to restart", "revert without restarting"
+// and "restart later" buttons and returns the index of the button chosen.
+// We can choose not to display the "restart later", or "revert" buttons,
+// altough the later still lets us revert by using the escape key.
 //
 // The constants are useful to interpret the return value of the function.
 const CONFIRM_RESTART_PROMPT_RESTART_NOW = 0;
 const CONFIRM_RESTART_PROMPT_CANCEL = 1;
-function confirmRestartPrompt(aRestartToEnable, aDefaultButtonIndex) {
+const CONFIRM_RESTART_PROMPT_RESTART_LATER = 2;
+function confirmRestartPrompt(aRestartToEnable, aDefaultButtonIndex,
+                              aWantRevertAsCancelButton,
+			      aWantRestartLaterButton) {
   let brandName = document.getElementById("bundleBrand").getString("brandShortName");
   let bundle = document.getElementById("bundlePreferences");
   let msg = bundle.getFormattedString(aRestartToEnable ?
                                       "featureEnableRequiresRestart" :
                                       "featureDisableRequiresRestart",
                                       [brandName]);
   let title = bundle.getFormattedString("shouldRestartTitle", [brandName]);
   let prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
 
   // Set up the first (index 0) button:
   let button0Text = bundle.getFormattedString("okToRestartButton", [brandName]);
   let buttonFlags = (Services.prompt.BUTTON_POS_0 *
                      Services.prompt.BUTTON_TITLE_IS_STRING);
 
 
   // Set up the second (index 1) button:
-  let button1Text = bundle.getString("revertNoRestartButton");
-  buttonFlags += (Services.prompt.BUTTON_POS_1 *
-                  Services.prompt.BUTTON_TITLE_IS_STRING);
+  let button1Text = null;
+  if (aWantRevertAsCancelButton) {
+    button1Text = bundle.getString("revertNoRestartButton");
+    buttonFlags += (Services.prompt.BUTTON_POS_1 *
+                    Services.prompt.BUTTON_TITLE_IS_STRING);
+  } else {
+    buttonFlags += (Services.prompt.BUTTON_POS_1 *
+                    Services.prompt.BUTTON_TITLE_CANCEL);
+  }
+
+  // Set up the third (index 2) button:
+  let button2Text = null;
+  if (aWantRestartLaterButton) {
+    button2Text = bundle.getString("restartLater");
+    buttonFlags += (Services.prompt.BUTTON_POS_2 *
+                    Services.prompt.BUTTON_TITLE_IS_STRING);
+  }
 
   switch(aDefaultButtonIndex) {
     case 0:
       buttonFlags += Services.prompt.BUTTON_POS_0_DEFAULT;
       break;
     case 1:
       buttonFlags += Services.prompt.BUTTON_POS_1_DEFAULT;
       break;
+    case 2:
+      buttonFlags += Services.prompt.BUTTON_POS_2_DEFAULT;
+      break;
     default:
       break;
   }
 
   let buttonIndex = prompts.confirmEx(window, title, msg, buttonFlags,
-                                      button0Text, button1Text, null,
+                                      button0Text, button1Text, button2Text,
                                       null, {});
   return buttonIndex;
 }
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -365,17 +365,18 @@ var gPrivacyPane = {
           return;
       }
 
       if (!this._shouldPromptForRestart) {
         // We're performing a revert. Just let it happen.
         return;
       }
 
-      let buttonIndex = confirmRestartPrompt(autoStart.checked, 1);
+      let buttonIndex = confirmRestartPrompt(autoStart.checked, 1,
+                                             true, false);
       if (buttonIndex == CONFIRM_RESTART_PROMPT_RESTART_NOW) {
         const Cc = Components.classes, Ci = Components.interfaces;
         let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
                            .createInstance(Ci.nsISupportsPRBool);
         Services.obs.notifyObservers(cancelQuit, "quit-application-requested",
                                      "restart");
         if (!cancelQuit.data) {
           pref.value = autoStart.hasAttribute('checked');