michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = ["ResetProfile"]; michael@0: michael@0: const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; michael@0: #expand const MOZ_APP_NAME = "__MOZ_APP_NAME__"; michael@0: #expand const MOZ_BUILD_APP = "__MOZ_BUILD_APP__"; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: this.ResetProfile = { michael@0: /** michael@0: * Check if reset is supported for the currently running profile. michael@0: * michael@0: * @return boolean whether reset is supported. michael@0: */ michael@0: resetSupported: function() { michael@0: let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]. michael@0: getService(Ci.nsIToolkitProfileService); michael@0: let currentProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile); michael@0: michael@0: // Reset is only supported for the default profile if the self-migrator used for reset exists. michael@0: try { michael@0: return currentProfileDir.equals(profileService.selectedProfile.rootDir) && michael@0: ("@mozilla.org/profile/migrator;1?app=" + MOZ_BUILD_APP + "&type=" + MOZ_APP_NAME in Cc); michael@0: } catch (e) { michael@0: // Catch exception when there is no selected profile. michael@0: Cu.reportError(e); michael@0: } michael@0: return false; michael@0: }, michael@0: michael@0: getMigratedData: function() { michael@0: Cu.import("resource:///modules/MigrationUtils.jsm"); michael@0: michael@0: // From migration.properties michael@0: const MIGRATED_TYPES = [ michael@0: 128,// Windows/Tabs michael@0: 4, // History and Bookmarks michael@0: 16, // Passwords michael@0: 8, // Form History michael@0: 2, // Cookies michael@0: ]; michael@0: michael@0: // Loop over possible data to migrate to give the user a list of what will be preserved. michael@0: let dataTypes = []; michael@0: for (let itemID of MIGRATED_TYPES) { michael@0: try { michael@0: let typeName = MigrationUtils.getLocalizedString(itemID + "_" + MOZ_APP_NAME); michael@0: dataTypes.push(typeName); michael@0: } catch (x) { michael@0: // Catch exceptions when the string for a data type doesn't exist. michael@0: Cu.reportError(x); michael@0: } michael@0: } michael@0: return dataTypes; michael@0: }, michael@0: michael@0: /** michael@0: * Ask the user if they wish to restart the application to reset the profile. michael@0: */ michael@0: openConfirmationDialog: function(window) { michael@0: // Prompt the user to confirm. michael@0: let params = { michael@0: reset: false, michael@0: }; michael@0: window.openDialog("chrome://global/content/resetProfile.xul", null, michael@0: "chrome,modal,centerscreen,titlebar,dialog=yes", params); michael@0: if (!params.reset) michael@0: return; michael@0: michael@0: // Set the reset profile environment variable. michael@0: let env = Cc["@mozilla.org/process/environment;1"] michael@0: .getService(Ci.nsIEnvironment); michael@0: env.set("MOZ_RESET_PROFILE_RESTART", "1"); michael@0: michael@0: let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); michael@0: appStartup.quit(Ci.nsIAppStartup.eForceQuit | Ci.nsIAppStartup.eRestart); michael@0: }, michael@0: };