1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/safeMode.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +let Cc = Components.classes; 1.10 +let Ci = Components.interfaces; 1.11 +let Cu = Components.utils; 1.12 + 1.13 +const appStartup = Services.startup; 1.14 + 1.15 +Cu.import("resource://gre/modules/ResetProfile.jsm"); 1.16 + 1.17 +let defaultToReset = false; 1.18 + 1.19 +function restartApp() { 1.20 + appStartup.quit(appStartup.eForceQuit | appStartup.eRestart); 1.21 +} 1.22 + 1.23 +function resetProfile() { 1.24 + // Set the reset profile environment variable. 1.25 + let env = Cc["@mozilla.org/process/environment;1"] 1.26 + .getService(Ci.nsIEnvironment); 1.27 + env.set("MOZ_RESET_PROFILE_RESTART", "1"); 1.28 +} 1.29 + 1.30 +function showResetDialog() { 1.31 + // Prompt the user to confirm the reset. 1.32 + let retVals = { 1.33 + reset: false, 1.34 + }; 1.35 + window.openDialog("chrome://global/content/resetProfile.xul", null, 1.36 + "chrome,modal,centerscreen,titlebar,dialog=yes", retVals); 1.37 + if (!retVals.reset) 1.38 + return; 1.39 + resetProfile(); 1.40 + restartApp(); 1.41 +} 1.42 + 1.43 +function onDefaultButton() { 1.44 + if (defaultToReset) { 1.45 + // Restart to reset the profile. 1.46 + resetProfile(); 1.47 + restartApp(); 1.48 + // Return false to prevent starting into safe mode while restarting. 1.49 + return false; 1.50 + } else { 1.51 + // Continue in safe mode. No restart needed. 1.52 + return true; 1.53 + } 1.54 +} 1.55 + 1.56 +function onCancel() { 1.57 + appStartup.quit(appStartup.eForceQuit); 1.58 +} 1.59 + 1.60 +function onExtra1() { 1.61 + if (defaultToReset) { 1.62 + // Continue in safe mode 1.63 + window.close(); 1.64 + return true; 1.65 + } else { 1.66 + // The reset dialog will handle starting the reset process if the user confirms. 1.67 + showResetDialog(); 1.68 + } 1.69 + return false; 1.70 +} 1.71 + 1.72 +function onLoad() { 1.73 + let dialog = document.documentElement; 1.74 + if (appStartup.automaticSafeModeNecessary) { 1.75 + document.getElementById("autoSafeMode").hidden = false; 1.76 + document.getElementById("safeMode").hidden = true; 1.77 + if (ResetProfile.resetSupported()) { 1.78 + populateResetPane("resetProfileItems"); 1.79 + document.getElementById("resetProfile").hidden = false; 1.80 + } else { 1.81 + // Hide the reset button is it's not supported. 1.82 + document.documentElement.getButton("extra1").hidden = true; 1.83 + } 1.84 + } else { 1.85 + if (!ResetProfile.resetSupported()) { 1.86 + // Hide the reset button and text if it's not supported. 1.87 + document.documentElement.getButton("extra1").hidden = true; 1.88 + document.getElementById("resetProfileInstead").hidden = true; 1.89 + } 1.90 + } 1.91 +}