2013-06-29 07:25:08 +04:00
|
|
|
/* 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";
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ["ResetProfile"];
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const { AppConstants } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/AppConstants.jsm"
|
|
|
|
);
|
2015-04-07 11:09:49 +03:00
|
|
|
|
|
|
|
const MOZ_APP_NAME = AppConstants.MOZ_APP_NAME;
|
|
|
|
const MOZ_BUILD_APP = AppConstants.MOZ_BUILD_APP;
|
2013-06-29 07:25:08 +04:00
|
|
|
|
|
|
|
var ResetProfile = {
|
|
|
|
/**
|
|
|
|
* Check if reset is supported for the currently running profile.
|
|
|
|
*
|
|
|
|
* @return boolean whether reset is supported.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
resetSupported() {
|
2018-03-28 19:44:07 +03:00
|
|
|
if (Services.policies && !Services.policies.isAllowed("profileRefresh")) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-05 23:38:49 +03:00
|
|
|
// 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.
|
2013-06-29 07:25:08 +04:00
|
|
|
let profileService = Cc[
|
|
|
|
"@mozilla.org/toolkit/profile-service;1"
|
|
|
|
].getService(Ci.nsIToolkitProfileService);
|
|
|
|
let currentProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
2018-08-19 05:27:50 +03:00
|
|
|
for (let profile of profileService.profiles) {
|
2016-05-05 23:38:49 +03:00
|
|
|
if (profile.rootDir && profile.rootDir.equals(currentProfileDir)) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-29 07:25:08 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ask the user if they wish to restart the application to reset the profile.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
openConfirmationDialog(window) {
|
2013-06-29 07:25:08 +04:00
|
|
|
// Prompt the user to confirm.
|
|
|
|
let params = {
|
|
|
|
reset: false,
|
|
|
|
};
|
2020-06-17 20:17:16 +03:00
|
|
|
window.browsingContext.topChromeWindow.openDialog(
|
2019-12-11 20:44:54 +03:00
|
|
|
"chrome://global/content/resetProfile.xhtml",
|
2013-06-29 07:25:08 +04:00
|
|
|
null,
|
2019-10-07 22:47:36 +03:00
|
|
|
"modal,centerscreen,titlebar",
|
2013-06-29 07:25:08 +04:00
|
|
|
params
|
|
|
|
);
|
|
|
|
if (!params.reset) {
|
|
|
|
return;
|
2019-07-05 12:15:43 +03:00
|
|
|
}
|
2013-06-29 07:25:08 +04:00
|
|
|
|
|
|
|
// Set the reset profile environment variable.
|
|
|
|
let env = Cc["@mozilla.org/process/environment;1"].getService(
|
|
|
|
Ci.nsIEnvironment
|
|
|
|
);
|
|
|
|
env.set("MOZ_RESET_PROFILE_RESTART", "1");
|
|
|
|
|
2017-11-09 19:36:57 +03:00
|
|
|
Services.startup.quit(
|
|
|
|
Ci.nsIAppStartup.eForceQuit | Ci.nsIAppStartup.eRestart
|
|
|
|
);
|
2013-06-29 07:25:08 +04:00
|
|
|
},
|
|
|
|
};
|