Bug 848569 - Replace DownloadsLogger with usage of ConsoleAPI. r=paolo

This commit is contained in:
Matthew Noorenberghe 2015-06-12 10:56:50 -07:00
parent 09fbbef1db
commit d53288070b
4 changed files with 19 additions and 99 deletions

View File

@ -358,8 +358,8 @@ pref("browser.urlbar.trimURLs", true);
pref("browser.altClickSave", false);
// Enable logging downloads operations to the Error Console.
pref("browser.download.debug", false);
// Enable logging downloads operations to the Console.
pref("browser.download.loglevel", "Error");
// Number of milliseconds to wait for the http headers (and thus
// the Content-Disposition filename) before giving up and falling back to

View File

@ -33,10 +33,7 @@ this.EXPORTED_SYMBOLS = [
////////////////////////////////////////////////////////////////////////////////
//// Globals
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
@ -65,8 +62,15 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsLogger",
"resource:///modules/DownloadsLogger.jsm");
XPCOMUtils.defineLazyGetter(this, "DownloadsLogger", () => {
let { ConsoleAPI } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
let consoleOptions = {
maxLogLevelPref: "browser.download.loglevel",
prefix: "Downloads"
};
return new ConsoleAPI(consoleOptions);
});
const nsIDM = Ci.nsIDownloadManager;
@ -124,7 +128,6 @@ let PrefObserver = {
PrefObserver.register({
// prefName: defaultValue
debug: false,
animateNotifications: true
});
@ -144,20 +147,6 @@ this.DownloadsCommon = {
BLOCK_VERDICT_POTENTIALLY_UNWANTED: "PotentiallyUnwanted",
BLOCK_VERDICT_UNCOMMON: "Uncommon",
log(...aMessageArgs) {
if (!PrefObserver.debug) {
return;
}
DownloadsLogger.log(...aMessageArgs);
},
error(...aMessageArgs) {
if (!PrefObserver.debug) {
return;
}
DownloadsLogger.reportError(...aMessageArgs);
},
/**
* Returns an object whose keys are the string names from the downloads string
* bundle, and whose values are either the translated strings or functions
@ -601,6 +590,13 @@ this.DownloadsCommon = {
}),
};
XPCOMUtils.defineLazyGetter(this.DownloadsCommon, "log", () => {
return DownloadsLogger.log.bind(DownloadsLogger);
});
XPCOMUtils.defineLazyGetter(this.DownloadsCommon, "error", () => {
return DownloadsLogger.error.bind(DownloadsLogger);
});
/**
* Returns true if we are executing on Windows Vista or a later version.
*/

View File

@ -1,75 +0,0 @@
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* 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/. */
/**
* The contents of this file were copied almost entirely from
* toolkit/identity/LogUtils.jsm. Until we've got a more generalized logging
* mechanism for toolkit, I think this is going to be how we roll.
*/
"use strict";
this.EXPORTED_SYMBOLS = ["DownloadsLogger"];
const PREF_DEBUG = "browser.download.debug";
const Cu = Components.utils;
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
this.DownloadsLogger = {
_generateLogMessage(args) {
// create a string representation of a list of arbitrary things
let strings = [];
for (let arg of args) {
if (typeof arg === 'string') {
strings.push(arg);
} else if (arg === undefined) {
strings.push('undefined');
} else if (arg === null) {
strings.push('null');
} else {
try {
strings.push(JSON.stringify(arg, null, 2));
} catch(err) {
strings.push("<<something>>");
}
}
};
return 'Downloads: ' + strings.join(' ');
},
/**
* log() - utility function to print a list of arbitrary things
*
* Enable with about:config pref browser.download.debug
*/
log(...args) {
let output = this._generateLogMessage(args);
dump(output + "\n");
// Additionally, make the output visible in the Error Console
Services.console.logStringMessage(output);
},
/**
* reportError() - report an error through component utils as well as
* our log function
*/
reportError(...aArgs) {
// Report the error in the browser
let output = this._generateLogMessage(aArgs);
Cu.reportError(output);
dump("ERROR:" + output + "\n");
for (let frame = Components.stack.caller; frame; frame = frame.caller) {
dump("\t" + frame + "\n");
}
},
};

View File

@ -14,7 +14,6 @@ JAR_MANIFESTS += ['jar.mn']
EXTRA_JS_MODULES += [
'DownloadsCommon.jsm',
'DownloadsLogger.jsm',
'DownloadsTaskbar.jsm',
'DownloadsViewUI.jsm',
]