Backed out 2 changesets (bug 1236916) for causing xpcshell failures on test_Safari_bookmarks.js
Backed out changeset 539dfe08bec7 (bug 1236916) Backed out changeset a0b5a7ade705 (bug 1236916)
This commit is contained in:
@@ -15,23 +15,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||
PropertyListUtils: "resource://gre/modules/PropertyListUtils.sys.mjs",
|
||||
});
|
||||
|
||||
// NSDate epoch is Jan 1, 2001 UTC
|
||||
const NS_DATE_EPOCH_MS = new Date("2001-01-01T00:00:00-00:00").getTime();
|
||||
|
||||
// Convert NSDate timestamp to UNIX timestamp.
|
||||
function parseNSDate(cocoaDateStr) {
|
||||
let asDouble = parseFloat(cocoaDateStr);
|
||||
if (!isNaN(asDouble)) {
|
||||
return new Date(NS_DATE_EPOCH_MS + asDouble * 1000);
|
||||
}
|
||||
return new Date();
|
||||
}
|
||||
|
||||
// Convert UNIX timestamp to NSDate timestamp.
|
||||
function msToNSDate(ms) {
|
||||
return parseFloat(ms - NS_DATE_EPOCH_MS) / 1000;
|
||||
}
|
||||
|
||||
function Bookmarks(aBookmarksFile) {
|
||||
this._file = aBookmarksFile;
|
||||
}
|
||||
@@ -346,86 +329,82 @@ Bookmarks.prototype = {
|
||||
},
|
||||
};
|
||||
|
||||
async function GetHistoryResource() {
|
||||
let dbPath = FileUtils.getDir(
|
||||
"ULibDir",
|
||||
["Safari", "History.db"],
|
||||
false
|
||||
).path;
|
||||
let maxAge = msToNSDate(
|
||||
Date.now() - MigrationUtils.HISTORY_MAX_AGE_IN_MILLISECONDS
|
||||
);
|
||||
function History(aHistoryFile) {
|
||||
this._file = aHistoryFile;
|
||||
}
|
||||
History.prototype = {
|
||||
type: MigrationUtils.resourceTypes.HISTORY,
|
||||
|
||||
let countQuery = `
|
||||
SELECT COUNT(*)
|
||||
FROM history_items LEFT JOIN history_visits
|
||||
ON history_items.id = history_visits.history_item
|
||||
WHERE history_visits.visit_time > ${maxAge}
|
||||
LIMIT 1;`;
|
||||
let selectQuery = `
|
||||
SELECT
|
||||
history_items.url as history_url,
|
||||
history_visits.title as history_title,
|
||||
history_visits.visit_time as history_time
|
||||
FROM history_items LEFT JOIN history_visits
|
||||
ON history_items.id = history_visits.history_item
|
||||
WHERE history_visits.visit_time > ${maxAge};`;
|
||||
|
||||
let countResult = await MigrationUtils.getRowsFromDBWithoutLocks(
|
||||
dbPath,
|
||||
"Safari history",
|
||||
countQuery
|
||||
);
|
||||
|
||||
if (!countResult[0].getResultByName("COUNT(*)")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
type: MigrationUtils.resourceTypes.HISTORY,
|
||||
|
||||
async migrate(callback) {
|
||||
callback(await this._migrate());
|
||||
},
|
||||
|
||||
async _migrate() {
|
||||
let historyRows;
|
||||
// Helper method for converting the visit date property to a PRTime value.
|
||||
// The visit date is stored as a string, so it's not read as a Date
|
||||
// object by PropertyListUtils.
|
||||
_parseCocoaDate: function H___parseCocoaDate(aCocoaDateStr) {
|
||||
let asDouble = parseFloat(aCocoaDateStr);
|
||||
if (!isNaN(asDouble)) {
|
||||
// reference date of NSDate.
|
||||
let date = new Date("1 January 2001, GMT");
|
||||
date.setMilliseconds(asDouble * 1000);
|
||||
return date;
|
||||
}
|
||||
return new Date();
|
||||
},
|
||||
|
||||
migrate: function H_migrate(aCallback) {
|
||||
lazy.PropertyListUtils.read(this._file, aDict => {
|
||||
try {
|
||||
historyRows = await MigrationUtils.getRowsFromDBWithoutLocks(
|
||||
dbPath,
|
||||
"Safari history",
|
||||
selectQuery
|
||||
);
|
||||
|
||||
if (!historyRows.length) {
|
||||
console.log("No history found");
|
||||
return false;
|
||||
if (!aDict) {
|
||||
throw new Error("Could not read history property list");
|
||||
}
|
||||
if (!aDict.has("WebHistoryDates")) {
|
||||
throw new Error("Unexpected history-property list format");
|
||||
}
|
||||
|
||||
let pageInfos = [];
|
||||
let entries = aDict.get("WebHistoryDates");
|
||||
let failedOnce = false;
|
||||
for (let entry of entries) {
|
||||
if (entry.has("lastVisitedDate")) {
|
||||
let date = this._parseCocoaDate(entry.get("lastVisitedDate"));
|
||||
try {
|
||||
pageInfos.push({
|
||||
url: new URL(entry.get("")),
|
||||
title: entry.get("title"),
|
||||
visits: [
|
||||
{
|
||||
// Safari's History file contains only top-level urls. It does not
|
||||
// distinguish between typed urls and linked urls.
|
||||
transition: lazy.PlacesUtils.history.TRANSITIONS.LINK,
|
||||
date,
|
||||
},
|
||||
],
|
||||
});
|
||||
} catch (ex) {
|
||||
// Safari's History file may contain malformed URIs which
|
||||
// will be ignored.
|
||||
console.error(ex);
|
||||
failedOnce = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pageInfos.length) {
|
||||
// If we failed at least once, then we didn't succeed in importing,
|
||||
// otherwise we didn't actually have anything to import, so we'll
|
||||
// report it as a success.
|
||||
aCallback(!failedOnce);
|
||||
return;
|
||||
}
|
||||
|
||||
MigrationUtils.insertVisitsWrapper(pageInfos).then(
|
||||
() => aCallback(true),
|
||||
() => aCallback(false)
|
||||
);
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
return false;
|
||||
aCallback(false);
|
||||
}
|
||||
|
||||
let pageInfos = [];
|
||||
for (let row of historyRows) {
|
||||
pageInfos.push({
|
||||
title: row.getResultByName("history_title"),
|
||||
url: new URL(row.getResultByName("history_url")),
|
||||
visits: [
|
||||
{
|
||||
transition: lazy.PlacesUtils.history.TRANSITIONS.TYPED,
|
||||
date: parseNSDate(row.getResultByName("history_time")),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
await MigrationUtils.insertVisitsWrapper(pageInfos);
|
||||
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Safari's preferences property list is independently used for three purposes:
|
||||
@@ -518,7 +497,7 @@ export class SafariProfileMigrator extends MigratorBase {
|
||||
return "chrome://browser/content/migration/brands/safari.png";
|
||||
}
|
||||
|
||||
async getResources() {
|
||||
getResources() {
|
||||
let profileDir = FileUtils.getDir("ULibDir", ["Safari"], false);
|
||||
if (!profileDir.exists()) {
|
||||
return null;
|
||||
@@ -533,6 +512,7 @@ export class SafariProfileMigrator extends MigratorBase {
|
||||
}
|
||||
};
|
||||
|
||||
pushProfileFileResource("History.plist", History);
|
||||
pushProfileFileResource("Bookmarks.plist", Bookmarks);
|
||||
|
||||
// The Reading List feature was introduced at the same time in Windows and
|
||||
@@ -547,11 +527,7 @@ export class SafariProfileMigrator extends MigratorBase {
|
||||
resources.push(new SearchStrings(prefs));
|
||||
}
|
||||
|
||||
resources.push(GetHistoryResource());
|
||||
|
||||
resources = await Promise.all(resources);
|
||||
|
||||
return resources.filter(r => r != null);
|
||||
return resources;
|
||||
}
|
||||
|
||||
async getLastUsedDate() {
|
||||
|
||||
Reference in New Issue
Block a user