diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 3498f0c2a178..a075bd901b01 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -83,14 +83,70 @@ const DEFAULT_PROVIDERS = [ "resource://gre/modules/LightweightThemeManager.jsm" ]; -["LOG", "WARN", "ERROR"].forEach(function(aName) { - this.__defineGetter__(aName, function logFuncGetter() { - Components.utils.import("resource://gre/modules/addons/AddonLogging.jsm"); +Cu.import("resource://gre/modules/Log.jsm"); +// Configure a logger at the parent 'addons' level to format +// messages for all the modules under addons.* +const PARENT_LOGGER_ID = "addons"; +let parentLogger = Log.repository.getLogger(PARENT_LOGGER_ID); +parentLogger.level = Log.Level.Warn; +let formatter = new Log.BasicFormatter(); +// Set parent logger (and its children) to append to +// the Javascript section of the Browser Console +parentLogger.addAppender(new Log.ConsoleAppender(formatter)); +// Set parent logger (and its children) to +// also append to standard out +parentLogger.addAppender(new Log.DumpAppender(formatter)); - LogManager.getLogger("addons.manager", this); - return this[aName]; - }); -}, this); +// Create a new logger (child of 'addons' logger) +// for use by the Addons Manager +const LOGGER_ID = "addons.manager"; +let logger = Log.repository.getLogger(LOGGER_ID); + +// Provide the ability to enable/disable logging +// messages at runtime. +// If the "extensions.logging.enabled" preference is +// missing or 'false', messages at the WARNING and higher +// severity should be logged to the JS console and standard error. +// If "extensions.logging.enabled" is set to 'true', messages +// at DEBUG and higher should go to JS console and standard error. +const PREF_LOGGING_ENABLED = "extensions.logging.enabled"; +const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed"; + +/** + * Preference listener which listens for a change in the + * "extensions.logging.enabled" preference and changes the logging level of the + * parent 'addons' level logger accordingly. + */ +var PrefObserver = { + init: function PrefObserver_init() { + Services.prefs.addObserver(PREF_LOGGING_ENABLED, this, false); + Services.obs.addObserver(this, "xpcom-shutdown", false); + this.observe(null, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, PREF_LOGGING_ENABLED); + }, + + observe: function PrefObserver_observe(aSubject, aTopic, aData) { + if (aTopic == "xpcom-shutdown") { + Services.prefs.removeObserver(PREF_LOGGING_ENABLED, this); + Services.obs.removeObserver(this, "xpcom-shutdown"); + } + else if (aTopic == NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) { + let debugLogEnabled = false; + try { + debugLogEnabled = Services.prefs.getBoolPref(PREF_LOGGING_ENABLED); + } + catch (e) { + } + if (debugLogEnabled) { + parentLogger.level = Log.Level.Debug; + } + else { + parentLogger.level = Log.Level.Warn; + } + } + } +}; + +PrefObserver.init(); /** * Calls a callback method consuming any thrown exception. Any parameters after @@ -104,7 +160,7 @@ function safeCall(aCallback, ...aArgs) { aCallback.apply(null, aArgs); } catch (e) { - WARN("Exception calling callback", e); + logger.warn("Exception calling callback", e); } } @@ -130,7 +186,7 @@ function callProvider(aProvider, aMethod, aDefault, ...aArgs) { return aProvider[aMethod].apply(aProvider, aArgs); } catch (e) { - ERROR("Exception calling provider " + aMethod, e); + logger.error("Exception calling provider " + aMethod, e); return aDefault; } } @@ -496,7 +552,7 @@ var AddonManagerInternal = { catch (e) { } if (appChanged !== false) { - LOG("Application has been upgraded"); + logger.debug("Application has been upgraded"); Services.prefs.setCharPref(PREF_EM_LAST_APP_VERSION, Services.appinfo.version); Services.prefs.setCharPref(PREF_EM_LAST_PLATFORM_VERSION, @@ -558,7 +614,7 @@ var AddonManagerInternal = { } catch (e) { AddonManagerPrivate.recordException("AMI", "provider " + url + " load failed", e); - ERROR("Exception loading default provider \"" + url + "\"", e); + logger.error("Exception loading default provider \"" + url + "\"", e); } }); } @@ -576,7 +632,7 @@ var AddonManagerInternal = { } catch (e) { AddonManagerPrivate.recordException("AMI", "provider " + url + " load failed", e); - ERROR("Exception loading provider " + entry + " from category \"" + + logger.error("Exception loading provider " + entry + " from category \"" + url + "\"", e); } } @@ -601,7 +657,7 @@ var AddonManagerInternal = { this.recordTimestamp("AMI_startup_end"); } catch (e) { - ERROR("startup failed", e); + logger.error("startup failed", e); AddonManagerPrivate.recordException("AMI", "startup failed", e); } }, @@ -629,7 +685,7 @@ var AddonManagerInternal = { aTypes.forEach(function(aType) { if (!(aType.id in this.types)) { if (!VALID_TYPES_REGEXP.test(aType.id)) { - WARN("Ignoring invalid type " + aType.id); + logger.warn("Ignoring invalid type " + aType.id); return; } @@ -716,7 +772,7 @@ var AddonManagerInternal = { provider[aMethod].apply(provider, aArgs); } catch (e) { - ERROR("Exception calling provider " + aMethod, e); + logger.error("Exception calling provider " + aMethod, e); } } }, @@ -751,12 +807,12 @@ var AddonManagerInternal = { // Log and swallow the errors from methods that do return promises. nextPromise = nextPromise.then( null, - e => ERROR("Exception calling provider " + aMethod, e)); + e => logger.error("Exception calling provider " + aMethod, e)); allProviders.push(nextPromise); } } catch (e) { - ERROR("Exception calling provider " + aMethod, e); + logger.error("Exception calling provider " + aMethod, e); } } // Because we use promise.then to catch and log all errors above, Promise.all() @@ -771,7 +827,7 @@ var AddonManagerInternal = { * have finished shutting down */ shutdown: function AMI_shutdown() { - LOG("shutdown"); + logger.debug("shutdown"); // Clean up listeners Services.prefs.removeObserver(PREF_EM_CHECK_COMPATIBILITY, this); Services.prefs.removeObserver(PREF_EM_STRICT_COMPATIBILITY, this); @@ -786,15 +842,15 @@ var AddonManagerInternal = { if (gStarted) { shuttingDown = this.callProvidersAsync("shutdown") .then(null, - err => ERROR("Failure during async provider shutdown", err)) + err => logger.error("Failure during async provider shutdown", err)) .then(() => AddonRepository.shutdown()); } else { shuttingDown = AddonRepository.shutdown(); } - shuttingDown.then(val => LOG("Async provider shutdown done"), - err => ERROR("Failure during AddonRepository shutdown", err)) + shuttingDown.then(val => logger.debug("Async provider shutdown done"), + err => logger.error("Failure during AddonRepository shutdown", err)) .then(() => { this.managerListeners.splice(0, this.managerListeners.length); this.installListeners.splice(0, this.installListeners.length); @@ -1088,7 +1144,7 @@ var AddonManagerInternal = { return; } - LOG("Downloading hotfix version " + update.version); + logger.debug("Downloading hotfix version " + update.version); AddonManager.getInstallForURL(update.updateURL, function BUC_getInstallForURL(aInstall) { aInstall.addListener({ @@ -1107,7 +1163,7 @@ var AddonManagerInternal = { CertUtils.readCertPrefs(PREF_EM_HOTFIX_CERTS)); } catch (e) { - WARN("The hotfix add-on was not signed by the expected " + + logger.warn("The hotfix add-on was not signed by the expected " + "certificate and so will not be installed."); aInstall.cancel(); } @@ -1224,7 +1280,7 @@ var AddonManagerInternal = { listener[aMethod].apply(listener, aArgs); } catch (e) { - WARN("AddonManagerListener threw exception when calling " + aMethod, e); + logger.warn("AddonManagerListener threw exception when calling " + aMethod, e); } } }, @@ -1268,7 +1324,7 @@ var AddonManagerInternal = { } } catch (e) { - WARN("InstallListener threw exception when calling " + aMethod, e); + logger.warn("InstallListener threw exception when calling " + aMethod, e); } } return result; @@ -1297,7 +1353,7 @@ var AddonManagerInternal = { listener[aMethod].apply(listener, aArgs); } catch (e) { - WARN("AddonListener threw exception when calling " + aMethod, e); + logger.warn("AddonListener threw exception when calling " + aMethod, e); } } }, @@ -1676,7 +1732,7 @@ var AddonManagerInternal = { Cr.NS_ERROR_INVALID_ARG); if (!("@mozilla.org/addons/web-install-listener;1" in Cc)) { - WARN("No web installer available, cancelling all installs"); + logger.warn("No web installer available, cancelling all installs"); aInstalls.forEach(function(aInstall) { aInstall.cancel(); }); @@ -1710,7 +1766,7 @@ var AddonManagerInternal = { // In the event that the weblistener throws during instantiation or when // calling onWebInstallBlocked or onWebInstallRequested all of the // installs should get cancelled. - WARN("Failure calling web installer", e); + logger.warn("Failure calling web installer", e); aInstalls.forEach(function(aInstall) { aInstall.cancel(); }); diff --git a/toolkit/mozapps/extensions/DeferredSave.jsm b/toolkit/mozapps/extensions/DeferredSave.jsm index e692255d169f..d7f5b88642e7 100644 --- a/toolkit/mozapps/extensions/DeferredSave.jsm +++ b/toolkit/mozapps/extensions/DeferredSave.jsm @@ -19,6 +19,68 @@ this.EXPORTED_SYMBOLS = ["DeferredSave"]; // If delay parameter is not provided, default is 50 milliseconds. const DEFAULT_SAVE_DELAY_MS = 50; +Cu.import("resource://gre/modules/Log.jsm"); +//Configure a logger at the parent 'DeferredSave' level to format +//messages for all the modules under DeferredSave.* +const DEFERREDSAVE_PARENT_LOGGER_ID = "DeferredSave"; +let parentLogger = Log.repository.getLogger(DEFERREDSAVE_PARENT_LOGGER_ID); +parentLogger.level = Log.Level.Warn; +let formatter = new Log.BasicFormatter(); +//Set parent logger (and its children) to append to +//the Javascript section of the Browser Console +parentLogger.addAppender(new Log.ConsoleAppender(formatter)); +//Set parent logger (and its children) to +//also append to standard out +parentLogger.addAppender(new Log.DumpAppender(formatter)); + +//Provide the ability to enable/disable logging +//messages at runtime. +//If the "extensions.logging.enabled" preference is +//missing or 'false', messages at the WARNING and higher +//severity should be logged to the JS console and standard error. +//If "extensions.logging.enabled" is set to 'true', messages +//at DEBUG and higher should go to JS console and standard error. +Cu.import("resource://gre/modules/Services.jsm"); + +const PREF_LOGGING_ENABLED = "extensions.logging.enabled"; +const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed"; + +/** +* Preference listener which listens for a change in the +* "extensions.logging.enabled" preference and changes the logging level of the +* parent 'addons' level logger accordingly. +*/ +var PrefObserver = { + init: function PrefObserver_init() { + Services.prefs.addObserver(PREF_LOGGING_ENABLED, this, false); + Services.obs.addObserver(this, "xpcom-shutdown", false); + this.observe(null, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, PREF_LOGGING_ENABLED); + }, + + observe: function PrefObserver_observe(aSubject, aTopic, aData) { + if (aTopic == "xpcom-shutdown") { + Services.prefs.removeObserver(PREF_LOGGING_ENABLED, this); + Services.obs.removeObserver(this, "xpcom-shutdown"); + } + else if (aTopic == NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) { + let debugLogEnabled = false; + try { + debugLogEnabled = Services.prefs.getBoolPref(PREF_LOGGING_ENABLED); + } + catch (e) { + } + if (debugLogEnabled) { + parentLogger.level = Log.Level.Debug; + } + else { + parentLogger.level = Log.Level.Warn; + } + } + } +}; + +PrefObserver.init(); + /** * A module to manage deferred, asynchronous writing of data files * to disk. Writing is deferred by waiting for a specified delay after @@ -42,10 +104,11 @@ const DEFAULT_SAVE_DELAY_MS = 50; * begins writing the data to disk. Default 50 milliseconds. */ this.DeferredSave = function (aPath, aDataProvider, aDelay) { - // Set up loggers for this instance of DeferredSave + // Create a new logger (child of 'DeferredSave' logger) + // for use by this particular instance of DeferredSave object let leafName = OS.Path.basename(aPath); - Cu.import("resource://gre/modules/addons/AddonLogging.jsm"); - LogManager.getLogger("DeferredSave/" + leafName, this); + let logger_id = DEFERREDSAVE_PARENT_LOGGER_ID + "." + leafName; + this.logger = Log.repository.getLogger(logger_id); // @type {Deferred|null}, null when no data needs to be written // @resolves with the result of OS.File.writeAtomic when all writes complete @@ -105,7 +168,7 @@ this.DeferredSave.prototype = { return; } - this.LOG("Starting timer"); + this.logger.debug("Starting timer"); if (!this._timer) this._timer = MakeTimer(); this._timer.initWithCallback(() => this._deferredSave(), @@ -118,10 +181,10 @@ this.DeferredSave.prototype = { * the promise is resolved with the number of bytes written. */ saveChanges: function() { - this.LOG("Save changes"); + this.logger.debug("Save changes"); if (!this._pending) { if (this.writeInProgress) { - this.LOG("Data changed while write in progress"); + this.logger.debug("Data changed while write in progress"); this.overlappedSaves++; } this._pending = Promise.defer(); @@ -145,7 +208,7 @@ this.DeferredSave.prototype = { toSave = this._dataProvider(); } catch(e) { - this.ERROR("Deferred save dataProvider failed", e); + this.logger.error("Deferred save dataProvider failed", e); writing.then(null, error => {}) .then(count => { pending.reject(e); @@ -155,7 +218,7 @@ this.DeferredSave.prototype = { writing.then(null, error => {return 0;}) .then(count => { - this.LOG("Starting write"); + this.logger.debug("Starting write"); this.totalSaves++; this.writeInProgress = true; @@ -164,13 +227,13 @@ this.DeferredSave.prototype = { result => { this._lastError = null; this.writeInProgress = false; - this.LOG("Write succeeded"); + this.logger.debug("Write succeeded"); pending.resolve(result); }, error => { this._lastError = error; this.writeInProgress = false; - this.WARN("Write failed", error); + this.logger.warn("Write failed", error); pending.reject(error); }); }); @@ -198,7 +261,7 @@ this.DeferredSave.prototype = { // immediately (_deferredSave queues the write for after the most // recent write completes, if it hasn't already) if (this._pending) { - this.LOG("Flush called while data is dirty"); + this.logger.debug("Flush called while data is dirty"); if (this._timer) { this._timer.cancel(); this._timer = null; @@ -208,4 +271,4 @@ this.DeferredSave.prototype = { return this._writing; } -} +}; diff --git a/toolkit/mozapps/extensions/amWebInstallListener.js b/toolkit/mozapps/extensions/amWebInstallListener.js index 2ca582bb6f82..a05258885cc7 100644 --- a/toolkit/mozapps/extensions/amWebInstallListener.js +++ b/toolkit/mozapps/extensions/amWebInstallListener.js @@ -14,10 +14,11 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cr = Components.results; +const Cu = Components.utils; -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); -Components.utils.import("resource://gre/modules/AddonManager.jsm"); -Components.utils.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/AddonManager.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); const URI_XPINSTALL_DIALOG = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul"; @@ -29,14 +30,12 @@ const READY_STATES = [ AddonManager.STATE_CANCELLED ]; -["LOG", "WARN", "ERROR"].forEach(function(aName) { - this.__defineGetter__(aName, function logFuncGetter() { - Components.utils.import("resource://gre/modules/addons/AddonLogging.jsm"); +Cu.import("resource://gre/modules/Log.jsm"); +const LOGGER_ID = "addons.weblistener"; - LogManager.getLogger("addons.weblistener", this); - return this[aName]; - }); -}, this); +// Create a new logger for use by the Addons Web Listener +// (Requires AddonManager.jsm) +let logger = Log.repository.getLogger(LOGGER_ID); function notifyObservers(aTopic, aWindow, aUri, aInstalls) { let info = { @@ -129,7 +128,7 @@ Installer.prototype = { // Just ignore cancelled downloads break; default: - WARN("Download of " + install.sourceURI.spec + " in unexpected state " + + logger.warn("Download of " + install.sourceURI.spec + " in unexpected state " + install.state); } } diff --git a/toolkit/mozapps/extensions/internal/AddonRepository.jsm b/toolkit/mozapps/extensions/internal/AddonRepository.jsm index adf2dfb9a66d..0c40b6002443 100644 --- a/toolkit/mozapps/extensions/internal/AddonRepository.jsm +++ b/toolkit/mozapps/extensions/internal/AddonRepository.jsm @@ -61,14 +61,12 @@ const BLANK_DB = function() { const TOOLKIT_ID = "toolkit@mozilla.org"; -["LOG", "WARN", "ERROR"].forEach(function(aName) { - this.__defineGetter__(aName, function logFuncGetter() { - Components.utils.import("resource://gre/modules/addons/AddonLogging.jsm"); +Cu.import("resource://gre/modules/Log.jsm"); +const LOGGER_ID = "addons.repository"; - LogManager.getLogger("addons.repository", this); - return this[aName]; - }); -}, this); +// Create a new logger for use by the Addons Repository +// (Requires AddonManager.jsm) +let logger = Log.repository.getLogger(LOGGER_ID); // A map between XML keys to AddonSearchResult keys for string values // that require no extra parsing from XML @@ -445,7 +443,7 @@ AddonSearchResult.prototype = { json[property] = value; } } catch (ex) { - WARN("Error writing property value for " + property); + logger.warn("Error writing property value for " + property); } } @@ -484,7 +482,7 @@ this.AddonRepository = { try { enabled = Services.prefs.getBoolPref(preference); } catch(e) { - WARN("cacheEnabled: Couldn't get pref: " + preference); + logger.warn("cacheEnabled: Couldn't get pref: " + preference); } return enabled; @@ -639,7 +637,7 @@ this.AddonRepository = { AddonDatabase.repopulate(aAddons, aCallback); }, searchFailed: function repopulateCacheInternal_searchFailed() { - WARN("Search failed when repopulating cache"); + logger.warn("Search failed when repopulating cache"); if (aCallback) aCallback(); } @@ -679,7 +677,7 @@ this.AddonRepository = { AddonDatabase.insertAddons(aAddons, aCallback); }, searchFailed: function cacheAddons_searchFailed() { - WARN("Search failed when adding add-ons to cache"); + logger.warn("Search failed when adding add-ons to cache"); if (aCallback) aCallback(); } @@ -1067,7 +1065,7 @@ this.AddonRepository = { addon.type = "dictionary"; break; default: - WARN("Unknown type id when parsing addon: " + id); + logger.warn("Unknown type id when parsing addon: " + id); } break; case "authors": @@ -1312,7 +1310,7 @@ this.AddonRepository = { _parseAddonCompatElement: function AddonRepo_parseAddonCompatElement(aResultObj, aElement) { let guid = this._getDescendantTextContent(aElement, "guid"); if (!guid) { - LOG("Compatibility override is missing guid."); + logger.debug("Compatibility override is missing guid."); return; } @@ -1348,7 +1346,7 @@ this.AddonRepository = { let type = aNode.getAttribute("type"); // Only "incompatible" (blacklisting) is supported for now. if (type != "incompatible") { - LOG("Compatibility override of unsupported type found."); + logger.debug("Compatibility override of unsupported type found."); return null; } @@ -1358,18 +1356,18 @@ this.AddonRepository = { override.maxVersion = this._getDirectDescendantTextContent(aNode, "max_version"); if (!override.minVersion) { - LOG("Compatibility override is missing min_version."); + logger.debug("Compatibility override is missing min_version."); return null; } if (!override.maxVersion) { - LOG("Compatibility override is missing max_version."); + logger.debug("Compatibility override is missing max_version."); return null; } let appRanges = aNode.querySelectorAll("compatible_applications > application"); let appRange = findMatchingAppRange.bind(this)(appRanges); if (!appRange) { - LOG("Compatibility override is missing a valid application range."); + logger.debug("Compatibility override is missing a valid application range."); return null; } @@ -1407,7 +1405,7 @@ this.AddonRepository = { this._callback = aCallback; this._maxResults = aMaxResults; - LOG("Requesting " + aURI); + logger.debug("Requesting " + aURI); this._request = new XHRequest(); this._request.mozBackgroundRequest = true; @@ -1475,7 +1473,7 @@ this.AddonRepository = { try { url = Services.prefs.getCharPref(aPreference); } catch(e) { - WARN("_formatURLPref: Couldn't get pref: " + aPreference); + logger.warn("_formatURLPref: Couldn't get pref: " + aPreference); return null; } @@ -1575,7 +1573,7 @@ var AddonDatabase = { } } catch (e if e.result == Cr.NS_ERROR_FILE_NOT_FOUND) { - LOG("No " + FILE_DATABASE + " found."); + logger.debug("No " + FILE_DATABASE + " found."); // Create a blank addons.json file this._saveDBToDisk(); @@ -1604,7 +1602,7 @@ var AddonDatabase = { return; } catch (e) { - ERROR("Malformed " + FILE_DATABASE + ": " + e); + logger.error("Malformed " + FILE_DATABASE + ": " + e); this.databaseOk = false; return; @@ -1675,7 +1673,7 @@ var AddonDatabase = { // shutdown(true) never rejects .then(() => this.shutdown(true)) .then(() => OS.File.remove(this.jsonFile.path, {})) - .then(null, error => ERROR("Unable to delete Addon Repository file " + + .then(null, error => logger.error("Unable to delete Addon Repository file " + this.jsonFile.path, error)) .then(aCallback); }, @@ -1866,7 +1864,7 @@ var AddonDatabase = { addon[expectedProperty] = value; } } catch (ex) { - WARN("Error in parsing property value for " + expectedProperty + " | " + ex); + logger.warn("Error in parsing property value for " + expectedProperty + " | " + ex); } // delete property from obj to indicate we've already @@ -1910,7 +1908,7 @@ var AddonDatabase = { _saveDBToDisk: function() { return this.Writer.saveChanges().then( function() Services.obs.notifyObservers(null, DB_DATA_WRITTEN_TOPIC, null), - ERROR); + logger.error); }, /** diff --git a/toolkit/mozapps/extensions/internal/AddonRepository_SQLiteMigrator.jsm b/toolkit/mozapps/extensions/internal/AddonRepository_SQLiteMigrator.jsm index f0738d52c48b..128146bbe666 100644 --- a/toolkit/mozapps/extensions/internal/AddonRepository_SQLiteMigrator.jsm +++ b/toolkit/mozapps/extensions/internal/AddonRepository_SQLiteMigrator.jsm @@ -6,10 +6,11 @@ const Cc = Components.classes; const Ci = Components.interfaces; +const Cu = Components.utils; -Components.utils.import("resource://gre/modules/Services.jsm"); -Components.utils.import("resource://gre/modules/AddonManager.jsm"); -Components.utils.import("resource://gre/modules/FileUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/AddonManager.jsm"); +Cu.import("resource://gre/modules/FileUtils.jsm"); const KEY_PROFILEDIR = "ProfD"; const FILE_DATABASE = "addons.sqlite"; @@ -24,16 +25,12 @@ const PROP_SINGLE = ["id", "type", "name", "version", "creator", "description", "dailyUsers", "sourceURI", "repositoryStatus", "size", "updateDate"]; +Cu.import("resource://gre/modules/Log.jsm"); +const LOGGER_ID = "addons.repository.sqlmigrator"; -["LOG", "WARN", "ERROR"].forEach(function(aName) { - this.__defineGetter__(aName, function logFuncGetter() { - Components.utils.import("resource://gre/modules/addons/AddonLogging.jsm"); - - LogManager.getLogger("addons.repository.sqlmigrator", this); - return this[aName]; - }); -}, this); - +// Create a new logger for use by the Addons Repository SQL Migrator +// (Requires AddonManager.jsm) +let logger = Log.repository.getLogger(LOGGER_ID); this.EXPORTED_SYMBOLS = ["AddonRepository_SQLiteMigrator"]; @@ -59,12 +56,12 @@ this.AddonRepository_SQLiteMigrator = { return false; } - LOG("Importing addon repository from previous " + FILE_DATABASE + " storage."); + logger.debug("Importing addon repository from previous " + FILE_DATABASE + " storage."); this._retrieveStoredData((results) => { this._closeConnection(); let resultArray = [addon for ([,addon] of Iterator(results))]; - LOG(resultArray.length + " addons imported.") + logger.debug(resultArray.length + " addons imported.") aCallback(resultArray); }); @@ -100,13 +97,13 @@ this.AddonRepository_SQLiteMigrator = { return false; case 1: - LOG("Upgrading database schema to version 2"); + logger.debug("Upgrading database schema to version 2"); this.connection.executeSimpleSQL("ALTER TABLE screenshot ADD COLUMN width INTEGER"); this.connection.executeSimpleSQL("ALTER TABLE screenshot ADD COLUMN height INTEGER"); this.connection.executeSimpleSQL("ALTER TABLE screenshot ADD COLUMN thumbnailWidth INTEGER"); this.connection.executeSimpleSQL("ALTER TABLE screenshot ADD COLUMN thumbnailHeight INTEGER"); case 2: - LOG("Upgrading database schema to version 3"); + logger.debug("Upgrading database schema to version 3"); this.connection.createTable("compatibility_override", "addon_internal_id INTEGER, " + "num INTEGER, " + @@ -118,7 +115,7 @@ this.AddonRepository_SQLiteMigrator = { "appMaxVersion TEXT, " + "PRIMARY KEY (addon_internal_id, num)"); case 3: - LOG("Upgrading database schema to version 4"); + logger.debug("Upgrading database schema to version 4"); this.connection.createTable("icon", "addon_internal_id INTEGER, " + "size INTEGER, " + @@ -134,7 +131,7 @@ this.AddonRepository_SQLiteMigrator = { } this.connection.commitTransaction(); } catch (e) { - ERROR("Failed to open " + FILE_DATABASE + ". Data import will not happen.", e); + logger.error("Failed to open " + FILE_DATABASE + ". Data import will not happen.", e); this.logSQLError(this.connection.lastError, this.connection.lastErrorString); this.connection.rollbackTransaction(); return false; @@ -180,7 +177,7 @@ this.AddonRepository_SQLiteMigrator = { handleCompletion: function getAllAddons_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { - ERROR("Error retrieving add-ons from database. Returning empty results"); + logger.error("Error retrieving add-ons from database. Returning empty results"); aCallback({}); return; } @@ -198,7 +195,7 @@ this.AddonRepository_SQLiteMigrator = { while ((row = aResults.getNextRow())) { let addon_internal_id = row.getResultByName("addon_internal_id"); if (!(addon_internal_id in addons)) { - WARN("Found a developer not linked to an add-on in database"); + logger.warn("Found a developer not linked to an add-on in database"); continue; } @@ -214,7 +211,7 @@ this.AddonRepository_SQLiteMigrator = { handleCompletion: function getAllDevelopers_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { - ERROR("Error retrieving developers from database. Returning empty results"); + logger.error("Error retrieving developers from database. Returning empty results"); aCallback({}); return; } @@ -232,7 +229,7 @@ this.AddonRepository_SQLiteMigrator = { while ((row = aResults.getNextRow())) { let addon_internal_id = row.getResultByName("addon_internal_id"); if (!(addon_internal_id in addons)) { - WARN("Found a screenshot not linked to an add-on in database"); + logger.warn("Found a screenshot not linked to an add-on in database"); continue; } @@ -247,7 +244,7 @@ this.AddonRepository_SQLiteMigrator = { handleCompletion: function getAllScreenshots_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { - ERROR("Error retrieving screenshots from database. Returning empty results"); + logger.error("Error retrieving screenshots from database. Returning empty results"); aCallback({}); return; } @@ -264,7 +261,7 @@ this.AddonRepository_SQLiteMigrator = { while ((row = aResults.getNextRow())) { let addon_internal_id = row.getResultByName("addon_internal_id"); if (!(addon_internal_id in addons)) { - WARN("Found a compatibility override not linked to an add-on in database"); + logger.warn("Found a compatibility override not linked to an add-on in database"); continue; } @@ -279,7 +276,7 @@ this.AddonRepository_SQLiteMigrator = { handleCompletion: function getAllCompatOverrides_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { - ERROR("Error retrieving compatibility overrides from database. Returning empty results"); + logger.error("Error retrieving compatibility overrides from database. Returning empty results"); aCallback({}); return; } @@ -296,7 +293,7 @@ this.AddonRepository_SQLiteMigrator = { while ((row = aResults.getNextRow())) { let addon_internal_id = row.getResultByName("addon_internal_id"); if (!(addon_internal_id in addons)) { - WARN("Found an icon not linked to an add-on in database"); + logger.warn("Found an icon not linked to an add-on in database"); continue; } @@ -312,7 +309,7 @@ this.AddonRepository_SQLiteMigrator = { handleCompletion: function getAllIcons_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { - ERROR("Error retrieving icons from database. Returning empty results"); + logger.error("Error retrieving icons from database. Returning empty results"); aCallback({}); return; } @@ -349,7 +346,7 @@ this.AddonRepository_SQLiteMigrator = { try { return this.asyncStatementsCache[aKey] = this.connection.createAsyncStatement(sql); } catch (e) { - ERROR("Error creating statement " + aKey + " (" + sql + ")"); + logger.error("Error creating statement " + aKey + " (" + sql + ")"); throw Components.Exception("Error creating statement " + aKey + " (" + sql + "): " + e, e.result); } @@ -478,7 +475,7 @@ this.AddonRepository_SQLiteMigrator = { * An error message */ logSQLError: function AD_logSQLError(aError, aErrorString) { - ERROR("SQL error " + aError + ": " + aErrorString); + logger.error("SQL error " + aError + ": " + aErrorString); }, /** @@ -488,7 +485,7 @@ this.AddonRepository_SQLiteMigrator = { * A mozIStorageError to log */ asyncErrorLogger: function AD_asyncErrorLogger(aError) { - ERROR("Async SQL error " + aError.result + ": " + aError.message); + logger.error("Async SQL error " + aError.result + ": " + aError.message); }, /** diff --git a/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm b/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm index c65070350d70..831b10417d83 100644 --- a/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm +++ b/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm @@ -44,15 +44,12 @@ XPCOMUtils.defineLazyGetter(this, "CertUtils", function certUtilsLazyGetter() { var gRDF = Cc["@mozilla.org/rdf/rdf-service;1"]. getService(Ci.nsIRDFService); -["LOG", "WARN", "ERROR"].forEach(function(aName) { - this.__defineGetter__(aName, function logFuncGetter() { - Components.utils.import("resource://gre/modules/addons/AddonLogging.jsm"); - - LogManager.getLogger("addons.updates", this); - return this[aName]; - }); -}, this); +Cu.import("resource://gre/modules/Log.jsm"); +const LOGGER_ID = "addons.updates"; +// Create a new logger for use by the Addons Update Checker +// (Requires AddonManager.jsm) +let logger = Log.repository.getLogger(LOGGER_ID); /** * A serialisation method for RDF data that produces an identical string @@ -309,7 +306,7 @@ function parseRDFManifest(aId, aUpdateKey, aRequest) { // A missing updates property doesn't count as a failure, just as no avialable // update information if (!updates) { - WARN("Update manifest for " + aId + " did not contain an updates property"); + logger.warn("Update manifest for " + aId + " did not contain an updates property"); return []; } @@ -330,11 +327,11 @@ function parseRDFManifest(aId, aUpdateKey, aRequest) { let item = items.getNext().QueryInterface(Ci.nsIRDFResource); let version = getProperty(ds, item, "version"); if (!version) { - WARN("Update manifest is missing a required version property."); + logger.warn("Update manifest is missing a required version property."); continue; } - LOG("Found an update entry for " + aId + " version " + version); + logger.debug("Found an update entry for " + aId + " version " + version); let targetApps = ds.GetTargets(item, EM_R("targetApplication"), true); while (targetApps.hasMoreElements()) { @@ -347,7 +344,7 @@ function parseRDFManifest(aId, aUpdateKey, aRequest) { appEntry.maxVersion = getRequiredProperty(ds, targetApp, "maxVersion"); } catch (e) { - WARN(e); + logger.warn(e); continue; } @@ -364,7 +361,7 @@ function parseRDFManifest(aId, aUpdateKey, aRequest) { if (result.updateURL && AddonManager.checkUpdateSecurity && result.updateURL.substring(0, 6) != "https:" && (!result.updateHash || result.updateHash.substring(0, 3) != "sha")) { - WARN("updateLink " + result.updateURL + " is not secure and is not verified" + + logger.warn("updateLink " + result.updateURL + " is not secure and is not verified" + " by a strong enough hash (needs to be sha1 or stronger)."); delete result.updateURL; delete result.updateHash; @@ -401,7 +398,7 @@ function UpdateParser(aId, aUpdateKey, aUrl, aObserver) { catch (e) { } - LOG("Requesting " + aUrl); + logger.debug("Requesting " + aUrl); try { this.request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. createInstance(Ci.nsIXMLHttpRequest); @@ -419,7 +416,7 @@ function UpdateParser(aId, aUpdateKey, aUrl, aObserver) { this.request.send(null); } catch (e) { - ERROR("Failed to request update manifest", e); + logger.error("Failed to request update manifest", e); } } @@ -453,14 +450,14 @@ UpdateParser.prototype = { } if (!Components.isSuccessCode(request.status)) { - WARN("Request failed: " + this.url + " - " + request.status); + logger.warn("Request failed: " + this.url + " - " + request.status); this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR); return; } let channel = request.channel; if (channel instanceof Ci.nsIHttpChannel && !channel.requestSucceeded) { - WARN("Request failed: " + this.url + " - " + channel.responseStatus + + logger.warn("Request failed: " + this.url + " - " + channel.responseStatus + ": " + channel.responseStatusText); this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR); return; @@ -468,7 +465,7 @@ UpdateParser.prototype = { let xml = request.responseXML; if (!xml || xml.documentElement.namespaceURI == XMLURI_PARSE_ERROR) { - WARN("Update manifest was not valid XML"); + logger.warn("Update manifest was not valid XML"); this.notifyError(AddonUpdateChecker.ERROR_PARSE_ERROR); return; } @@ -481,7 +478,7 @@ UpdateParser.prototype = { results = parseRDFManifest(this.id, this.updateKey, request); } catch (e) { - WARN(e); + logger.warn(e); this.notifyError(AddonUpdateChecker.ERROR_PARSE_ERROR); return; } @@ -490,13 +487,13 @@ UpdateParser.prototype = { this.observer.onUpdateCheckComplete(results); } catch (e) { - WARN("onUpdateCheckComplete notification failed", e); + logger.warn("onUpdateCheckComplete notification failed", e); } } return; } - WARN("Update manifest had an unrecognised namespace: " + xml.documentElement.namespaceURI); + logger.warn("Update manifest had an unrecognised namespace: " + xml.documentElement.namespaceURI); this.notifyError(AddonUpdateChecker.ERROR_UNKNOWN_FORMAT); }, @@ -505,7 +502,7 @@ UpdateParser.prototype = { */ onTimeout: function() { this.request = null; - WARN("Request for " + this.url + " timed out"); + logger.warn("Request for " + this.url + " timed out"); this.notifyError(AddonUpdateChecker.ERROR_TIMEOUT); }, @@ -514,22 +511,22 @@ UpdateParser.prototype = { */ onError: function UP_onError() { if (!Components.isSuccessCode(this.request.status)) { - WARN("Request failed: " + this.url + " - " + this.request.status); + logger.warn("Request failed: " + this.url + " - " + this.request.status); } else if (this.request.channel instanceof Ci.nsIHttpChannel) { try { if (this.request.channel.requestSucceeded) { - WARN("Request failed: " + this.url + " - " + + logger.warn("Request failed: " + this.url + " - " + this.request.channel.responseStatus + ": " + this.request.channel.responseStatusText); } } catch (e) { - WARN("HTTP Request failed for an unknown reason"); + logger.warn("HTTP Request failed for an unknown reason"); } } else { - WARN("Request failed for an unknown reason"); + logger.warn("Request failed for an unknown reason"); } this.request = null; @@ -546,7 +543,7 @@ UpdateParser.prototype = { this.observer.onUpdateCheckError(aStatus); } catch (e) { - WARN("onUpdateCheckError notification failed", e); + logger.warn("onUpdateCheckError notification failed", e); } } }, diff --git a/toolkit/mozapps/extensions/internal/PluginProvider.jsm b/toolkit/mozapps/extensions/internal/PluginProvider.jsm index ace38bcc8069..7b6e3353ffca 100644 --- a/toolkit/mozapps/extensions/internal/PluginProvider.jsm +++ b/toolkit/mozapps/extensions/internal/PluginProvider.jsm @@ -6,24 +6,23 @@ const Cc = Components.classes; const Ci = Components.interfaces; +const Cu = Components.utils; this.EXPORTED_SYMBOLS = []; -Components.utils.import("resource://gre/modules/AddonManager.jsm"); -Components.utils.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/AddonManager.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); const URI_EXTENSION_STRINGS = "chrome://mozapps/locale/extensions/extensions.properties"; const STRING_TYPE_NAME = "type.%ID%.name"; const LIST_UPDATED_TOPIC = "plugins-list-updated"; -for (let name of ["LOG", "WARN", "ERROR"]) { - this.__defineGetter__(name, function() { - Components.utils.import("resource://gre/modules/addons/AddonLogging.jsm"); +Cu.import("resource://gre/modules/Log.jsm"); +const LOGGER_ID = "addons.plugins"; - LogManager.getLogger("addons.plugins", this); - return this[name]; - }); -} +// Create a new logger for use by the Addons Plugin Provider +// (Requires AddonManager.jsm) +let logger = Log.repository.getLogger(LOGGER_ID); function getIDHashForString(aStr) { // return the two-digit hexadecimal code for a byte diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm index 778f3c255692..c94fcc170f0c 100644 --- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm @@ -192,18 +192,12 @@ var gGlobalScope = this; */ var gIDTest = /^(\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}|[a-z0-9-\._]*\@[a-z0-9-\._]+)$/i; -["LOG", "WARN", "ERROR"].forEach(function(aName) { - Object.defineProperty(this, aName, { - get: function logFuncGetter() { - Components.utils.import("resource://gre/modules/addons/AddonLogging.jsm"); - - LogManager.getLogger("addons.xpi", this); - return this[aName]; - }, - configurable: true - }); -}, this); +Cu.import("resource://gre/modules/Log.jsm"); +const LOGGER_ID = "addons.xpi"; +// Create a new logger for use by all objects in this Addons XPI Provider module +// (Requires AddonManager.jsm) +let logger = Log.repository.getLogger(LOGGER_ID); const LAZY_OBJECTS = ["XPIDatabase"]; @@ -261,7 +255,7 @@ function setFilePermissions(aFile, aPermissions) { aFile.permissions = aPermissions; } catch (e) { - WARN("Failed to set permissions " + aPermissions.toString(8) + " on " + + logger.warn("Failed to set permissions " + aPermissions.toString(8) + " on " + aFile.path, e); } } @@ -295,7 +289,7 @@ SafeInstallOperation.prototype = { newFile.moveTo(aTargetDirectory, null); } catch (e) { - ERROR("Failed to " + (aCopy ? "copy" : "move") + " file " + aFile.path + + logger.error("Failed to " + (aCopy ? "copy" : "move") + " file " + aFile.path + " to " + aTargetDirectory.path, e); throw e; } @@ -309,7 +303,7 @@ SafeInstallOperation.prototype = { newDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); } catch (e) { - ERROR("Failed to create directory " + newDir.path, e); + logger.error("Failed to create directory " + newDir.path, e); throw e; } this._createdDirs.push(newDir); @@ -324,7 +318,7 @@ SafeInstallOperation.prototype = { this._installDirEntry(aEntry, newDir, aCopy); } catch (e) { - ERROR("Failed to " + (aCopy ? "copy" : "move") + " entry " + + logger.error("Failed to " + (aCopy ? "copy" : "move") + " entry " + aEntry.path, e); throw e; } @@ -341,7 +335,7 @@ SafeInstallOperation.prototype = { aDirectory.remove(false); } catch (e) { - ERROR("Failed to remove directory " + aDirectory.path, e); + logger.error("Failed to remove directory " + aDirectory.path, e); throw e; } @@ -363,7 +357,7 @@ SafeInstallOperation.prototype = { if (e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) return; - ERROR("Failure " + (aCopy ? "copying" : "moving") + " " + aDirEntry.path + + logger.error("Failure " + (aCopy ? "copying" : "moving") + " " + aDirEntry.path + " to " + aTargetDirectory.path); throw e; } @@ -375,7 +369,7 @@ SafeInstallOperation.prototype = { this._installFile(aDirEntry, aTargetDirectory, aCopy); } catch (e) { - ERROR("Failure " + (aCopy ? "copying" : "moving") + " " + aDirEntry.path + + logger.error("Failure " + (aCopy ? "copying" : "moving") + " " + aDirEntry.path + " to " + aTargetDirectory.path); throw e; } @@ -715,11 +709,11 @@ function loadManifestFromRDF(aUri, aStream) { while (targets.hasMoreElements()) { let localeName = getRDFValue(targets.getNext()); if (!localeName) { - WARN("Ignoring empty locale in localized properties"); + logger.warn("Ignoring empty locale in localized properties"); continue; } if (aSeenLocales.indexOf(localeName) != -1) { - WARN("Ignoring duplicate locale in localized properties"); + logger.warn("Ignoring duplicate locale in localized properties"); continue; } aSeenLocales.push(localeName); @@ -727,7 +721,7 @@ function loadManifestFromRDF(aUri, aStream) { } if (locale.locales.length == 0) { - WARN("Ignoring localized properties with no listed locales"); + logger.warn("Ignoring localized properties with no listed locales"); return null; } } @@ -864,11 +858,11 @@ function loadManifestFromRDF(aUri, aStream) { }); if (!targetAppInfo.id || !targetAppInfo.minVersion || !targetAppInfo.maxVersion) { - WARN("Ignoring invalid targetApplication entry in install manifest"); + logger.warn("Ignoring invalid targetApplication entry in install manifest"); continue; } if (seenApplications.indexOf(targetAppInfo.id) != -1) { - WARN("Ignoring duplicate targetApplication entry for " + targetAppInfo.id + + logger.warn("Ignoring duplicate targetApplication entry for " + targetAppInfo.id + " in install manifest"); continue; } @@ -1167,13 +1161,13 @@ function saveStreamAsync(aPath, aStream, aFile) { aStream.close(); } catch (e) { - ERROR("Failed to close JAR stream for " + aPath); + logger.error("Failed to close JAR stream for " + aPath); } aFile.close().then(function() { deferred.reject(error); }, function(e) { - ERROR("Failed to close file for " + aPath); + logger.error("Failed to close file for " + aPath); deferred.reject(error); }); } @@ -1239,7 +1233,7 @@ function extractFilesAsync(aZipFile, aDir) { yield OS.File.makeDir(path); } catch (e) { - ERROR("extractFilesAsync: failed to create directory " + path, e); + logger.error("extractFilesAsync: failed to create directory " + path, e); throw e; } } @@ -1253,7 +1247,7 @@ function extractFilesAsync(aZipFile, aDir) { yield saveStreamAsync(path, zipReader.getInputStream(entryName), file); } catch (e) { - ERROR("extractFilesAsync: failed to extract file " + path, e); + logger.error("extractFilesAsync: failed to extract file " + path, e); throw e; } } @@ -1299,7 +1293,7 @@ function extractFiles(aZipFile, aDir) { FileUtils.PERMS_DIRECTORY); } catch (e) { - ERROR("extractFiles: failed to create target directory for " + + logger.error("extractFiles: failed to create target directory for " + "extraction file = " + target.path, e); } } @@ -1317,7 +1311,7 @@ function extractFiles(aZipFile, aDir) { target.permissions |= FileUtils.PERMS_FILE; } catch (e) { - WARN("Failed to set permissions " + aPermissions.toString(8) + " on " + + logger.warn("Failed to set permissions " + aPermissions.toString(8) + " on " + target.path, e); } } @@ -1450,7 +1444,7 @@ function recursiveRemove(aFile) { } catch (e) { if (!aFile.isDirectory()) { - ERROR("Failed to remove file " + aFile.path, e); + logger.error("Failed to remove file " + aFile.path, e); throw e; } } @@ -1466,7 +1460,7 @@ function recursiveRemove(aFile) { aFile.remove(true); } catch (e) { - ERROR("Failed to remove empty directory " + aFile.path, e); + logger.error("Failed to remove empty directory " + aFile.path, e); throw e; } } @@ -1505,7 +1499,7 @@ function recursiveLastModifiedTime(aFile) { } } catch (e) { - WARN("Problem getting last modified time for " + aFile.path, e); + logger.warn("Problem getting last modified time for " + aFile.path, e); } // If the file is something else, just ignore it. @@ -1710,7 +1704,7 @@ function makeSafe(aFunction) { return aFunction(...aArgs); } catch(ex) { - WARN("XPIProvider callback failed", ex); + logger.warn("XPIProvider callback failed", ex); } return undefined; } @@ -1786,7 +1780,7 @@ var XPIProvider = { c.cancel(); } catch (e) { - WARN("Cancel failed", e); + logger.warn("Cancel failed", e); } this._inProgress.delete(c); } @@ -1812,7 +1806,7 @@ var XPIProvider = { this._uriMappings[aID] = uri.spec; } catch (ex) { - WARN("Failed to add URI mapping", ex); + logger.warn("Failed to add URI mapping", ex); } }, @@ -1927,7 +1921,7 @@ var XPIProvider = { * if it is a new profile or the version is unknown */ startup: function XPI_startup(aAppChanged, aOldAppVersion, aOldPlatformVersion) { - LOG("startup"); + logger.debug("startup"); this.runPhase = XPI_STARTING; this.installs = []; this.installLocations = []; @@ -1948,7 +1942,7 @@ var XPIProvider = { } catch (e) { // Some directories aren't defined on some platforms, ignore them - LOG("Skipping unavailable install location " + aName); + logger.debug("Skipping unavailable install location " + aName); return; } @@ -1956,7 +1950,7 @@ var XPIProvider = { var location = new DirectoryInstallLocation(aName, dir, aScope, aLocked); } catch (e) { - WARN("Failed to add directory install location " + aName, e); + logger.warn("Failed to add directory install location " + aName, e); return; } @@ -1969,7 +1963,7 @@ var XPIProvider = { var location = new WinRegInstallLocation(aName, aRootkey, aScope); } catch (e) { - WARN("Failed to add registry install location " + aName, e); + logger.warn("Failed to add registry install location " + aName, e); return; } @@ -2098,14 +2092,14 @@ var XPIProvider = { "startup", reason); } catch (e) { - ERROR("Failed to load bootstrap addon " + id + " from " + + logger.error("Failed to load bootstrap addon " + id + " from " + this.bootstrappedAddons[id].descriptor, e); } } AddonManagerPrivate.recordTimestamp("XPI_bootstrap_addons_end"); } catch (e) { - ERROR("bootstrap startup failed", e); + logger.error("bootstrap startup failed", e); AddonManagerPrivate.recordException("XPI-BOOTSTRAP", "startup failed", e); } @@ -2139,7 +2133,7 @@ var XPIProvider = { this.runPhase = XPI_BEFORE_UI_STARTUP; } catch (e) { - ERROR("startup failed", e); + logger.error("startup failed", e); AddonManagerPrivate.recordException("XPI", "startup failed", e); } }, @@ -2151,7 +2145,7 @@ var XPIProvider = { * 0 otherwise. */ shutdown: function XPI_shutdown() { - LOG("shutdown"); + logger.debug("shutdown"); // Stop anything we were doing asynchronously this.cancelAll(); @@ -2185,11 +2179,11 @@ var XPIProvider = { let done = XPIDatabase.shutdown(); done.then( ret => { - LOG("Notifying XPI shutdown observers"); + logger.debug("Notifying XPI shutdown observers"); Services.obs.notifyObservers(null, "xpi-provider-shutdown", null); }, err => { - LOG("Notifying XPI shutdown observers"); + logger.debug("Notifying XPI shutdown observers"); this._shutdownError = err; Services.obs.notifyObservers(null, "xpi-provider-shutdown", err); } @@ -2197,7 +2191,7 @@ var XPIProvider = { return done; } else { - LOG("Notifying XPI shutdown observers"); + logger.debug("Notifying XPI shutdown observers"); Services.obs.notifyObservers(null, "xpi-provider-shutdown", null); } }, @@ -2215,11 +2209,11 @@ var XPIProvider = { Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, this.selectedSkin); Services.prefs.clearUserPref(PREF_DSS_SKIN_TO_SELECT); - LOG("Changed skin to " + this.selectedSkin); + logger.debug("Changed skin to " + this.selectedSkin); this.currentSkin = this.selectedSkin; } catch (e) { - ERROR("Error applying theme change", e); + logger.error("Error applying theme change", e); } Services.prefs.clearUserPref(PREF_DSS_SWITCHPENDING); }, @@ -2382,7 +2376,7 @@ var XPIProvider = { let stageDirEntry = entries.nextFile; if (!stageDirEntry.isDirectory()) { - WARN("Ignoring file in XPI staging directory: " + stageDirEntry.path); + logger.warn("Ignoring file in XPI staging directory: " + stageDirEntry.path); continue; } @@ -2413,11 +2407,11 @@ var XPIProvider = { addon = loadManifestFromZipFile(stagedXPI); } catch (e) { - ERROR("Unable to read add-on manifest from " + stagedXPI.path, e); + logger.error("Unable to read add-on manifest from " + stagedXPI.path, e); continue; } - LOG("Migrating staged install of " + addon.id + " in " + aLocation.name); + logger.debug("Migrating staged install of " + addon.id + " in " + aLocation.name); if (addon.unpack || Prefs.getBoolPref(PREF_XPI_UNPACK, false)) { let targetDir = stagingDir.clone(); @@ -2426,7 +2420,7 @@ var XPIProvider = { targetDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); } catch (e) { - ERROR("Failed to create staging directory for add-on " + addon.id, e); + logger.error("Failed to create staging directory for add-on " + addon.id, e); continue; } @@ -2434,7 +2428,7 @@ var XPIProvider = { extractFiles(stagedXPI, targetDir); } catch (e) { - ERROR("Failed to extract staged XPI for add-on " + addon.id + " in " + + logger.error("Failed to extract staged XPI for add-on " + addon.id + " in " + aLocation.name, e); } } @@ -2443,7 +2437,7 @@ var XPIProvider = { stagedXPI.moveTo(stagingDir, addon.id + ".xpi"); } catch (e) { - ERROR("Failed to move staged XPI for add-on " + addon.id + " in " + + logger.error("Failed to move staged XPI for add-on " + addon.id + " in " + aLocation.name, e); } } @@ -2457,7 +2451,7 @@ var XPIProvider = { } catch (e) { // Non-critical, just saves some perf on startup if we clean this up. - LOG("Error removing XPI staging dir " + stagedXPIDir.path, e); + logger.debug("Error removing XPI staging dir " + stagedXPIDir.path, e); } } @@ -2466,7 +2460,7 @@ var XPIProvider = { return; } catch (e) { - WARN("Failed to find staging directory", e); + logger.warn("Failed to find staging directory", e); return; } @@ -2496,7 +2490,7 @@ var XPIProvider = { } else { if (id.substring(id.length - 5).toLowerCase() != ".json") { - WARN("Ignoring file: " + stageDirEntry.path); + logger.warn("Ignoring file: " + stageDirEntry.path); seenFiles.push(stageDirEntry.leafName); } continue; @@ -2505,7 +2499,7 @@ var XPIProvider = { // Check that the directory's name is a valid ID. if (!gIDTest.test(id)) { - WARN("Ignoring directory whose name is not a valid add-on ID: " + + logger.warn("Ignoring directory whose name is not a valid add-on ID: " + stageDirEntry.path); seenFiles.push(stageDirEntry.leafName); continue; @@ -2521,13 +2515,13 @@ var XPIProvider = { // If the install manifest doesn't exist uninstall this add-on in this // install location. if (!manifest.exists()) { - LOG("Processing uninstall of " + id + " in " + aLocation.name); + logger.debug("Processing uninstall of " + id + " in " + aLocation.name); try { aLocation.uninstallAddon(id); seenFiles.push(stageDirEntry.leafName); } catch (e) { - ERROR("Failed to uninstall add-on " + id + " in " + aLocation.name, e); + logger.error("Failed to uninstall add-on " + id + " in " + aLocation.name, e); } // The file check later will spot the removal and cleanup the database continue; @@ -2544,7 +2538,7 @@ var XPIProvider = { aManifests[aLocation.name][id] = loadManifestFromFile(stageDirEntry); } catch (e) { - ERROR("Unable to read add-on manifest from " + stageDirEntry.path, e); + logger.error("Unable to read add-on manifest from " + stageDirEntry.path, e); // This add-on can't be installed so just remove it now seenFiles.push(stageDirEntry.leafName); seenFiles.push(jsonfile.leafName); @@ -2554,7 +2548,7 @@ var XPIProvider = { // Check for a cached metadata for this add-on, it may contain updated // compatibility information if (jsonfile.exists()) { - LOG("Found updated metadata for " + id + " in " + aLocation.name); + logger.debug("Found updated metadata for " + id + " in " + aLocation.name); let fis = Cc["@mozilla.org/network/file-input-stream;1"]. createInstance(Ci.nsIFileInputStream); let json = Cc["@mozilla.org/dom/json;1"]. @@ -2569,7 +2563,7 @@ var XPIProvider = { // If some data can't be recovered from the cached metadata then it // is unlikely to be a problem big enough to justify throwing away // the install, just log and error and continue - ERROR("Unable to read metadata from " + jsonfile.path, e); + logger.error("Unable to read metadata from " + jsonfile.path, e); } finally { fis.close(); @@ -2580,7 +2574,7 @@ var XPIProvider = { existingAddonID = aManifests[aLocation.name][id].existingAddonID || id; var oldBootstrap = null; - LOG("Processing install of " + id + " in " + aLocation.name); + logger.debug("Processing install of " + id + " in " + aLocation.name); if (existingAddonID in this.bootstrappedAddons) { try { var existingAddon = aLocation.getLocationForID(existingAddonID); @@ -2614,7 +2608,7 @@ var XPIProvider = { aManifests[aLocation.name][id]._sourceBundle = addonInstallLocation; } catch (e) { - ERROR("Failed to install staged add-on " + id + " in " + aLocation.name, + logger.error("Failed to install staged add-on " + id + " in " + aLocation.name, e); // Re-create the staged install AddonInstall.createStagedInstall(aLocation, stageDirEntry, @@ -2639,7 +2633,7 @@ var XPIProvider = { } catch (e) { // Non-critical, just saves some perf on startup if we clean this up. - LOG("Error cleaning staging dir " + stagingDir.path, e); + logger.debug("Error cleaning staging dir " + stagingDir.path, e); } }, this); return changed; @@ -2686,18 +2680,18 @@ var XPIProvider = { id = id.substring(0, id.length - 4); } else { - LOG("Ignoring distribution add-on that isn't an XPI: " + entry.path); + logger.debug("Ignoring distribution add-on that isn't an XPI: " + entry.path); continue; } } else if (!entry.isDirectory()) { - LOG("Ignoring distribution add-on that isn't a file or directory: " + + logger.debug("Ignoring distribution add-on that isn't a file or directory: " + entry.path); continue; } if (!gIDTest.test(id)) { - LOG("Ignoring distribution add-on whose name is not a valid add-on ID: " + + logger.debug("Ignoring distribution add-on whose name is not a valid add-on ID: " + entry.path); continue; } @@ -2707,12 +2701,12 @@ var XPIProvider = { addon = loadManifestFromFile(entry); } catch (e) { - WARN("File entry " + entry.path + " contains an invalid add-on", e); + logger.warn("File entry " + entry.path + " contains an invalid add-on", e); continue; } if (addon.id != id) { - WARN("File entry " + entry.path + " contains an add-on with an " + + logger.warn("File entry " + entry.path + " contains an add-on with an " + "incorrect ID") continue; } @@ -2734,7 +2728,7 @@ var XPIProvider = { } catch (e) { // Bad add-on in the profile so just proceed and install over the top - WARN("Profile contains an add-on with a bad or missing install " + + logger.warn("Profile contains an add-on with a bad or missing install " + "manifest at " + existingEntry.path + ", overwriting", e); } } @@ -2745,7 +2739,7 @@ var XPIProvider = { // Install the add-on try { profileLocation.installAddon(id, entry, null, true); - LOG("Installed distribution add-on " + id); + logger.debug("Installed distribution add-on " + id); Services.prefs.setBoolPref(PREF_BRANCH_INSTALLED_ADDON + id, true) @@ -2758,7 +2752,7 @@ var XPIProvider = { changed = true; } catch (e) { - ERROR("Failed to install distribution add-on " + entry.path, e); + logger.error("Failed to install distribution add-on " + entry.path, e); } } @@ -2814,7 +2808,7 @@ var XPIProvider = { * changing this add-on */ function updateMetadata(aInstallLocation, aOldAddon, aAddonState) { - LOG("Add-on " + aOldAddon.id + " modified in " + aInstallLocation.name); + logger.debug("Add-on " + aOldAddon.id + " modified in " + aInstallLocation.name); // Check if there is an updated install manifest for this add-on let newAddon = aManifests[aInstallLocation.name][aOldAddon.id]; @@ -2839,12 +2833,12 @@ var XPIProvider = { throw new Error("Incorrect id in install manifest"); } catch (e) { - WARN("Add-on is invalid", e); + logger.warn("Add-on is invalid", e); XPIDatabase.removeAddonMetadata(aOldAddon); if (!aInstallLocation.locked) aInstallLocation.uninstallAddon(aOldAddon.id); else - WARN("Could not uninstall invalid item from locked install location"); + logger.warn("Could not uninstall invalid item from locked install location"); // If this was an active add-on then we must force a restart if (aOldAddon.active) return true; @@ -2909,7 +2903,7 @@ var XPIProvider = { * changing this add-on */ function updateDescriptor(aInstallLocation, aOldAddon, aAddonState) { - LOG("Add-on " + aOldAddon.id + " moved to " + aAddonState.descriptor); + logger.debug("Add-on " + aOldAddon.id + " moved to " + aAddonState.descriptor); aOldAddon.descriptor = aAddonState.descriptor; aOldAddon.visible = !(aOldAddon.id in visibleAddons); @@ -3002,7 +2996,7 @@ var XPIProvider = { if (wasAppDisabled != aOldAddon.appDisabled || wasUserDisabled != aOldAddon.userDisabled || wasSoftDisabled != aOldAddon.softDisabled) { - LOG("Add-on " + aOldAddon.id + " changed appDisabled state to " + + logger.debug("Add-on " + aOldAddon.id + " changed appDisabled state to " + aOldAddon.appDisabled + ", userDisabled state to " + aOldAddon.userDisabled + " and softDisabled state to " + aOldAddon.softDisabled); @@ -3049,7 +3043,7 @@ var XPIProvider = { */ function removeMetadata(aOldAddon) { // This add-on has disappeared - LOG("Add-on " + aOldAddon.id + " removed from " + aOldAddon.location); + logger.debug("Add-on " + aOldAddon.id + " removed from " + aOldAddon.location); XPIDatabase.removeAddonMetadata(aOldAddon); // Remember add-ons that were uninstalled during startup @@ -3096,7 +3090,7 @@ var XPIProvider = { * changing this add-on */ function addMetadata(aInstallLocation, aId, aAddonState, aMigrateData) { - LOG("New add-on " + aId + " installed in " + aInstallLocation.name); + logger.debug("New add-on " + aId + " installed in " + aInstallLocation.name); let newAddon = null; let sameVersion = false; @@ -3128,14 +3122,14 @@ var XPIProvider = { } } catch (e) { - WARN("Add-on is invalid", e); + logger.warn("Add-on is invalid", e); // Remove the invalid add-on from the install location if the install // location isn't locked, no restart will be necessary if (!aInstallLocation.locked) aInstallLocation.uninstallAddon(aId); else - WARN("Could not uninstall invalid item from locked install location"); + logger.warn("Could not uninstall invalid item from locked install location"); return false; } @@ -3148,7 +3142,7 @@ var XPIProvider = { if (aMigrateData) { // If there is migration data then apply it. - LOG("Migrating data from old database"); + logger.debug("Migrating data from old database"); DB_MIGRATE_METADATA.forEach(function(aProp) { // A theme's disabled state is determined by the selected theme @@ -3168,7 +3162,7 @@ var XPIProvider = { // The version property isn't a perfect check for this but covers the // vast majority of cases. if (aMigrateData.version == newAddon.version) { - LOG("Migrating compatibility info"); + logger.debug("Migrating compatibility info"); sameVersion = true; if ("targetApplications" in aMigrateData) newAddon.applyCompatibilityUpdate(aMigrateData, true); @@ -3449,7 +3443,7 @@ var XPIProvider = { */ checkForChanges: function XPI_checkForChanges(aAppChanged, aOldAppVersion, aOldPlatformVersion) { - LOG("checkForChanges"); + logger.debug("checkForChanges"); // Keep track of whether and why we need to open and update the database at // startup time. @@ -3464,7 +3458,7 @@ var XPIProvider = { this.bootstrappedAddons = JSON.parse(Prefs.getCharPref(PREF_BOOTSTRAP_ADDONS, "{}")); } catch (e) { - WARN("Error parsing enabled bootstrapped extensions cache", e); + logger.warn("Error parsing enabled bootstrapped extensions cache", e); } // First install any new add-ons into the locations, if there are any @@ -3506,7 +3500,7 @@ var XPIProvider = { // makes a difference let newState = JSON.stringify(this.installStates); if (cache != newState) { - LOG("Directory state JSON differs: cache " + cache + " state " + newState); + logger.debug("Directory state JSON differs: cache " + cache + " state " + newState); if (directoryStateDiffers(this.installStates, cache)) { updateReasons.push("directoryState"); } @@ -3520,7 +3514,7 @@ var XPIProvider = { // If we don't have any add-ons, just update the pref, since we don't need to // write the database if (this.installStates.length == 0) { - LOG("Empty XPI database, setting schema version preference to " + DB_SCHEMA); + logger.debug("Empty XPI database, setting schema version preference to " + DB_SCHEMA); Services.prefs.setIntPref(PREF_DB_SCHEMA, DB_SCHEMA); } else { @@ -3549,7 +3543,7 @@ var XPIProvider = { }); if (bootstrapDescriptors.length > 0) { - WARN("Bootstrap state is invalid (missing add-ons: " + bootstrapDescriptors.toSource() + ")"); + logger.warn("Bootstrap state is invalid (missing add-ons: " + bootstrapDescriptors.toSource() + ")"); updateReasons.push("missingBootstrapAddon"); } } @@ -3569,7 +3563,7 @@ var XPIProvider = { aOldPlatformVersion); } catch (e) { - ERROR("Failed to process extension changes at startup", e); + logger.error("Failed to process extension changes at startup", e); } } @@ -3590,14 +3584,14 @@ var XPIProvider = { oldCache.remove(true); } catch (e) { - WARN("Unable to remove old extension cache " + oldCache.path, e); + logger.warn("Unable to remove old extension cache " + oldCache.path, e); } } // If the application crashed before completing any pending operations then // we should perform them now. if (extensionListChanged || hasPendingChanges) { - LOG("Updating database with changes to installed add-ons"); + logger.debug("Updating database with changes to installed add-ons"); XPIDatabase.updateActiveAddons(); Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, !XPIDatabase.writeAddonsList()); @@ -3606,17 +3600,17 @@ var XPIProvider = { return true; } - LOG("No changes found"); + logger.debug("No changes found"); } catch (e) { - ERROR("Error during startup file checks", e); + logger.error("Error during startup file checks", e); } // Check that the add-ons list still exists let addonsList = FileUtils.getFile(KEY_PROFILEDIR, [FILE_XPI_ADDONS_LIST], true); if (addonsList.exists() == (this.installStates.length == 0)) { - LOG("Add-ons list is invalid, rebuilding"); + logger.debug("Add-ons list is invalid, rebuilding"); XPIDatabase.writeAddonsList(); } @@ -3955,7 +3949,7 @@ var XPIProvider = { * to enable the default theme. */ enableDefaultTheme: function XPI_enableDefaultTheme() { - LOG("Activating default theme"); + logger.debug("Activating default theme"); let addon = XPIDatabase.getVisibleAddonForInternalName(this.defaultSkin); if (addon) { if (addon.userDisabled) { @@ -3972,11 +3966,11 @@ var XPIProvider = { Prefs.clearUserPref(PREF_DSS_SWITCHPENDING); } else { - WARN("Attempting to activate an already active default theme"); + logger.warn("Attempting to activate an already active default theme"); } } else { - WARN("Unable to activate the default theme"); + logger.warn("Unable to activate the default theme"); } }, @@ -4192,7 +4186,7 @@ var XPIProvider = { return; } - LOG("Loading bootstrap scope from " + aFile.path); + logger.debug("Loading bootstrap scope from " + aFile.path); let principal = Cc["@mozilla.org/systemprincipal;1"]. createInstance(Ci.nsIPrincipal); @@ -4201,7 +4195,7 @@ var XPIProvider = { this.bootstrapScopes[aId] = new Cu.Sandbox(principal, {sandboxName: aFile.path, wantGlobalProperties: ["indexedDB"]}); - ERROR("Attempted to load bootstrap scope from missing directory " + aFile.path); + logger.error("Attempted to load bootstrap scope from missing directory " + aFile.path); return; } @@ -4242,7 +4236,7 @@ var XPIProvider = { .loadSubScript(__SCRIPT_URI_SPEC__);", this.bootstrapScopes[aId], "ECMAv5"); } catch (e) { - WARN("Error loading bootstrap.js for " + aId, e); + logger.warn("Error loading bootstrap.js for " + aId, e); } }, @@ -4287,7 +4281,7 @@ var XPIProvider = { let timeStart = new Date(); if (aMethod == "startup") { - LOG("Registering manifest for " + aFile.path); + logger.debug("Registering manifest for " + aFile.path); Components.manager.addBootstrappedManifestLocation(aFile); } @@ -4301,7 +4295,7 @@ var XPIProvider = { return; if (!(aMethod in this.bootstrapScopes[aId])) { - WARN("Add-on " + aId + " is missing bootstrap method " + aMethod); + logger.warn("Add-on " + aId + " is missing bootstrap method " + aMethod); return; } @@ -4318,18 +4312,18 @@ var XPIProvider = { } } - LOG("Calling bootstrap method " + aMethod + " on " + aId + " version " + + logger.debug("Calling bootstrap method " + aMethod + " on " + aId + " version " + aVersion); try { this.bootstrapScopes[aId][aMethod](params, aReason); } catch (e) { - WARN("Exception running bootstrap method " + aMethod + " on " + aId, e); + logger.warn("Exception running bootstrap method " + aMethod + " on " + aId, e); } } finally { if (aMethod == "shutdown" && aReason != BOOTSTRAP_REASONS.APP_SHUTDOWN) { - LOG("Removing manifest for " + aFile.path); + logger.debug("Removing manifest for " + aFile.path); Components.manager.removeBootstrappedManifestLocation(aFile); } this.setTelemetry(aId, aMethod + "_MS", new Date() - timeStart); @@ -4473,7 +4467,7 @@ var XPIProvider = { aAddon._hasResourceCache = new Map(); if (aAddon._updateCheck) { - LOG("Cancel in-progress update check for " + aAddon.id); + logger.debug("Cancel in-progress update check for " + aAddon.id); aAddon._updateCheck.cancel(); } @@ -4658,8 +4652,8 @@ function AddonInstall(aInstallLocation, aUrl, aHash, aReleaseNotesURI, else this.window = null; - this.WARN = WARN; - this.LOG = LOG; + // Giving each instance of AddonInstall a reference to the logger. + this.logger = logger; } AddonInstall.prototype = { @@ -4730,7 +4724,7 @@ AddonInstall.prototype = { this.file = this.sourceURI.QueryInterface(Ci.nsIFileURL).file; if (!this.file.exists()) { - WARN("XPI file " + this.file.path + " does not exist"); + logger.warn("XPI file " + this.file.path + " does not exist"); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = AddonManager.ERROR_NETWORK_FAILURE; aCallback(this); @@ -4748,7 +4742,7 @@ AddonInstall.prototype = { crypto.initWithString(this.hash.algorithm); } catch (e) { - WARN("Unknown hash algorithm '" + this.hash.algorithm + "' for addon " + this.sourceURI.spec, e); + logger.warn("Unknown hash algorithm '" + this.hash.algorithm + "' for addon " + this.sourceURI.spec, e); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = AddonManager.ERROR_INCORRECT_HASH; aCallback(this); @@ -4761,7 +4755,7 @@ AddonInstall.prototype = { crypto.updateFromStream(fis, this.file.fileSize); let calculatedHash = getHashStringForCrypto(crypto); if (calculatedHash != this.hash.data) { - WARN("File hash (" + calculatedHash + ") did not match provided hash (" + + logger.warn("File hash (" + calculatedHash + ") did not match provided hash (" + this.hash.data + ")"); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = AddonManager.ERROR_INCORRECT_HASH; @@ -4807,7 +4801,7 @@ AddonInstall.prototype = { }); } catch (e) { - WARN("Invalid XPI", e); + logger.warn("Invalid XPI", e); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = AddonManager.ERROR_CORRUPT_FILE; aCallback(this); @@ -4893,7 +4887,7 @@ AddonInstall.prototype = { this.channel.cancel(Cr.NS_BINDING_ABORTED); case AddonManager.STATE_AVAILABLE: case AddonManager.STATE_DOWNLOADED: - LOG("Cancelling download of " + this.sourceURI.spec); + logger.debug("Cancelling download of " + this.sourceURI.spec); this.state = AddonManager.STATE_CANCELLED; XPIProvider.removeActiveInstall(this); AddonManagerPrivate.callInstallListeners("onDownloadCancelled", @@ -4901,7 +4895,7 @@ AddonInstall.prototype = { this.removeTemporaryFile(); break; case AddonManager.STATE_INSTALLED: - LOG("Cancelling install of " + this.addon.id); + logger.debug("Cancelling install of " + this.addon.id); let xpi = this.installLocation.getStagingDir(); xpi.append(this.addon.id + ".xpi"); flushJarCache(xpi); @@ -4956,18 +4950,18 @@ AddonInstall.prototype = { removeTemporaryFile: function AI_removeTemporaryFile() { // Only proceed if this AddonInstall owns its XPI file if (!this.ownsTempFile) { - this.LOG("removeTemporaryFile: " + this.sourceURI.spec + " does not own temp file"); + this.logger.debug("removeTemporaryFile: " + this.sourceURI.spec + " does not own temp file"); return; } try { - this.LOG("removeTemporaryFile: " + this.sourceURI.spec + " removing temp file " + + this.logger.debug("removeTemporaryFile: " + this.sourceURI.spec + " removing temp file " + this.file.path); this.file.remove(true); this.ownsTempFile = false; } catch (e) { - this.WARN("Failed to remove temporary file " + this.file.path + " for addon " + + this.logger.warn("Failed to remove temporary file " + this.file.path + " for addon " + this.sourceURI.spec, e); } @@ -5009,7 +5003,7 @@ AddonInstall.prototype = { files.push(target); } catch (e) { - WARN("Failed to extract " + entryName + " from multi-package " + + logger.warn("Failed to extract " + entryName + " from multi-package " + "XPI", e); target.remove(false); } @@ -5035,7 +5029,7 @@ AddonInstall.prototype = { break; } catch (e) { - WARN(this.file.leafName + " cannot be installed from multi-package " + + logger.warn(this.file.leafName + " cannot be installed from multi-package " + "XPI", e); } } @@ -5146,7 +5140,7 @@ AddonInstall.prototype = { let principal = zipreader.getCertificatePrincipal(null); if (principal && principal.hasCertificate) { - LOG("Verifying XPI signature"); + logger.debug("Verifying XPI signature"); if (verifyZipSigning(zipreader, principal)) { let x509 = principal.certificate; if (x509 instanceof Ci.nsIX509Cert) @@ -5207,7 +5201,7 @@ AddonInstall.prototype = { this.state = AddonManager.STATE_DOWNLOADING; if (!AddonManagerPrivate.callInstallListeners("onDownloadStarted", this.listeners, this.wrapper)) { - LOG("onDownloadStarted listeners cancelled installation of addon " + this.sourceURI.spec); + logger.debug("onDownloadStarted listeners cancelled installation of addon " + this.sourceURI.spec); this.state = AddonManager.STATE_CANCELLED; XPIProvider.removeActiveInstall(this); AddonManagerPrivate.callInstallListeners("onDownloadCancelled", @@ -5222,7 +5216,7 @@ AddonInstall.prototype = { if (this.channel) { // A previous download attempt hasn't finished cleaning up yet, signal // that it should restart when complete - LOG("Waiting for previous download to complete"); + logger.debug("Waiting for previous download to complete"); this.restartDownload = true; return; } @@ -5242,7 +5236,7 @@ AddonInstall.prototype = { FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE, 0); } catch (e) { - WARN("Failed to start download for addon " + this.sourceURI.spec, e); + logger.warn("Failed to start download for addon " + this.sourceURI.spec, e); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = AddonManager.ERROR_FILE_ACCESS; XPIProvider.removeActiveInstall(this); @@ -5268,7 +5262,7 @@ AddonInstall.prototype = { Services.obs.addObserver(this, "network:offline-about-to-go-offline", false); } catch (e) { - WARN("Failed to start download for addon " + this.sourceURI.spec, e); + logger.warn("Failed to start download for addon " + this.sourceURI.spec, e); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = AddonManager.ERROR_NETWORK_FAILURE; XPIProvider.removeActiveInstall(this); @@ -5336,7 +5330,7 @@ AddonInstall.prototype = { this.crypto.initWithString(this.hash.algorithm); } catch (e) { - WARN("Unknown hash algorithm '" + this.hash.algorithm + "' for addon " + this.sourceURI.spec, e); + logger.warn("Unknown hash algorithm '" + this.hash.algorithm + "' for addon " + this.sourceURI.spec, e); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = AddonManager.ERROR_INCORRECT_HASH; XPIProvider.removeActiveInstall(this); @@ -5359,7 +5353,7 @@ AddonInstall.prototype = { } catch (e) { } - LOG("Download started for " + this.sourceURI.spec + " to file " + + logger.debug("Download started for " + this.sourceURI.spec + " to file " + this.file.path); } }, @@ -5383,7 +5377,7 @@ AddonInstall.prototype = { return; } - LOG("Download of " + this.sourceURI.spec + " completed."); + logger.debug("Download of " + this.sourceURI.spec + " completed."); if (Components.isSuccessCode(aStatus)) { if (!(aRequest instanceof Ci.nsIHttpChannel) || aRequest.requestSucceeded) { @@ -5451,7 +5445,7 @@ AddonInstall.prototype = { * The error code to pass to the listeners */ downloadFailed: function AI_downloadFailed(aReason, aError) { - WARN("Download failed", aError); + logger.warn("Download failed", aError); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = aReason; XPIProvider.removeActiveInstall(this); @@ -5461,11 +5455,11 @@ AddonInstall.prototype = { // If the listener hasn't restarted the download then remove any temporary // file if (this.state == AddonManager.STATE_DOWNLOAD_FAILED) { - LOG("downloadFailed: removing temp file for " + this.sourceURI.spec); + logger.debug("downloadFailed: removing temp file for " + this.sourceURI.spec); this.removeTemporaryFile(); } else - LOG("downloadFailed: listener changed AddonInstall state for " + + logger.debug("downloadFailed: listener changed AddonInstall state for " + this.sourceURI.spec + " to " + this.state); }, @@ -5538,7 +5532,7 @@ AddonInstall.prototype = { this.existingAddon._installLocation == this.installLocation; let requiresRestart = XPIProvider.installRequiresRestart(this.addon); - LOG("Starting install of " + this.sourceURI.spec); + logger.debug("Starting install of " + this.sourceURI.spec); AddonManagerPrivate.callAddonListeners("onInstalling", createWrapper(this.addon), requiresRestart); @@ -5552,7 +5546,7 @@ AddonInstall.prototype = { // First stage the file regardless of whether restarting is necessary if (this.addon.unpack || Prefs.getBoolPref(PREF_XPI_UNPACK, false)) { - LOG("Addon " + this.addon.id + " will be installed as " + + logger.debug("Addon " + this.addon.id + " will be installed as " + "an unpacked directory"); stagedAddon.append(this.addon.id); yield removeAsync(stagedAddon); @@ -5561,7 +5555,7 @@ AddonInstall.prototype = { installedUnpacked = 1; } else { - LOG("Addon " + this.addon.id + " will be installed as " + + logger.debug("Addon " + this.addon.id + " will be installed as " + "a packed xpi"); stagedAddon.append(this.addon.id + ".xpi"); yield removeAsync(stagedAddon); @@ -5594,7 +5588,7 @@ AddonInstall.prototype = { stream.close(); } - LOG("Staged install of " + this.sourceURI.spec + " ready; waiting for restart."); + logger.debug("Staged install of " + this.sourceURI.spec + " ready; waiting for restart."); this.state = AddonManager.STATE_INSTALLED; if (isUpgrade) { delete this.existingAddon.pendingUpgrade; @@ -5682,7 +5676,7 @@ AddonInstall.prototype = { AddonManagerPrivate.callAddonListeners("onInstalled", createWrapper(this.addon)); - LOG("Install of " + this.sourceURI.spec + " completed."); + logger.debug("Install of " + this.sourceURI.spec + " completed."); this.state = AddonManager.STATE_INSTALLED; AddonManagerPrivate.callInstallListeners("onInstallEnded", this.listeners, this.wrapper, @@ -5711,7 +5705,7 @@ AddonInstall.prototype = { } } }).bind(this)).then(null, (e) => { - WARN("Failed to install " + this.file.path + " from " + this.sourceURI.spec, e); + logger.warn("Failed to install " + this.file.path + " from " + this.sourceURI.spec, e); if (stagedAddon.exists()) recursiveRemove(stagedAddon); this.state = AddonManager.STATE_INSTALL_FAILED; @@ -5776,7 +5770,7 @@ AddonInstall.createInstall = function AI_createInstall(aCallback, aFile) { install.initLocalInstall(aCallback); } catch(e) { - ERROR("Error creating install", e); + logger.error("Error creating install", e); makeSafe(aCallback)(null); } }; @@ -5967,7 +5961,7 @@ UpdateChecker.prototype = { this.listener[aMethod].apply(this.listener, aArgs); } catch (e) { - WARN("Exception calling UpdateListener method " + aMethod, e); + logger.warn("Exception calling UpdateListener method " + aMethod, e); } }, @@ -6898,13 +6892,13 @@ DirectoryInstallLocation.prototype = { } if (!linkedDirectory.exists()) { - WARN("File pointer " + aFile.path + " points to " + linkedDirectory.path + + logger.warn("File pointer " + aFile.path + " points to " + linkedDirectory.path + " which does not exist"); return null; } if (!linkedDirectory.isDirectory()) { - WARN("File pointer " + aFile.path + " points to " + linkedDirectory.path + + logger.warn("File pointer " + aFile.path + " points to " + linkedDirectory.path + " which is not a directory"); return null; } @@ -6912,7 +6906,7 @@ DirectoryInstallLocation.prototype = { return linkedDirectory; } - WARN("File pointer " + aFile.path + " does not contain a path"); + logger.warn("File pointer " + aFile.path + " does not contain a path"); return null; }, @@ -6938,7 +6932,7 @@ DirectoryInstallLocation.prototype = { } if (!gIDTest.test(id)) { - LOG("Ignoring file entry whose name is not a valid add-on ID: " + + logger.debug("Ignoring file entry whose name is not a valid add-on ID: " + entry.path); continue; } @@ -6946,12 +6940,12 @@ DirectoryInstallLocation.prototype = { if (entry.isFile() && !directLoad) { let newEntry = this._readDirectoryFromFile(entry); if (!newEntry) { - LOG("Deleting stale pointer file " + entry.path); + logger.debug("Deleting stale pointer file " + entry.path); try { entry.remove(true); } catch (e) { - WARN("Failed to remove stale pointer file " + entry.path, e); + logger.warn("Failed to remove stale pointer file " + entry.path, e); // Failing to remove the stale pointer file is ignorable } continue; @@ -7014,7 +7008,7 @@ DirectoryInstallLocation.prototype = { return this._stagingDirPromise = OS.File.makeDir(stagepath).then(null, (e) => { if (e instanceof OS.File.Error && e.becauseExists) return; - ERROR("Failed to create staging directory", e); + logger.error("Failed to create staging directory", e); throw e; }); }, @@ -7064,7 +7058,7 @@ DirectoryInstallLocation.prototype = { dir.remove(false); } catch (e) { - WARN("Failed to remove staging dir", e); + logger.warn("Failed to remove staging dir", e); // Failing to remove the staging directory is ignorable } }, @@ -7159,7 +7153,7 @@ DirectoryInstallLocation.prototype = { recursiveRemove(trashDir); } catch (e) { - WARN("Failed to remove trash directory when installing " + aId, e); + logger.warn("Failed to remove trash directory when installing " + aId, e); } } @@ -7168,7 +7162,7 @@ DirectoryInstallLocation.prototype = { try { newFile.lastModifiedTime = Date.now(); } catch (e) { - WARN("failed to set lastModifiedTime on " + newFile.path, e); + logger.warn("failed to set lastModifiedTime on " + newFile.path, e); } this._FileToIDMap[newFile.path] = aId; this._IDToFileMap[aId] = newFile; @@ -7192,7 +7186,7 @@ DirectoryInstallLocation.prototype = { uninstallAddon: function DirInstallLocation_uninstallAddon(aId) { let file = this._IDToFileMap[aId]; if (!file) { - WARN("Attempted to remove " + aId + " from " + + logger.warn("Attempted to remove " + aId + " from " + this._name + " but it was already gone"); return; } @@ -7203,7 +7197,7 @@ DirectoryInstallLocation.prototype = { file.leafName += ".xpi"; if (!file.exists()) { - WARN("Attempted to remove " + aId + " from " + + logger.warn("Attempted to remove " + aId + " from " + this._name + " but it was already gone"); delete this._FileToIDMap[file.path]; @@ -7214,7 +7208,7 @@ DirectoryInstallLocation.prototype = { let trashDir = this.getTrashDir(); if (file.leafName != aId) { - LOG("uninstallAddon: flushing jar cache " + file.path + " for addon " + aId); + logger.debug("uninstallAddon: flushing jar cache " + file.path + " for addon " + aId); flushJarCache(file); } @@ -7230,7 +7224,7 @@ DirectoryInstallLocation.prototype = { recursiveRemove(trashDir); } catch (e) { - WARN("Failed to remove trash directory when uninstalling " + aId, e); + logger.warn("Failed to remove trash directory when uninstalling " + aId, e); } } @@ -7360,7 +7354,7 @@ WinRegInstallLocation.prototype = { file.initWithPath(aKey.readStringValue(id)); if (!file.exists()) { - WARN("Ignoring missing add-on in " + file.path); + logger.warn("Ignoring missing add-on in " + file.path); continue; } diff --git a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js index 835507b8de14..728b3c4d2c23 100644 --- a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js +++ b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js @@ -24,18 +24,12 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise", XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm"); -["LOG", "WARN", "ERROR"].forEach(function(aName) { - Object.defineProperty(this, aName, { - get: function logFuncGetter () { - Cu.import("resource://gre/modules/addons/AddonLogging.jsm"); - - LogManager.getLogger("addons.xpi-utils", this); - return this[aName]; - }, - configurable: true - }); -}, this); +Cu.import("resource://gre/modules/Log.jsm"); +const LOGGER_ID = "addons.xpi-utils"; +// Create a new logger for use by the Addons XPI Provider Utils +// (Requires AddonManager.jsm) +let logger = Log.repository.getLogger(LOGGER_ID); const KEY_PROFILEDIR = "ProfD"; const FILE_DATABASE = "extensions.sqlite"; @@ -152,7 +146,7 @@ function makeSafe(aCallback) { aCallback(...aArgs); } catch(ex) { - WARN("XPI Database callback failed", ex); + logger.warn("XPI Database callback failed", ex); } } } @@ -195,7 +189,7 @@ function asyncMap(aObjects, aMethod, aCallback) { }); } catch (e) { - WARN("Async map function failed", e); + logger.warn("Async map function failed", e); asyncMap_gotValue(aIndex, undefined); } }); @@ -227,7 +221,7 @@ function resultRows(aStatement) { * An error message */ function logSQLError(aError, aErrorString) { - ERROR("SQL error " + aError + ": " + aErrorString); + logger.error("SQL error " + aError + ": " + aErrorString); } /** @@ -442,7 +436,7 @@ this.XPIDatabase = { count => { // Update the XPIDB schema version preference the first time we successfully // save the database. - LOG("XPI Database saved, setting schema version preference to " + DB_SCHEMA); + logger.debug("XPI Database saved, setting schema version preference to " + DB_SCHEMA); Services.prefs.setIntPref(PREF_DB_SCHEMA, DB_SCHEMA); // Reading the DB worked once, so we don't need the load error this._loadError = null; @@ -450,7 +444,7 @@ this.XPIDatabase = { error => { // Need to try setting the schema version again later this._schemaVersionSet = false; - WARN("Failed to save XPI database", error); + logger.warn("Failed to save XPI database", error); // this._deferredSave.lastError has the most recent error so we don't // need this any more this._loadError = null; @@ -502,10 +496,10 @@ this.XPIDatabase = { connection = Services.storage.openUnsharedDatabase(dbfile); } catch (e) { - WARN("Failed to open sqlite database " + dbfile.path + " for upgrade", e); + logger.warn("Failed to open sqlite database " + dbfile.path + " for upgrade", e); return null; } - LOG("Migrating data from sqlite"); + logger.debug("Migrating data from sqlite"); let migrateData = this.getMigrateDataFromDatabase(connection); connection.close(); return migrateData; @@ -535,7 +529,7 @@ this.XPIDatabase = { let data = ""; try { let readTimer = AddonManagerPrivate.simpleTimer("XPIDB_syncRead_MS"); - LOG("Opening XPI database " + this.jsonFile.path); + logger.debug("Opening XPI database " + this.jsonFile.path); fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]. createInstance(Components.interfaces.nsIFileInputStream); fstream.init(this.jsonFile, -1, 0, 0); @@ -555,7 +549,7 @@ this.XPIDatabase = { this.parseDB(data, aRebuildOnError); } catch(e) { - ERROR("Failed to load XPI JSON data from profile", e); + logger.error("Failed to load XPI JSON data from profile", e); let rebuildTimer = AddonManagerPrivate.simpleTimer("XPIDB_rebuildReadFailed_MS"); this.rebuildDatabase(aRebuildOnError); rebuildTimer.done(); @@ -601,7 +595,7 @@ this.XPIDatabase = { if (!("schemaVersion" in inputAddons) || !("addons" in inputAddons)) { parseTimer.done(); // Content of JSON file is bad, need to rebuild from scratch - ERROR("bad JSON file contents"); + logger.error("bad JSON file contents"); AddonManagerPrivate.recordSimpleMeasure("XPIDB_startupError", "badJSON"); let rebuildTimer = AddonManagerPrivate.simpleTimer("XPIDB_rebuildBadJSON_MS"); this.rebuildDatabase(aRebuildOnError); @@ -614,7 +608,7 @@ this.XPIDatabase = { // don't know about (bug 902956) AddonManagerPrivate.recordSimpleMeasure("XPIDB_startupError", "schemaMismatch-" + inputAddons.schemaVersion); - LOG("JSON schema mismatch: expected " + DB_SCHEMA + + logger.debug("JSON schema mismatch: expected " + DB_SCHEMA + ", actual " + inputAddons.schemaVersion); // When we rev the schema of the JSON database, we need to make sure we // force the DB to save so that the DB_SCHEMA value in the JSON file and @@ -629,7 +623,7 @@ this.XPIDatabase = { }; parseTimer.done(); this.addonDB = addonDB; - LOG("Successfully read XPI database"); + logger.debug("Successfully read XPI database"); this.initialized = true; } catch(e) { @@ -637,11 +631,11 @@ this.XPIDatabase = { // parser, the xpcshell test harness fails the test for us: bug 870828 parseTimer.done(); if (e.name == "SyntaxError") { - ERROR("Syntax error parsing saved XPI JSON data"); + logger.error("Syntax error parsing saved XPI JSON data"); AddonManagerPrivate.recordSimpleMeasure("XPIDB_startupError", "syntax"); } else { - ERROR("Failed to load XPI JSON data from profile", e); + logger.error("Failed to load XPI JSON data from profile", e); AddonManagerPrivate.recordSimpleMeasure("XPIDB_startupError", "other"); } let rebuildTimer = AddonManagerPrivate.simpleTimer("XPIDB_rebuildReadFailed_MS"); @@ -659,7 +653,7 @@ this.XPIDatabase = { let schemaVersion = Services.prefs.getIntPref(PREF_DB_SCHEMA); if (schemaVersion <= LAST_SQLITE_DB_SCHEMA) { // we should have an older SQLITE database - LOG("Attempting to upgrade from SQLITE database"); + logger.debug("Attempting to upgrade from SQLITE database"); this.migrateData = this.getMigrateDataFromSQLITE(); } else { @@ -684,7 +678,7 @@ this.XPIDatabase = { */ rebuildUnreadableDB: function(aError, aRebuildOnError) { let rebuildTimer = AddonManagerPrivate.simpleTimer("XPIDB_rebuildUnreadableDB_MS"); - WARN("Extensions database " + this.jsonFile.path + + logger.warn("Extensions database " + this.jsonFile.path + " exists but is not readable; rebuilding", aError); // Remember the error message until we try and write at least once, so // we know at shutdown time that there was a problem @@ -708,21 +702,21 @@ this.XPIDatabase = { return this._dbPromise; } - LOG("Starting async load of XPI database " + this.jsonFile.path); + logger.debug("Starting async load of XPI database " + this.jsonFile.path); AddonManagerPrivate.recordSimpleMeasure("XPIDB_async_load", XPIProvider.runPhase); let readOptions = { outExecutionDuration: 0 }; return this._dbPromise = OS.File.read(this.jsonFile.path, null, readOptions).then( byteArray => { - LOG("Async JSON file read took " + readOptions.outExecutionDuration + " MS"); + logger.debug("Async JSON file read took " + readOptions.outExecutionDuration + " MS"); AddonManagerPrivate.recordSimpleMeasure("XPIDB_asyncRead_MS", readOptions.outExecutionDuration); if (this._addonDB) { - LOG("Synchronous load completed while waiting for async load"); + logger.debug("Synchronous load completed while waiting for async load"); return this.addonDB; } - LOG("Finished async read of XPI database, parsing..."); + logger.debug("Finished async read of XPI database, parsing..."); let decodeTimer = AddonManagerPrivate.simpleTimer("XPIDB_decode_MS"); let decoder = new TextDecoder(); let data = decoder.decode(byteArray); @@ -733,7 +727,7 @@ this.XPIDatabase = { .then(null, error => { if (this._addonDB) { - LOG("Synchronous load completed while waiting for async load"); + logger.debug("Synchronous load completed while waiting for async load"); return this.addonDB; } if (error.becauseNoSuchFile) { @@ -762,7 +756,7 @@ this.XPIDatabase = { if (XPIProvider.installStates && XPIProvider.installStates.length == 0) { // No extensions installed, so we're done - LOG("Rebuilding XPI database with no extensions"); + logger.debug("Rebuilding XPI database with no extensions"); return; } @@ -772,12 +766,12 @@ this.XPIDatabase = { this.activeBundles = this.getActiveBundles(); if (aRebuildOnError) { - WARN("Rebuilding add-ons database from installed extensions."); + logger.warn("Rebuilding add-ons database from installed extensions."); try { XPIProvider.processFileChanges(XPIProvider.installStates, {}, false); } catch (e) { - ERROR("Failed to rebuild XPI database from installed extensions", e); + logger.error("Failed to rebuild XPI database from installed extensions", e); } // Make sure to update the active add-ons and add-ons list on shutdown Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, true); @@ -814,7 +808,7 @@ this.XPIDatabase = { bundles.push(parser.getString("ExtensionDirs", keys.getNext())); } catch (e) { - WARN("Failed to parse extensions.ini", e); + logger.warn("Failed to parse extensions.ini", e); return null; } @@ -838,7 +832,7 @@ this.XPIDatabase = { if (!rdffile.exists()) return null; - LOG("Migrating data from " + FILE_OLD_DATABASE); + logger.debug("Migrating data from " + FILE_OLD_DATABASE); let migrateData = {}; try { @@ -890,7 +884,7 @@ this.XPIDatabase = { } } catch (e) { - WARN("Error reading " + FILE_OLD_DATABASE, e); + logger.warn("Error reading " + FILE_OLD_DATABASE, e); migrateData = null; } @@ -930,7 +924,7 @@ this.XPIDatabase = { } if (reqCount < REQUIRED.length) { - ERROR("Unable to read anything useful from the database"); + logger.error("Unable to read anything useful from the database"); return null; } stmt.finalize(); @@ -975,7 +969,7 @@ this.XPIDatabase = { } catch (e) { // An error here means the schema is too different to read - ERROR("Error migrating data", e); + logger.error("Error migrating data", e); return null; } finally { @@ -995,7 +989,7 @@ this.XPIDatabase = { * all cleanup is done */ shutdown: function XPIDB_shutdown() { - LOG("shutdown"); + logger.debug("shutdown"); if (this.initialized) { // If our last database I/O had an error, try one last time to save. if (this.lastError) @@ -1016,7 +1010,7 @@ this.XPIDatabase = { // are finished cleaning up let flushPromise = this.flush(); flushPromise.then(null, error => { - ERROR("Flush of XPI database failed", error); + logger.error("Flush of XPI database failed", error); AddonManagerPrivate.recordSimpleMeasure("XPIDB_shutdownFlush_failed", 1); // If our last attempt to read or write the DB failed, force a new // extensions.ini to be written to disk on the next startup @@ -1073,7 +1067,7 @@ this.XPIDatabase = { }) .then(null, error => { - ERROR("getAddonList failed", e); + logger.error("getAddonList failed", e); makeSafe(aCallback)([]); }); }, @@ -1093,7 +1087,7 @@ this.XPIDatabase = { }) .then(null, error => { - ERROR("getAddon failed", e); + logger.error("getAddon failed", e); makeSafe(aCallback)(null); }); }, @@ -1167,7 +1161,7 @@ this.XPIDatabase = { // jank-tastic! Must synchronously load DB if the theme switches from // an XPI theme to a lightweight theme before the DB has loaded, // because we're called from sync XPIProvider.addonChanged - WARN("Synchronous load of XPI database due to getAddonsByType(" + aType + ")"); + logger.warn("Synchronous load of XPI database due to getAddonsByType(" + aType + ")"); AddonManagerPrivate.recordSimpleMeasure("XPIDB_lateOpen_byType", XPIProvider.runPhase); this.syncLoadDB(true); } @@ -1184,7 +1178,7 @@ this.XPIDatabase = { getVisibleAddonForInternalName: function XPIDB_getVisibleAddonForInternalName(aInternalName) { if (!this.addonDB) { // This may be called when the DB hasn't otherwise been loaded - WARN("Synchronous load of XPI database due to getVisibleAddonForInternalName"); + logger.warn("Synchronous load of XPI database due to getVisibleAddonForInternalName"); AddonManagerPrivate.recordSimpleMeasure("XPIDB_lateOpen_forInternalName", XPIProvider.runPhase); this.syncLoadDB(true); @@ -1321,10 +1315,10 @@ this.XPIDatabase = { * A callback to pass the DBAddonInternal to */ makeAddonVisible: function XPIDB_makeAddonVisible(aAddon) { - LOG("Make addon " + aAddon._key + " visible"); + logger.debug("Make addon " + aAddon._key + " visible"); for (let [, otherAddon] of this.addonDB) { if ((otherAddon.id == aAddon.id) && (otherAddon._key != aAddon._key)) { - LOG("Hide addon " + otherAddon._key); + logger.debug("Hide addon " + otherAddon._key); otherAddon.visible = false; } } @@ -1378,7 +1372,7 @@ this.XPIDatabase = { * The DBAddonInternal to update */ updateAddonActive: function XPIDB_updateAddonActive(aAddon, aActive) { - LOG("Updating active state for add-on " + aAddon.id + " to " + aActive); + logger.debug("Updating active state for add-on " + aAddon.id + " to " + aActive); aAddon.active = aActive; this.saveChanges(); @@ -1389,13 +1383,13 @@ this.XPIDatabase = { */ updateActiveAddons: function XPIDB_updateActiveAddons() { if (!this.addonDB) { - WARN("updateActiveAddons called when DB isn't loaded"); + logger.warn("updateActiveAddons called when DB isn't loaded"); // force the DB to load AddonManagerPrivate.recordSimpleMeasure("XPIDB_lateOpen_updateActive", XPIProvider.runPhase); this.syncLoadDB(true); } - LOG("Updating add-on states"); + logger.debug("Updating add-on states"); for (let [, addon] of this.addonDB) { let newActive = (addon.visible && !addon.userDisabled && !addon.softDisabled && !addon.appDisabled && @@ -1472,7 +1466,7 @@ this.XPIDatabase = { } if (fullCount > 0) { - LOG("Writing add-ons list"); + logger.debug("Writing add-ons list"); try { let addonsListTmp = FileUtils.getFile(KEY_PROFILEDIR, [FILE_XPI_ADDONS_LIST + ".tmp"], @@ -1485,19 +1479,19 @@ this.XPIDatabase = { Services.prefs.setCharPref(PREF_EM_ENABLED_ADDONS, enabledAddons.join(",")); } catch (e) { - ERROR("Failed to write add-ons list to " + addonsListTmp.parent + "/" + + logger.error("Failed to write add-ons list to " + addonsListTmp.parent + "/" + FILE_XPI_ADDONS_LIST, e); return false; } } else { if (addonsList.exists()) { - LOG("Deleting add-ons list"); + logger.debug("Deleting add-ons list"); try { addonsList.remove(false); } catch (e) { - ERROR("Failed to remove " + addonsList.path, e); + logger.error("Failed to remove " + addonsList.path, e); return false; } }