[NAVIGATOR] Remove Migration

custom-2020
Matt A. Tobin 4 years ago committed by Roy Tam
parent 6cbfab7161
commit 2d64bbe1f7
  1. 1
      navigator/components/build/moz.build
  2. 7
      navigator/components/build/nsModule.cpp
  3. 2
      navigator/components/migration/SuiteProfileMigrator.manifest
  4. 418
      navigator/components/migration/content/migration.js
  5. 96
      navigator/components/migration/content/migration.xul
  6. 7
      navigator/components/migration/jar.mn
  7. 28
      navigator/components/migration/moz.build
  8. 77
      navigator/components/migration/public/nsISuiteProfileMigrator.idl
  9. 135
      navigator/components/migration/src/SuiteProfileMigrator.js
  10. 1030
      navigator/components/migration/src/nsNetscapeProfileMigratorBase.cpp
  11. 162
      navigator/components/migration/src/nsNetscapeProfileMigratorBase.h
  12. 190
      navigator/components/migration/src/nsSuiteProfileMigratorUtils.cpp
  13. 81
      navigator/components/migration/src/nsSuiteProfileMigratorUtils.h
  14. 600
      navigator/components/migration/src/nsThunderbirdProfileMigrator.cpp
  15. 48
      navigator/components/migration/src/nsThunderbirdProfileMigrator.h
  16. 1
      navigator/components/moz.build
  17. 28
      navigator/locales/en-US/chrome/common/migration/migration.dtd
  18. 52
      navigator/locales/en-US/chrome/common/migration/migration.properties
  19. 2
      navigator/locales/jar.mn

@ -12,7 +12,6 @@ XPCOMBinaryComponent('navigator')
LOCAL_INCLUDES += [
'../dirprovider/src',
'../feeds/src',
'../migration/src',
'../shell/src',
]

@ -5,7 +5,6 @@
#include "mozilla/ModuleUtils.h"
#include "nsSuiteDirectoryProvider.h"
#include "nsThunderbirdProfileMigrator.h"
#include "nsNetCID.h"
#include "nsRDFCID.h"
#include "nsFeedSniffer.h"
@ -18,8 +17,6 @@
#include "nsGNOMEShellService.h"
#endif
#define NS_SUITEPROFILEMIGRATOR_CONTRACTID_PREFIX "@mozilla.org/profile/migrator;1?app=suite&type="
/////////////////////////////////////////////////////////////////////////////
#if defined(XP_WIN)
@ -30,7 +27,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacShellService)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGNOMEShellService, Init)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSuiteDirectoryProvider)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsThunderbirdProfileMigrator)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFeedSniffer)
#if defined(NS_SUITEWININTEGRATION_CID)
@ -41,7 +37,6 @@ NS_DEFINE_NAMED_CID(NS_SUITEMACINTEGRATION_CID);
NS_DEFINE_NAMED_CID(NS_SUITEGNOMEINTEGRATION_CID);
#endif
NS_DEFINE_NAMED_CID(NS_SUITEDIRECTORYPROVIDER_CID);
NS_DEFINE_NAMED_CID(NS_THUNDERBIRDPROFILEMIGRATOR_CID);
NS_DEFINE_NAMED_CID(NS_FEEDSNIFFER_CID);
/////////////////////////////////////////////////////////////////////////////
@ -55,7 +50,6 @@ static const mozilla::Module::CIDEntry kSuiteCIDs[] = {
{ &kNS_SUITEGNOMEINTEGRATION_CID, false, NULL, nsGNOMEShellServiceConstructor },
#endif
{ &kNS_SUITEDIRECTORYPROVIDER_CID, false, NULL, nsSuiteDirectoryProviderConstructor },
{ &kNS_THUNDERBIRDPROFILEMIGRATOR_CID, false, NULL, nsThunderbirdProfileMigratorConstructor },
{ &kNS_FEEDSNIFFER_CID, false, NULL, nsFeedSnifferConstructor },
{ NULL }
};
@ -69,7 +63,6 @@ static const mozilla::Module::ContractIDEntry kSuiteContracts[] = {
{ NS_SUITESHELLSERVICE_CONTRACTID, &kNS_SUITEGNOMEINTEGRATION_CID },
#endif
{ NS_SUITEDIRECTORYPROVIDER_CONTRACTID, &kNS_SUITEDIRECTORYPROVIDER_CID },
{ NS_SUITEPROFILEMIGRATOR_CONTRACTID_PREFIX "thunderbird", &kNS_THUNDERBIRDPROFILEMIGRATOR_CID },
{ NS_FEEDSNIFFER_CONTRACTID, &kNS_FEEDSNIFFER_CID },
{ NULL }
};

@ -1,2 +0,0 @@
component {d5148b7c-ba4e-4f7a-a80b-1ae48b90b910} SuiteProfileMigrator.js
contract @mozilla.org/toolkit/profile-migrator;1 {d5148b7c-ba4e-4f7a-a80b-1ae48b90b910}

