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 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
9 ChromeUtils.defineLazyGetter(lazy, "MigrationUtils", () => {
10 // MigrationUtils is currently only available in browser builds.
11 if (AppConstants.MOZ_BUILD_APP != "browser") {
16 let { MigrationUtils } = ChromeUtils.importESModule(
17 "resource:///modules/MigrationUtils.sys.mjs"
19 return MigrationUtils;
21 console.error(`Unable to load MigrationUtils.sys.mjs: ${e}`);
26 const MOZ_APP_NAME = AppConstants.MOZ_APP_NAME;
28 export var ResetProfile = {
30 * Check if reset is supported for the currently running profile.
32 * @return boolean whether reset is supported.
35 if (Services.policies && !Services.policies.isAllowed("profileRefresh")) {
39 // Reset is only supported if the self-migrator used for reset exists.
41 !lazy.MigrationUtils ||
42 !lazy.MigrationUtils.migratorExists(MOZ_APP_NAME)
47 // We also need to be using a profile the profile manager knows about.
48 let profileService = Cc[
49 "@mozilla.org/toolkit/profile-service;1"
50 ].getService(Ci.nsIToolkitProfileService);
51 let currentProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
52 for (let profile of profileService.profiles) {
53 if (profile.rootDir && profile.rootDir.equals(currentProfileDir)) {
61 * Ask the user if they wish to restart the application to reset the profile.
63 async openConfirmationDialog(window) {
65 // If we are, for instance, on an about page, get the chrome window to
66 // access its gDialogBox.
67 if (win.docShell.chromeEventHandler) {
68 win = win.browsingContext?.topChromeWindow;
77 await win.gDialogBox.open(
78 "chrome://global/content/resetProfile.xhtml",
83 "chrome://global/content/resetProfile.xhtml",
85 "modal,centerscreen,titlebar",
90 if (params.learnMore) {
91 win.openTrustedLinkIn(
92 "https://support.mozilla.org/kb/refresh-firefox-reset-add-ons-and-settings",
102 // Set the reset profile environment variable.
103 Services.env.set("MOZ_RESET_PROFILE_RESTART", "1");
105 Services.startup.quit(
106 Ci.nsIAppStartup.eForceQuit | Ci.nsIAppStartup.eRestart