From 11b45755624e3a1baa5231a10cc674504fb0f1a9 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Fri, 12 Jun 2015 10:56:50 -0700 Subject: [PATCH] Bug 848569 - Replace DownloadsLogger with usage of ConsoleAPI. r=paolo --HG-- extra : commitid : EMrV14ODX7k extra : rebase_source : 38c4f62ec0097e5ae75054d3164c8b6b7252f679 --- browser/app/profile/firefox.js | 4 +- .../components/downloads/DownloadsCommon.jsm | 38 +++++----- .../components/downloads/DownloadsLogger.jsm | 75 ------------------- browser/components/downloads/moz.build | 1 - 4 files changed, 19 insertions(+), 99 deletions(-) delete mode 100644 browser/components/downloads/DownloadsLogger.jsm diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 8092c6543cab..c5470ca0f5e4 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -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 diff --git a/browser/components/downloads/DownloadsCommon.jsm b/browser/components/downloads/DownloadsCommon.jsm index 2fb06126ed29..1df637571909 100644 --- a/browser/components/downloads/DownloadsCommon.jsm +++ b/browser/components/downloads/DownloadsCommon.jsm @@ -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. */ diff --git a/browser/components/downloads/DownloadsLogger.jsm b/browser/components/downloads/DownloadsLogger.jsm deleted file mode 100644 index a24c9acc8a1c..000000000000 --- a/browser/components/downloads/DownloadsLogger.jsm +++ /dev/null @@ -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("<>"); - } - } - }; - 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"); - } - }, -}; diff --git a/browser/components/downloads/moz.build b/browser/components/downloads/moz.build index 87e7c39e791f..9d205cae6467 100644 --- a/browser/components/downloads/moz.build +++ b/browser/components/downloads/moz.build @@ -14,7 +14,6 @@ JAR_MANIFESTS += ['jar.mn'] EXTRA_JS_MODULES += [ 'DownloadsCommon.jsm', - 'DownloadsLogger.jsm', 'DownloadsTaskbar.jsm', 'DownloadsViewUI.jsm', ]