@ -1,418 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
Components.utils.import("resource://gre/modules/Services.jsm");
const nsISuiteProfileMigrator = Components.interfaces.nsISuiteProfileMigrator;
const nsIProfileStartup = Components.interfaces.nsIProfileStartup;
const nsISupportsString = Components.interfaces.nsISupportsString;
const NS_PROFILE_MIGRATOR_CONTRACTID = "@mozilla.org/profile/migrator;1?app=suite&type=";
var MigrationWizard = {
_source: "", // Source Profile Migrator ContractID suffix
_itemsFlags: nsISuiteProfileMigrator.ALL, // Selected Import Data Sources
_selectedProfile: null, // Selected Profile name to import from
_wiz: null, // Shortcut to the wizard
_migrator: null, // The actual profile migrator.
_autoMigrate: null, // Whether or not we are actually migrating.
_singleItem: false, // Are we choosing just to import a single
// item into the current profile?
_newHomePage: null, // Are we setting a new home page - what to?
init: function() {
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(this, "Migration:Started", false);
os.addObserver(this, "Migration:ItemBeforeMigrate", false);
os.addObserver(this, "Migration:ItemAfterMigrate", false);
os.addObserver(this, "Migration:Ended", false);
os.addObserver(this, "Migration:Progress", false);
this._wiz = document.documentElement;
this._wiz.canRewind = false;
if ("arguments" in window) {
if ("arguments" in window && window.arguments[0] == "bookmarks") {
this._singleItem = true;
this._itemsFlags = nsISuiteProfileMigrator.BOOKMARKS;
document.getElementById("fromFile").hidden = false;
document.getElementById("importBookmarks").hidden = false;
document.getElementById("importAll").hidden = true;
}
else if (window.arguments.length > 1) {
this._source = window.arguments[0];
this._migrator = window.arguments[1] instanceof nsISuiteProfileMigrator ?
window.arguments[1] : null;
this._autoMigrate = window.arguments[2]
.QueryInterface(nsIProfileStartup);
// Show the "nothing" option in the automigrate case to provide an
// easily identifiable way to avoid migration and create a new profile.
document.getElementById("nothing").hidden = false;
}
}
this.onImportSourcePageShow();
},
uninit: function() {
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.removeObserver(this, "Migration:Started");
os.removeObserver(this, "Migration:ItemBeforeMigrate");
os.removeObserver(this, "Migration:ItemAfterMigrate");
os.removeObserver(this, "Migration:Ended");
os.removeObserver(this, "Migration:Progress", false);
},
// 1 - Import Source
onImportSourcePageShow: function() {
// Figure out what source apps are are available to import from:
var group = document.getElementById("importSourceGroup");
var firstSelectable = null;
for (var i = 0; i < group.childNodes.length; ++i) {
var suffix = group.childNodes[i].id;
if (suffix != "nothing" && suffix != "fromFile") {
var contractID = NS_PROFILE_MIGRATOR_CONTRACTID + suffix;
var migrator = null;
if (contractID in Components.classes) {
migrator = Components.classes[contractID]
.createInstance(nsISuiteProfileMigrator);
} else {
dump("*** invalid contractID =" + contractID + "\n");
// This is an invalid contract id, therefore hide this element
// and allow things to continue - that way we should be able to
// copy with anything happening.
group.childNodes[i].hidden = true;
break;
}
// Ensure that we only allow import selections for profile
// migrators that support the requested action.
if (!migrator.sourceExists ||
!(migrator.supportedItems & this._itemsFlags)) {
group.childNodes[i].hidden = true;
break;
}
if (!firstSelectable && !group.childNodes[i].disabled &&
!group.childNodes[i].hidden) {
firstSelectable = group.childNodes[i];
}
}
}
if (this._source) {
// Somehow the Profile Migrator got confused, and gave us a migrate source
// that doesn't actually exist. This could be because of a bogus registry
// state. Set the _source property to null so the first visible item in
// the list is selected instead.
if (document.getElementById(this._source).hidden)
this._source = null;
}
group.selectedItem = this._source ?
document.getElementById(this._source) : firstSelectable;
},
onImportSourcePageAdvanced: function() {
var newSource = document.getElementById("importSourceGroup").value;
if (newSource == "nothing" || newSource == "fromFile") {
if (newSource == "fromFile") {
window.opener.fromFile = true;
}
document.documentElement.cancel();
// Don't let the wizard migrate to the next page event though we've
// called cancel - cancel may not get processed first.
return false;
}
if (!this._migrator || newSource != this._source) {
// Create the migrator for the selected source.
var contractID = NS_PROFILE_MIGRATOR_CONTRACTID + newSource;
this._migrator = Components.classes[contractID]
.createInstance(nsISuiteProfileMigrator);
this._selectedProfile = null;
}
this._source = newSource;
// check for more than one source profile
if (this._migrator.sourceHasMultipleProfiles)
this._wiz.currentPage.next = "selectProfile";
else {
if (this._autoMigrate)
this._wiz.currentPage.next = "homePageImport";
else if (this._singleItem)
this._wiz.currentPage.next = "migrating";
else
this._wiz.currentPage.next = "importItems";
var sourceProfiles = this._migrator.sourceProfiles;
if (sourceProfiles && sourceProfiles.length == 1) {
this._selectedProfile = sourceProfiles
.queryElementAt(0, nsISupportsString).data;
}
else
this._selectedProfile = "";
}
return true;
},
// 2 - [Profile Selection]
onSelectProfilePageShow: function() {
var profiles = document.getElementById("profiles");
while (profiles.hasChildNodes())
profiles.lastChild.remove();
var sourceProfiles = this._migrator.sourceProfiles;
var count = sourceProfiles.length;
for (var i = 0; i < count; ++i) {
var item = document.createElement("radio");
item.id = sourceProfiles.queryElementAt(i, nsISupportsString).data;
item.setAttribute("label", item.id);
profiles.appendChild(item);
}
profiles.selectedItem = this._selectedProfile ?
document.getElementById(this._selectedProfile) : profiles.firstChild;
},
onSelectProfilePageAdvanced: function() {
this._selectedProfile = document.getElementById("profiles").selectedItem.id;
// If we're automigrating or just doing bookmarks don't show the item
// selection page
if (this._autoMigrate)
this._wiz.currentPage.next = "homePageImport";
else if (this._singleItem)
this._wiz.currentPage.next = "migrating"
},
// 3 - ImportItems
onImportItemsPageShow: function() {
var dataSources = document.getElementById("dataSources");
while (dataSources.hasChildNodes())
dataSources.lastChild.remove();
var bundle = document.getElementById("bundle");
var items = this._migrator.getMigrateData(this._selectedProfile,
this._autoMigrate);
for (var i = 0; i < 16; ++i) {
var itemID = items & (1 << i);
if (itemID) {
var checkbox = document.createElement("checkbox");
checkbox.id = itemID;
try {
checkbox.setAttribute("label",
bundle.getString(itemID + "_" + this._source));
}
catch (ex) {
checkbox.setAttribute("label",
bundle.getString(itemID + "_generic"));
}
dataSources.appendChild(checkbox);
if (this._itemsFlags & itemID)
checkbox.setAttribute("checked", true);
}
}
},
onImportItemsPageRewound: function() {
this._wiz.canAdvance = true;
this.onImportItemsPageAdvanced();
},
onImportItemsPageAdvanced: function() {
var dataSources = document.getElementById("dataSources");
this._itemsFlags = 0;
for (var i = 0; i < dataSources.childNodes.length; ++i) {
var checkbox = dataSources.childNodes[i];
if (checkbox.checked)
this._itemsFlags |= checkbox.id;
}
},
onImportItemCommand: function(aEvent) {
this._wiz.canAdvance = document
.getElementById("dataSources")
.getElementsByAttribute("checked", "true").item(0) != null;
},
// 4 - Home Page Selection
onHomePageMigrationPageShow: function() {
// only want this on the first run
if (!this._autoMigrate) {
this._wiz.advance();
return;
}
var bundle = document.getElementById("bundle");
var pageTitle = bundle.getString("homePageMigrationPageTitle");
var pageDesc = bundle.getString("homePageMigrationDescription");
document.getElementById("homePageImport").setAttribute("label", pageTitle);
document.getElementById("homePageImportDesc")
.setAttribute("value", pageDesc);
this._wiz._adjustWizardHeader();
var homePageStart = document.getElementById("homePageStart");
// Find out if the target profile already has a homepage or not
var mainStr = this.targetHasHomePageURL() ?
bundle.getString("homePageStartCurrent") :
bundle.getString("homePageStartDefault");
homePageStart.setAttribute("label", mainStr);
var source = null;
if (this._source != "") {
source = "sourceName" + this._source;
}
var availableItems = this._migrator.getMigrateData(this._selectedProfile,
this._autoMigrate);
if (source && (availableItems & nsISuiteProfileMigrator.HOMEPAGEDATA)) {
var appName = document.getElementById("bundle").getString(source);
var oldHomePageLabel = bundle.getFormattedString("homePageImport",
[appName]);
var oldHomePage = document.getElementById("oldHomePage");
oldHomePage.setAttribute("label", oldHomePageLabel);
oldHomePage.setAttribute("value", "source");
oldHomePage.removeAttribute("hidden");
oldHomePage.focus();
document.getElementById("homePageRadioGroup").selectedItem = oldHomePage;
}
else {
// if we don't have at least two options, just advance
this._wiz.advance();
}
},
onHomePageMigrationPageAdvanced: function() {
// we might not have a selectedItem if we're in fallback mode
try {
this._newHomePage = document.getElementById("homePageRadioGroup")
.value;
} catch(ex) {}
},
// 5 - Migrating
onMigratingPageShow: function() {
this._wiz.getButton("cancel").disabled = true;
this._wiz.canRewind = false;
this._wiz.canAdvance = false;
// When migrating a profile on startup, show all of the data that can be
// received from this source, but exclude home pages if the user didn't
// want to migrate it.
if (this._autoMigrate) {
this._itemsFlags = this._migrator.getMigrateData(this._selectedProfile,
this._autoMigrate);
if (!this._newHomePage)
this._itemsFlags &= ~nsISuiteProfileMigrator.HOMEPAGEDATA;
}
this._listItems("migratingItems");
setTimeout(this.onMigratingMigrate, 0, this);
},
onMigratingMigrate: function(aOuter) {
aOuter._migrator.migrate(aOuter._itemsFlags,
aOuter._autoMigrate,
aOuter._selectedProfile);
},
_listItems: function(aID) {
var items = document.getElementById(aID);
while (items.hasChildNodes())
items.lastChild.remove();
var bundle = document.getElementById("bundle");
var itemID;
for (var x = 1; x < nsISuiteProfileMigrator.ALL;
x = x << 1) {
if (x & this._itemsFlags) {
var label = document.createElement("label");
label.id = x + "_migrated";
try {
label.setAttribute("value",
bundle.stringBundle
.GetStringFromName(x + "_"+ this._source));
label.setAttribute("class", "migration-pending");
items.appendChild(label);
}
catch (ex) {
try {
label.setAttribute("value", bundle.getString(x + "_generic"));
label.setAttribute("class", "migration-pending");
items.appendChild(label);
}
catch (e) {
// if the block above throws, we've enumerated all the import
// data types we currently support and are now just wasting time.
break;
}
}
}
}
},
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "Migration:Progress":
document.getElementById("progressBar").value = aData;
break;
case "Migration:Started":
break;
case "Migration:ItemBeforeMigrate":
var label = document.getElementById(aData + "_migrated");
if (label)
label.setAttribute("class", "migration-in-progress");
break;
case "Migration:ItemAfterMigrate":
var label = document.getElementById(aData + "_migrated");
if (label)
label.setAttribute("class", "migration-finished");
break;
case "Migration:Ended":
// We're done now.
this._wiz.canAdvance = true;
this._wiz.advance();
if (this._autoMigrate)
setTimeout(close, 5000);
break;
}
},
onDonePageShow: function() {
this._wiz.getButton("cancel").disabled = true;
this._wiz.canRewind = false;
this._listItems("doneItems");
},
targetHasHomePageURL: function() {
var targetPrefsFile = this._autoMigrate.directory;
targetPrefsFile.append("prefs.js");
// If the target prefs file doesn't exist, then we can't have a
// homepage set in the target profile.
if (!targetPrefsFile.exists())
return false;
Services.prefs.resetPrefs();
Services.prefs.readUserPrefs(targetPrefsFile);
return Services.prefs.prefHasUserValue("browser.startup.homepage");
}
};

