Bug 1156176 - Add Restart Later button for the setting that allows Dev Edition and Firefox to run at the same time. r=jaws
authorMaurya Talisetti <maurya1985@yahoo.com>
Thu, 18 Feb 2016 08:57:00 +0100
changeset 321276 967a62006b5749752a3f85b02efbf7e189a0339f
parent 321275 b995a277b126f554e86b555408cc636d0f92dade
child 321277 eb76ccb9bc1798ca98392d5a96aa1175f8adb2ec
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1156176
milestone47.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 1156176 - Add Restart Later button for the setting that allows Dev Edition and Firefox to run at the same time. r=jaws
browser/components/preferences/in-content/main.js
browser/locales/en-US/chrome/browser/preferences/preferences.properties
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -2,16 +2,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/Downloads.jsm");
 Components.utils.import("resource://gre/modules/FileUtils.jsm");
 Components.utils.import("resource://gre/modules/Task.jsm");
 Components.utils.import("resource:///modules/ShellService.jsm");
 Components.utils.import("resource:///modules/TransientPrefs.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "OS",
+                                  "resource://gre/modules/osfile.jsm");
+
 #ifdef E10S_TESTING_ONLY
 XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
                                   "resource://gre/modules/UpdateUtils.jsm");
 #endif
 
 var gMainPane = {
   /**
    * Initialization of this.
@@ -96,17 +100,16 @@ var gMainPane = {
 
       // but if it's force disabled, then the checkbox is disabled.
       e10sCheckbox.disabled = !Services.appinfo.browserTabsRemoteAutostart;
     }
 
 #endif
 
 #ifdef MOZ_DEV_EDITION
-    Cu.import("resource://gre/modules/osfile.jsm");
     let uAppData = OS.Constants.Path.userApplicationDataDir;
     let ignoreSeparateProfile = OS.Path.join(uAppData, "ignore-dev-edition-profile");
 
     setEventListener("separateProfileMode", "command", gMainPane.separateProfileModeChange);
     let separateProfileModeCheckbox = document.getElementById("separateProfileMode");
     setEventListener("getStarted", "click", gMainPane.onGetStarted);
 
     OS.File.stat(ignoreSeparateProfile).then(() => separateProfileModeCheckbox.checked = false,
@@ -180,49 +183,72 @@ var gMainPane = {
       Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit |  Ci.nsIAppStartup.eRestartNotSameProfile);
     }
     function revertCheckbox(error) {
       separateProfileModeCheckbox.checked = !separateProfileModeCheckbox.checked;
       if (error) {
         Cu.reportError("Failed to toggle separate profile mode: " + error);
       }
     }
+    function createOrRemoveSpecialDevEditionFile(onSuccess) {
+      let uAppData = OS.Constants.Path.userApplicationDataDir;
+      let ignoreSeparateProfile = OS.Path.join(uAppData, "ignore-dev-edition-profile");
+
+      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 shouldProceed = Services.prompt.confirm(window, title, msg)
-    if (shouldProceed) {
-      let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
-                         .createInstance(Ci.nsISupportsPRBool);
-      Services.obs.notifyObservers(cancelQuit, "quit-application-requested",
-                                   "restart");
-      shouldProceed = !cancelQuit.data;
+    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;
 
-      if (shouldProceed) {
-        Cu.import("resource://gre/modules/osfile.jsm");
-        let uAppData = OS.Constants.Path.userApplicationDataDir;
-        let ignoreSeparateProfile = OS.Path.join(uAppData, "ignore-dev-edition-profile");
+    switch (button_index) {
+      case CANCEL_BUTTON_INDEX:
+        revertCheckbox();
+        return;
+      case RESTART_NOW_BUTTON_INDEX:
+        let shouldProceed = false;
+        let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
+                           .createInstance(Ci.nsISupportsPRBool);
+        Services.obs.notifyObservers(cancelQuit, "quit-application-requested",
+                                      "restart");
+        shouldProceed = !cancelQuit.data;
 
-        if (separateProfileModeCheckbox.checked) {
-          OS.File.remove(ignoreSeparateProfile).then(quitApp, revertCheckbox);
-        } else {
-          OS.File.writeAtomic(ignoreSeparateProfile, new Uint8Array()).then(quitApp, revertCheckbox);
+        if (shouldProceed) {
+          createOrRemoveSpecialDevEditionFile(quitApp);
+          return;
         }
+
+        // Revert the checkbox in case we didn't quit
+        revertCheckbox();
         return;
-      }
+      case RESTART_LATER_BUTTON_INDEX:
+        createOrRemoveSpecialDevEditionFile();
+        return;
     }
-
-    // Revert the checkbox in case we didn't quit
-    revertCheckbox();
   },
 
   onGetStarted: function (aEvent) {
     const Cc = Components.classes, Ci = Components.interfaces;
     let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
                 .getService(Ci.nsIWindowMediator);
     let win = wm.getMostRecentWindow("navigator:browser");
 
--- a/browser/locales/en-US/chrome/browser/preferences/preferences.properties
+++ b/browser/locales/en-US/chrome/browser/preferences/preferences.properties
@@ -166,12 +166,15 @@ syncUnlink.title=Do you want to unlink y
 syncUnlink.label=This device will no longer be associated with your Sync account. All of your personal data, both on this device and in your Sync account, will remain intact.
 syncUnlinkConfirm.label=Unlink
 
 # LOCALIZATION NOTE (featureEnableRequiresRestart, featureDisableRequiresRestart, restartTitle): %S = brandShortName
 featureEnableRequiresRestart=%S must restart to enable this feature.
 featureDisableRequiresRestart=%S must restart to disable this feature.
 shouldRestartTitle=Restart %S
 
+restartNow=Restart Now
+restartLater=Restart Later
+
 #### e10S
 # LOCALIZATION NOTE (e10sFeedbackAfterRestart): This message appears when the user
 # unchecks "Enable multi-process" on the "General" preferences tab.
 e10sFeedbackAfterRestart=After restart, a tab will open to input.mozilla.org where you can provide us feedback about your e10s experience.