summaryrefslogtreecommitdiffstats
path: root/toolkit/modules/ResetProfile.jsm
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/modules/ResetProfile.jsm
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/modules/ResetProfile.jsm')
-rw-r--r--toolkit/modules/ResetProfile.jsm65
1 files changed, 65 insertions, 0 deletions
diff --git a/toolkit/modules/ResetProfile.jsm b/toolkit/modules/ResetProfile.jsm
new file mode 100644
index 000000000..fe0d1cfe8
--- /dev/null
+++ b/toolkit/modules/ResetProfile.jsm
@@ -0,0 +1,65 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["ResetProfile"];
+
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/AppConstants.jsm");
+
+const MOZ_APP_NAME = AppConstants.MOZ_APP_NAME;
+const MOZ_BUILD_APP = AppConstants.MOZ_BUILD_APP;
+
+this.ResetProfile = {
+ /**
+ * Check if reset is supported for the currently running profile.
+ *
+ * @return boolean whether reset is supported.
+ */
+ resetSupported: function() {
+ // Reset is only supported if the self-migrator used for reset exists.
+ let migrator = "@mozilla.org/profile/migrator;1?app=" + MOZ_BUILD_APP +
+ "&type=" + MOZ_APP_NAME;
+ if (!(migrator in Cc)) {
+ return false;
+ }
+ // We also need to be using a profile the profile manager knows about.
+ let profileService = Cc["@mozilla.org/toolkit/profile-service;1"].
+ getService(Ci.nsIToolkitProfileService);
+ let currentProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ let profileEnumerator = profileService.profiles;
+ while (profileEnumerator.hasMoreElements()) {
+ let profile = profileEnumerator.getNext().QueryInterface(Ci.nsIToolkitProfile);
+ if (profile.rootDir && profile.rootDir.equals(currentProfileDir)) {
+ return true;
+ }
+ }
+ return false;
+ },
+
+ /**
+ * Ask the user if they wish to restart the application to reset the profile.
+ */
+ openConfirmationDialog: function(window) {
+ // Prompt the user to confirm.
+ let params = {
+ reset: false,
+ };
+ window.openDialog("chrome://global/content/resetProfile.xul", null,
+ "chrome,modal,centerscreen,titlebar,dialog=yes", params);
+ if (!params.reset)
+ return;
+
+ // Set the reset profile environment variable.
+ let env = Cc["@mozilla.org/process/environment;1"]
+ .getService(Ci.nsIEnvironment);
+ env.set("MOZ_RESET_PROFILE_RESTART", "1");
+
+ let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
+ appStartup.quit(Ci.nsIAppStartup.eForceQuit | Ci.nsIAppStartup.eRestart);
+ },
+};