toolkit/modules/ResetProfile.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial