michael@0: /* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let Cc = Components.classes; michael@0: let Ci = Components.interfaces; michael@0: let Cu = Components.utils; michael@0: michael@0: const appStartup = Services.startup; michael@0: michael@0: Cu.import("resource://gre/modules/ResetProfile.jsm"); michael@0: michael@0: let defaultToReset = false; michael@0: michael@0: function restartApp() { michael@0: appStartup.quit(appStartup.eForceQuit | appStartup.eRestart); michael@0: } michael@0: michael@0: function resetProfile() { michael@0: // Set the reset profile environment variable. michael@0: let env = Cc["@mozilla.org/process/environment;1"] michael@0: .getService(Ci.nsIEnvironment); michael@0: env.set("MOZ_RESET_PROFILE_RESTART", "1"); michael@0: } michael@0: michael@0: function showResetDialog() { michael@0: // Prompt the user to confirm the reset. michael@0: let retVals = { michael@0: reset: false, michael@0: }; michael@0: window.openDialog("chrome://global/content/resetProfile.xul", null, michael@0: "chrome,modal,centerscreen,titlebar,dialog=yes", retVals); michael@0: if (!retVals.reset) michael@0: return; michael@0: resetProfile(); michael@0: restartApp(); michael@0: } michael@0: michael@0: function onDefaultButton() { michael@0: if (defaultToReset) { michael@0: // Restart to reset the profile. michael@0: resetProfile(); michael@0: restartApp(); michael@0: // Return false to prevent starting into safe mode while restarting. michael@0: return false; michael@0: } else { michael@0: // Continue in safe mode. No restart needed. michael@0: return true; michael@0: } michael@0: } michael@0: michael@0: function onCancel() { michael@0: appStartup.quit(appStartup.eForceQuit); michael@0: } michael@0: michael@0: function onExtra1() { michael@0: if (defaultToReset) { michael@0: // Continue in safe mode michael@0: window.close(); michael@0: return true; michael@0: } else { michael@0: // The reset dialog will handle starting the reset process if the user confirms. michael@0: showResetDialog(); michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: function onLoad() { michael@0: let dialog = document.documentElement; michael@0: if (appStartup.automaticSafeModeNecessary) { michael@0: document.getElementById("autoSafeMode").hidden = false; michael@0: document.getElementById("safeMode").hidden = true; michael@0: if (ResetProfile.resetSupported()) { michael@0: populateResetPane("resetProfileItems"); michael@0: document.getElementById("resetProfile").hidden = false; michael@0: } else { michael@0: // Hide the reset button is it's not supported. michael@0: document.documentElement.getButton("extra1").hidden = true; michael@0: } michael@0: } else { michael@0: if (!ResetProfile.resetSupported()) { michael@0: // Hide the reset button and text if it's not supported. michael@0: document.documentElement.getButton("extra1").hidden = true; michael@0: document.getElementById("resetProfileInstead").hidden = true; michael@0: } michael@0: } michael@0: }