зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1557960 - cope with 0 values in Chrome's date/time columns when importing, r=mak
Differential Revision: https://phabricator.services.mozilla.com/D37810 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6e0169a2cf
Коммит
2b449941ae
|
@ -321,11 +321,20 @@ var ChromeMigrationUtils = {
|
|||
*
|
||||
* @param aTime
|
||||
* Chrome time
|
||||
* @param aFallbackValue
|
||||
* a date or timestamp (valid argument for the Date constructor)
|
||||
* that will be used if the chrometime value passed is invalid.
|
||||
* @return converted Date object
|
||||
* @note Google Chrome uses FILETIME / 10 as time.
|
||||
* FILETIME is based on same structure of Windows.
|
||||
*/
|
||||
chromeTimeToDate(aTime) {
|
||||
chromeTimeToDate(aTime, aFallbackValue) {
|
||||
// The date value may be 0 in some cases. Because of the subtraction below,
|
||||
// that'd generate a date before the unix epoch, which can upset consumers
|
||||
// due to the unix timestamp then being negative. Catch this case:
|
||||
if (!aTime) {
|
||||
return new Date(aFallbackValue);
|
||||
}
|
||||
return new Date((aTime * S100NS_PER_MS - S100NS_FROM1601TO1970) / 10000);
|
||||
},
|
||||
|
||||
|
|
|
@ -302,6 +302,7 @@ async function GetHistoryResource(aProfileFolder) {
|
|||
query
|
||||
);
|
||||
let pageInfos = [];
|
||||
let fallbackVisitDate = new Date();
|
||||
for (let row of rows) {
|
||||
try {
|
||||
// if having typed_count, we changes transition type to typed.
|
||||
|
@ -317,7 +318,8 @@ async function GetHistoryResource(aProfileFolder) {
|
|||
{
|
||||
transition,
|
||||
date: ChromeMigrationUtils.chromeTimeToDate(
|
||||
row.getResultByName("last_visit_time")
|
||||
row.getResultByName("last_visit_time"),
|
||||
fallbackVisitDate
|
||||
),
|
||||
},
|
||||
],
|
||||
|
@ -390,6 +392,7 @@ async function GetCookiesResource(aProfileFolder) {
|
|||
return;
|
||||
}
|
||||
|
||||
let fallbackExpiryDate = 0;
|
||||
for (let row of rows) {
|
||||
let host_key = row.getResultByName("host_key");
|
||||
if (host_key.match(/^\./)) {
|
||||
|
@ -400,8 +403,13 @@ async function GetCookiesResource(aProfileFolder) {
|
|||
try {
|
||||
let expiresUtc =
|
||||
ChromeMigrationUtils.chromeTimeToDate(
|
||||
row.getResultByName("expires_utc")
|
||||
row.getResultByName("expires_utc"),
|
||||
fallbackExpiryDate
|
||||
) / 1000;
|
||||
// No point adding cookies that don't have a valid expiry.
|
||||
if (!expiresUtc) {
|
||||
continue;
|
||||
}
|
||||
Services.cookies.add(
|
||||
host_key,
|
||||
row.getResultByName("path"),
|
||||
|
@ -450,6 +458,7 @@ async function GetWindowsPasswordsResource(aProfileFolder) {
|
|||
}
|
||||
let crypto = new OSCrypto();
|
||||
let logins = [];
|
||||
let fallbackCreationDate = new Date();
|
||||
for (let row of rows) {
|
||||
try {
|
||||
let origin_url = NetUtil.newURI(row.getResultByName("origin_url"));
|
||||
|
@ -471,7 +480,8 @@ async function GetWindowsPasswordsResource(aProfileFolder) {
|
|||
usernameElement: row.getResultByName("username_element"),
|
||||
passwordElement: row.getResultByName("password_element"),
|
||||
timeCreated: ChromeMigrationUtils.chromeTimeToDate(
|
||||
row.getResultByName("date_created") + 0
|
||||
row.getResultByName("date_created") + 0,
|
||||
fallbackCreationDate
|
||||
).getTime(),
|
||||
timesUsed: row.getResultByName("times_used") + 0,
|
||||
};
|
||||
|
|
|
@ -107,7 +107,8 @@ function assertEntryMatches(entry, urlInfo, dateWasInFuture = false) {
|
|||
Assert.equal(
|
||||
entry.visits[index].date.getTime(),
|
||||
ChromeMigrationUtils.chromeTimeToDate(
|
||||
urlInfo.visits[index].visit_time
|
||||
urlInfo.visits[index].visit_time,
|
||||
new Date()
|
||||
).getTime(),
|
||||
"Should have the correct date"
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче