|
1 /* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 let Cc = Components.classes; |
|
7 let Ci = Components.interfaces; |
|
8 let Cu = Components.utils; |
|
9 |
|
10 const appStartup = Services.startup; |
|
11 |
|
12 Cu.import("resource://gre/modules/ResetProfile.jsm"); |
|
13 |
|
14 let defaultToReset = false; |
|
15 |
|
16 function restartApp() { |
|
17 appStartup.quit(appStartup.eForceQuit | appStartup.eRestart); |
|
18 } |
|
19 |
|
20 function resetProfile() { |
|
21 // Set the reset profile environment variable. |
|
22 let env = Cc["@mozilla.org/process/environment;1"] |
|
23 .getService(Ci.nsIEnvironment); |
|
24 env.set("MOZ_RESET_PROFILE_RESTART", "1"); |
|
25 } |
|
26 |
|
27 function showResetDialog() { |
|
28 // Prompt the user to confirm the reset. |
|
29 let retVals = { |
|
30 reset: false, |
|
31 }; |
|
32 window.openDialog("chrome://global/content/resetProfile.xul", null, |
|
33 "chrome,modal,centerscreen,titlebar,dialog=yes", retVals); |
|
34 if (!retVals.reset) |
|
35 return; |
|
36 resetProfile(); |
|
37 restartApp(); |
|
38 } |
|
39 |
|
40 function onDefaultButton() { |
|
41 if (defaultToReset) { |
|
42 // Restart to reset the profile. |
|
43 resetProfile(); |
|
44 restartApp(); |
|
45 // Return false to prevent starting into safe mode while restarting. |
|
46 return false; |
|
47 } else { |
|
48 // Continue in safe mode. No restart needed. |
|
49 return true; |
|
50 } |
|
51 } |
|
52 |
|
53 function onCancel() { |
|
54 appStartup.quit(appStartup.eForceQuit); |
|
55 } |
|
56 |
|
57 function onExtra1() { |
|
58 if (defaultToReset) { |
|
59 // Continue in safe mode |
|
60 window.close(); |
|
61 return true; |
|
62 } else { |
|
63 // The reset dialog will handle starting the reset process if the user confirms. |
|
64 showResetDialog(); |
|
65 } |
|
66 return false; |
|
67 } |
|
68 |
|
69 function onLoad() { |
|
70 let dialog = document.documentElement; |
|
71 if (appStartup.automaticSafeModeNecessary) { |
|
72 document.getElementById("autoSafeMode").hidden = false; |
|
73 document.getElementById("safeMode").hidden = true; |
|
74 if (ResetProfile.resetSupported()) { |
|
75 populateResetPane("resetProfileItems"); |
|
76 document.getElementById("resetProfile").hidden = false; |
|
77 } else { |
|
78 // Hide the reset button is it's not supported. |
|
79 document.documentElement.getButton("extra1").hidden = true; |
|
80 } |
|
81 } else { |
|
82 if (!ResetProfile.resetSupported()) { |
|
83 // Hide the reset button and text if it's not supported. |
|
84 document.documentElement.getButton("extra1").hidden = true; |
|
85 document.getElementById("resetProfileInstead").hidden = true; |
|
86 } |
|
87 } |
|
88 } |