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