@ -1,96 +0,0 @@
<?xml version="1.0"?>
<!-- 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/. -->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/migration/migration.dtd" >
<wizard id="migrationWizard"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&migrationWizard.title;"
onload="MigrationWizard.init()"
onunload="MigrationWizard.uninit()"
style="width: 40em; height: 32em;"
branded="true"
buttons="accept,cancel"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<script type="application/javascript"
src="chrome://communicator/content/migration/migration.js"/>
<stringbundle id="bundle"
src="chrome://communicator/locale/migration/migration.properties"/>
<wizardpage id="importSource" pageid="importSource" next="selectProfile"
label="&importSource.title;"
onpageadvanced="return MigrationWizard.onImportSourcePageAdvanced();">
<label id="importAll"
control="importSourceGroup">&importAllFrom.label;</label>
<label id="importBookmarks" control="importSourceGroup"
hidden="true">&importBookmarksFrom.label;</label>
<radiogroup id="importSourceGroup" align="start">
<radio id="thunderbird" label="&importFromThunderbird.label;"
accesskey="&importFromThunderbird.accesskey;"
value="thunderbird"/>
<!-- fromfile is used for bookmark importing -->
<radio id="fromFile" label="&importFromFile.label;" value="fromFile"
accesskey="&importFromFile.accesskey;" hidden="true"/>
<radio id="nothing" label="&importFromNothing.label;" value="nothing"
accesskey="&importFromNothing.accesskey;" hidden="true"/>
</radiogroup>
</wizardpage>
<wizardpage id="selectProfile" pageid="selectProfile"
label="&selectProfile.title;" next="importItems"
onpageshow="return MigrationWizard.onSelectProfilePageShow();"
onpageadvanced="return MigrationWizard.onSelectProfilePageAdvanced();">
<label control="profiles">&selectProfile.label;</label>
<radiogroup id="profiles" align="left"/>
</wizardpage>
<wizardpage id="importItems" pageid="importItems" label="&importItems.title;"
next="homePageImport"
onpageshow="return MigrationWizard.onImportItemsPageShow();"
onpageadvanced="return MigrationWizard.onImportItemsPageAdvanced();"
oncommand="MigrationWizard.onImportItemCommand();">
<label control="dataSources">&importItems.label;</label>
<vbox id="dataSources" style="overflow-y: auto;"
align="left" flex="1" role="group"/>
</wizardpage>
<wizardpage id="homePageImport" pageid="homePageImport"
next="migrating"
onpageshow="return MigrationWizard.onHomePageMigrationPageShow();"
onpageadvanced="return MigrationWizard.onHomePageMigrationPageAdvanced();">
<label id="homePageImportDesc" control="homePageRadioGroup"/>
<radiogroup id="homePageRadioGroup" align="start">
<radio id="oldHomePage" hidden="true"/>
<radio id="homePageStart" selected="true"/>
</radiogroup>
</wizardpage>
<wizardpage id="migrating" pageid="migrating" label="&migrating.title;"
next="done" onpageshow="MigrationWizard.onMigratingPageShow();">
<label control="migratingItems">&migrating.label;</label>
<vbox id="migratingItems" style="overflow-y: auto;" align="left" role="group"/>
<hbox>
<progressmeter class="progressmeter-statusbar" id="progressBar"
flex="1" mode="normal" value="0"/>
</hbox>
</wizardpage>
<wizardpage id="done" pageid="done" label="&done.title;"
onpageshow="MigrationWizard.onDonePageShow();">
<label control="doneItems">&done.label;</label>
<vbox id="doneItems" style="overflow-y: auto;" align="left" role="group"/>
</wizardpage>
</wizard>

