|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 this.EXPORTED_SYMBOLS = ["ResetProfile"]; |
|
8 |
|
9 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
|
10 #expand const MOZ_APP_NAME = "__MOZ_APP_NAME__"; |
|
11 #expand const MOZ_BUILD_APP = "__MOZ_BUILD_APP__"; |
|
12 |
|
13 Cu.import("resource://gre/modules/Services.jsm"); |
|
14 |
|
15 this.ResetProfile = { |
|
16 /** |
|
17 * Check if reset is supported for the currently running profile. |
|
18 * |
|
19 * @return boolean whether reset is supported. |
|
20 */ |
|
21 resetSupported: function() { |
|
22 let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]. |
|
23 getService(Ci.nsIToolkitProfileService); |
|
24 let currentProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile); |
|
25 |
|
26 // Reset is only supported for the default profile if the self-migrator used for reset exists. |
|
27 try { |
|
28 return currentProfileDir.equals(profileService.selectedProfile.rootDir) && |
|
29 ("@mozilla.org/profile/migrator;1?app=" + MOZ_BUILD_APP + "&type=" + MOZ_APP_NAME in Cc); |
|
30 } catch (e) { |
|
31 // Catch exception when there is no selected profile. |
|
32 Cu.reportError(e); |
|
33 } |
|
34 return false; |
|
35 }, |
|
36 |
|
37 getMigratedData: function() { |
|
38 Cu.import("resource:///modules/MigrationUtils.jsm"); |
|
39 |
|
40 // From migration.properties |
|
41 const MIGRATED_TYPES = [ |
|
42 128,// Windows/Tabs |
|
43 4, // History and Bookmarks |
|
44 16, // Passwords |
|
45 8, // Form History |
|
46 2, // Cookies |
|
47 ]; |
|
48 |
|
49 // Loop over possible data to migrate to give the user a list of what will be preserved. |
|
50 let dataTypes = []; |
|
51 for (let itemID of MIGRATED_TYPES) { |
|
52 try { |
|
53 let typeName = MigrationUtils.getLocalizedString(itemID + "_" + MOZ_APP_NAME); |
|
54 dataTypes.push(typeName); |
|
55 } catch (x) { |
|
56 // Catch exceptions when the string for a data type doesn't exist. |
|
57 Cu.reportError(x); |
|
58 } |
|
59 } |
|
60 return dataTypes; |
|
61 }, |
|
62 |
|
63 /** |
|
64 * Ask the user if they wish to restart the application to reset the profile. |
|
65 */ |
|
66 openConfirmationDialog: function(window) { |
|
67 // Prompt the user to confirm. |
|
68 let params = { |
|
69 reset: false, |
|
70 }; |
|
71 window.openDialog("chrome://global/content/resetProfile.xul", null, |
|
72 "chrome,modal,centerscreen,titlebar,dialog=yes", params); |
|
73 if (!params.reset) |
|
74 return; |
|
75 |
|
76 // Set the reset profile environment variable. |
|
77 let env = Cc["@mozilla.org/process/environment;1"] |
|
78 .getService(Ci.nsIEnvironment); |
|
79 env.set("MOZ_RESET_PROFILE_RESTART", "1"); |
|
80 |
|
81 let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); |
|
82 appStartup.quit(Ci.nsIAppStartup.eForceQuit | Ci.nsIAppStartup.eRestart); |
|
83 }, |
|
84 }; |