1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/modules/ResetProfile.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +this.EXPORTED_SYMBOLS = ["ResetProfile"]; 1.11 + 1.12 +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; 1.13 +#expand const MOZ_APP_NAME = "__MOZ_APP_NAME__"; 1.14 +#expand const MOZ_BUILD_APP = "__MOZ_BUILD_APP__"; 1.15 + 1.16 +Cu.import("resource://gre/modules/Services.jsm"); 1.17 + 1.18 +this.ResetProfile = { 1.19 + /** 1.20 + * Check if reset is supported for the currently running profile. 1.21 + * 1.22 + * @return boolean whether reset is supported. 1.23 + */ 1.24 + resetSupported: function() { 1.25 + let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]. 1.26 + getService(Ci.nsIToolkitProfileService); 1.27 + let currentProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile); 1.28 + 1.29 + // Reset is only supported for the default profile if the self-migrator used for reset exists. 1.30 + try { 1.31 + return currentProfileDir.equals(profileService.selectedProfile.rootDir) && 1.32 + ("@mozilla.org/profile/migrator;1?app=" + MOZ_BUILD_APP + "&type=" + MOZ_APP_NAME in Cc); 1.33 + } catch (e) { 1.34 + // Catch exception when there is no selected profile. 1.35 + Cu.reportError(e); 1.36 + } 1.37 + return false; 1.38 + }, 1.39 + 1.40 + getMigratedData: function() { 1.41 + Cu.import("resource:///modules/MigrationUtils.jsm"); 1.42 + 1.43 + // From migration.properties 1.44 + const MIGRATED_TYPES = [ 1.45 + 128,// Windows/Tabs 1.46 + 4, // History and Bookmarks 1.47 + 16, // Passwords 1.48 + 8, // Form History 1.49 + 2, // Cookies 1.50 + ]; 1.51 + 1.52 + // Loop over possible data to migrate to give the user a list of what will be preserved. 1.53 + let dataTypes = []; 1.54 + for (let itemID of MIGRATED_TYPES) { 1.55 + try { 1.56 + let typeName = MigrationUtils.getLocalizedString(itemID + "_" + MOZ_APP_NAME); 1.57 + dataTypes.push(typeName); 1.58 + } catch (x) { 1.59 + // Catch exceptions when the string for a data type doesn't exist. 1.60 + Cu.reportError(x); 1.61 + } 1.62 + } 1.63 + return dataTypes; 1.64 + }, 1.65 + 1.66 + /** 1.67 + * Ask the user if they wish to restart the application to reset the profile. 1.68 + */ 1.69 + openConfirmationDialog: function(window) { 1.70 + // Prompt the user to confirm. 1.71 + let params = { 1.72 + reset: false, 1.73 + }; 1.74 + window.openDialog("chrome://global/content/resetProfile.xul", null, 1.75 + "chrome,modal,centerscreen,titlebar,dialog=yes", params); 1.76 + if (!params.reset) 1.77 + return; 1.78 + 1.79 + // Set the reset profile environment variable. 1.80 + let env = Cc["@mozilla.org/process/environment;1"] 1.81 + .getService(Ci.nsIEnvironment); 1.82 + env.set("MOZ_RESET_PROFILE_RESTART", "1"); 1.83 + 1.84 + let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); 1.85 + appStartup.quit(Ci.nsIAppStartup.eForceQuit | Ci.nsIAppStartup.eRestart); 1.86 + }, 1.87 +};