@ -1,7 +0,0 @@
# 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/.
comm.jar:
content/communicator/migration/migration.xul (content/migration.xul)
content/communicator/migration/migration.js (content/migration.js)

@ -1,28 +0,0 @@
# vim: set filetype=python:
# 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/.
XPIDL_SOURCES += [
'public/nsISuiteProfileMigrator.idl',
]
XPIDL_MODULE = 'suitemigration'
SOURCES += [
'src/nsNetscapeProfileMigratorBase.cpp',
'src/nsSuiteProfileMigratorUtils.cpp',
'src/nsThunderbirdProfileMigrator.cpp',
]
EXTRA_COMPONENTS += [
'SuiteProfileMigrator.manifest',
]
EXTRA_PP_COMPONENTS += [
'src/SuiteProfileMigrator.js',
]
FINAL_LIBRARY = 'navigator'
JAR_MANIFESTS += ['jar.mn']

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsISupports.idl"
interface nsIArray;
interface nsIProfileStartup;
[scriptable, uuid(b6adb2b8-5e3b-4fdd-b085-d58998b5c21a)]
interface nsISuiteProfileMigrator : nsISupports
{
/**
* profile items to migrate. use with migrate().
*/
const unsigned short SETTINGS = 0x0001;
const unsigned short COOKIES = 0x0002;
const unsigned short HISTORY = 0x0004;
const unsigned short HOMEPAGEDATA = 0x0008;
const unsigned short PASSWORDS = 0x0010;
const unsigned short BOOKMARKS = 0x0020;
const unsigned short OTHERDATA = 0x0040;
const unsigned short ACCOUNT_SETTINGS = 0x0080;
const unsigned short ADDRESSBOOK_DATA = 0x0100;
const unsigned short JUNKTRAINING = 0x0200;
const unsigned short NEWSDATA = 0x0400;
const unsigned short MAILDATA = 0x0800;
const unsigned short ALL = 0x0FFF;
/**
* Copy user profile information to the current active profile.
*
* @param aItems list of data items to migrate. see above for values.
* @param aReplace replace or append current data where applicable.
* @param aProfile profile to migrate from, if there is more than one.
*/
void migrate(in unsigned short aItems, in nsIProfileStartup aStartup,
in wstring aProfile);
/**
* A bit field containing profile items that this migrator is able
* to import for a specified source profile.
*
* @param aProfile the profile that we are looking for available data
* to import
* @param aStarting "true" if the profile is not currently being used.
* @returns bit field containing profile items (see above)
*/
unsigned short getMigrateData(in wstring aProfile, in boolean aDoingStartup);
/**
* A bit field containing profile items that this migrator may be able
* to import for any source profile of its type.
*/
readonly attribute unsigned short supportedItems;
/**
* Whether or not there is any data that can be imported from this
* browser (i.e. whether or not it is installed, and there exists
* a user profile)
*/
readonly attribute boolean sourceExists;
/**
* Whether or not the import source implementing this interface
* has multiple user profiles configured.
*/
readonly attribute boolean sourceHasMultipleProfiles;
/**
* An enumeration of available profiles. If the import source does
* not support profiles, this attribute is null.
*/
readonly attribute nsIArray sourceProfiles;
};

