summaryrefslogtreecommitdiffstats
path: root/application/palemoon/components/migration/FirefoxProfileMigrator.js
diff options
context:
space:
mode:
Diffstat (limited to 'application/palemoon/components/migration/FirefoxProfileMigrator.js')
-rw-r--r--application/palemoon/components/migration/FirefoxProfileMigrator.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/application/palemoon/components/migration/FirefoxProfileMigrator.js b/application/palemoon/components/migration/FirefoxProfileMigrator.js
new file mode 100644
index 000000000..9101974cf
--- /dev/null
+++ b/application/palemoon/components/migration/FirefoxProfileMigrator.js
@@ -0,0 +1,126 @@
+/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 sts=2 et */
+ /* 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";
+
+/*
+ * Migrates from a Pale Moon profile in a lossy manner in order to clean up a
+ * user's profile. Data is only migrated where the benefits outweigh the
+ * potential problems caused by importing undesired/invalid configurations
+ * from the source profile.
+ */
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource:///modules/MigrationUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
+ "resource://gre/modules/PlacesBackups.jsm");
+
+function FirefoxProfileMigrator() { }
+
+FirefoxProfileMigrator.prototype = Object.create(MigratorPrototype);
+
+FirefoxProfileMigrator.prototype._getAllProfiles = function () {
+ let allProfiles = new Map();
+ let profiles =
+ Components.classes["@mozilla.org/toolkit/profile-service;1"]
+ .getService(Components.interfaces.nsIToolkitProfileService)
+ .profiles;
+ while (profiles.hasMoreElements()) {
+ let profile = profiles.getNext().QueryInterface(Components.interfaces.nsIToolkitProfile);
+ let rootDir = profile.rootDir;
+
+ if (rootDir.exists() && rootDir.isReadable() &&
+ !rootDir.equals(MigrationUtils.profileStartup.directory)) {
+ allProfiles.set(profile.name, rootDir);
+ }
+ }
+ return allProfiles;
+};
+
+function sorter(a, b) {
+ return a.id.toLocaleLowerCase().localeCompare(b.id.toLocaleLowerCase());
+}
+
+Object.defineProperty(FirefoxProfileMigrator.prototype, "sourceProfiles", {
+ get: function() {
+ // Tycho: return [{id: x, name: x} for (x of this._getAllProfiles().keys())].sort(sorter);
+ let items = [];
+ for (let x of this._getAllProfiles().keys()) {
+ items.push({id: x, name: x});
+ }
+ return items.sort(sorter);
+ }
+});
+
+FirefoxProfileMigrator.prototype.getResources = function(aProfile) {
+ let sourceProfileDir = aProfile ? this._getAllProfiles().get(aProfile.id) :
+ Components.classes["@mozilla.org/toolkit/profile-service;1"]
+ .getService(Components.interfaces.nsIToolkitProfileService)
+ .selectedProfile.rootDir;
+ if (!sourceProfileDir || !sourceProfileDir.exists() ||
+ !sourceProfileDir.isReadable())
+ return null;
+
+ // Being a startup-only migrator, we can rely on
+ // MigrationUtils.profileStartup being set.
+ let currentProfileDir = MigrationUtils.profileStartup.directory;
+
+ // Surely data cannot be imported from the current profile.
+ if (sourceProfileDir.equals(currentProfileDir))
+ return null;
+
+ let getFileResource = function(aMigrationType, aFileNames) {
+ let files = [];
+ for (let fileName of aFileNames) {
+ let file = sourceProfileDir.clone();
+ file.append(fileName);
+
+ if (file.exists()) {
+ files.push(file);
+ }
+ }
+ if (!files.length) {
+ return null;
+ }
+ return {
+ type: aMigrationType,
+ migrate: function(aCallback) {
+ for (let file of files) {
+ file.copyTo(currentProfileDir, "");
+ }
+ aCallback(true);
+ }
+ };
+ };
+
+ let types = MigrationUtils.resourceTypes;
+ let places = getFileResource(types.HISTORY, ["places.sqlite", "places.sqlite-wal"]);
+ let cookies = getFileResource(types.COOKIES, ["cookies.sqlite", "cookies.sqlite-wal"]);
+ let passwords = getFileResource(types.PASSWORDS,
+ ["signons.sqlite", "logins.json", "key3.db"]);
+ let formData = getFileResource(types.FORMDATA, ["formhistory.sqlite"]);
+ let bookmarksBackups = getFileResource(types.OTHERDATA,
+ [PlacesBackups.profileRelativeFolderPath]);
+ let dictionary = getFileResource(types.OTHERDATA, ["persdict.dat"]);
+
+ /* Tycho:
+ return [r for each (r in [places, cookies, passwords, formData,
+ dictionary, bookmarksBackups]) if (r)];
+ */
+ return [places, cookies, passwords, formData, dictionary, bookmarksBackups]
+ .filter(r => r);
+}
+
+Object.defineProperty(FirefoxProfileMigrator.prototype, "startupOnlyMigrator", {
+ get: function() true
+});
+
+
+FirefoxProfileMigrator.prototype.classDescription = "Firefox Profile Migrator";
+FirefoxProfileMigrator.prototype.contractID = "@mozilla.org/profile/migrator;1?app=browser&type=firefox";
+FirefoxProfileMigrator.prototype.classID = Components.ID("{91185366-ba97-4438-acba-48deaca63386}");
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FirefoxProfileMigrator]);