2012-05-29 15:52:43 +00:00
|
|
|
/* 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/. */
|
2012-03-21 19:20:47 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-02-23 19:50:01 +00:00
|
|
|
var EXPORTED_SYMBOLS = ["MigrationUtils", "MigratorPrototype"];
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2012-05-28 09:43:59 +00:00
|
|
|
const TOPIC_WILL_IMPORT_BOOKMARKS =
|
|
|
|
"initial-migration-will-import-default-bookmarks";
|
|
|
|
const TOPIC_DID_IMPORT_BOOKMARKS =
|
|
|
|
"initial-migration-did-import-default-bookmarks";
|
2016-10-13 16:02:29 +00:00
|
|
|
const TOPIC_PLACES_DEFAULTS_FINISHED = "places-browser-init-complete";
|
2012-05-28 09:43:59 +00:00
|
|
|
|
2019-01-17 18:18:31 +00:00
|
|
|
const { AppConstants } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/AppConstants.jsm"
|
|
|
|
);
|
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
|
|
);
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2018-05-26 00:02:29 +00:00
|
|
|
XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
|
2016-11-30 11:56:25 +00:00
|
|
|
|
2018-01-29 23:20:18 +00:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"BookmarkHTMLUtils",
|
|
|
|
"resource://gre/modules/BookmarkHTMLUtils.jsm"
|
|
|
|
);
|
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"LoginHelper",
|
|
|
|
"resource://gre/modules/LoginHelper.jsm"
|
|
|
|
);
|
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"PlacesUtils",
|
|
|
|
"resource://gre/modules/PlacesUtils.jsm"
|
|
|
|
);
|
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"PromiseUtils",
|
|
|
|
"resource://gre/modules/PromiseUtils.jsm"
|
|
|
|
);
|
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"ResponsivenessMonitor",
|
|
|
|
"resource://gre/modules/ResponsivenessMonitor.jsm"
|
|
|
|
);
|
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"Sqlite",
|
|
|
|
"resource://gre/modules/Sqlite.jsm"
|
|
|
|
);
|
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"WindowsRegistry",
|
|
|
|
"resource://gre/modules/WindowsRegistry.jsm"
|
|
|
|
);
|
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"setTimeout",
|
|
|
|
"resource://gre/modules/Timer.jsm"
|
|
|
|
);
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var gMigrators = null;
|
|
|
|
var gProfileStartup = null;
|
|
|
|
var gMigrationBundle = null;
|
Bug 1319816 - fix default browser determination on Windows 7 and below in the automigration case, r=jaws
As noted on the bug, because we call getMigratorKeyForDefaultBrowser() multiple times,
its value no longer reflects the (deleted) registry key for subsequent calls.
While we can fix this for the automigrate case by just passing the default we determined a few
lines earlier (and that seems worth doing to avoid busywork), there are 2 small problems
with this:
1) if the default browser has no data, `migratorKey` won't be set, and so we'll call the same
method again anyway, and the message reported in the error console will be that we can't
migrate from Firefox, when the real problem is that we can't migrate from the original
default browser.
2) there are other callers besides AutoMigrate. Specifically, migration.js also calls this
method.
To deal with these, I've fixed getMigratorKeyForDefaultBrowser() to return the same
registry-based value for its lifetime if we hit the 'the default is firefox, go look for an
earlier default' case.
I've verified that either the s/aMigratorKey/migratorKey/ or the change to
getMigratorKeyForDefaultBrowser() are sufficient to make this work properly in the
automigration case.
While I was here, I also updated one of the error messages to be more explicit.
MozReview-Commit-ID: GeUNTfScMMB
--HG--
extra : rebase_source : 09b4b5fef85c4668bc0931de2c8cf3d1a32e2b42
2016-11-23 16:06:00 +00:00
|
|
|
var gPreviousDefaultBrowserKey = "";
|
2012-04-14 09:50:44 +00:00
|
|
|
|
2018-02-15 19:55:10 +00:00
|
|
|
let gForceExitSpinResolve = false;
|
2016-11-30 11:48:03 +00:00
|
|
|
let gKeepUndoData = false;
|
|
|
|
let gUndoData = null;
|
|
|
|
|
2016-02-08 12:54:38 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gAvailableMigratorKeys", function() {
|
|
|
|
if (AppConstants.platform == "win") {
|
2016-08-23 21:49:39 +00:00
|
|
|
return ["firefox", "edge", "ie", "chrome", "chromium", "360se", "canary"];
|
2016-02-08 12:54:38 +00:00
|
|
|
}
|
|
|
|
if (AppConstants.platform == "macosx") {
|
|
|
|
return ["firefox", "safari", "chrome", "chromium", "canary"];
|
|
|
|
}
|
|
|
|
if (AppConstants.XP_UNIX) {
|
2018-03-01 14:03:06 +00:00
|
|
|
return ["firefox", "chrome", "chrome-beta", "chrome-dev", "chromium"];
|
2016-02-08 12:54:38 +00:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
2012-04-14 09:50:44 +00:00
|
|
|
function getMigrationBundle() {
|
|
|
|
if (!gMigrationBundle) {
|
|
|
|
gMigrationBundle = Services.strings.createBundle(
|
2015-04-08 18:49:47 +00:00
|
|
|
"chrome://browser/locale/migration/migration.properties"
|
|
|
|
);
|
2012-04-14 09:50:44 +00:00
|
|
|
}
|
|
|
|
return gMigrationBundle;
|
|
|
|
}
|
2012-03-21 19:20:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shared prototype for migrators, implementing nsIBrowserProfileMigrator.
|
|
|
|
*
|
|
|
|
* To implement a migrator:
|
|
|
|
* 1. Import this module.
|
|
|
|
* 2. Create the prototype for the migrator, extending MigratorPrototype.
|
|
|
|
* Namely: MosaicMigrator.prototype = Object.create(MigratorPrototype);
|
|
|
|
* 3. Set classDescription, contractID and classID for your migrator, and set
|
|
|
|
* NSGetFactory appropriately.
|
|
|
|
* 4. If the migrator supports multiple profiles, override the sourceProfiles
|
|
|
|
* Here we default for single-profile migrator.
|
|
|
|
* 5. Implement getResources(aProfile) (see below).
|
2018-02-07 10:18:46 +00:00
|
|
|
* 6. For startup-only migrators, override |startupOnlyMigrator|.
|
2012-03-21 19:20:47 +00:00
|
|
|
*/
|
2018-02-23 19:50:01 +00:00
|
|
|
var MigratorPrototype = {
|
2018-04-23 03:55:06 +00:00
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIBrowserProfileMigrator]),
|
2012-03-21 19:20:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* OVERRIDE IF AND ONLY IF the source supports multiple profiles.
|
|
|
|
*
|
2014-06-04 07:56:18 +00:00
|
|
|
* Returns array of profile objects from which data may be imported. The object
|
|
|
|
* should have the following keys:
|
|
|
|
* id - a unique string identifier for the profile
|
|
|
|
* name - a pretty name to display to the user in the UI
|
2012-03-21 19:20:47 +00:00
|
|
|
*
|
|
|
|
* Only profiles from which data can be imported should be listed. Otherwise
|
|
|
|
* the behavior of the migration wizard isn't well-defined.
|
|
|
|
*
|
|
|
|
* For a single-profile source (e.g. safari, ie), this returns null,
|
|
|
|
* and not an empty array. That is the default implementation.
|
|
|
|
*/
|
2018-01-12 17:06:21 +00:00
|
|
|
getSourceProfiles() {
|
2015-09-23 09:36:21 +00:00
|
|
|
return null;
|
|
|
|
},
|
2012-03-21 19:20:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MUST BE OVERRIDDEN.
|
|
|
|
*
|
|
|
|
* Returns an array of "migration resources" objects for the given profile,
|
|
|
|
* or for the "default" profile, if the migrator does not support multiple
|
|
|
|
* profiles.
|
|
|
|
*
|
|
|
|
* Each migration resource should provide:
|
2016-06-01 18:00:53 +00:00
|
|
|
* - a |type| getter, returning any of the migration types (see
|
2012-03-21 19:20:47 +00:00
|
|
|
* nsIBrowserProfileMigrator).
|
|
|
|
*
|
|
|
|
* - a |migrate| method, taking a single argument, aCallback(bool success),
|
|
|
|
* for migrating the data for this resource. It may do its job
|
|
|
|
* synchronously or asynchronously. Either way, it must call
|
|
|
|
* aCallback(bool aSuccess) when it's done. In the case of an exception
|
|
|
|
* thrown from |migrate|, it's taken as if aCallback(false) is called.
|
|
|
|
*
|
|
|
|
* Note: In the case of a simple asynchronous implementation, you may find
|
|
|
|
* MigrationUtils.wrapMigrateFunction handy for handling aCallback easily.
|
|
|
|
*
|
|
|
|
* For each migration type listed in nsIBrowserProfileMigrator, multiple
|
|
|
|
* migration resources may be provided. This practice is useful when the
|
|
|
|
* data for a certain migration type is independently stored in few
|
|
|
|
* locations. For example, the mac version of Safari stores its "reading list"
|
|
|
|
* bookmarks in a separate property list.
|
|
|
|
*
|
|
|
|
* Note that the importation of a particular migration type is reported as
|
|
|
|
* successful if _any_ of its resources succeeded to import (that is, called,
|
|
|
|
* |aCallback(true)|). However, completion-status for a particular migration
|
|
|
|
* type is reported to the UI only once all of its migrators have called
|
|
|
|
* aCallback.
|
|
|
|
*
|
|
|
|
* @note The returned array should only include resources from which data
|
|
|
|
* can be imported. So, for example, before adding a resource for the
|
|
|
|
* BOOKMARKS migration type, you should check if you should check that the
|
|
|
|
* bookmarks file exists.
|
|
|
|
*
|
|
|
|
* @param aProfile
|
|
|
|
* The profile from which data may be imported, or an empty string
|
|
|
|
* in the case of a single-profile migrator.
|
|
|
|
* In the case of multiple-profiles migrator, it is guaranteed that
|
|
|
|
* aProfile is a value returned by the sourceProfiles getter (see
|
|
|
|
* above).
|
|
|
|
*/
|
2016-10-18 15:03:06 +00:00
|
|
|
getResources: function MP_getResources(/* aProfile */) {
|
2012-03-21 19:20:47 +00:00
|
|
|
throw new Error("getResources must be overridden");
|
|
|
|
},
|
|
|
|
|
2016-05-30 16:10:54 +00:00
|
|
|
/**
|
|
|
|
* OVERRIDE in order to provide an estimate of when the last time was
|
|
|
|
* that somebody used the browser. It is OK that this is somewhat fuzzy -
|
|
|
|
* history may not be available (or be wiped or not present due to e.g.
|
|
|
|
* incognito mode).
|
|
|
|
*
|
|
|
|
* @return a Promise that resolves to the last used date.
|
|
|
|
*
|
|
|
|
* @note If not overridden, the promise will resolve to the unix epoch.
|
|
|
|
*/
|
|
|
|
getLastUsedDate() {
|
|
|
|
return Promise.resolve(new Date(0));
|
|
|
|
},
|
|
|
|
|
2012-03-21 19:20:47 +00:00
|
|
|
/**
|
|
|
|
* OVERRIDE IF AND ONLY IF the migrator is a startup-only migrator (For now,
|
|
|
|
* that is just the Firefox migrator, see bug 737381). Default: false.
|
|
|
|
*
|
|
|
|
* Startup-only migrators are different in two ways:
|
|
|
|
* - they may only be used during startup.
|
|
|
|
* - the user-profile is half baked during migration. The folder exists,
|
|
|
|
* but it's only accessible through MigrationUtils.profileStartup.
|
|
|
|
* The migrator can call MigrationUtils.profileStartup.doStartup
|
|
|
|
* at any point in order to initialize the profile.
|
|
|
|
*/
|
2015-09-23 09:36:21 +00:00
|
|
|
get startupOnlyMigrator() {
|
|
|
|
return false;
|
|
|
|
},
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2015-08-08 06:36:32 +00:00
|
|
|
/**
|
|
|
|
* Override if the data to migrate is locked/in-use and the user should
|
|
|
|
* probably shutdown the source browser.
|
|
|
|
*/
|
2015-09-23 09:36:21 +00:00
|
|
|
get sourceLocked() {
|
|
|
|
return false;
|
|
|
|
},
|
2015-08-08 06:36:32 +00:00
|
|
|
|
2012-03-21 19:20:47 +00:00
|
|
|
/**
|
|
|
|
* DO NOT OVERRIDE - After deCOMing migration, the UI will just call
|
|
|
|
* getResources.
|
|
|
|
*
|
|
|
|
* @see nsIBrowserProfileMigrator
|
|
|
|
*/
|
2018-01-12 17:06:21 +00:00
|
|
|
getMigrateData: async function MP_getMigrateData(aProfile) {
|
|
|
|
let resources = await this._getMaybeCachedResources(aProfile);
|
2015-10-18 16:27:39 +00:00
|
|
|
if (!resources) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
let types = resources.map(r => r.type);
|
2017-05-28 18:57:46 +00:00
|
|
|
return types.reduce((a, b) => {
|
|
|
|
a |= b;
|
|
|
|
return a;
|
|
|
|
}, 0);
|
2012-03-21 19:20:47 +00:00
|
|
|
},
|
|
|
|
|
2017-02-17 23:01:50 +00:00
|
|
|
getBrowserKey: function MP_getBrowserKey() {
|
2016-07-26 17:05:08 +00:00
|
|
|
return this.contractID.match(/\=([^\=]+)$/)[1];
|
|
|
|
},
|
|
|
|
|
2012-03-21 19:20:47 +00:00
|
|
|
/**
|
|
|
|
* DO NOT OVERRIDE - After deCOMing migration, the UI will just call
|
|
|
|
* migrate for each resource.
|
|
|
|
*
|
|
|
|
* @see nsIBrowserProfileMigrator
|
|
|
|
*/
|
2018-01-12 17:06:21 +00:00
|
|
|
migrate: async function MP_migrate(aItems, aStartup, aProfile) {
|
|
|
|
let resources = await this._getMaybeCachedResources(aProfile);
|
2012-03-21 19:20:47 +00:00
|
|
|
if (resources.length == 0) {
|
|
|
|
throw new Error("migrate called for a non-existent source");
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2012-03-21 19:20:47 +00:00
|
|
|
|
|
|
|
if (aItems != Ci.nsIBrowserProfileMigrator.ALL) {
|
2015-10-18 16:27:39 +00:00
|
|
|
resources = resources.filter(r => aItems & r.type);
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2016-05-24 15:29:30 +00:00
|
|
|
// Used to periodically give back control to the main-thread loop.
|
2016-11-11 16:10:51 +00:00
|
|
|
let unblockMainThread = function() {
|
2016-05-24 15:29:30 +00:00
|
|
|
return new Promise(resolve => {
|
2017-04-14 16:29:12 +00:00
|
|
|
Services.tm.dispatchToMainThread(resolve);
|
2016-05-24 15:29:30 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-02-17 23:01:50 +00:00
|
|
|
let getHistogramIdForResourceType = (resourceType, template) => {
|
2016-07-26 17:05:08 +00:00
|
|
|
if (resourceType == MigrationUtils.resourceTypes.HISTORY) {
|
2017-02-17 23:01:50 +00:00
|
|
|
return template.replace("*", "HISTORY");
|
2016-07-26 17:05:08 +00:00
|
|
|
}
|
|
|
|
if (resourceType == MigrationUtils.resourceTypes.BOOKMARKS) {
|
2017-02-17 23:01:50 +00:00
|
|
|
return template.replace("*", "BOOKMARKS");
|
2016-07-26 17:05:08 +00:00
|
|
|
}
|
|
|
|
if (resourceType == MigrationUtils.resourceTypes.PASSWORDS) {
|
2017-02-17 23:01:50 +00:00
|
|
|
return template.replace("*", "LOGINS");
|
2016-07-26 17:05:08 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
2017-02-17 23:01:50 +00:00
|
|
|
|
|
|
|
let browserKey = this.getBrowserKey();
|
|
|
|
|
|
|
|
let maybeStartTelemetryStopwatch = resourceType => {
|
|
|
|
let histogramId = getHistogramIdForResourceType(
|
|
|
|
resourceType,
|
|
|
|
"FX_MIGRATION_*_IMPORT_MS"
|
|
|
|
);
|
|
|
|
if (histogramId) {
|
|
|
|
TelemetryStopwatch.startKeyed(histogramId, browserKey);
|
2016-07-26 17:05:08 +00:00
|
|
|
}
|
2017-02-17 23:01:50 +00:00
|
|
|
return histogramId;
|
2016-07-26 17:05:08 +00:00
|
|
|
};
|
2017-02-17 23:01:50 +00:00
|
|
|
|
|
|
|
let maybeStartResponsivenessMonitor = resourceType => {
|
|
|
|
let responsivenessMonitor;
|
|
|
|
let responsivenessHistogramId = getHistogramIdForResourceType(
|
|
|
|
resourceType,
|
|
|
|
"FX_MIGRATION_*_JANK_MS"
|
|
|
|
);
|
|
|
|
if (responsivenessHistogramId) {
|
|
|
|
responsivenessMonitor = new ResponsivenessMonitor();
|
|
|
|
}
|
|
|
|
return { responsivenessMonitor, responsivenessHistogramId };
|
|
|
|
};
|
|
|
|
|
|
|
|
let maybeFinishResponsivenessMonitor = (
|
|
|
|
responsivenessMonitor,
|
|
|
|
histogramId
|
|
|
|
) => {
|
|
|
|
if (responsivenessMonitor) {
|
|
|
|
let accumulatedDelay = responsivenessMonitor.finish();
|
|
|
|
if (histogramId) {
|
|
|
|
try {
|
|
|
|
Services.telemetry
|
|
|
|
.getKeyedHistogramById(histogramId)
|
|
|
|
.add(browserKey, accumulatedDelay);
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(histogramId + ": " + ex);
|
|
|
|
}
|
|
|
|
}
|
2016-07-26 17:05:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-22 13:40:48 +00:00
|
|
|
let collectQuantityTelemetry = () => {
|
2017-02-17 23:01:50 +00:00
|
|
|
for (let resourceType of Object.keys(MigrationUtils._importQuantities)) {
|
|
|
|
let histogramId =
|
|
|
|
"FX_MIGRATION_" + resourceType.toUpperCase() + "_QUANTITY";
|
|
|
|
try {
|
|
|
|
Services.telemetry
|
|
|
|
.getKeyedHistogramById(histogramId)
|
|
|
|
.add(browserKey, MigrationUtils._importQuantities[resourceType]);
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(histogramId + ": " + ex);
|
2016-10-22 13:40:48 +00:00
|
|
|
}
|
2017-02-17 23:01:50 +00:00
|
|
|
}
|
2016-10-22 13:40:48 +00:00
|
|
|
};
|
|
|
|
|
2012-05-28 09:43:59 +00:00
|
|
|
// Called either directly or through the bookmarks import callback.
|
2017-05-12 12:42:39 +00:00
|
|
|
let doMigrate = async function() {
|
2015-04-08 18:49:47 +00:00
|
|
|
let resourcesGroupedByItems = new Map();
|
2012-05-28 09:43:59 +00:00
|
|
|
resources.forEach(function(resource) {
|
2016-05-24 15:29:30 +00:00
|
|
|
if (!resourcesGroupedByItems.has(resource.type)) {
|
|
|
|
resourcesGroupedByItems.set(resource.type, new Set());
|
|
|
|
}
|
2016-10-18 15:03:06 +00:00
|
|
|
resourcesGroupedByItems.get(resource.type).add(resource);
|
2012-05-28 09:43:59 +00:00
|
|
|
});
|
|
|
|
|
2015-04-08 18:49:47 +00:00
|
|
|
if (resourcesGroupedByItems.size == 0) {
|
2012-05-28 09:43:59 +00:00
|
|
|
throw new Error("No items to import");
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2012-05-28 09:43:59 +00:00
|
|
|
|
|
|
|
let notify = function(aMsg, aItemType) {
|
|
|
|
Services.obs.notifyObservers(null, aMsg, aItemType);
|
2016-10-18 15:03:06 +00:00
|
|
|
};
|
2012-05-28 09:43:59 +00:00
|
|
|
|
2016-10-22 13:40:48 +00:00
|
|
|
for (let resourceType of Object.keys(MigrationUtils._importQuantities)) {
|
|
|
|
MigrationUtils._importQuantities[resourceType] = 0;
|
|
|
|
}
|
2012-05-28 09:43:59 +00:00
|
|
|
notify("Migration:Started");
|
2016-12-22 11:03:28 +00:00
|
|
|
for (let [migrationType, itemResources] of resourcesGroupedByItems) {
|
2012-05-28 09:43:59 +00:00
|
|
|
notify("Migration:ItemBeforeMigrate", migrationType);
|
|
|
|
|
2017-02-17 23:01:50 +00:00
|
|
|
let stopwatchHistogramId = maybeStartTelemetryStopwatch(migrationType);
|
|
|
|
|
|
|
|
let {
|
|
|
|
responsivenessMonitor,
|
|
|
|
responsivenessHistogramId,
|
|
|
|
} = maybeStartResponsivenessMonitor(migrationType);
|
2017-02-11 20:14:52 +00:00
|
|
|
|
2012-05-28 09:43:59 +00:00
|
|
|
let itemSuccess = false;
|
2015-04-08 18:49:47 +00:00
|
|
|
for (let res of itemResources) {
|
2016-05-24 15:29:30 +00:00
|
|
|
let completeDeferred = PromiseUtils.defer();
|
2012-05-28 09:43:59 +00:00
|
|
|
let resourceDone = function(aSuccess) {
|
2016-12-22 11:03:28 +00:00
|
|
|
itemResources.delete(res);
|
2016-05-24 15:29:30 +00:00
|
|
|
itemSuccess |= aSuccess;
|
|
|
|
if (itemResources.size == 0) {
|
|
|
|
notify(
|
|
|
|
itemSuccess
|
|
|
|
? "Migration:ItemAfterMigrate"
|
|
|
|
: "Migration:ItemError",
|
|
|
|
migrationType
|
|
|
|
);
|
|
|
|
resourcesGroupedByItems.delete(migrationType);
|
2017-02-11 20:14:52 +00:00
|
|
|
|
2017-02-17 23:01:50 +00:00
|
|
|
if (stopwatchHistogramId) {
|
|
|
|
TelemetryStopwatch.finishKeyed(
|
|
|
|
stopwatchHistogramId,
|
|
|
|
browserKey
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
maybeFinishResponsivenessMonitor(
|
|
|
|
responsivenessMonitor,
|
|
|
|
responsivenessHistogramId
|
|
|
|
);
|
2017-02-11 20:14:52 +00:00
|
|
|
|
2016-05-24 15:29:30 +00:00
|
|
|
if (resourcesGroupedByItems.size == 0) {
|
2016-10-22 13:40:48 +00:00
|
|
|
collectQuantityTelemetry();
|
2016-05-24 15:29:30 +00:00
|
|
|
notify("Migration:Ended");
|
2012-05-28 09:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-24 15:29:30 +00:00
|
|
|
completeDeferred.resolve();
|
2016-10-18 15:03:06 +00:00
|
|
|
};
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2016-05-24 15:29:30 +00:00
|
|
|
// If migrate throws, an error occurred, and the callback
|
|
|
|
// (itemMayBeDone) might haven't been called.
|
|
|
|
try {
|
2016-12-22 11:03:28 +00:00
|
|
|
res.migrate(resourceDone);
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (ex) {
|
2016-05-24 15:29:30 +00:00
|
|
|
Cu.reportError(ex);
|
|
|
|
resourceDone(false);
|
|
|
|
}
|
|
|
|
|
2017-11-17 19:45:44 +00:00
|
|
|
await completeDeferred.promise;
|
2017-05-12 12:42:39 +00:00
|
|
|
await unblockMainThread();
|
2015-04-08 18:49:47 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
};
|
2012-05-28 09:43:59 +00:00
|
|
|
|
2018-03-17 00:02:05 +00:00
|
|
|
if (
|
|
|
|
MigrationUtils.isStartupMigration &&
|
|
|
|
!this.startupOnlyMigrator &&
|
|
|
|
Services.policies.isAllowed("defaultBookmarks")
|
|
|
|
) {
|
2012-05-28 09:43:59 +00:00
|
|
|
MigrationUtils.profileStartup.doStartup();
|
2016-10-13 16:02:29 +00:00
|
|
|
// First import the default bookmarks.
|
|
|
|
// Note: We do not need to do so for the Firefox migrator
|
2012-05-28 09:43:59 +00:00
|
|
|
// (=startupOnlyMigrator), as it just copies over the places database
|
|
|
|
// from another profile.
|
2017-05-12 12:42:39 +00:00
|
|
|
(async function() {
|
2016-10-13 16:02:29 +00:00
|
|
|
// Tell nsBrowserGlue we're importing default bookmarks.
|
2012-05-28 09:43:59 +00:00
|
|
|
let browserGlue = Cc["@mozilla.org/browser/browserglue;1"].getService(
|
|
|
|
Ci.nsIObserver
|
|
|
|
);
|
|
|
|
browserGlue.observe(null, TOPIC_WILL_IMPORT_BOOKMARKS, "");
|
|
|
|
|
2016-10-13 16:02:29 +00:00
|
|
|
// Import the default bookmarks. We ignore whether or not we succeed.
|
2017-05-12 12:42:39 +00:00
|
|
|
await BookmarkHTMLUtils.importFromURL(
|
2018-03-01 21:37:13 +00:00
|
|
|
"chrome://browser/locale/bookmarks.html",
|
|
|
|
{
|
|
|
|
replace: true,
|
|
|
|
source: PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP,
|
|
|
|
}
|
|
|
|
).catch(Cu.reportError);
|
2016-10-13 16:02:29 +00:00
|
|
|
|
|
|
|
// We'll tell nsBrowserGlue we've imported bookmarks, but before that
|
|
|
|
// we need to make sure we're going to know when it's finished
|
|
|
|
// initializing places:
|
|
|
|
let placesInitedPromise = new Promise(resolve => {
|
|
|
|
let onPlacesInited = function() {
|
|
|
|
Services.obs.removeObserver(
|
|
|
|
onPlacesInited,
|
|
|
|
TOPIC_PLACES_DEFAULTS_FINISHED
|
|
|
|
);
|
|
|
|
resolve();
|
|
|
|
};
|
2017-04-14 19:51:38 +00:00
|
|
|
Services.obs.addObserver(
|
|
|
|
onPlacesInited,
|
|
|
|
TOPIC_PLACES_DEFAULTS_FINISHED
|
|
|
|
);
|
2016-10-13 16:02:29 +00:00
|
|
|
});
|
|
|
|
browserGlue.observe(null, TOPIC_DID_IMPORT_BOOKMARKS, "");
|
2017-05-12 12:42:39 +00:00
|
|
|
await placesInitedPromise;
|
2016-10-13 16:02:29 +00:00
|
|
|
doMigrate();
|
2017-05-12 12:42:39 +00:00
|
|
|
})();
|
2016-10-13 16:02:29 +00:00
|
|
|
return;
|
2012-05-28 09:43:59 +00:00
|
|
|
}
|
|
|
|
doMigrate();
|
2012-03-21 19:20:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DO NOT OVERRIDE - After deCOMing migration, this code
|
|
|
|
* won't be part of the migrator itself.
|
|
|
|
*
|
|
|
|
* @see nsIBrowserProfileMigrator
|
|
|
|
*/
|
2018-01-12 17:06:21 +00:00
|
|
|
async isSourceAvailable() {
|
2012-03-21 19:20:47 +00:00
|
|
|
if (this.startupOnlyMigrator && !MigrationUtils.isStartupMigration) {
|
|
|
|
return false;
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2012-03-21 19:20:47 +00:00
|
|
|
|
|
|
|
// For a single-profile source, check if any data is available.
|
|
|
|
// For multiple-profiles source, make sure that at least one
|
|
|
|
// profile is available.
|
2012-04-14 09:50:44 +00:00
|
|
|
let exists = false;
|
|
|
|
try {
|
2018-01-12 17:06:21 +00:00
|
|
|
let profiles = await this.getSourceProfiles();
|
2012-04-14 09:50:44 +00:00
|
|
|
if (!profiles) {
|
2018-01-12 17:06:21 +00:00
|
|
|
let resources = await this._getMaybeCachedResources("");
|
2012-04-14 09:50:44 +00:00
|
|
|
if (resources && resources.length > 0) {
|
|
|
|
exists = true;
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} else {
|
2012-04-14 09:50:44 +00:00
|
|
|
exists = profiles.length > 0;
|
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (ex) {
|
2012-04-14 09:50:44 +00:00
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
|
|
|
return exists;
|
2012-03-21 19:20:47 +00:00
|
|
|
},
|
|
|
|
|
2016-10-24 17:14:19 +00:00
|
|
|
/** * PRIVATE STUFF - DO NOT OVERRIDE ***/
|
2018-01-12 17:06:21 +00:00
|
|
|
_getMaybeCachedResources: async function PMB__getMaybeCachedResources(
|
|
|
|
aProfile
|
|
|
|
) {
|
2014-06-04 07:56:18 +00:00
|
|
|
let profileKey = aProfile ? aProfile.id : "";
|
2012-03-21 19:20:47 +00:00
|
|
|
if (this._resourcesByProfile) {
|
2014-06-04 07:56:18 +00:00
|
|
|
if (profileKey in this._resourcesByProfile) {
|
|
|
|
return this._resourcesByProfile[profileKey];
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} else {
|
2012-03-21 19:20:47 +00:00
|
|
|
this._resourcesByProfile = {};
|
|
|
|
}
|
2018-01-12 17:06:21 +00:00
|
|
|
this._resourcesByProfile[profileKey] = await this.getResources(aProfile);
|
2016-10-18 15:03:06 +00:00
|
|
|
return this._resourcesByProfile[profileKey];
|
2018-01-22 23:22:35 +00:00
|
|
|
},
|
2012-03-21 19:20:47 +00:00
|
|
|
};
|
|
|
|
|
2018-02-23 19:50:01 +00:00
|
|
|
var MigrationUtils = Object.freeze({
|
2012-04-14 09:50:44 +00:00
|
|
|
resourceTypes: {
|
|
|
|
SETTINGS: Ci.nsIBrowserProfileMigrator.SETTINGS,
|
|
|
|
COOKIES: Ci.nsIBrowserProfileMigrator.COOKIES,
|
|
|
|
HISTORY: Ci.nsIBrowserProfileMigrator.HISTORY,
|
|
|
|
FORMDATA: Ci.nsIBrowserProfileMigrator.FORMDATA,
|
|
|
|
PASSWORDS: Ci.nsIBrowserProfileMigrator.PASSWORDS,
|
|
|
|
BOOKMARKS: Ci.nsIBrowserProfileMigrator.BOOKMARKS,
|
2013-06-28 21:45:05 +00:00
|
|
|
OTHERDATA: Ci.nsIBrowserProfileMigrator.OTHERDATA,
|
|
|
|
SESSION: Ci.nsIBrowserProfileMigrator.SESSION,
|
2012-04-14 09:50:44 +00:00
|
|
|
},
|
|
|
|
|
2012-03-21 19:20:47 +00:00
|
|
|
/**
|
|
|
|
* Helper for implementing simple asynchronous cases of migration resources'
|
|
|
|
* |migrate(aCallback)| (see MigratorPrototype). If your |migrate| method
|
|
|
|
* just waits for some file to be read, for example, and then migrates
|
|
|
|
* everything right away, you can wrap the async-function with this helper
|
|
|
|
* and not worry about notifying the callback.
|
|
|
|
*
|
|
|
|
* For example, instead of writing:
|
|
|
|
* setTimeout(function() {
|
|
|
|
* try {
|
|
|
|
* ....
|
|
|
|
* aCallback(true);
|
|
|
|
* }
|
|
|
|
* catch() {
|
|
|
|
* aCallback(false);
|
|
|
|
* }
|
|
|
|
* }, 0);
|
|
|
|
*
|
|
|
|
* You may write:
|
|
|
|
* setTimeout(MigrationUtils.wrapMigrateFunction(function() {
|
|
|
|
* if (importingFromMosaic)
|
|
|
|
* throw Cr.NS_ERROR_UNEXPECTED;
|
|
|
|
* }, aCallback), 0);
|
|
|
|
*
|
|
|
|
* ... and aCallback will be called with aSuccess=false when importing
|
|
|
|
* from Mosaic, or with aSuccess=true otherwise.
|
|
|
|
*
|
|
|
|
* @param aFunction
|
|
|
|
* the function that will be called sometime later. If aFunction
|
|
|
|
* throws when it's called, aCallback(false) is called, otherwise
|
|
|
|
* aCallback(true) is called.
|
|
|
|
* @param aCallback
|
|
|
|
* the callback function passed to |migrate|.
|
|
|
|
* @return the wrapped function.
|
|
|
|
*/
|
|
|
|
wrapMigrateFunction: function MU_wrapMigrateFunction(aFunction, aCallback) {
|
|
|
|
return function() {
|
|
|
|
let success = false;
|
|
|
|
try {
|
|
|
|
aFunction.apply(null, arguments);
|
|
|
|
success = true;
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (ex) {
|
2012-03-21 19:20:47 +00:00
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
|
|
|
// Do not change this to call aCallback directly in try try & catch
|
|
|
|
// blocks, because if aCallback throws, we may end up calling aCallback
|
|
|
|
// twice.
|
|
|
|
aCallback(success);
|
2016-10-18 15:03:06 +00:00
|
|
|
};
|
2012-03-21 19:20:47 +00:00
|
|
|
},
|
|
|
|
|
2012-04-14 09:50:44 +00:00
|
|
|
/**
|
|
|
|
* Gets a string from the migration bundle. Shorthand for
|
|
|
|
* nsIStringBundle.GetStringFromName, if aReplacements isn't passed, or for
|
|
|
|
* nsIStringBundle.formatStringFromName if it is.
|
|
|
|
*
|
|
|
|
* This method also takes care of "bumped" keys (See bug 737381 comment 8 for
|
|
|
|
* details).
|
|
|
|
*
|
|
|
|
* @param aKey
|
|
|
|
* The key of the string to retrieve.
|
2015-08-06 07:02:22 +00:00
|
|
|
* @param aReplacements
|
2012-04-14 09:50:44 +00:00
|
|
|
* [optioanl] Array of replacements to run on the retrieved string.
|
|
|
|
* @return the retrieved string.
|
|
|
|
*
|
|
|
|
* @see nsIStringBundle
|
|
|
|
*/
|
|
|
|
getLocalizedString: function MU_getLocalizedString(aKey, aReplacements) {
|
2018-03-01 14:03:06 +00:00
|
|
|
aKey = aKey.replace(
|
|
|
|
/_(canary|chromium|chrome-beta|chrome-dev)$/,
|
|
|
|
"_chrome"
|
|
|
|
);
|
2015-08-06 07:02:22 +00:00
|
|
|
|
2012-04-14 09:50:44 +00:00
|
|
|
const OVERRIDES = {
|
2013-04-08 21:17:18 +00:00
|
|
|
"4_firefox": "4_firefox_history_and_bookmarks",
|
2018-01-22 23:22:35 +00:00
|
|
|
"64_firefox": "64_firefox_other",
|
2012-04-14 09:50:44 +00:00
|
|
|
};
|
|
|
|
aKey = OVERRIDES[aKey] || aKey;
|
|
|
|
|
|
|
|
if (aReplacements === undefined) {
|
|
|
|
return getMigrationBundle().GetStringFromName(aKey);
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2019-06-11 15:51:51 +00:00
|
|
|
return getMigrationBundle().formatStringFromName(aKey, aReplacements);
|
2012-04-14 09:50:44 +00:00
|
|
|
},
|
|
|
|
|
2016-07-26 11:48:37 +00:00
|
|
|
_getLocalePropertyForBrowser(browserId) {
|
|
|
|
switch (browserId) {
|
|
|
|
case "edge":
|
|
|
|
return "sourceNameEdge";
|
|
|
|
case "ie":
|
|
|
|
return "sourceNameIE";
|
|
|
|
case "safari":
|
|
|
|
return "sourceNameSafari";
|
|
|
|
case "canary":
|
|
|
|
return "sourceNameCanary";
|
|
|
|
case "chrome":
|
|
|
|
return "sourceNameChrome";
|
2018-03-01 14:03:06 +00:00
|
|
|
case "chrome-beta":
|
|
|
|
return "sourceNameChromeBeta";
|
|
|
|
case "chrome-dev":
|
|
|
|
return "sourceNameChromeDev";
|
2016-07-26 11:48:37 +00:00
|
|
|
case "chromium":
|
|
|
|
return "sourceNameChromium";
|
|
|
|
case "firefox":
|
|
|
|
return "sourceNameFirefox";
|
|
|
|
case "360se":
|
|
|
|
return "sourceName360se";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
getBrowserName(browserId) {
|
|
|
|
let prop = this._getLocalePropertyForBrowser(browserId);
|
|
|
|
if (prop) {
|
|
|
|
return this.getLocalizedString(prop);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2012-03-21 19:20:47 +00:00
|
|
|
/**
|
|
|
|
* Helper for creating a folder for imported bookmarks from a particular
|
|
|
|
* migration source. The folder is created at the end of the given folder.
|
|
|
|
*
|
2015-04-20 14:32:49 +00:00
|
|
|
* @param sourceNameStr
|
2012-03-21 19:20:47 +00:00
|
|
|
* the source name (first letter capitalized). This is used
|
|
|
|
* for reading the localized source name from the migration
|
|
|
|
* bundle (e.g. if aSourceNameStr is Mosaic, this will try to read
|
|
|
|
* sourceNameMosaic from the migration bundle).
|
2015-04-20 14:32:49 +00:00
|
|
|
* @param parentGuid
|
|
|
|
* the GUID of the folder in which the new folder should be created.
|
|
|
|
* @return the GUID of the new folder.
|
2012-03-21 19:20:47 +00:00
|
|
|
*/
|
2017-05-12 12:42:39 +00:00
|
|
|
async createImportedBookmarksFolder(sourceNameStr, parentGuid) {
|
2015-04-20 14:32:49 +00:00
|
|
|
let source = this.getLocalizedString("sourceName" + sourceNameStr);
|
|
|
|
let title = this.getLocalizedString("importedBookmarksFolder", [source]);
|
2017-05-12 12:42:39 +00:00
|
|
|
return (await PlacesUtils.bookmarks.insert({
|
2018-01-22 23:22:35 +00:00
|
|
|
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
|
|
|
parentGuid,
|
|
|
|
title,
|
2015-04-20 14:32:49 +00:00
|
|
|
})).guid;
|
2017-05-12 12:42:39 +00:00
|
|
|
},
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2016-10-03 15:17:06 +00:00
|
|
|
/**
|
|
|
|
* Get all the rows corresponding to a select query from a database, without
|
|
|
|
* requiring a lock on the database. If fetching data fails (because someone
|
|
|
|
* else tried to write to the DB at the same time, for example), we will
|
|
|
|
* retry the fetch after a 100ms timeout, up to 10 times.
|
|
|
|
*
|
|
|
|
* @param path
|
|
|
|
* the file path to the database we want to open.
|
|
|
|
* @param description
|
|
|
|
* a developer-readable string identifying what kind of database we're
|
|
|
|
* trying to open.
|
|
|
|
* @param selectQuery
|
|
|
|
* the SELECT query to use to fetch the rows.
|
|
|
|
*
|
|
|
|
* @return a promise that resolves to an array of rows. The promise will be
|
|
|
|
* rejected if the read/fetch failed even after retrying.
|
|
|
|
*/
|
|
|
|
getRowsFromDBWithoutLocks(path, description, selectQuery) {
|
|
|
|
let dbOptions = {
|
|
|
|
readOnly: true,
|
|
|
|
ignoreLockingMode: true,
|
|
|
|
path,
|
|
|
|
};
|
|
|
|
|
|
|
|
const RETRYLIMIT = 10;
|
|
|
|
const RETRYINTERVAL = 100;
|
2017-05-12 12:42:39 +00:00
|
|
|
return (async function innerGetRows() {
|
2016-10-03 15:17:06 +00:00
|
|
|
let rows = null;
|
|
|
|
for (let retryCount = RETRYLIMIT; retryCount && !rows; retryCount--) {
|
|
|
|
// Attempt to get the rows. If this succeeds, we will bail out of the loop,
|
|
|
|
// close the database in a failsafe way, and pass the rows back.
|
|
|
|
// If fetching the rows throws, we will wait RETRYINTERVAL ms
|
|
|
|
// and try again. This will repeat a maximum of RETRYLIMIT times.
|
|
|
|
let db;
|
|
|
|
let didOpen = false;
|
|
|
|
let exceptionSeen;
|
|
|
|
try {
|
2017-05-12 12:42:39 +00:00
|
|
|
db = await Sqlite.openConnection(dbOptions);
|
2016-10-03 15:17:06 +00:00
|
|
|
didOpen = true;
|
2017-05-12 12:42:39 +00:00
|
|
|
rows = await db.execute(selectQuery);
|
2016-10-03 15:17:06 +00:00
|
|
|
} catch (ex) {
|
|
|
|
if (!exceptionSeen) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
|
|
|
exceptionSeen = ex;
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (didOpen) {
|
2017-05-12 12:42:39 +00:00
|
|
|
await db.close();
|
2016-10-03 15:17:06 +00:00
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
}
|
|
|
|
if (exceptionSeen) {
|
2017-05-12 12:42:39 +00:00
|
|
|
await new Promise(resolve => setTimeout(resolve, RETRYINTERVAL));
|
2016-10-03 15:17:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!rows) {
|
|
|
|
throw new Error(
|
|
|
|
"Couldn't get rows from the " + description + " database."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return rows;
|
2017-05-12 12:42:39 +00:00
|
|
|
})();
|
2016-10-03 15:17:06 +00:00
|
|
|
},
|
|
|
|
|
2015-04-08 18:49:47 +00:00
|
|
|
get _migrators() {
|
2016-10-18 15:03:06 +00:00
|
|
|
if (!gMigrators) {
|
|
|
|
gMigrators = new Map();
|
|
|
|
}
|
|
|
|
return gMigrators;
|
2015-04-08 18:49:47 +00:00
|
|
|
},
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2018-02-15 19:55:10 +00:00
|
|
|
forceExitSpinResolve: function MU_forceExitSpinResolve() {
|
|
|
|
gForceExitSpinResolve = true;
|
|
|
|
},
|
|
|
|
|
2018-01-12 17:06:21 +00:00
|
|
|
spinResolve: function MU_spinResolve(promise) {
|
|
|
|
if (!(promise instanceof Promise)) {
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
let done = false;
|
|
|
|
let result = null;
|
|
|
|
let error = null;
|
2018-02-15 19:55:10 +00:00
|
|
|
gForceExitSpinResolve = false;
|
2018-01-12 17:06:21 +00:00
|
|
|
promise
|
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
})
|
|
|
|
.then(r => {
|
|
|
|
result = r;
|
|
|
|
done = true;
|
|
|
|
});
|
|
|
|
|
2018-02-15 19:55:10 +00:00
|
|
|
Services.tm.spinEventLoopUntil(() => done || gForceExitSpinResolve);
|
|
|
|
if (!done) {
|
|
|
|
throw new Error("Forcefully exited event loop.");
|
|
|
|
} else if (error) {
|
2018-01-12 17:06:21 +00:00
|
|
|
throw error;
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-21 19:20:47 +00:00
|
|
|
/*
|
|
|
|
* Returns the migrator for the given source, if any data is available
|
|
|
|
* for this source, or null otherwise.
|
|
|
|
*
|
|
|
|
* @param aKey internal name of the migration source.
|
|
|
|
* Supported values: ie (windows),
|
2015-08-19 16:41:30 +00:00
|
|
|
* edge (windows),
|
2016-08-23 21:49:39 +00:00
|
|
|
* safari (mac),
|
2015-08-06 07:02:22 +00:00
|
|
|
* canary (mac/windows),
|
2012-06-14 10:42:15 +00:00
|
|
|
* chrome (mac/windows/linux),
|
2015-08-06 07:02:22 +00:00
|
|
|
* chromium (mac/windows/linux),
|
2015-05-13 10:00:55 +00:00
|
|
|
* 360se (windows),
|
2012-06-14 10:42:15 +00:00
|
|
|
* firefox.
|
2012-03-21 19:20:47 +00:00
|
|
|
*
|
|
|
|
* If null is returned, either no data can be imported
|
|
|
|
* for the given migrator, or aMigratorKey is invalid (e.g. ie on mac,
|
|
|
|
* or mosaic everywhere). This method should be used rather than direct
|
|
|
|
* getService for future compatibility (see bug 718280).
|
|
|
|
*
|
|
|
|
* @return profile migrator implementing nsIBrowserProfileMigrator, if it can
|
|
|
|
* import any data, null otherwise.
|
|
|
|
*/
|
2018-01-12 17:06:21 +00:00
|
|
|
getMigrator: async function MU_getMigrator(aKey) {
|
2012-03-21 19:20:47 +00:00
|
|
|
let migrator = null;
|
|
|
|
if (this._migrators.has(aKey)) {
|
|
|
|
migrator = this._migrators.get(aKey);
|
2016-12-31 02:47:25 +00:00
|
|
|
} else {
|
2012-03-21 19:20:47 +00:00
|
|
|
try {
|
|
|
|
migrator = Cc[
|
|
|
|
"@mozilla.org/profile/migrator;1?app=browser&type=" + aKey
|
|
|
|
].createInstance(Ci.nsIBrowserProfileMigrator);
|
2017-05-28 18:57:46 +00:00
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
2012-03-21 19:20:47 +00:00
|
|
|
this._migrators.set(aKey, migrator);
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:53:10 +00:00
|
|
|
try {
|
2018-01-12 17:06:21 +00:00
|
|
|
return migrator && (await migrator.isSourceAvailable()) ? migrator : null;
|
2017-05-28 18:57:46 +00:00
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
return null;
|
|
|
|
}
|
2012-03-21 19:20:47 +00:00
|
|
|
},
|
|
|
|
|
2016-05-24 10:44:49 +00:00
|
|
|
/**
|
|
|
|
* Figure out what is the default browser, and if there is a migrator
|
|
|
|
* for it, return that migrator's internal name.
|
|
|
|
* For the time being, the "internal name" of a migrator is its contract-id
|
|
|
|
* trailer (e.g. ie for @mozilla.org/profile/migrator;1?app=browser&type=ie),
|
|
|
|
* but it will soon be exposed properly.
|
|
|
|
*/
|
|
|
|
getMigratorKeyForDefaultBrowser() {
|
|
|
|
// Canary uses the same description as Chrome so we can't distinguish them.
|
|
|
|
const APP_DESC_TO_KEY = {
|
|
|
|
"Internet Explorer": "ie",
|
2016-06-29 18:37:48 +00:00
|
|
|
"Microsoft Edge": "edge",
|
2016-05-24 10:44:49 +00:00
|
|
|
Safari: "safari",
|
|
|
|
Firefox: "firefox",
|
2016-11-01 11:57:30 +00:00
|
|
|
Nightly: "firefox",
|
2016-05-24 10:44:49 +00:00
|
|
|
"Google Chrome": "chrome", // Windows, Linux
|
|
|
|
Chrome: "chrome", // OS X
|
|
|
|
Chromium: "chromium", // Windows, OS X
|
|
|
|
"Chromium Web Browser": "chromium", // Linux
|
|
|
|
"360\u5b89\u5168\u6d4f\u89c8\u5668": "360se",
|
|
|
|
};
|
|
|
|
|
2016-09-23 15:27:20 +00:00
|
|
|
let key = "";
|
2016-05-24 10:44:49 +00:00
|
|
|
try {
|
2016-10-18 15:03:06 +00:00
|
|
|
let browserDesc = Cc["@mozilla.org/uriloader/external-protocol-service;1"]
|
|
|
|
.getService(Ci.nsIExternalProtocolService)
|
|
|
|
.getApplicationDescription("http");
|
2016-09-23 15:27:20 +00:00
|
|
|
key = APP_DESC_TO_KEY[browserDesc] || "";
|
2016-11-01 11:57:30 +00:00
|
|
|
// Handle devedition, as well as "FirefoxNightly" on OS X.
|
|
|
|
if (!key && browserDesc.startsWith("Firefox")) {
|
|
|
|
key = "firefox";
|
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (ex) {
|
2016-05-24 10:44:49 +00:00
|
|
|
Cu.reportError("Could not detect default browser: " + ex);
|
|
|
|
}
|
2016-09-23 15:27:20 +00:00
|
|
|
|
|
|
|
// "firefox" is the least useful entry here, and might just be because we've set
|
|
|
|
// ourselves as the default (on Windows 7 and below). In that case, check if we
|
|
|
|
// have a registry key that tells us where to go:
|
|
|
|
if (
|
|
|
|
key == "firefox" &&
|
|
|
|
AppConstants.isPlatformAndVersionAtMost("win", "6.2")
|
|
|
|
) {
|
Bug 1319816 - fix default browser determination on Windows 7 and below in the automigration case, r=jaws
As noted on the bug, because we call getMigratorKeyForDefaultBrowser() multiple times,
its value no longer reflects the (deleted) registry key for subsequent calls.
While we can fix this for the automigrate case by just passing the default we determined a few
lines earlier (and that seems worth doing to avoid busywork), there are 2 small problems
with this:
1) if the default browser has no data, `migratorKey` won't be set, and so we'll call the same
method again anyway, and the message reported in the error console will be that we can't
migrate from Firefox, when the real problem is that we can't migrate from the original
default browser.
2) there are other callers besides AutoMigrate. Specifically, migration.js also calls this
method.
To deal with these, I've fixed getMigratorKeyForDefaultBrowser() to return the same
registry-based value for its lifetime if we hit the 'the default is firefox, go look for an
earlier default' case.
I've verified that either the s/aMigratorKey/migratorKey/ or the change to
getMigratorKeyForDefaultBrowser() are sufficient to make this work properly in the
automigration case.
While I was here, I also updated one of the error messages to be more explicit.
MozReview-Commit-ID: GeUNTfScMMB
--HG--
extra : rebase_source : 09b4b5fef85c4668bc0931de2c8cf3d1a32e2b42
2016-11-23 16:06:00 +00:00
|
|
|
// Because we remove the registry key, reading the registry key only works once.
|
|
|
|
// We save the value for subsequent calls to avoid hard-to-trace bugs when multiple
|
|
|
|
// consumers ask for this key.
|
|
|
|
if (gPreviousDefaultBrowserKey) {
|
|
|
|
key = gPreviousDefaultBrowserKey;
|
|
|
|
} else {
|
|
|
|
// We didn't have a saved value, so check the registry.
|
|
|
|
const kRegPath = "Software\\Mozilla\\Firefox";
|
|
|
|
let oldDefault = WindowsRegistry.readRegKey(
|
|
|
|
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
|
|
|
|
kRegPath,
|
|
|
|
"OldDefaultBrowserCommand"
|
|
|
|
);
|
|
|
|
if (oldDefault) {
|
|
|
|
// Remove the key:
|
|
|
|
WindowsRegistry.removeRegKey(
|
|
|
|
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
|
|
|
|
kRegPath,
|
|
|
|
"OldDefaultBrowserCommand"
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
let file = Cc["@mozilla.org/file/local;1"].createInstance(
|
|
|
|
Ci.nsILocalFileWin
|
|
|
|
);
|
|
|
|
file.initWithCommandLine(oldDefault);
|
|
|
|
key =
|
|
|
|
APP_DESC_TO_KEY[file.getVersionInfoField("FileDescription")] ||
|
|
|
|
key;
|
|
|
|
// Save the value for future callers.
|
|
|
|
gPreviousDefaultBrowserKey = key;
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(
|
|
|
|
"Could not convert old default browser value to description."
|
|
|
|
);
|
|
|
|
}
|
2016-09-23 15:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return key;
|
2016-05-24 10:44:49 +00:00
|
|
|
},
|
|
|
|
|
2012-03-21 19:20:47 +00:00
|
|
|
// Whether or not we're in the process of startup migration
|
2015-09-23 09:36:21 +00:00
|
|
|
get isStartupMigration() {
|
|
|
|
return gProfileStartup != null;
|
|
|
|
},
|
2012-03-21 19:20:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* In the case of startup migration, this is set to the nsIProfileStartup
|
|
|
|
* instance passed to ProfileMigrator's migrate.
|
|
|
|
*
|
|
|
|
* @see showMigrationWizard
|
|
|
|
*/
|
2015-09-23 09:36:21 +00:00
|
|
|
get profileStartup() {
|
|
|
|
return gProfileStartup;
|
|
|
|
},
|
2012-03-21 19:20:47 +00:00
|
|
|
|
|
|
|
/**
|
2012-05-28 09:43:59 +00:00
|
|
|
* Show the migration wizard. On mac, this may just focus the wizard if it's
|
|
|
|
* already running, in which case aOpener and aParams are ignored.
|
2012-03-21 19:20:47 +00:00
|
|
|
*
|
2015-10-07 12:34:46 +00:00
|
|
|
* @param {Window} [aOpener]
|
|
|
|
* optional; the window that asks to open the wizard.
|
|
|
|
* @param {Array} [aParams]
|
|
|
|
* optional arguments for the migration wizard, in the form of an array
|
2012-05-28 09:43:59 +00:00
|
|
|
* This is passed as-is for the params argument of
|
2015-10-07 12:34:46 +00:00
|
|
|
* nsIWindowWatcher.openWindow. The array elements we expect are, in
|
|
|
|
* order:
|
|
|
|
* - {Number} migration entry point constant (see below)
|
|
|
|
* - {String} source browser identifier
|
|
|
|
* - {nsIBrowserProfileMigrator} actual migrator object
|
|
|
|
* - {Boolean} whether this is a startup migration
|
|
|
|
* - {Boolean} whether to skip the 'source' page
|
2016-05-05 20:38:49 +00:00
|
|
|
* - {String} an identifier for the profile to use when migrating
|
2015-10-07 12:34:46 +00:00
|
|
|
* NB: If you add new consumers, please add a migration entry point
|
|
|
|
* constant below, and specify at least the first element of the array
|
|
|
|
* (the migration entry point for purposes of telemetry).
|
2012-03-21 19:20:47 +00:00
|
|
|
*/
|
2012-05-28 09:43:59 +00:00
|
|
|
showMigrationWizard: function MU_showMigrationWizard(aOpener, aParams) {
|
|
|
|
let features = "chrome,dialog,modal,centerscreen,titlebar,resizable=no";
|
2016-02-08 12:54:38 +00:00
|
|
|
if (AppConstants.platform == "macosx" && !this.isStartupMigration) {
|
2012-03-21 19:20:47 +00:00
|
|
|
let win = Services.wm.getMostRecentWindow("Browser:MigrationWizard");
|
|
|
|
if (win) {
|
|
|
|
win.focus();
|
|
|
|
return;
|
|
|
|
}
|
2012-05-28 09:43:59 +00:00
|
|
|
// On mac, the migration wiazrd should only be modal in the case of
|
|
|
|
// startup-migration.
|
2012-03-21 19:20:47 +00:00
|
|
|
features = "centerscreen,chrome,resizable=no";
|
2012-05-28 09:43:59 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 12:16:15 +00:00
|
|
|
// nsIWindowWatcher doesn't deal with raw arrays, so we convert the input
|
|
|
|
let params;
|
|
|
|
if (Array.isArray(aParams)) {
|
|
|
|
params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
|
|
|
|
for (let item of aParams) {
|
|
|
|
let comtaminatedVal;
|
|
|
|
if (item && item instanceof Ci.nsISupports) {
|
|
|
|
comtaminatedVal = item;
|
|
|
|
} else {
|
|
|
|
switch (typeof item) {
|
|
|
|
case "boolean":
|
|
|
|
comtaminatedVal = Cc[
|
|
|
|
"@mozilla.org/supports-PRBool;1"
|
|
|
|
].createInstance(Ci.nsISupportsPRBool);
|
|
|
|
comtaminatedVal.data = item;
|
|
|
|
break;
|
|
|
|
case "number":
|
|
|
|
comtaminatedVal = Cc[
|
|
|
|
"@mozilla.org/supports-PRUint32;1"
|
|
|
|
].createInstance(Ci.nsISupportsPRUint32);
|
|
|
|
comtaminatedVal.data = item;
|
|
|
|
break;
|
|
|
|
case "string":
|
|
|
|
comtaminatedVal = Cc[
|
|
|
|
"@mozilla.org/supports-cstring;1"
|
|
|
|
].createInstance(Ci.nsISupportsCString);
|
|
|
|
comtaminatedVal.data = item;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "undefined":
|
|
|
|
case "object":
|
|
|
|
if (!item) {
|
|
|
|
comtaminatedVal = null;
|
|
|
|
break;
|
|
|
|
}
|
2016-10-18 15:03:06 +00:00
|
|
|
/* intentionally falling through to error out here for
|
|
|
|
non-null/undefined things: */
|
2015-10-29 12:16:15 +00:00
|
|
|
default:
|
|
|
|
throw new Error(
|
|
|
|
"Unexpected parameter type " + typeof item + ": " + item
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-04-14 19:51:39 +00:00
|
|
|
params.appendElement(comtaminatedVal);
|
2015-10-29 12:16:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
params = aParams;
|
|
|
|
}
|
|
|
|
|
2012-05-28 09:43:59 +00:00
|
|
|
Services.ww.openWindow(
|
|
|
|
aOpener,
|
|
|
|
"chrome://browser/content/migration/migration.xul",
|
|
|
|
"_blank",
|
|
|
|
features,
|
2015-10-29 12:16:15 +00:00
|
|
|
params
|
|
|
|
);
|
2012-05-28 09:43:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the migration wizard for startup-migration. This should only be
|
|
|
|
* called by ProfileMigrator (see ProfileMigrator.js), which implements
|
2018-01-12 17:06:21 +00:00
|
|
|
* nsIProfileMigrator. This runs asynchronously if we are running an
|
|
|
|
* automigration.
|
2012-05-28 09:43:59 +00:00
|
|
|
*
|
|
|
|
* @param aProfileStartup
|
|
|
|
* the nsIProfileStartup instance provided to ProfileMigrator.migrate.
|
|
|
|
* @param [optional] aMigratorKey
|
|
|
|
* If set, the migration wizard will import from the corresponding
|
|
|
|
* migrator, bypassing the source-selection page. Otherwise, the
|
|
|
|
* source-selection page will be displayed, either with the default
|
|
|
|
* browser selected, if it could be detected and if there is a
|
|
|
|
* migrator for it, or with the first option selected as a fallback
|
|
|
|
* (The first option is hardcoded to be the most common browser for
|
|
|
|
* the OS we run on. See migration.xul).
|
2016-05-05 20:38:49 +00:00
|
|
|
* @param [optional] aProfileToMigrate
|
|
|
|
* If set, the migration wizard will import from the profile indicated.
|
2012-05-28 09:43:59 +00:00
|
|
|
* @throws if aMigratorKey is invalid or if it points to a non-existent
|
|
|
|
* source.
|
|
|
|
*/
|
2016-05-05 20:38:49 +00:00
|
|
|
startupMigration: function MU_startupMigrator(
|
|
|
|
aProfileStartup,
|
|
|
|
aMigratorKey,
|
|
|
|
aProfileToMigrate
|
|
|
|
) {
|
2018-10-11 17:04:59 +00:00
|
|
|
this.spinResolve(
|
|
|
|
this.asyncStartupMigration(
|
|
|
|
aProfileStartup,
|
|
|
|
aMigratorKey,
|
|
|
|
aProfileToMigrate
|
2019-07-05 07:53:32 +00:00
|
|
|
)
|
2018-10-11 17:04:59 +00:00
|
|
|
);
|
2018-01-12 17:06:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
asyncStartupMigration: async function MU_asyncStartupMigrator(
|
|
|
|
aProfileStartup,
|
|
|
|
aMigratorKey,
|
|
|
|
aProfileToMigrate
|
|
|
|
) {
|
2012-05-28 09:43:59 +00:00
|
|
|
if (!aProfileStartup) {
|
|
|
|
throw new Error(
|
|
|
|
"an profile-startup instance is required for startup-migration"
|
|
|
|
);
|
2012-03-21 19:20:47 +00:00
|
|
|
}
|
2012-05-28 09:43:59 +00:00
|
|
|
gProfileStartup = aProfileStartup;
|
2012-03-21 19:20:47 +00:00
|
|
|
|
2012-05-28 09:43:59 +00:00
|
|
|
let skipSourcePage = false,
|
|
|
|
migrator = null,
|
|
|
|
migratorKey = "";
|
|
|
|
if (aMigratorKey) {
|
2018-01-12 17:06:21 +00:00
|
|
|
migrator = await this.getMigrator(aMigratorKey);
|
2012-03-21 19:20:47 +00:00
|
|
|
if (!migrator) {
|
2012-05-28 09:43:59 +00:00
|
|
|
// aMigratorKey must point to a valid source, so, if it doesn't
|
|
|
|
// cleanup and throw.
|
|
|
|
this.finishMigration();
|
|
|
|
throw new Error(
|
|
|
|
"startMigration was asked to open auto-migrate from " +
|
|
|
|
"a non-existent source: " +
|
|
|
|
aMigratorKey
|
|
|
|
);
|
2012-03-21 19:20:47 +00:00
|
|
|
}
|
2012-05-28 09:43:59 +00:00
|
|
|
migratorKey = aMigratorKey;
|
|
|
|
skipSourcePage = true;
|
2016-12-31 02:47:25 +00:00
|
|
|
} else {
|
2016-05-24 10:44:49 +00:00
|
|
|
let defaultBrowserKey = this.getMigratorKeyForDefaultBrowser();
|
2012-05-28 09:43:59 +00:00
|
|
|
if (defaultBrowserKey) {
|
2018-01-12 17:06:21 +00:00
|
|
|
migrator = await this.getMigrator(defaultBrowserKey);
|
2012-05-28 09:43:59 +00:00
|
|
|
if (migrator) {
|
|
|
|
migratorKey = defaultBrowserKey;
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2012-03-21 19:20:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-14 10:42:15 +00:00
|
|
|
if (!migrator) {
|
2018-01-12 17:06:21 +00:00
|
|
|
let migrators = await Promise.all(
|
|
|
|
gAvailableMigratorKeys.map(key => this.getMigrator(key))
|
|
|
|
);
|
2012-06-14 10:42:15 +00:00
|
|
|
// If there's no migrator set so far, ensure that there is at least one
|
|
|
|
// migrator available before opening the wizard.
|
2016-02-08 12:54:38 +00:00
|
|
|
// Note that we don't need to check the default browser first, because
|
|
|
|
// if that one existed we would have used it in the block above this one.
|
2018-01-12 17:06:21 +00:00
|
|
|
if (!migrators.some(m => m)) {
|
2016-02-08 12:54:38 +00:00
|
|
|
// None of the keys produced a usable migrator, so finish up here:
|
2012-06-14 10:42:15 +00:00
|
|
|
this.finishMigration();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-01 18:00:53 +00:00
|
|
|
let isRefresh =
|
|
|
|
migrator && skipSourcePage && migratorKey == AppConstants.MOZ_APP_NAME;
|
|
|
|
|
2015-10-07 12:34:46 +00:00
|
|
|
let migrationEntryPoint = this.MIGRATION_ENTRYPOINT_FIRSTRUN;
|
2016-06-01 18:00:53 +00:00
|
|
|
if (isRefresh) {
|
2015-10-07 12:34:46 +00:00
|
|
|
migrationEntryPoint = this.MIGRATION_ENTRYPOINT_FXREFRESH;
|
|
|
|
}
|
2012-05-28 09:43:59 +00:00
|
|
|
|
2015-10-07 12:34:46 +00:00
|
|
|
let params = [
|
|
|
|
migrationEntryPoint,
|
|
|
|
migratorKey,
|
|
|
|
migrator,
|
|
|
|
aProfileStartup,
|
2016-05-05 20:38:49 +00:00
|
|
|
skipSourcePage,
|
|
|
|
aProfileToMigrate,
|
2015-10-07 12:34:46 +00:00
|
|
|
];
|
2012-05-28 09:43:59 +00:00
|
|
|
this.showMigrationWizard(null, params);
|
2012-03-21 19:20:47 +00:00
|
|
|
},
|
|
|
|
|
2016-10-22 13:40:48 +00:00
|
|
|
_importQuantities: {
|
|
|
|
bookmarks: 0,
|
|
|
|
logins: 0,
|
|
|
|
history: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
insertBookmarkWrapper(bookmark) {
|
|
|
|
this._importQuantities.bookmarks++;
|
2016-11-30 11:48:03 +00:00
|
|
|
let insertionPromise = PlacesUtils.bookmarks.insert(bookmark);
|
|
|
|
if (!gKeepUndoData) {
|
|
|
|
return insertionPromise;
|
|
|
|
}
|
|
|
|
// If we keep undo data, add a promise handler that stores the undo data once
|
|
|
|
// the bookmark has been inserted in the DB, and then returns the bookmark.
|
|
|
|
let { parentGuid } = bookmark;
|
|
|
|
return insertionPromise.then(bm => {
|
|
|
|
let { guid, lastModified, type } = bm;
|
|
|
|
gUndoData.get("bookmarks").push({
|
2018-01-22 23:22:35 +00:00
|
|
|
parentGuid,
|
|
|
|
guid,
|
|
|
|
lastModified,
|
|
|
|
type,
|
2016-11-30 11:48:03 +00:00
|
|
|
});
|
|
|
|
return bm;
|
|
|
|
});
|
2016-10-22 13:40:48 +00:00
|
|
|
},
|
|
|
|
|
2017-03-13 23:46:16 +00:00
|
|
|
insertManyBookmarksWrapper(bookmarks, parent) {
|
|
|
|
let insertionPromise = PlacesUtils.bookmarks.insertTree({
|
|
|
|
guid: parent,
|
|
|
|
children: bookmarks,
|
|
|
|
});
|
|
|
|
return insertionPromise.then(
|
|
|
|
insertedItems => {
|
|
|
|
this._importQuantities.bookmarks += insertedItems.length;
|
|
|
|
if (gKeepUndoData) {
|
|
|
|
let bmData = gUndoData.get("bookmarks");
|
|
|
|
for (let bm of insertedItems) {
|
|
|
|
let { parentGuid, guid, lastModified, type } = bm;
|
|
|
|
bmData.push({ parentGuid, guid, lastModified, type });
|
2019-07-05 07:53:32 +00:00
|
|
|
}
|
2017-03-13 23:46:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
ex => Cu.reportError(ex)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2018-03-20 12:36:31 +00:00
|
|
|
insertVisitsWrapper(pageInfos) {
|
2019-01-29 12:06:05 +00:00
|
|
|
let now = new Date();
|
|
|
|
// Ensure that none of the dates are in the future. If they are, rewrite
|
|
|
|
// them to be now. This means we don't loose history entries, but they will
|
|
|
|
// be valid for the history store.
|
|
|
|
for (let pageInfo of pageInfos) {
|
|
|
|
for (let visit of pageInfo.visits) {
|
|
|
|
if (visit.date && visit.date > now) {
|
|
|
|
visit.date = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-20 12:36:31 +00:00
|
|
|
this._importQuantities.history += pageInfos.length;
|
2016-11-30 11:56:25 +00:00
|
|
|
if (gKeepUndoData) {
|
2018-03-20 12:36:31 +00:00
|
|
|
this._updateHistoryUndo(pageInfos);
|
2016-11-30 11:56:25 +00:00
|
|
|
}
|
2018-03-20 12:36:31 +00:00
|
|
|
return PlacesUtils.history.insertMany(pageInfos);
|
2016-10-22 13:40:48 +00:00
|
|
|
},
|
|
|
|
|
2018-01-04 23:10:54 +00:00
|
|
|
async insertLoginsWrapper(logins) {
|
|
|
|
this._importQuantities.logins += logins.length;
|
|
|
|
let inserted = await LoginHelper.maybeImportLogins(logins);
|
|
|
|
// Note that this means that if we import a login that has a newer password
|
|
|
|
// than we know about, we will update the login, and an undo of the import
|
|
|
|
// will not revert this. This seems preferable over removing the login
|
|
|
|
// outright or storing the old password in the undo file.
|
|
|
|
if (gKeepUndoData) {
|
|
|
|
for (let { guid, timePasswordChanged } of inserted) {
|
|
|
|
gUndoData.get("logins").push({ guid, timePasswordChanged });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-30 11:48:03 +00:00
|
|
|
initializeUndoData() {
|
|
|
|
gKeepUndoData = true;
|
2016-11-30 11:56:25 +00:00
|
|
|
gUndoData = new Map([["bookmarks", []], ["visits", []], ["logins", []]]);
|
2016-11-30 11:48:03 +00:00
|
|
|
},
|
|
|
|
|
2017-05-12 12:42:39 +00:00
|
|
|
async _postProcessUndoData(state) {
|
2016-11-30 11:48:03 +00:00
|
|
|
if (!state) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
let bookmarkFolders = state
|
|
|
|
.get("bookmarks")
|
|
|
|
.filter(b => b.type == PlacesUtils.bookmarks.TYPE_FOLDER);
|
|
|
|
|
|
|
|
let bookmarkFolderData = [];
|
|
|
|
let bmPromises = bookmarkFolders.map(({ guid }) => {
|
|
|
|
// Ignore bookmarks where the promise doesn't resolve (ie that are missing)
|
|
|
|
// Also check that the bookmark fetch returns isn't null before adding it.
|
|
|
|
return PlacesUtils.bookmarks
|
|
|
|
.fetch(guid)
|
|
|
|
.then(bm => bm && bookmarkFolderData.push(bm), () => {});
|
|
|
|
});
|
|
|
|
|
2017-05-12 12:42:39 +00:00
|
|
|
await Promise.all(bmPromises);
|
2016-11-30 11:48:03 +00:00
|
|
|
let folderLMMap = new Map(
|
|
|
|
bookmarkFolderData.map(b => [b.guid, b.lastModified])
|
|
|
|
);
|
|
|
|
for (let bookmark of bookmarkFolders) {
|
|
|
|
let lastModified = folderLMMap.get(bookmark.guid);
|
|
|
|
// If the bookmark was deleted, the map will be returning null, so check:
|
|
|
|
if (lastModified) {
|
|
|
|
bookmark.lastModified = lastModified;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state;
|
2017-05-12 12:42:39 +00:00
|
|
|
},
|
2016-11-30 11:48:03 +00:00
|
|
|
|
|
|
|
stopAndRetrieveUndoData() {
|
|
|
|
let undoData = gUndoData;
|
|
|
|
gUndoData = null;
|
|
|
|
gKeepUndoData = false;
|
|
|
|
return this._postProcessUndoData(undoData);
|
|
|
|
},
|
|
|
|
|
2018-03-20 12:36:31 +00:00
|
|
|
_updateHistoryUndo(pageInfos) {
|
2016-11-30 11:56:25 +00:00
|
|
|
let visits = gUndoData.get("visits");
|
|
|
|
let visitMap = new Map(visits.map(v => [v.url, v]));
|
2018-03-20 12:36:31 +00:00
|
|
|
for (let pageInfo of pageInfos) {
|
|
|
|
let visitCount = pageInfo.visits.length;
|
2017-02-20 16:06:27 +00:00
|
|
|
let first, last;
|
|
|
|
if (visitCount > 1) {
|
2018-03-20 12:36:31 +00:00
|
|
|
let dates = pageInfo.visits.map(v => v.date);
|
|
|
|
first = Math.min.apply(Math, dates);
|
|
|
|
last = Math.max.apply(Math, dates);
|
2017-02-20 16:06:27 +00:00
|
|
|
} else {
|
2018-03-20 12:36:31 +00:00
|
|
|
first = last = pageInfo.visits[0].date;
|
2017-02-20 16:06:27 +00:00
|
|
|
}
|
2018-03-20 12:36:31 +00:00
|
|
|
let url = pageInfo.url;
|
|
|
|
if (url instanceof Ci.nsIURI) {
|
|
|
|
url = pageInfo.url.spec;
|
|
|
|
} else if (typeof url != "string") {
|
|
|
|
pageInfo.url.href;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:56:25 +00:00
|
|
|
try {
|
|
|
|
new URL(url);
|
|
|
|
} catch (ex) {
|
|
|
|
// This won't save and we won't need to 'undo' it, so ignore this URL.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!visitMap.has(url)) {
|
|
|
|
visitMap.set(url, { url, visitCount, first, last });
|
|
|
|
} else {
|
|
|
|
let currentData = visitMap.get(url);
|
|
|
|
currentData.visitCount += visitCount;
|
|
|
|
currentData.first = Math.min(currentData.first, first);
|
|
|
|
currentData.last = Math.max(currentData.last, last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gUndoData.set("visits", Array.from(visitMap.values()));
|
|
|
|
},
|
|
|
|
|
2012-03-21 19:20:47 +00:00
|
|
|
/**
|
|
|
|
* Cleans up references to migrators and nsIProfileInstance instances.
|
|
|
|
*/
|
|
|
|
finishMigration: function MU_finishMigration() {
|
|
|
|
gMigrators = null;
|
|
|
|
gProfileStartup = null;
|
2012-04-14 09:50:44 +00:00
|
|
|
gMigrationBundle = null;
|
2015-10-07 12:34:46 +00:00
|
|
|
},
|
|
|
|
|
2016-06-01 18:00:53 +00:00
|
|
|
gAvailableMigratorKeys,
|
|
|
|
|
2015-10-07 12:34:46 +00:00
|
|
|
MIGRATION_ENTRYPOINT_UNKNOWN: 0,
|
|
|
|
MIGRATION_ENTRYPOINT_FIRSTRUN: 1,
|
|
|
|
MIGRATION_ENTRYPOINT_FXREFRESH: 2,
|
|
|
|
MIGRATION_ENTRYPOINT_PLACES: 3,
|
|
|
|
MIGRATION_ENTRYPOINT_PASSWORDS: 4,
|
2017-05-24 08:56:00 +00:00
|
|
|
MIGRATION_ENTRYPOINT_NEWTAB: 5,
|
2019-03-04 23:29:03 +00:00
|
|
|
MIGRATION_ENTRYPOINT_FILE_MENU: 6,
|
2015-10-07 12:34:46 +00:00
|
|
|
|
|
|
|
_sourceNameToIdMapping: {
|
|
|
|
nothing: 1,
|
|
|
|
firefox: 2,
|
|
|
|
edge: 3,
|
|
|
|
ie: 4,
|
|
|
|
chrome: 5,
|
|
|
|
chromium: 6,
|
|
|
|
canary: 7,
|
|
|
|
safari: 8,
|
|
|
|
"360se": 9,
|
|
|
|
},
|
|
|
|
getSourceIdForTelemetry(sourceName) {
|
|
|
|
return this._sourceNameToIdMapping[sourceName] || 0;
|
|
|
|
},
|
2012-03-21 19:20:47 +00:00
|
|
|
});
|