--- a/browser/components/migration/ChromeProfileMigrator.js
+++ b/browser/components/migration/ChromeProfileMigrator.js
@@ -14,33 +14,57 @@ const S100NS_FROM1601TO1970 = 0x19DB1DED
const S100NS_PER_MS = 10;
const AUTH_TYPE = {
SCHEME_HTML: 0,
SCHEME_BASIC: 1,
SCHEME_DIGEST: 2
};
+Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource:///modules/MigrationUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OSCrypto",
"resource://gre/modules/OSCrypto.jsm");
/**
+ * Get an nsIFile instance representing the expected location of user data
+ * for this copy of Chrome/Chromium/Canary on different OSes.
+ * @param subfoldersWin {Array} an array of subfolders to use for Windows
+ * @param subfoldersOSX {Array} an array of subfolders to use for OS X
+ * @param subfoldersUnix {Array} an array of subfolders to use for *nix systems
+ * @returns {nsIFile} the place we expect data to live. Might not actually exist!
+ */
+function getDataFolder(subfoldersWin, subfoldersOSX, subfoldersUnix) {
+ let dirServiceID, subfolders;
+ if (AppConstants.platform == "win") {
+ dirServiceID = "LocalAppData";
+ subfolders = subfoldersWin.concat(["User Data"]);
+ } else if (AppConstants.platform == "macosx") {
+ dirServiceID = "ULibDir";
+ subfolders = ["Application Support"].concat(subfoldersOSX);
+ } else {
+ dirServiceID = "Home";
+ subfolders = [".config"].concat(subfoldersUnix);
+ }
+ return FileUtils.getDir(dirServiceID, subfolders, false);
+}
+
+/**
* Convert Chrome time format to Date object
*
* @param aTime
- * Chrome time
+ * Chrome time
* @return converted Date object
* @note Google Chrome uses FILETIME / 10 as time.
* FILETIME is based on same structure of Windows.
*/
function chromeTimeToDate(aTime)
{
return new Date((aTime * S100NS_PER_MS - S100NS_FROM1601TO1970 ) / 10000);
}
@@ -78,44 +102,38 @@ function* insertBookmarkItems(parentGuid
Cu.reportError(e);
errorAccumulator(e);
}
}
}
function ChromeProfileMigrator() {
- let chromeUserDataFolder = FileUtils.getDir(
-#ifdef XP_WIN
- "LocalAppData", ["Google", "Chrome", "User Data"]
-#elifdef XP_MACOSX
- "ULibDir", ["Application Support", "Google", "Chrome"]
-#else
- "Home", [".config", "google-chrome"]
-#endif
- , false);
+ let chromeUserDataFolder =
+ getDataFolder(["Google", "Chrome"], ["Google", "Chrome"], ["google-chrome"]);
this._chromeUserDataFolder = chromeUserDataFolder.exists() ?
chromeUserDataFolder : null;
}
ChromeProfileMigrator.prototype = Object.create(MigratorPrototype);
ChromeProfileMigrator.prototype.getResources =
function Chrome_getResources(aProfile) {
if (this._chromeUserDataFolder) {
let profileFolder = this._chromeUserDataFolder.clone();
profileFolder.append(aProfile.id);
if (profileFolder.exists()) {
- let possibleResources = [GetBookmarksResource(profileFolder),
- GetHistoryResource(profileFolder),
- GetCookiesResource(profileFolder),
-#ifdef XP_WIN
- GetWindowsPasswordsResource(profileFolder)
-#endif
- ];
+ let possibleResources = [
+ GetBookmarksResource(profileFolder),
+ GetHistoryResource(profileFolder),
+ GetCookiesResource(profileFolder),
+ ];
+ if (AppConstants.platform == "win") {
+ possibleResources.push(GetWindowsPasswordsResource(profileFolder));
+ }
return possibleResources.filter(r => r != null);
}
}
return [];
};
Object.defineProperty(ChromeProfileMigrator.prototype, "sourceProfiles", {
get: function Chrome_sourceProfiles() {
@@ -483,51 +501,37 @@ ChromeProfileMigrator.prototype.classDes
ChromeProfileMigrator.prototype.contractID = "@mozilla.org/profile/migrator;1?app=browser&type=chrome";
ChromeProfileMigrator.prototype.classID = Components.ID("{4cec1de4-1671-4fc3-a53e-6c539dc77a26}");
/**
* Chromium migration
**/
function ChromiumProfileMigrator() {
- let chromiumUserDataFolder = FileUtils.getDir(
-#ifdef XP_WIN
- "LocalAppData", ["Chromium", "User Data"]
-#elifdef XP_MACOSX
- "ULibDir", ["Application Support", "Chromium"]
-#else
- "Home", [".config", "chromium"]
-#endif
- , false);
+ let chromiumUserDataFolder = getDataFolder(["Chromium"], ["Chromium"], ["chromium"]);
this._chromeUserDataFolder = chromiumUserDataFolder.exists() ? chromiumUserDataFolder : null;
}
ChromiumProfileMigrator.prototype = Object.create(ChromeProfileMigrator.prototype);
ChromiumProfileMigrator.prototype.classDescription = "Chromium Profile Migrator";
ChromiumProfileMigrator.prototype.contractID = "@mozilla.org/profile/migrator;1?app=browser&type=chromium";
ChromiumProfileMigrator.prototype.classID = Components.ID("{8cece922-9720-42de-b7db-7cef88cb07ca}");
var componentsArray = [ChromeProfileMigrator, ChromiumProfileMigrator];
-#if defined(XP_WIN) || defined(XP_MACOSX)
/**
* Chrome Canary
* Not available on Linux
**/
function CanaryProfileMigrator() {
- let chromeUserDataFolder = FileUtils.getDir(
-#ifdef XP_WIN
- "LocalAppData", ["Google", "Chrome SxS", "User Data"]
-#elifdef XP_MACOSX
- "ULibDir", ["Application Support", "Google", "Chrome Canary"]
-#endif
- , false);
+ let chromeUserDataFolder = getDataFolder(["Google", "Chrome SxS"], ["Google", "Chrome Canary"]);
this._chromeUserDataFolder = chromeUserDataFolder.exists() ? chromeUserDataFolder : null;
}
CanaryProfileMigrator.prototype = Object.create(ChromeProfileMigrator.prototype);
CanaryProfileMigrator.prototype.classDescription = "Chrome Canary Profile Migrator";
CanaryProfileMigrator.prototype.contractID = "@mozilla.org/profile/migrator;1?app=browser&type=canary";
CanaryProfileMigrator.prototype.classID = Components.ID("{4bf85aa5-4e21-46ca-825f-f9c51a5e8c76}");
-componentsArray.push(CanaryProfileMigrator);
-#endif
+if (AppConstants.platform == "win" || AppConstants.platform == "macosx") {
+ componentsArray.push(CanaryProfileMigrator);
+}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(componentsArray);
--- a/browser/components/migration/MSMigrationUtils.jsm
+++ b/browser/components/migration/MSMigrationUtils.jsm
@@ -305,17 +305,17 @@ function getEdgeLocalDataFolder() {
gEdgeDir = subDir;
return subDir.clone();
}
}
} catch (ex) {
Cu.reportError("Exception trying to find the Edge favorites directory: " + ex);
}
return null;
-};
+}
function Bookmarks(migrationType) {
this._migrationType = migrationType;
}
Bookmarks.prototype = {
type: MigrationUtils.resourceTypes.BOOKMARKS,
--- a/browser/components/migration/MigrationUtils.jsm
+++ b/browser/components/migration/MigrationUtils.jsm
@@ -19,16 +19,32 @@ XPCOMUtils.defineLazyModuleGetter(this,
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
"resource://gre/modules/BookmarkHTMLUtils.jsm");
var gMigrators = null;
var gProfileStartup = null;
var gMigrationBundle = null;
+XPCOMUtils.defineLazyGetter(this, "gAvailableMigratorKeys", function() {
+ if (AppConstants.platform == "win") {
+ return [
+ "firefox", "edge", "ie", "chrome", "chromium", "safari", "360se",
+ "canary"
+ ];
+ }
+ if (AppConstants.platform == "macosx") {
+ return ["firefox", "safari", "chrome", "chromium", "canary"];
+ }
+ if (AppConstants.XP_UNIX) {
+ return ["firefox", "chrome", "chromium"];
+ }
+ return [];
+});
+
function getMigrationBundle() {
if (!gMigrationBundle) {
gMigrationBundle = Services.strings.createBundle(
"chrome://browser/locale/migration/migration.properties");
}
return gMigrationBundle;
}
@@ -227,18 +243,18 @@ this.MigratorPrototype = {
throw new Error("No items to import");
let notify = function(aMsg, aItemType) {
Services.obs.notifyObservers(null, aMsg, aItemType);
}
notify("Migration:Started");
for (let [key, value] of resourcesGroupedByItems) {
- // TODO: (bug 449811).
- let migrationType = key, itemResources = value;
+ // TODO: (bug 449811).
+ let migrationType = key, itemResources = value;
notify("Migration:ItemBeforeMigrate", migrationType);
let itemSuccess = false;
for (let res of itemResources) {
let resource = res;
let resourceDone = function(aSuccess) {
let resourceIndex = itemResources.indexOf(resource);
@@ -500,42 +516,16 @@ this.MigrationUtils = Object.freeze({
this._migrators.set(aKey, migrator);
}
try {
return migrator && migrator.sourceExists ? migrator : null;
} catch (ex) { Cu.reportError(ex); return null }
},
- // Iterates the available migrators, in the most suitable
- // order for the running platform.
- get migrators() {
- let migratorKeysOrdered = [
-#ifdef XP_WIN
- "firefox", "edge", "ie", "chrome", "chromium", "safari", "360se", "canary"
-#elifdef XP_MACOSX
- "firefox", "safari", "chrome", "chromium", "canary"
-#elifdef XP_UNIX
- "firefox", "chrome", "chromium"
-#endif
- ];
-
- // If a supported default browser is found check it first
- // so that the wizard defaults to import from that browser.
- let defaultBrowserKey = getMigratorKeyForDefaultBrowser();
- if (defaultBrowserKey)
- migratorKeysOrdered.sort((a, b) => b == defaultBrowserKey ? 1 : 0);
-
- for (let migratorKey of migratorKeysOrdered) {
- let migrator = this.getMigrator(migratorKey);
- if (migrator)
- yield migrator;
- }
- },
-
// Whether or not we're in the process of startup migration
get isStartupMigration() {
return gProfileStartup != null;
},
/**
* In the case of startup migration, this is set to the nsIProfileStartup
* instance passed to ProfileMigrator's migrate.
@@ -564,28 +554,26 @@ this.MigrationUtils = Object.freeze({
* - {Boolean} whether to skip the 'source' page
* 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).
*/
showMigrationWizard:
function MU_showMigrationWizard(aOpener, aParams) {
let features = "chrome,dialog,modal,centerscreen,titlebar,resizable=no";
-#ifdef XP_MACOSX
- if (!this.isStartupMigration) {
+ if (AppConstants.platform == "macosx" && !this.isStartupMigration) {
let win = Services.wm.getMostRecentWindow("Browser:MigrationWizard");
if (win) {
win.focus();
return;
}
// On mac, the migration wiazrd should only be modal in the case of
// startup-migration.
features = "centerscreen,chrome,resizable=no";
}
-#endif
// 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) {
@@ -676,23 +664,21 @@ this.MigrationUtils = Object.freeze({
if (migrator)
migratorKey = defaultBrowserKey;
}
}
if (!migrator) {
// If there's no migrator set so far, ensure that there is at least one
// migrator available before opening the wizard.
- try {
- this.migrators.next();
- }
- catch(ex) {
+ // 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.
+ if (!gAvailableMigratorKeys.some(key => !!this.getMigrator(key))) {
+ // None of the keys produced a usable migrator, so finish up here:
this.finishMigration();
- if (!(ex instanceof StopIteration))
- throw ex;
return;
}
}
let migrationEntryPoint = this.MIGRATION_ENTRYPOINT_FIRSTRUN;
if (migrator && skipSourcePage && migratorKey == AppConstants.MOZ_APP_NAME) {
migrationEntryPoint = this.MIGRATION_ENTRYPOINT_FXREFRESH;
}
--- a/browser/components/migration/SafariProfileMigrator.js
+++ b/browser/components/migration/SafariProfileMigrator.js
@@ -3,16 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
+Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource:///modules/MigrationUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
"resource://gre/modules/Downloads.jsm");
@@ -98,17 +99,17 @@ Bookmarks.prototype = {
return;
let folderGuid = -1;
switch (aCollection) {
case this.ROOT_COLLECTION: {
// In Safari, it is possible (though quite cumbersome) to move
// bookmarks to the bookmarks root, which is the parent folder of
// all bookmarks "collections". That is somewhat in parallel with
- // both the places root and the unfiled-bookmarks root.
+ // both the places root and the unfiled-bookmarks root.
// Because the former is only an implementation detail in our UI,
// the unfiled root seems to be the best choice.
folderGuid = PlacesUtils.bookmarks.unfiledGuid;
break;
}
case this.MENU_COLLECTION: {
folderGuid = PlacesUtils.bookmarks.menuGuid;
if (!MigrationUtils.isStartupMigration) {
@@ -292,17 +293,17 @@ MainPreferencesPropertyList.prototype =
}
},
// Workaround for nsIBrowserProfileMigrator.sourceHomePageURL until
// it's replaced with an async method.
_readSync: function MPPL__readSync() {
if ("_dict" in this)
return this._dict;
-
+
let inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(Ci.nsIFileInputStream);
inputStream.init(this._file, -1, -1, 0);
let binaryStream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIBinaryInputStream);
binaryStream.setInputStream(inputStream);
let bytes = binaryStream.readByteArray(inputStream.available());
this._dict = PropertyListUtils._readFromArrayBufferSync(
@@ -339,27 +340,27 @@ Preferences.prototype = {
// Firefox has an elaborate set of Image preferences. The correlation is:
// Mode: Safari Firefox
// Blocked FALSE 2
// Allowed TRUE 1
// Allowed, originating site only -- 3
this._set("WebKitDisplayImagesKey", "permissions.default.image",
webkitVal => webkitVal ? 1 : 2);
-#ifdef XP_WIN
- // Cookie-accept policy.
- // For the OS X version, see WebFoundationCookieBehavior.
- // Setting Safari Firefox
- // Always Accept 0 0
- // Accept from Originating 2 1
- // Never Accept 1 2
- this._set("WebKitCookieStorageAcceptPolicy",
- "network.cookie.cookieBehavior",
- webkitVal => webkitVal == 0 ? 0 : webkitVal == 1 ? 2 : 1);
-#endif
+ if (AppConstants.platform == "win") {
+ // Cookie-accept policy.
+ // For the OS X version, see WebFoundationCookieBehavior.
+ // Setting Safari Firefox
+ // Always Accept 0 0
+ // Accept from Originating 2 1
+ // Never Accept 1 2
+ this._set("WebKitCookieStorageAcceptPolicy",
+ "network.cookie.cookieBehavior",
+ webkitVal => webkitVal == 0 ? 0 : webkitVal == 1 ? 2 : 1);
+ }
this._migrateFontSettings();
yield this._migrateDownloadsFolder();
}.bind(this)).then(() => aCallback(true), ex => {
Cu.reportError(ex);
aCallback(false);
}).catch(Cu.reportError);
@@ -539,17 +540,16 @@ SearchStrings.prototype = {
value: searchString}));
FormHistory.update(changes);
}
}
}.bind(this), aCallback));
}
};
-#ifdef XP_MACOSX
// On OS X, the cookie-accept policy preference is stored in a separate
// property list.
// For the Windows version, check Preferences.migrate.
function WebFoundationCookieBehavior(aWebFoundationFile) {
this._file = aWebFoundationFile;
}
WebFoundationCookieBehavior.prototype = {
type: MigrationUtils.resourceTypes.SETTINGS,
@@ -569,84 +569,83 @@ WebFoundationCookieBehavior.prototype =
let cookieValue = acceptCookies == "never" ? 2 :
acceptCookies == "current page" ? 1 : 0;
Services.prefs.setIntPref("network.cookie.cookieBehavior",
cookieValue);
}
}.bind(this), aCallback));
}
};
-#endif
function SafariProfileMigrator() {
}
SafariProfileMigrator.prototype = Object.create(MigratorPrototype);
SafariProfileMigrator.prototype.getResources = function SM_getResources() {
- let profileDir =
-#ifdef XP_MACOSX
- FileUtils.getDir("ULibDir", ["Safari"], false);
-#else
- FileUtils.getDir("AppData", ["Apple Computer", "Safari"], false);
-#endif
+ let profileDir;
+ if (AppConstants.platform == "macosx") {
+ profileDir = FileUtils.getDir("ULibDir", ["Safari"], false);
+ } else {
+ profileDir = FileUtils.getDir("AppData", ["Apple Computer", "Safari"], false);
+ }
if (!profileDir.exists())
return null;
let resources = [];
let pushProfileFileResource = function(aFileName, aConstructor) {
let file = profileDir.clone();
file.append(aFileName);
if (file.exists())
resources.push(new aConstructor(file));
};
pushProfileFileResource("History.plist", History);
pushProfileFileResource("Bookmarks.plist", Bookmarks);
-
+
// The Reading List feature was introduced at the same time in Windows and
// Mac versions of Safari. Not surprisingly, they are stored in the same
// format in both versions. Surpsingly, only on Windows there is a
- // separate property list for it. This isn't #ifdefed out on mac, because
+ // separate property list for it. This code is used on mac too, because
// Apple may fix this at some point.
pushProfileFileResource("ReadingList.plist", Bookmarks);
- let prefsDir =
-#ifdef XP_MACOSX
- FileUtils.getDir("UsrPrfs", [], false);
-#else
- FileUtils.getDir("AppData", ["Apple Computer", "Preferences"], false);
-#endif
+ let prefsDir;
+ if (AppConstants.platform == "macosx") {
+ prefsDir = FileUtils.getDir("UsrPrfs", [], false);
+ } else {
+ prefsDir = FileUtils.getDir("AppData", ["Apple Computer", "Preferences"], false);
+ }
let prefs = this.mainPreferencesPropertyList;
if (prefs) {
resources.push(new Preferences(prefs));
resources.push(new SearchStrings(prefs));
}
-#ifdef XP_MACOSX
- // On OS X, the cookie-accept policy preference is stored in a separate
- // property list.
- let wfFile = FileUtils.getFile("UsrPrfs", ["com.apple.WebFoundation.plist"]);
- if (wfFile.exists())
- resources.push(new WebFoundationCookieBehavior(wfFile));
-#endif
+ if (AppConstants.platform == "macosx") {
+ // On OS X, the cookie-accept policy preference is stored in a separate
+ // property list.
+ let wfFile = FileUtils.getFile("UsrPrfs", ["com.apple.WebFoundation.plist"]);
+ if (wfFile.exists())
+ resources.push(new WebFoundationCookieBehavior(wfFile));
+ }
return resources;
};
Object.defineProperty(SafariProfileMigrator.prototype, "mainPreferencesPropertyList", {
get: function get_mainPreferencesPropertyList() {
if (this._mainPreferencesPropertyList === undefined) {
- let file =
-#ifdef XP_MACOSX
- FileUtils.getDir("UsrPrfs", [], false);
-#else
- FileUtils.getDir("AppData", ["Apple Computer", "Preferences"], false);
-#endif
+ let file;
+ if (AppConstants.platform == "macosx") {
+ file = FileUtils.getDir("UsrPrfs", [], false);
+ } else {
+ file = FileUtils.getDir("AppData", ["Apple Computer", "Preferences"], false);
+ }
if (file.exists()) {
file.append("com.apple.Safari.plist");
if (file.exists()) {
return this._mainPreferencesPropertyList =
new MainPreferencesPropertyList(file);
}
}
return this._mainPreferencesPropertyList = null;
--- a/browser/components/migration/content/migration.js
+++ b/browser/components/migration/content/migration.js
@@ -391,17 +391,17 @@ var MigrationWizard = {
{
var items = document.getElementById(aID);
while (items.hasChildNodes())
items.removeChild(items.firstChild);
var brandBundle = document.getElementById("brandBundle");
var itemID;
for (var i = 0; i < 16; ++i) {
- var itemID = (this._itemsFlags >> i) & 0x1 ? Math.pow(2, i) : 0;
+ itemID = (this._itemsFlags >> i) & 0x1 ? Math.pow(2, i) : 0;
if (itemID > 0) {
var label = document.createElement("label");
label.id = itemID + "_migrated";
try {
label.setAttribute("value",
MigrationUtils.getLocalizedString(itemID + "_" + this._source));
items.appendChild(label);
}
@@ -411,26 +411,27 @@ var MigrationWizard = {
break;
}
}
}
},
observe: function (aSubject, aTopic, aData)
{
+ var label;
switch (aTopic) {
case "Migration:Started":
break;
case "Migration:ItemBeforeMigrate":
- var label = document.getElementById(aData + "_migrated");
+ label = document.getElementById(aData + "_migrated");
if (label)
label.setAttribute("style", "font-weight: bold");
break;
case "Migration:ItemAfterMigrate":
- var label = document.getElementById(aData + "_migrated");
+ label = document.getElementById(aData + "_migrated");
if (label)
label.removeAttribute("style");
break;
case "Migration:Ended":
if (this._autoMigrate) {
Services.telemetry.getKeyedHistogramById("FX_MIGRATION_HOMEPAGE_IMPORTED")
.add(this._source, !!this._newHomePage);
if (this._newHomePage) {