Bug 718280 - Part 1: Move resource type constants into MigrationUtils. r=NeilDeakin
Differential Revision: https://phabricator.services.mozilla.com/D164138
This commit is contained in:
@@ -42,13 +42,15 @@ function getL10n() {
|
||||
*/
|
||||
class MigrationUtils {
|
||||
resourceTypes = Object.freeze({
|
||||
COOKIES: Ci.nsIBrowserProfileMigrator.COOKIES,
|
||||
HISTORY: Ci.nsIBrowserProfileMigrator.HISTORY,
|
||||
FORMDATA: Ci.nsIBrowserProfileMigrator.FORMDATA,
|
||||
PASSWORDS: Ci.nsIBrowserProfileMigrator.PASSWORDS,
|
||||
BOOKMARKS: Ci.nsIBrowserProfileMigrator.BOOKMARKS,
|
||||
OTHERDATA: Ci.nsIBrowserProfileMigrator.OTHERDATA,
|
||||
SESSION: Ci.nsIBrowserProfileMigrator.SESSION,
|
||||
ALL: 0x0000,
|
||||
/* 0x01 used to be used for settings, but was removed. */
|
||||
COOKIES: 0x0002,
|
||||
HISTORY: 0x0004,
|
||||
FORMDATA: 0x0008,
|
||||
PASSWORDS: 0x0010,
|
||||
BOOKMARKS: 0x0020,
|
||||
OTHERDATA: 0x0040,
|
||||
SESSION: 0x0080,
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||
* A resource returned by a subclass of MigratorBase that can migrate
|
||||
* data to this browser.
|
||||
* @property {number} type
|
||||
* A bitfield with bits from nsIBrowserProfileMigrator flipped to indicate
|
||||
* A bitfield with bits from MigrationUtils.resourceTypes flipped to indicate
|
||||
* what this resource represents. A resource can represent one or more types
|
||||
* of data, for example HISTORY and FORMDATA.
|
||||
* @property {Function} migrate
|
||||
@@ -76,8 +76,8 @@ export class MigratorBase {
|
||||
* profiles.
|
||||
*
|
||||
* Each migration resource should provide:
|
||||
* - a |type| getter, returning any of the migration types (see
|
||||
* nsIBrowserProfileMigrator).
|
||||
* - a |type| getter, returning any of the migration resource types (see
|
||||
* MigrationUtils.resourceTypes).
|
||||
*
|
||||
* - a |migrate| method, taking a single argument, aCallback(bool success),
|
||||
* for migrating the data for this resource. It may do its job
|
||||
@@ -88,7 +88,7 @@ export class MigratorBase {
|
||||
* 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
|
||||
* For each migration type listed in MigrationUtils.resourceTypes, 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"
|
||||
@@ -198,8 +198,10 @@ export class MigratorBase {
|
||||
*
|
||||
* See nsIBrowserProfileMigrator.
|
||||
*
|
||||
* @see MigrationUtils
|
||||
*
|
||||
* @param {number} aItems
|
||||
* A bitfield with bits from nsIBrowserProfileMigrator flipped to indicate
|
||||
* A bitfield with bits from MigrationUtils.resourceTypes flipped to indicate
|
||||
* what types of resources should be migrated.
|
||||
* @param {boolean} aStartup
|
||||
* True if this migration is occurring during startup.
|
||||
@@ -212,7 +214,7 @@ export class MigratorBase {
|
||||
throw new Error("migrate called for a non-existent source");
|
||||
}
|
||||
|
||||
if (aItems != Ci.nsIBrowserProfileMigrator.ALL) {
|
||||
if (aItems != lazy.MigrationUtils.resourceTypes.ALL) {
|
||||
resources = resources.filter(r => aItems & r.type);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ const kDataToStringMap = new Map([
|
||||
var MigrationWizard = {
|
||||
/* exported MigrationWizard */
|
||||
_source: "", // Source Profile Migrator ContractID suffix
|
||||
_itemsFlags: kIMig.ALL, // Selected Import Data Sources (16-bit bitfield)
|
||||
_itemsFlags: MigrationUtils.resourceTypes.ALL, // Selected Import Data Sources (16-bit bitfield)
|
||||
_selectedProfile: null, // Selected Profile name to import from
|
||||
_wiz: null,
|
||||
_migrator: null,
|
||||
@@ -265,7 +265,7 @@ var MigrationWizard = {
|
||||
// Create the migrator for the selected source.
|
||||
this._migrator = this.spinResolve(MigrationUtils.getMigrator(newSource));
|
||||
|
||||
this._itemsFlags = kIMig.ALL;
|
||||
this._itemsFlags = MigrationUtils.resourceTypes.ALL;
|
||||
this._selectedProfile = null;
|
||||
}
|
||||
this._source = newSource;
|
||||
@@ -355,7 +355,7 @@ var MigrationWizard = {
|
||||
);
|
||||
|
||||
for (let itemType of kDataToStringMap.keys()) {
|
||||
let itemValue = Ci.nsIBrowserProfileMigrator[itemType.toUpperCase()];
|
||||
let itemValue = MigrationUtils.resourceTypes[itemType.toUpperCase()];
|
||||
if (items & itemValue) {
|
||||
let checkbox = document.createXULElement("checkbox");
|
||||
checkbox.id = itemValue;
|
||||
@@ -422,8 +422,8 @@ var MigrationWizard = {
|
||||
if (
|
||||
this._source == "safari" &&
|
||||
AppConstants.isPlatformAndVersionAtLeast("macosx", "18") &&
|
||||
(this._itemsFlags & Ci.nsIBrowserProfileMigrator.BOOKMARKS ||
|
||||
this._itemsFlags == Ci.nsIBrowserProfileMigrator.ALL)
|
||||
(this._itemsFlags & MigrationUtils.resourceTypes.BOOKMARKS ||
|
||||
this._itemsFlags == MigrationUtils.resourceTypes.ALL)
|
||||
) {
|
||||
let migrator = this._migrator.wrappedJSObject;
|
||||
let havePermissions = this.spinResolve(migrator.hasPermissions());
|
||||
@@ -505,7 +505,7 @@ var MigrationWizard = {
|
||||
}
|
||||
|
||||
for (let itemType of kDataToStringMap.keys()) {
|
||||
let itemValue = Ci.nsIBrowserProfileMigrator[itemType.toUpperCase()];
|
||||
let itemValue = MigrationUtils.resourceTypes[itemType.toUpperCase()];
|
||||
if (this._itemsFlags & itemValue) {
|
||||
var label = document.createXULElement("label");
|
||||
label.id = itemValue + "_migrated";
|
||||
@@ -567,22 +567,22 @@ var MigrationWizard = {
|
||||
let type = "undefined";
|
||||
let numericType = parseInt(aData);
|
||||
switch (numericType) {
|
||||
case Ci.nsIBrowserProfileMigrator.COOKIES:
|
||||
case MigrationUtils.resourceTypes.COOKIES:
|
||||
type = "cookies";
|
||||
break;
|
||||
case Ci.nsIBrowserProfileMigrator.HISTORY:
|
||||
case MigrationUtils.resourceTypes.HISTORY:
|
||||
type = "history";
|
||||
break;
|
||||
case Ci.nsIBrowserProfileMigrator.FORMDATA:
|
||||
case MigrationUtils.resourceTypes.FORMDATA:
|
||||
type = "form data";
|
||||
break;
|
||||
case Ci.nsIBrowserProfileMigrator.PASSWORDS:
|
||||
case MigrationUtils.resourceTypes.PASSWORDS:
|
||||
type = "passwords";
|
||||
break;
|
||||
case Ci.nsIBrowserProfileMigrator.BOOKMARKS:
|
||||
case MigrationUtils.resourceTypes.BOOKMARKS:
|
||||
type = "bookmarks";
|
||||
break;
|
||||
case Ci.nsIBrowserProfileMigrator.OTHERDATA:
|
||||
case MigrationUtils.resourceTypes.OTHERDATA:
|
||||
type = "misc. data";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -11,19 +11,6 @@ interface nsIProfileStartup;
|
||||
[scriptable, uuid(22b56ffc-3149-43c5-b5a9-b3a6b678de93)]
|
||||
interface nsIBrowserProfileMigrator : nsISupports
|
||||
{
|
||||
/**
|
||||
* profile items to migrate. use with migrate().
|
||||
*/
|
||||
const unsigned short ALL = 0x0000;
|
||||
/* 0x01 used to be used for settings, but was removed. */
|
||||
const unsigned short COOKIES = 0x0002;
|
||||
const unsigned short HISTORY = 0x0004;
|
||||
const unsigned short FORMDATA = 0x0008;
|
||||
const unsigned short PASSWORDS = 0x0010;
|
||||
const unsigned short BOOKMARKS = 0x0020;
|
||||
const unsigned short OTHERDATA = 0x0040;
|
||||
const unsigned short SESSION = 0x0080;
|
||||
|
||||
/**
|
||||
* Copy user profile information to the current active profile.
|
||||
* @param aItems list of data items to migrate. see above for values.
|
||||
|
||||
@@ -1870,7 +1870,7 @@ export var PlacesUIUtils = {
|
||||
// Otherwise, wait for a successful migration:
|
||||
let obs = (subject, topic, data) => {
|
||||
if (
|
||||
data == Ci.nsIBrowserProfileMigrator.BOOKMARKS &&
|
||||
data == lazy.MigrationUtils.resourceTypes.BOOKMARKS &&
|
||||
lazy.MigrationUtils.getImportedCount("bookmarks") > 0
|
||||
) {
|
||||
lazy.CustomizableUI.removeWidgetFromArea("import-button");
|
||||
|
||||
@@ -80,7 +80,7 @@ add_task(async function test_bookmark_import_button_removal() {
|
||||
Services.obs.notifyObservers(
|
||||
null,
|
||||
"Migration:ItemAfterMigrate",
|
||||
Ci.nsIBrowserProfileMigrator.BOOKMARKS
|
||||
MigrationUtils.resourceTypes.BOOKMARKS
|
||||
);
|
||||
|
||||
is(
|
||||
@@ -95,7 +95,7 @@ add_task(async function test_bookmark_import_button_removal() {
|
||||
Services.obs.notifyObservers(
|
||||
null,
|
||||
"Migration:ItemAfterMigrate",
|
||||
Ci.nsIBrowserProfileMigrator.BOOKMARKS
|
||||
MigrationUtils.resourceTypes.BOOKMARKS
|
||||
);
|
||||
|
||||
is(Services.prefs.prefHasUserValue(kPref), false, "Pref should be removed.");
|
||||
@@ -159,7 +159,7 @@ add_task(async function test_bookmark_import_button_errors() {
|
||||
Services.obs.notifyObservers(
|
||||
null,
|
||||
"Migration:ItemError",
|
||||
Ci.nsIBrowserProfileMigrator.BOOKMARKS
|
||||
MigrationUtils.resourceTypes.BOOKMARKS
|
||||
);
|
||||
|
||||
is(
|
||||
@@ -174,7 +174,7 @@ add_task(async function test_bookmark_import_button_errors() {
|
||||
Services.obs.notifyObservers(
|
||||
null,
|
||||
"Migration:ItemError",
|
||||
Ci.nsIBrowserProfileMigrator.BOOKMARKS
|
||||
MigrationUtils.resourceTypes.BOOKMARKS
|
||||
);
|
||||
|
||||
is(Services.prefs.prefHasUserValue(kPref), false, "Pref should be removed.");
|
||||
|
||||
Reference in New Issue
Block a user