Bug 1586801 - Use the contextual WalkerFront in _duplicateNode(). r=pbro
[gecko.git] / toolkit / modules / ResetProfile.jsm
blob9ae079721f3e2c03ecfd1e2d4575b24ea5835dbd
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 var EXPORTED_SYMBOLS = ["ResetProfile"];
9 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
10 const { AppConstants } = ChromeUtils.import(
11   "resource://gre/modules/AppConstants.jsm"
14 const MOZ_APP_NAME = AppConstants.MOZ_APP_NAME;
15 const MOZ_BUILD_APP = AppConstants.MOZ_BUILD_APP;
17 var ResetProfile = {
18   /**
19    * Check if reset is supported for the currently running profile.
20    *
21    * @return boolean whether reset is supported.
22    */
23   resetSupported() {
24     if (Services.policies && !Services.policies.isAllowed("profileRefresh")) {
25       return false;
26     }
27     // Reset is only supported if the self-migrator used for reset exists.
28     let migrator =
29       "@mozilla.org/profile/migrator;1?app=" +
30       MOZ_BUILD_APP +
31       "&type=" +
32       MOZ_APP_NAME;
33     if (!(migrator in Cc)) {
34       return false;
35     }
36     // We also need to be using a profile the profile manager knows about.
37     let profileService = Cc[
38       "@mozilla.org/toolkit/profile-service;1"
39     ].getService(Ci.nsIToolkitProfileService);
40     let currentProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
41     for (let profile of profileService.profiles) {
42       if (profile.rootDir && profile.rootDir.equals(currentProfileDir)) {
43         return true;
44       }
45     }
46     return false;
47   },
49   /**
50    * Ask the user if they wish to restart the application to reset the profile.
51    */
52   openConfirmationDialog(window) {
53     // Prompt the user to confirm.
54     let params = {
55       reset: false,
56     };
57     window.docShell.rootTreeItem.domWindow.openDialog(
58       "chrome://global/content/resetProfile.xul",
59       null,
60       "modal,centerscreen,titlebar",
61       params
62     );
63     if (!params.reset) {
64       return;
65     }
67     // Set the reset profile environment variable.
68     let env = Cc["@mozilla.org/process/environment;1"].getService(
69       Ci.nsIEnvironment
70     );
71     env.set("MOZ_RESET_PROFILE_RESTART", "1");
73     Services.startup.quit(
74       Ci.nsIAppStartup.eForceQuit | Ci.nsIAppStartup.eRestart
75     );
76   },