This patch includes fixes for bug 297121 "many timer messages in javascript console",

and it also includes the following fixes:
 - make binaryToHex work for octets < 0x10
 - make selectUpdate return non-null
 - no need for "map" variable in _verifyDownload
This commit is contained in:
darin%meer.net 2005-06-09 22:15:49 +00:00
Родитель 9997797e84
Коммит 3fb76ebfa2
1 изменённых файлов: 28 добавлений и 23 удалений

Просмотреть файл

@ -47,6 +47,7 @@ const PREF_APP_UPDATE_AUTOINSTALL_ENABLED = "app.update.autoInstallEnabled";
const PREF_APP_UPDATE_AUTOINSTALL_MODE = "app.update.autoInstallMode";
const PREF_APP_UPDATE_INTERVAL = "app.update.interval";
const PREF_APP_UPDATE_TIMER = "app.update.timer";
const PREF_APP_UPDATE_LOG_ENABLED = "app.update.logEnabled";
const PREF_APP_UPDATE_URL = "app.update.url";
@ -92,10 +93,11 @@ const nsICryptoHash = Components.interfaces.nsICryptoHash;
const Node = Components.interfaces.nsIDOMNode;
var gApp = null;
var gPref = null;
var gOS = null;
var gConsole = null;
var gApp = null;
var gPref = null;
var gOS = null;
var gConsole = null;
var gLogEnabled = false;
/**
* Logs a string to the error console.
@ -103,8 +105,10 @@ var gConsole = null;
* The string to write to the error console..
*/
function LOG(string) {
// dump("*** " + string + "\n");
gConsole.logStringMessage(string);
if (gLogEnabled) {
dump("*** " + string + "\n");
gConsole.logStringMessage(string);
}
}
/**
@ -113,7 +117,10 @@ function LOG(string) {
function binaryToHex(input) {
var result = "";
for (var i = 0; i < input.length; ++i) {
result += input.charCodeAt(i).toString(16);
var hex = input.charCodeAt(i).toString(16);
if (hex.length == 1)
hex = "0" + hex;
result += hex;
}
return result;
}
@ -368,6 +375,8 @@ function UpdateService() {
// Observe xpcom-shutdown to unhook pref branch observers above to avoid
// shutdown leaks.
gOS.addObserver(this, "xpcom-shutdown", false);
gLogEnabled = getPref("getBoolPref", PREF_APP_UPDATE_LOG_ENABLED, false);
}
UpdateService.prototype = {
@ -487,17 +496,17 @@ UpdateService.prototype = {
// Choose the newest of the available minor and major updates.
var majorUpdate = null, minorUpdate = null;
var newestMinor = updates[0], newestMajor = updates[0];
var vc = new VersionChecker();
for (var i = 0; i < updates.length; ++i) {
if (updates[i].type == "major" &&
vc.compare(newestMajor.version, updates[i].version) < 0)
vc.compare(newestMajor.version, updates[i].version) <= 0)
majorUpdate = newestMajor = updates[i];
if (updates[i].type == "minor" &&
vc.compare(newestMinor.version, updates[i].version) < 0)
vc.compare(newestMinor.version, updates[i].version) <= 0)
minorUpdate = newestMinor = updates[i];
}
// If there's a major update, always try and fetch that one first,
// otherwise fall back to the newest minor update.
return majorUpdate || minorUpdate;
@ -890,19 +899,15 @@ Downloader.prototype = {
try {
var hash = Components.classes["@mozilla.org/security/hash;1"].
createInstance(nsICryptoHash);
const map = {
"MD2" : nsICryptoHash.MD2,
"MD5" : nsICryptoHash.MD5,
"SHA1" : nsICryptoHash.SHA1,
"SHA256" : nsICryptoHash.SHA256,
"SHA384" : nsICryptoHash.SHA384,
"SHA512" : nsICryptoHash.SHA512
};
var hashfunction = this._patch.hashfunction.toUpperCase();
if (!(hashfunction in map))
var hashfunction = nsICryptoHash[this._patch.hashfunction.toUpperCase()];
if (hashfunction == undefined)
return false;
hash.init(map[hashfunction]);
hash.init(hashfunction);
hash.updateFromStream(fileStream, -1);
// NOTE: For now, we assume that the format of _patch.hashvalue is hex
// encoded binary (such as what is typically output by programs like
// sha1sum). In the future, this may change to base64 depending on how
// we choose to compute these hashes.
digest = binaryToHex(hash.finish(false));
} catch (e) {
LOG("failed to compute hash of downloaded update archive");
@ -911,7 +916,7 @@ Downloader.prototype = {
fileStream.close();
return digest == this._patch.hashvalue;
return digest == this._patch.hashvalue.toLowerCase();
},
/**