@ -1,135 +0,0 @@
/* 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";
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
function ProfileMigrator() {
}
ProfileMigrator.prototype = {
migrate: function PM_migrate(aStartup) {
// By opening the wizard with a supplied migrator, it will automatically
// migrate from it.
let [key, migrator] = this._getDefaultMigrator();
if (!key)
return;
let params = Components.classes["@mozilla.org/array;1"]
.createInstance(Components.interfaces.nsIMutableArray);
params.appendElement(this._toString(key), false);
params.appendElement(migrator, false);
params.appendElement(aStartup, false);
Services.ww.openWindow(null,
"chrome://communicator/content/migration/migration.xul",
"_blank",
"chrome,dialog,modal,centerscreen,titlebar",
params);
},
_toString: function PM__toString(aStr) {
let str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
str.data = aStr;
return str;
},
_getMigratorIfSourceExists: function PM__getMigratorIfSourceExists(aKey) {
let cid = "@mozilla.org/profile/migrator;1?app=suite&type=" + aKey;
let migrator = Components.classes[cid]
.createInstance(Components.interfaces
.nsISuiteProfileMigrator);
if (migrator.sourceExists)
return migrator;
return null;
},
// We don't yet support checking for the default browser on all platforms,
// needless to say we don't have migrators for all browsers. Thus, for each
// platform, there's a fallback list of migrators used in these cases.
_PLATFORM_FALLBACK_LIST:
["thunderbird"],
_getDefaultMigrator: function PM__getDefaultMigrator() {
let migratorsOrdered = Array.slice(this._PLATFORM_FALLBACK_LIST);
#if 0
let defaultBrowser = "";
#ifdef XP_WIN
try {
const REG_KEY = "SOFTWARE\\Classes\\HTTP\\shell\\open\\command";
let regKey = Components.classes["@mozilla.org/windows-registry-key;1"]
.createInstance(Components.interfaces.nsIWindowsRegKey);
regKey.open(regKey.ROOT_KEY_LOCAL_MACHINE, REG_KEY,
regKey.ACCESS_READ);
let value = regKey.readStringValue("").toLowerCase();
let pathMatches = value.match(/^"?(.+?\.exe)"?/);
if (!pathMatches) {
throw new Error("Could not extract path from " +
REG_KEY + "(" + value + ")");
}
// We want to find out what the default browser is but the path in and of
// itself isn't enough. Why? Because sometimes on Windows paths get
// truncated like so: C:\PROGRA~1\MOZILL~2\MOZILL~1.EXE. How do we know
// what product that is? Mozilla's file objects do nothing to 'normalize'
// the path so we need to attain an actual product descriptor from the
// file somehow, and in this case it means getting the "InternalName"
// field of the file's VERSIONINFO resource.
//
// In the file's resource segment there is a VERSIONINFO section that is
// laid out like this:
//
// VERSIONINFO
// StringFileInfo
// <TranslationID>
// InternalName "iexplore"
// VarFileInfo
// Translation <TranslationID>
//
// By Querying the VERSIONINFO section for its Tranlations, we can find
// out where the InternalName lives (A file can have more than one
// translation of its VERSIONINFO segment, but we just assume the first
// one).
let file = FileUtils.File(pathMatches[1])
.QueryInterface(Components.interfaces.nsILocalFileWin);
switch (file.getVersionInfoField("InternalName").toLowerCase()) {
case "iexplore":
defaultBrowser = "ie";
break;
case "chrome":
defaultBrowser = "chrome";
break;
}
}
catch (ex) {
Components.utils.reportError("Could not retrieve default browser: " + ex);
}
#endif
// If we found the default browser and we have support for that browser,
// make sure to check it before any other browser, by moving it to the head
// of the array.
if (defaultBrowser)
migratorsOrdered.sort((a, b) => b == defaultBrowser ? 1 : 0);
#endif
for (let key of migratorsOrdered) {
let migrator = this._getMigratorIfSourceExists(key);
if (migrator)
return [key, migrator];
}
return ["", null];
},
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIProfileMigrator]),
classDescription: "Profile Migrator",
contractID: "@mozilla.org/toolkit/profile-migrator;1",
classID: Components.ID("{d5148b7c-ba4e-4f7a-a80b-1ae48b90b910}"),
};
var NSGetFactory = XPCOMUtils.generateNSGetFactory([ProfileMigrator]);

@ -1,162 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef netscapeprofilemigratorbase___h___
#define netscapeprofilemigratorbase___h___
#include "nsIFile.h"
#include "nsIMutableArray.h"
#include "nsStringAPI.h"
#include "nsTArray.h"
#include "nsITimer.h"
#include "nsIObserverService.h"
#include "nsISuiteProfileMigrator.h"
class nsIPrefBranch;
class nsIPrefService;
struct fileTransactionEntry {
nsCOMPtr<nsIFile> srcFile; // the src path including leaf name
nsCOMPtr<nsIFile> destFile; // the destination path
nsString newName; // only valid if the file should be renamed after
// getting copied
};
#define FILE_NAME_BOOKMARKS "bookmarks.html"
#define FILE_NAME_COOKIES "cookies.txt"
#define FILE_NAME_COOKIES_SQLITE "cookies.sqlite"
#define FILE_NAME_PREFS "prefs.js"
#define FILE_NAME_JUNKTRAINING "training.dat"
#define FILE_NAME_VIRTUALFOLDERS "virtualFolders.dat"
#define FILE_NAME_USERCONTENT "userContent.css"
#define DIR_NAME_SEARCH "searchplugins"
#define FILE_NAME_DOWNLOADS "downloads.rdf"
#define F(a) nsNetscapeProfileMigratorBase::a
#define MAKEPREFTRANSFORM(pref, newpref, getmethod, setmethod) \
{ pref, newpref, F(Get##getmethod), F(Set##setmethod), false, { -1 } }
#define MAKESAMETYPEPREFTRANSFORM(pref, method) \
{ pref, 0, F(Get##method), F(Set##method), false, { -1 } }
class nsNetscapeProfileMigratorBase : public nsISuiteProfileMigrator,
public nsITimerCallback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITIMERCALLBACK
nsNetscapeProfileMigratorBase();
struct PrefTransform;
typedef nsresult(*prefConverter)(PrefTransform*, nsIPrefBranch*);
struct PrefTransform {
const char* sourcePrefName;
const char* targetPrefName;
prefConverter prefGetterFunc;
prefConverter prefSetterFunc;
bool prefHasValue;
union {
int32_t intValue;
bool boolValue;
char* stringValue;
};
};
struct PrefBranchStruct {
char* prefName;
int32_t type;
union {
char* stringValue;
int32_t intValue;
bool boolValue;
};
};
typedef nsTArray<PrefBranchStruct*> PBStructArray;
// nsISuiteProfileMigrator methods
NS_IMETHOD GetSourceExists(bool* aSourceExists) override;
NS_IMETHOD GetSourceHasMultipleProfiles(bool* aSourceHasMultipleProfiles) override;
NS_IMETHOD GetSourceProfiles(nsIArray** aResult) override;
// Pref Transform Methods
static nsresult GetString(PrefTransform* aTransform, nsIPrefBranch* aBranch);
static nsresult SetString(PrefTransform* aTransform, nsIPrefBranch* aBranch);
static nsresult GetBool(PrefTransform* aTransform, nsIPrefBranch* aBranch);
static nsresult SetBool(PrefTransform* aTransform, nsIPrefBranch* aBranch);
static nsresult GetInt(PrefTransform* aTransform, nsIPrefBranch* aBranch);
static nsresult SetInt(PrefTransform* aTransform, nsIPrefBranch* aBranch);
static nsresult SetFile(PrefTransform* aTransform, nsIPrefBranch* aBranch);
static nsresult SetImage(PrefTransform* aTransform, nsIPrefBranch* aBranch);
static nsresult SetCookie(PrefTransform* aTransform, nsIPrefBranch* aBranch);
protected:
virtual ~nsNetscapeProfileMigratorBase() {}
// This function is designed to be overriden by derived classes so that
// the required profile data for the specific application can be obtained.
virtual nsresult FillProfileDataFromRegistry() = 0;
// General Utility Methods
nsresult GetSourceProfile(const char16_t* aProfile);
nsresult GetProfileDataFromProfilesIni(nsIFile* aDataDir,
nsIMutableArray* aProfileNames,
nsIMutableArray* aProfileLocations);
nsresult GetFileValue(nsIPrefBranch* aPrefBranch, const char* aRelPrefName,
const char* aPrefName, nsIFile** aReturnFile);
nsresult CopyFile(const char* aSourceFileName,
const char* aTargetFileName);
nsresult RecursiveCopy(nsIFile* srcDir, nsIFile* destDir);
void ReadBranch(const char * branchName, nsIPrefService* aPrefService,
PBStructArray &aPrefs);
void WriteBranch(const char * branchName, nsIPrefService* aPrefService,
PBStructArray &aPrefs);
// Generic Import Functions
nsresult CopyCookies(bool aReplace);
nsresult CopyUserSheet(const char* aFileName);
// Browser Import Functions
nsresult CopyBookmarks(bool aReplace);
nsresult CopyOtherData(bool aReplace);
nsresult ImportNetscapeBookmarks(const char* aBookmarksFileName,
const char* aImportSourceNameKey);
bool GetSourceHasHomePageURL();
nsresult CopyHomePageData(bool aReplace);
// Mail Import Functions
nsresult CopyAddressBookDirectories(PBStructArray &aLdapServers,
nsIPrefService* aPrefService);
nsresult CopySignatureFiles(PBStructArray &aIdentities,
nsIPrefService* aPrefService);
nsresult CopyJunkTraining(bool aReplace);
nsresult CopyMailFolderPrefs(PBStructArray &aMailServers,
nsIPrefService* aPrefService);
void CopyMailFolders();
void CopyNextFolder();
void EndCopyFolders();
// Source & Target profiles
nsCOMPtr<nsIFile> mSourceProfile;
nsCOMPtr<nsIFile> mTargetProfile;
// list of src/destination files we still have to copy into the new profile
// directory
nsTArray<fileTransactionEntry> mFileCopyTransactions;
uint32_t mFileCopyTransactionIndex;
nsCOMPtr<nsIObserverService> mObserverService;
int64_t mMaxProgress;
int64_t mCurrentProgress;
nsCOMPtr<nsIMutableArray> mProfileNames;
nsCOMPtr<nsIMutableArray> mProfileLocations;
nsCOMPtr<nsITimer> mFileIOTimer;
};
#endif

@ -1,190 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsSuiteProfileMigratorUtils.h"
#include "nsIPrefBranch.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsILineInputStream.h"
#include "nsIProfileMigrator.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
#include "nsIProperties.h"
#include "nsServiceManagerUtils.h"
#include "nsISupportsPrimitives.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIRDFService.h"
#include "nsIStringBundle.h"
#include "nsCRT.h"
#define MIGRATION_BUNDLE "chrome://communicator/migration/locale/migration.properties"
void SetUnicharPref(const char* aPref, const nsAString& aValue,
nsIPrefBranch* aPrefs)
{
nsCOMPtr<nsISupportsString> supportsString =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
if (supportsString) {
supportsString->SetData(aValue);
aPrefs->SetComplexValue(aPref, NS_GET_IID(nsISupportsString),
supportsString);
}
}
void SetProxyPref(const nsAString& aHostPort, const char* aPref,
const char* aPortPref, nsIPrefBranch* aPrefs)
{
nsCOMPtr<nsIURI> uri;
nsAutoCString host;
int32_t portValue;
// try parsing it as a URI first
if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), aHostPort)) &&
NS_SUCCEEDED(uri->GetHost(host)) &&
!host.IsEmpty() &&
NS_SUCCEEDED(uri->GetPort(&portValue))) {
SetUnicharPref(aPref, NS_ConvertUTF8toUTF16(host), aPrefs);
aPrefs->SetIntPref(aPortPref, portValue);
}
else {
nsAutoString hostPort(aHostPort);
int32_t portDelimOffset = hostPort.RFindChar(':');
if (portDelimOffset > 0) {
SetUnicharPref(aPref, Substring(hostPort, 0, portDelimOffset), aPrefs);
nsAutoString port(Substring(hostPort, portDelimOffset + 1));
nsresult error;
portValue = port.ToInteger(&error);
aPrefs->SetIntPref(aPortPref, portValue);
}
else
SetUnicharPref(aPref, hostPort, aPrefs);
}
}
void ParseOverrideServers(const nsAString& aServers, nsIPrefBranch* aBranch)
{
// Windows (and Opera) formats its proxy override list in the form:
// server;server;server where server is a server name or ip address,
// or "<local>". Mozilla's format is server,server,server, and <local>
// must be translated to "localhost,127.0.0.1"
nsAutoString override(aServers);
int32_t left = 0, right = 0;
for (;;) {
right = override.FindChar(';', right);
const nsAString& host =
Substring(override, left,
(right < 0 ? override.Length() : right) - left);
if (host.EqualsLiteral("<local>"))
override.Replace(left, 7, NS_LITERAL_STRING("localhost,127.0.0.1"));
if (right < 0)
break;
left = right + 1;
override.Replace(right, 1, NS_LITERAL_STRING(","));
}
SetUnicharPref("network.proxy.no_proxies_on", override, aBranch);
}
void GetMigrateDataFromArray(MigrationData* aDataArray,
int32_t aDataArrayLength,
bool aReplace, nsIFile* aSourceProfile,
uint16_t* aResult)
{
nsCOMPtr<nsIFile> sourceFile;
bool exists;
MigrationData* cursor;
MigrationData* end = aDataArray + aDataArrayLength;
for (cursor = aDataArray; cursor < end; ++cursor) {
// When in replace mode, all items can be imported.
// When in non-replace mode, only items that do not require file
// replacement can be imported.
if (aReplace || !cursor->replaceOnly) {
aSourceProfile->Clone(getter_AddRefs(sourceFile));
sourceFile->AppendNative(nsDependentCString(cursor->fileName));
sourceFile->Exists(&exists);
if (exists)
*aResult |= cursor->sourceFlag;
}
}
}
void
GetProfilePath(nsIProfileStartup* aStartup, nsIFile** aProfileDir)
{
*aProfileDir = nullptr;
if (aStartup) {
aStartup->GetDirectory(aProfileDir);
}
else {
nsCOMPtr<nsIProperties> dirSvc
(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
if (dirSvc) {
dirSvc->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile),
(void**)aProfileDir);
}
}
}
nsresult
AnnotatePersonalToolbarFolder(nsIFile* aSourceBookmarksFile,
nsIFile* aTargetBookmarksFile,
const char* aToolbarFolderName)
{
nsCOMPtr<nsIInputStream> fileInputStream;
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream),
aSourceBookmarksFile);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIOutputStream> outputStream;
rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream),
aTargetBookmarksFile);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILineInputStream> lineInputStream =
do_QueryInterface(fileInputStream, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString sourceBuffer;
nsAutoCString targetBuffer;
bool moreData = false;
uint32_t bytesWritten = 0;
do {
lineInputStream->ReadLine(sourceBuffer, &moreData);
if (!moreData)
break;
int32_t nameOffset = sourceBuffer.Find(aToolbarFolderName);
if (nameOffset >= 0) {
// Found the personal toolbar name on a line, check to make sure it's
// actually a folder.
NS_NAMED_LITERAL_CSTRING(folderPrefix, "<DT><H3 ");
int32_t folderPrefixOffset = sourceBuffer.Find(folderPrefix);
if (folderPrefixOffset >= 0)
sourceBuffer.Insert(
NS_LITERAL_CSTRING("PERSONAL_TOOLBAR_FOLDER=\"true\" "),
folderPrefixOffset + folderPrefix.Length());
}
targetBuffer.Assign(sourceBuffer);
targetBuffer.Append("\r\n");
outputStream->Write(targetBuffer.get(), targetBuffer.Length(),
&bytesWritten);
}
while (1);
outputStream->Close();
return NS_OK;
}
nsresult
ImportBookmarksHTML(nsIFile* aBookmarksFile,
const char16_t* aImportSourceNameKey)
{
// XXX: need to make this work with places
return NS_OK;
}

@ -1,81 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef SuiteProfileMigratorUtils_h__
#define SuiteProfileMigratorUtils_h__
#define MIGRATION_ITEMBEFOREMIGRATE "Migration:ItemBeforeMigrate"
#define MIGRATION_ITEMAFTERMIGRATE "Migration:ItemAfterMigrate"
#define MIGRATION_STARTED "Migration:Started"
#define MIGRATION_ENDED "Migration:Ended"
#define MIGRATION_PROGRESS "Migration:Progress"
#define NOTIFY_OBSERVERS(message, item) \
mObserverService->NotifyObservers(nullptr, message, item)
#define COPY_DATA(func, replace, itemIndex) \
if (NS_SUCCEEDED(rv) && (aItems & itemIndex || !aItems)) { \
nsAutoString index; \
index.AppendInt(itemIndex); \
NOTIFY_OBSERVERS(MIGRATION_ITEMBEFOREMIGRATE, index.get()); \
rv = func(replace); \
NOTIFY_OBSERVERS(MIGRATION_ITEMAFTERMIGRATE, index.get()); \
}
#define NC_URI(property) \
NS_LITERAL_CSTRING("http://home.netscape.com/NC-rdf#"#property)
#include "nsStringAPI.h"
#include "nscore.h"
#include "nsCOMPtr.h"
class nsIPrefBranch;
class nsIProfileStartup;
class nsIFile;
void SetUnicharPref(const char* aPref, const nsAString& aValue,
nsIPrefBranch* aPrefs);
// Proxy utilities shared by the Opera and IE migrators
void ParseOverrideServers(const nsAString& aServers, nsIPrefBranch* aBranch);
void SetProxyPref(const nsAString& aHostPort, const char* aPref,
const char* aPortPref, nsIPrefBranch* aPrefs);
struct MigrationData {
const char* fileName;
uint32_t sourceFlag;
bool replaceOnly;
};
class nsIFile;
void GetMigrateDataFromArray(MigrationData* aDataArray,
int32_t aDataArrayLength,
bool aReplace,
nsIFile* aSourceProfile,
uint16_t* aResult);
// get the base directory of the *target* profile
// this is already cloned, modify it to your heart's content
void GetProfilePath(nsIProfileStartup* aStartup,
nsIFile** aProfileDir);
// The Netscape Bookmarks Format (bookmarks.html) is fairly standard but
// each browser vendor seems to have their own way of identifying the
// Personal Toolbar Folder. This function scans for the vendor-specific
// name in the source Bookmarks file and then writes out a normalized
// variant into the target folder.
nsresult AnnotatePersonalToolbarFolder(nsIFile* aSourceBookmarksFile,
nsIFile* aTargetBookmarksFile,
const char* aToolbarFolderName);
// In-place import from aBookmarksFile into a folder in the user's bookmarks
// with the name "From (STR:aImportSourceNameKey)" (aImportSourceNameKey
// is a key into migration.properties with the pretty name of the application.
nsresult ImportBookmarksHTML(nsIFile* aBookmarksFile,
const char16_t* aImportSourceNameKey);
#endif

@ -1,600 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsSuiteProfileMigratorUtils.h"
#include "mozilla/ArrayUtils.h"
#include "nsCRT.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIObserverService.h"
#include "nsIPrefLocalizedString.h"
#include "nsIPrefService.h"
#include "nsIServiceManager.h"
#include "nsISupportsPrimitives.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsIProperties.h"
#include "nsServiceManagerUtils.h"
#include "nsThunderbirdProfileMigrator.h"
#include "prprf.h"
///////////////////////////////////////////////////////////////////////////////
// nsThunderbirdProfileMigrator
#define FILE_NAME_SITEPERM_OLD "cookperm.txt"
#define FILE_NAME_SITEPERM_NEW "hostperm.1"
#define FILE_NAME_CERT8DB "cert8.db"
#define FILE_NAME_KEY3DB "key3.db"
#define FILE_NAME_SECMODDB "secmod.db"
#define FILE_NAME_HISTORY "history.dat"
#define FILE_NAME_SIGNONS "signons.sqlite"
#define FILE_NAME_MIMETYPES "mimeTypes.rdf"
#define FILE_NAME_USER_PREFS "user.js"
#define FILE_NAME_PERSONALDICTIONARY "persdict.dat"
#define FILE_NAME_MAILVIEWS "mailViews.dat"
NS_IMPL_ISUPPORTS(nsThunderbirdProfileMigrator, nsISuiteProfileMigrator,
nsITimerCallback)
nsThunderbirdProfileMigrator::nsThunderbirdProfileMigrator()
{
}
nsThunderbirdProfileMigrator::~nsThunderbirdProfileMigrator()
{
}
///////////////////////////////////////////////////////////////////////////////
// nsISuiteProfileMigrator
NS_IMETHODIMP
nsThunderbirdProfileMigrator::Migrate(uint16_t aItems,
nsIProfileStartup* aStartup,
const char16_t* aProfile)
{
nsresult rv = NS_OK;
bool aReplace = aStartup ? true : false;
if (!mTargetProfile) {
GetProfilePath(aStartup, getter_AddRefs(mTargetProfile));
if (!mTargetProfile)
return NS_ERROR_FILE_NOT_FOUND;
}
if (!mSourceProfile) {
GetSourceProfile(aProfile);
if (!mSourceProfile)
return NS_ERROR_FILE_NOT_FOUND;
}
NOTIFY_OBSERVERS(MIGRATION_STARTED, nullptr);
COPY_DATA(CopyPreferences, aReplace, nsISuiteProfileMigrator::SETTINGS);
COPY_DATA(CopyCookies, aReplace, nsISuiteProfileMigrator::COOKIES);
COPY_DATA(CopyHistory, aReplace, nsISuiteProfileMigrator::HISTORY);
COPY_DATA(CopyPasswords, aReplace, nsISuiteProfileMigrator::PASSWORDS);
COPY_DATA(CopyOtherData, aReplace, nsISuiteProfileMigrator::OTHERDATA);
// fake notifications for things we've already imported as part of
// CopyPreferences
nsAutoString index;
index.AppendInt(nsISuiteProfileMigrator::ACCOUNT_SETTINGS);
NOTIFY_OBSERVERS(MIGRATION_ITEMBEFOREMIGRATE, index.get());
NOTIFY_OBSERVERS(MIGRATION_ITEMAFTERMIGRATE, index.get());
index.Truncate();
index.AppendInt(nsISuiteProfileMigrator::NEWSDATA);
NOTIFY_OBSERVERS(MIGRATION_ITEMBEFOREMIGRATE, index.get());
NOTIFY_OBSERVERS(MIGRATION_ITEMAFTERMIGRATE, index.get());
// copy junk mail training file
COPY_DATA(CopyJunkTraining, aReplace, nsISuiteProfileMigrator::JUNKTRAINING);
if (aReplace &&
(aItems & nsISuiteProfileMigrator::SETTINGS ||
aItems & nsISuiteProfileMigrator::COOKIES ||
aItems & nsISuiteProfileMigrator::PASSWORDS ||
!aItems)) {
// Permissions (Images, Cookies, Popups)
if (NS_SUCCEEDED(rv))
rv = CopyFile(FILE_NAME_SITEPERM_NEW, FILE_NAME_SITEPERM_NEW);
if (NS_SUCCEEDED(rv))
rv = CopyFile(FILE_NAME_SITEPERM_OLD, FILE_NAME_SITEPERM_OLD);
}
// the last thing to do is to actually copy over any mail folders
// we have marked for copying we want to do this last and it will be
// asynchronous so the UI doesn't freeze up while we perform
// this potentially very long operation.
CopyMailFolders();
return rv;
}
NS_IMETHODIMP
nsThunderbirdProfileMigrator::GetMigrateData(const char16_t* aProfile,
bool aReplace,
uint16_t* aResult)
{
*aResult = 0;
if (!mSourceProfile) {
GetSourceProfile(aProfile);
if (!mSourceProfile)
return NS_ERROR_FILE_NOT_FOUND;
}
// migration