Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: js2; js2-basic-offset: 2; indent-tabs-mode: nil; -*- */ |
michael@0 | 2 | /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | * The contents of this file were copied almost entirely from |
michael@0 | 9 | * toolkit/identity/LogUtils.jsm. Until we've got a more generalized logging |
michael@0 | 10 | * mechanism for toolkit, I think this is going to be how we roll. |
michael@0 | 11 | */ |
michael@0 | 12 | |
michael@0 | 13 | "use strict"; |
michael@0 | 14 | |
michael@0 | 15 | this.EXPORTED_SYMBOLS = ["DownloadsLogger"]; |
michael@0 | 16 | const PREF_DEBUG = "browser.download.debug"; |
michael@0 | 17 | |
michael@0 | 18 | const Cu = Components.utils; |
michael@0 | 19 | const Ci = Components.interfaces; |
michael@0 | 20 | const Cc = Components.classes; |
michael@0 | 21 | const Cr = Components.results; |
michael@0 | 22 | |
michael@0 | 23 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 24 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 25 | |
michael@0 | 26 | this.DownloadsLogger = { |
michael@0 | 27 | _generateLogMessage: function _generateLogMessage(args) { |
michael@0 | 28 | // create a string representation of a list of arbitrary things |
michael@0 | 29 | let strings = []; |
michael@0 | 30 | |
michael@0 | 31 | for (let arg of args) { |
michael@0 | 32 | if (typeof arg === 'string') { |
michael@0 | 33 | strings.push(arg); |
michael@0 | 34 | } else if (arg === undefined) { |
michael@0 | 35 | strings.push('undefined'); |
michael@0 | 36 | } else if (arg === null) { |
michael@0 | 37 | strings.push('null'); |
michael@0 | 38 | } else { |
michael@0 | 39 | try { |
michael@0 | 40 | strings.push(JSON.stringify(arg, null, 2)); |
michael@0 | 41 | } catch(err) { |
michael@0 | 42 | strings.push("<<something>>"); |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | }; |
michael@0 | 46 | return 'Downloads: ' + strings.join(' '); |
michael@0 | 47 | }, |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * log() - utility function to print a list of arbitrary things |
michael@0 | 51 | * |
michael@0 | 52 | * Enable with about:config pref browser.download.debug |
michael@0 | 53 | */ |
michael@0 | 54 | log: function DL_log(...args) { |
michael@0 | 55 | let output = this._generateLogMessage(args); |
michael@0 | 56 | dump(output + "\n"); |
michael@0 | 57 | |
michael@0 | 58 | // Additionally, make the output visible in the Error Console |
michael@0 | 59 | Services.console.logStringMessage(output); |
michael@0 | 60 | }, |
michael@0 | 61 | |
michael@0 | 62 | /** |
michael@0 | 63 | * reportError() - report an error through component utils as well as |
michael@0 | 64 | * our log function |
michael@0 | 65 | */ |
michael@0 | 66 | reportError: function DL_reportError(...aArgs) { |
michael@0 | 67 | // Report the error in the browser |
michael@0 | 68 | let output = this._generateLogMessage(aArgs); |
michael@0 | 69 | Cu.reportError(output); |
michael@0 | 70 | dump("ERROR:" + output + "\n"); |
michael@0 | 71 | for (let frame = Components.stack.caller; frame; frame = frame.caller) { |
michael@0 | 72 | dump("\t" + frame + "\n"); |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | }; |