michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let Ci = Components.interfaces, Cc = Components.classes, Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/DownloadUtils.jsm"); michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/PluralForm.jsm"); michael@0: Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); michael@0: michael@0: XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm"); michael@0: michael@0: let gStrings = Services.strings.createBundle("chrome://browser/locale/aboutDownloads.properties"); michael@0: michael@0: let downloadTemplate = michael@0: "
  • " + michael@0: "" + michael@0: "
    " + michael@0: "
    " + michael@0: // This is a hack so that we can crop this label in its center michael@0: "" + michael@0: "
    {date}
    " + michael@0: "
    " + michael@0: "
    {size}
    " + michael@0: "
    {domain}
    " + michael@0: "
    {displayState}
    " + michael@0: "
    " + michael@0: "
  • "; michael@0: michael@0: XPCOMUtils.defineLazyGetter(window, "gChromeWin", function () michael@0: window.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIWebNavigation) michael@0: .QueryInterface(Ci.nsIDocShellTreeItem) michael@0: .rootTreeItem michael@0: .QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindow) michael@0: .QueryInterface(Ci.nsIDOMChromeWindow)); michael@0: michael@0: michael@0: var ContextMenus = { michael@0: target: null, michael@0: michael@0: init: function() { michael@0: document.addEventListener("contextmenu", this, false); michael@0: document.getElementById("contextmenu-open").addEventListener("click", this.open.bind(this), false); michael@0: document.getElementById("contextmenu-retry").addEventListener("click", this.retry.bind(this), false); michael@0: document.getElementById("contextmenu-remove").addEventListener("click", this.remove.bind(this), false); michael@0: document.getElementById("contextmenu-pause").addEventListener("click", this.pause.bind(this), false); michael@0: document.getElementById("contextmenu-resume").addEventListener("click", this.resume.bind(this), false); michael@0: document.getElementById("contextmenu-cancel").addEventListener("click", this.cancel.bind(this), false); michael@0: document.getElementById("contextmenu-removeall").addEventListener("click", this.removeAll.bind(this), false); michael@0: this.items = [ michael@0: { name: "open", states: [Downloads._dlmgr.DOWNLOAD_FINISHED] }, michael@0: { name: "retry", states: [Downloads._dlmgr.DOWNLOAD_FAILED, Downloads._dlmgr.DOWNLOAD_CANCELED] }, michael@0: { name: "remove", states: [Downloads._dlmgr.DOWNLOAD_FINISHED,Downloads._dlmgr.DOWNLOAD_FAILED, Downloads._dlmgr.DOWNLOAD_CANCELED] }, michael@0: { name: "removeall", states: [Downloads._dlmgr.DOWNLOAD_FINISHED,Downloads._dlmgr.DOWNLOAD_FAILED, Downloads._dlmgr.DOWNLOAD_CANCELED] }, michael@0: { name: "pause", states: [Downloads._dlmgr.DOWNLOAD_DOWNLOADING] }, michael@0: { name: "resume", states: [Downloads._dlmgr.DOWNLOAD_PAUSED] }, michael@0: { name: "cancel", states: [Downloads._dlmgr.DOWNLOAD_DOWNLOADING, Downloads._dlmgr.DOWNLOAD_NOTSTARTED, Downloads._dlmgr.DOWNLOAD_QUEUED, Downloads._dlmgr.DOWNLOAD_PAUSED] }, michael@0: ]; michael@0: }, michael@0: michael@0: handleEvent: function(event) { michael@0: // store the target of context menu events so that we know which app to act on michael@0: this.target = event.target; michael@0: while (!this.target.hasAttribute("contextmenu")) { michael@0: this.target = this.target.parentNode; michael@0: } michael@0: if (!this.target) michael@0: return; michael@0: michael@0: let state = parseInt(this.target.getAttribute("state")); michael@0: for (let i = 0; i < this.items.length; i++) { michael@0: var item = this.items[i]; michael@0: let enabled = (item.states.indexOf(state) > -1); michael@0: if (enabled) michael@0: document.getElementById("contextmenu-" + item.name).removeAttribute("hidden"); michael@0: else michael@0: document.getElementById("contextmenu-" + item.name).setAttribute("hidden", "true"); michael@0: } michael@0: }, michael@0: michael@0: // Open shown only for downloads that completed successfully michael@0: open: function(event) { michael@0: Downloads.openDownload(this.target); michael@0: this.target = null; michael@0: }, michael@0: michael@0: // Retry shown when its failed, canceled, blocked(covered in failed, see _getState()) michael@0: retry: function (event) { michael@0: Downloads.retryDownload(this.target); michael@0: this.target = null; michael@0: }, michael@0: michael@0: // Remove shown when its canceled, finished, failed(failed includes blocked and dirty, see _getState()) michael@0: remove: function (event) { michael@0: Downloads.removeDownload(this.target); michael@0: this.target = null; michael@0: }, michael@0: michael@0: // Pause shown when item is currently downloading michael@0: pause: function (event) { michael@0: Downloads.pauseDownload(this.target); michael@0: this.target = null; michael@0: }, michael@0: michael@0: // Resume shown for paused items only michael@0: resume: function (event) { michael@0: Downloads.resumeDownload(this.target); michael@0: this.target = null; michael@0: }, michael@0: michael@0: // Cancel shown when its downloading, notstarted, queued or paused michael@0: cancel: function (event) { michael@0: Downloads.cancelDownload(this.target); michael@0: this.target = null; michael@0: }, michael@0: michael@0: removeAll: function(event) { michael@0: Downloads.removeAll(); michael@0: this.target = null; michael@0: } michael@0: } michael@0: michael@0: michael@0: let Downloads = { michael@0: init: function dl_init() { michael@0: function onClick(evt) { michael@0: let target = evt.target; michael@0: while (target.nodeName != "li") { michael@0: target = target.parentNode; michael@0: if (!target) michael@0: return; michael@0: } michael@0: michael@0: Downloads.openDownload(target); michael@0: } michael@0: michael@0: this._normalList = document.getElementById("normal-downloads-list"); michael@0: this._privateList = document.getElementById("private-downloads-list"); michael@0: michael@0: this._normalList.addEventListener("click", onClick, false); michael@0: this._privateList.addEventListener("click", onClick, false); michael@0: michael@0: this._dlmgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager); michael@0: this._dlmgr.addPrivacyAwareListener(this); michael@0: michael@0: Services.obs.addObserver(this, "last-pb-context-exited", false); michael@0: Services.obs.addObserver(this, "download-manager-remove-download-guid", false); michael@0: michael@0: // If we have private downloads, show them all immediately. If we were to michael@0: // add them asynchronously, there's a small chance we could get a michael@0: // "last-pb-context-exited" notification before downloads are added to the michael@0: // list, meaning we'd show private downloads without any private tabs open. michael@0: let privateEntries = this.getDownloads({ isPrivate: true }); michael@0: this._stepAddEntries(privateEntries, this._privateList, privateEntries.length); michael@0: michael@0: // Add non-private downloads michael@0: let normalEntries = this.getDownloads({ isPrivate: false }); michael@0: this._stepAddEntries(normalEntries, this._normalList, 1, this._scrollToSelectedDownload.bind(this)); michael@0: ContextMenus.init(); michael@0: }, michael@0: michael@0: uninit: function dl_uninit() { michael@0: let contextmenus = gChromeWin.NativeWindow.contextmenus; michael@0: contextmenus.remove(this.openMenuItem); michael@0: contextmenus.remove(this.removeMenuItem); michael@0: contextmenus.remove(this.pauseMenuItem); michael@0: contextmenus.remove(this.resumeMenuItem); michael@0: contextmenus.remove(this.retryMenuItem); michael@0: contextmenus.remove(this.cancelMenuItem); michael@0: contextmenus.remove(this.deleteAllMenuItem); michael@0: michael@0: this._dlmgr.removeListener(this); michael@0: Services.obs.removeObserver(this, "last-pb-context-exited"); michael@0: Services.obs.removeObserver(this, "download-manager-remove-download-guid"); michael@0: }, michael@0: michael@0: onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, michael@0: aCurTotalProgress, aMaxTotalProgress, aDownload) { }, michael@0: onDownloadStateChange: function(aState, aDownload) { michael@0: switch (aDownload.state) { michael@0: case Ci.nsIDownloadManager.DOWNLOAD_FAILED: michael@0: case Ci.nsIDownloadManager.DOWNLOAD_CANCELED: michael@0: case Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL: michael@0: case Ci.nsIDownloadManager.DOWNLOAD_DIRTY: michael@0: case Ci.nsIDownloadManager.DOWNLOAD_FINISHED: michael@0: // For all "completed" states, move them after active downloads michael@0: this._moveDownloadAfterActive(this._getElementForDownload(aDownload.guid)); michael@0: michael@0: // Fall-through the rest michael@0: case Ci.nsIDownloadManager.DOWNLOAD_SCANNING: michael@0: case Ci.nsIDownloadManager.DOWNLOAD_QUEUED: michael@0: case Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING: michael@0: let item = this._getElementForDownload(aDownload.guid); michael@0: if (item) michael@0: this._updateDownloadRow(item, aDownload); michael@0: else michael@0: this._insertDownloadRow(aDownload); michael@0: break; michael@0: } michael@0: }, michael@0: onStateChange: function(aWebProgress, aRequest, aState, aStatus, aDownload) { }, michael@0: onSecurityChange: function(aWebProgress, aRequest, aState, aDownload) { }, michael@0: michael@0: observe: function (aSubject, aTopic, aData) { michael@0: switch (aTopic) { michael@0: case "last-pb-context-exited": michael@0: this._privateList.innerHTML = ""; michael@0: break; michael@0: case "download-manager-remove-download-guid": { michael@0: let guid = aSubject.QueryInterface(Ci.nsISupportsCString).data; michael@0: this._removeItem(this._getElementForDownload(guid)); michael@0: break; michael@0: } michael@0: } michael@0: }, michael@0: michael@0: _moveDownloadAfterActive: function dl_moveDownloadAfterActive(aItem) { michael@0: // Move downloads that just reached a "completed" state below any active michael@0: try { michael@0: // Iterate down until we find a non-active download michael@0: let next = aItem.nextElementSibling; michael@0: while (next && this._inProgress(next.getAttribute("state"))) michael@0: next = next.nextElementSibling; michael@0: // Move the item michael@0: aItem.parentNode.insertBefore(aItem, next); michael@0: } catch (ex) { michael@0: this.logError("_moveDownloadAfterActive() " + ex); michael@0: } michael@0: }, michael@0: michael@0: _inProgress: function dl_inProgress(aState) { michael@0: return [ michael@0: this._dlmgr.DOWNLOAD_NOTSTARTED, michael@0: this._dlmgr.DOWNLOAD_QUEUED, michael@0: this._dlmgr.DOWNLOAD_DOWNLOADING, michael@0: this._dlmgr.DOWNLOAD_PAUSED, michael@0: this._dlmgr.DOWNLOAD_SCANNING, michael@0: ].indexOf(parseInt(aState)) != -1; michael@0: }, michael@0: michael@0: _insertDownloadRow: function dl_insertDownloadRow(aDownload) { michael@0: let updatedState = this._getState(aDownload.state); michael@0: let item = this._createItem(downloadTemplate, { michael@0: guid: aDownload.guid, michael@0: target: aDownload.displayName, michael@0: icon: "moz-icon://" + aDownload.displayName + "?size=64", michael@0: date: DownloadUtils.getReadableDates(new Date())[0], michael@0: domain: DownloadUtils.getURIHost(aDownload.source.spec)[0], michael@0: size: this._getDownloadSize(aDownload.size), michael@0: displayState: this._getStateString(updatedState), michael@0: state: updatedState michael@0: }); michael@0: list = aDownload.isPrivate ? this._privateList : this._normalList; michael@0: list.insertAdjacentHTML("afterbegin", item); michael@0: }, michael@0: michael@0: _getDownloadSize: function dl_getDownloadSize(aSize) { michael@0: if (aSize > 0) { michael@0: let displaySize = DownloadUtils.convertByteUnits(aSize); michael@0: return displaySize.join(""); // [0] is size, [1] is units michael@0: } michael@0: return gStrings.GetStringFromName("downloadState.unknownSize"); michael@0: }, michael@0: michael@0: // Not all states are displayed as-is on mobile, some are translated to a generic state michael@0: _getState: function dl_getState(aState) { michael@0: let str; michael@0: switch (aState) { michael@0: // Downloading and Scanning states show up as "Downloading" michael@0: case this._dlmgr.DOWNLOAD_DOWNLOADING: michael@0: case this._dlmgr.DOWNLOAD_SCANNING: michael@0: str = this._dlmgr.DOWNLOAD_DOWNLOADING; michael@0: break; michael@0: michael@0: // Failed, Dirty and Blocked states show up as "Failed" michael@0: case this._dlmgr.DOWNLOAD_FAILED: michael@0: case this._dlmgr.DOWNLOAD_DIRTY: michael@0: case this._dlmgr.DOWNLOAD_BLOCKED_POLICY: michael@0: case this._dlmgr.DOWNLOAD_BLOCKED_PARENTAL: michael@0: str = this._dlmgr.DOWNLOAD_FAILED; michael@0: break; michael@0: michael@0: /* QUEUED and NOTSTARTED are not translated as they michael@0: dont fall under a common state but we still need michael@0: to display a common "status" on the UI */ michael@0: michael@0: default: michael@0: str = aState; michael@0: } michael@0: return str; michael@0: }, michael@0: michael@0: // Note: This doesn't cover all states as some of the states are translated in _getState() michael@0: _getStateString: function dl_getStateString(aState) { michael@0: let str; michael@0: switch (aState) { michael@0: case this._dlmgr.DOWNLOAD_DOWNLOADING: michael@0: str = "downloadState.downloading"; michael@0: break; michael@0: case this._dlmgr.DOWNLOAD_CANCELED: michael@0: str = "downloadState.canceled"; michael@0: break; michael@0: case this._dlmgr.DOWNLOAD_FAILED: michael@0: str = "downloadState.failed"; michael@0: break; michael@0: case this._dlmgr.DOWNLOAD_PAUSED: michael@0: str = "downloadState.paused"; michael@0: break; michael@0: michael@0: // Queued and Notstarted show up as "Starting..." michael@0: case this._dlmgr.DOWNLOAD_QUEUED: michael@0: case this._dlmgr.DOWNLOAD_NOTSTARTED: michael@0: str = "downloadState.starting"; michael@0: break; michael@0: michael@0: default: michael@0: return ""; michael@0: } michael@0: return gStrings.GetStringFromName(str); michael@0: }, michael@0: michael@0: _updateItem: function dl_updateItem(aItem, aValues) { michael@0: for (let i in aValues) { michael@0: aItem.querySelector("." + i).textContent = aValues[i]; michael@0: } michael@0: }, michael@0: michael@0: _initStatement: function dv__initStatement(aIsPrivate) { michael@0: let dbConn = aIsPrivate ? this._dlmgr.privateDBConnection : this._dlmgr.DBConnection; michael@0: return dbConn.createStatement( michael@0: "SELECT guid, name, source, state, startTime, endTime, referrer, " + michael@0: "currBytes, maxBytes, state IN (?1, ?2, ?3, ?4, ?5) isActive " + michael@0: "FROM moz_downloads " + michael@0: "ORDER BY isActive DESC, endTime DESC, startTime DESC"); michael@0: }, michael@0: michael@0: _createItem: function _createItem(aTemplate, aValues) { michael@0: function htmlEscape(s) { michael@0: s = s.replace(/&/g, "&"); michael@0: s = s.replace(/>/g, ">"); michael@0: s = s.replace(/ 1) { michael@0: this._stepAddEntries(aEntries, aList, aNumItems - 1, aCallback); michael@0: } else { michael@0: // Use a shorter delay for earlier downloads to display them faster michael@0: let delay = Math.min(aList.itemCount * 10, 300); michael@0: setTimeout(function () { michael@0: this._stepAddEntries(aEntries, aList, 5, aCallback); michael@0: }.bind(this), delay); michael@0: } michael@0: }, michael@0: michael@0: getDownloads: function dl_getDownloads(aParams) { michael@0: aParams = aParams || {}; michael@0: let stmt = this._initStatement(aParams.isPrivate); michael@0: michael@0: stmt.reset(); michael@0: stmt.bindInt32Parameter(0, Ci.nsIDownloadManager.DOWNLOAD_NOTSTARTED); michael@0: stmt.bindInt32Parameter(1, Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING); michael@0: stmt.bindInt32Parameter(2, Ci.nsIDownloadManager.DOWNLOAD_PAUSED); michael@0: stmt.bindInt32Parameter(3, Ci.nsIDownloadManager.DOWNLOAD_QUEUED); michael@0: stmt.bindInt32Parameter(4, Ci.nsIDownloadManager.DOWNLOAD_SCANNING); michael@0: michael@0: let entries = []; michael@0: while (entry = this._getEntry(stmt)) { michael@0: entries.push(entry); michael@0: } michael@0: michael@0: stmt.finalize(); michael@0: michael@0: return entries; michael@0: }, michael@0: michael@0: _getElementForDownload: function dl_getElementForDownload(aKey) { michael@0: return document.body.querySelector("li[downloadGUID='" + aKey + "']"); michael@0: }, michael@0: michael@0: _getDownloadForElement: function dl_getDownloadForElement(aElement, aCallback) { michael@0: let guid = aElement.getAttribute("downloadGUID"); michael@0: this._dlmgr.getDownloadByGUID(guid, function(status, download) { michael@0: if (!Components.isSuccessCode(status)) { michael@0: return; michael@0: } michael@0: aCallback(download); michael@0: }); michael@0: }, michael@0: michael@0: _removeItem: function dl_removeItem(aItem) { michael@0: // Make sure we have an item to remove michael@0: if (!aItem) michael@0: return; michael@0: michael@0: aItem.parentNode.removeChild(aItem); michael@0: }, michael@0: michael@0: openDownload: function dl_openDownload(aItem) { michael@0: this._getDownloadForElement(aItem, function(aDownload) { michael@0: if (aDownload.state !== Ci.nsIDownloadManager.DOWNLOAD_FINISHED) { michael@0: // Do not open unfinished downloads. michael@0: return; michael@0: } michael@0: try { michael@0: let f = aDownload.targetFile; michael@0: if (f) f.launch(); michael@0: } catch (ex) { michael@0: this.logError("openDownload() " + ex, aDownload); michael@0: } michael@0: }.bind(this)); michael@0: }, michael@0: michael@0: removeDownload: function dl_removeDownload(aItem) { michael@0: this._getDownloadForElement(aItem, function(aDownload) { michael@0: if (aDownload.targetFile) { michael@0: OS.File.remove(aDownload.targetFile.path).then(null, function onError(reason) { michael@0: if (!(reason instanceof OS.File.Error && reason.becauseNoSuchFile)) { michael@0: this.logError("removeDownload() " + reason, aDownload); michael@0: } michael@0: }.bind(this)); michael@0: } michael@0: michael@0: aDownload.remove(); michael@0: }.bind(this)); michael@0: }, michael@0: michael@0: removeAll: function dl_removeAll() { michael@0: let title = gStrings.GetStringFromName("downloadAction.deleteAll"); michael@0: let messageForm = gStrings.GetStringFromName("downloadMessage.deleteAll"); michael@0: let elements = document.body.querySelectorAll("li[state='" + this._dlmgr.DOWNLOAD_FINISHED + "']," + michael@0: "li[state='" + this._dlmgr.DOWNLOAD_CANCELED + "']," + michael@0: "li[state='" + this._dlmgr.DOWNLOAD_FAILED + "']"); michael@0: let message = PluralForm.get(elements.length, messageForm) michael@0: .replace("#1", elements.length); michael@0: let flags = Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_OK + michael@0: Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL; michael@0: let choice = Services.prompt.confirmEx(null, title, message, flags, michael@0: null, null, null, null, {}); michael@0: if (choice == 0) { michael@0: for (let i = 0; i < elements.length; i++) { michael@0: this.removeDownload(elements[i]); michael@0: } michael@0: } michael@0: }, michael@0: michael@0: pauseDownload: function dl_pauseDownload(aItem) { michael@0: this._getDownloadForElement(aItem, function(aDownload) { michael@0: try { michael@0: aDownload.pause(); michael@0: this._updateDownloadRow(aItem, aDownload); michael@0: } catch (ex) { michael@0: this.logError("Error: pauseDownload() " + ex, aDownload); michael@0: } michael@0: }.bind(this)); michael@0: }, michael@0: michael@0: resumeDownload: function dl_resumeDownload(aItem) { michael@0: this._getDownloadForElement(aItem, function(aDownload) { michael@0: try { michael@0: aDownload.resume(); michael@0: this._updateDownloadRow(aItem, aDownload); michael@0: } catch (ex) { michael@0: this.logError("resumeDownload() " + ex, aDownload); michael@0: } michael@0: }.bind(this)); michael@0: }, michael@0: michael@0: retryDownload: function dl_retryDownload(aItem) { michael@0: this._getDownloadForElement(aItem, function(aDownload) { michael@0: try { michael@0: this._removeItem(aItem); michael@0: aDownload.retry(); michael@0: } catch (ex) { michael@0: this.logError("retryDownload() " + ex, aDownload); michael@0: } michael@0: }.bind(this)); michael@0: }, michael@0: michael@0: cancelDownload: function dl_cancelDownload(aItem) { michael@0: this._getDownloadForElement(aItem, function(aDownload) { michael@0: OS.File.remove(aDownload.targetFile.path).then(null, function onError(reason) { michael@0: if (!(reason instanceof OS.File.Error && reason.becauseNoSuchFile)) { michael@0: this.logError("cancelDownload() " + reason, aDownload); michael@0: } michael@0: }.bind(this)); michael@0: michael@0: aDownload.cancel(); michael@0: michael@0: this._updateDownloadRow(aItem, aDownload); michael@0: }.bind(this)); michael@0: }, michael@0: michael@0: _updateDownloadRow: function dl_updateDownloadRow(aItem, aDownload) { michael@0: try { michael@0: let updatedState = this._getState(aDownload.state); michael@0: aItem.setAttribute("state", updatedState); michael@0: this._updateItem(aItem, { michael@0: size: this._getDownloadSize(aDownload.size), michael@0: displayState: this._getStateString(updatedState), michael@0: date: DownloadUtils.getReadableDates(new Date())[0] michael@0: }); michael@0: } catch (ex) { michael@0: this.logError("_updateDownloadRow() " + ex, aDownload); michael@0: } michael@0: }, michael@0: michael@0: /** michael@0: * In case a specific downloadId was passed while opening, scrolls the list to michael@0: * the given elemenet michael@0: */ michael@0: michael@0: _scrollToSelectedDownload : function dl_scrollToSelected() { michael@0: let spec = document.location.href; michael@0: let pos = spec.indexOf("?"); michael@0: let query = ""; michael@0: if (pos >= 0) michael@0: query = spec.substring(pos + 1); michael@0: michael@0: // Just assume the query is "id=" michael@0: let id = query.substring(3); michael@0: if (!id) { michael@0: return; michael@0: } michael@0: downloadElement = this._getElementForDownload(id); michael@0: if (!downloadElement) { michael@0: return; michael@0: } michael@0: michael@0: downloadElement.scrollIntoView(); michael@0: }, michael@0: michael@0: /** michael@0: * Logs the error to the console. michael@0: * michael@0: * @param aMessage error message to log michael@0: * @param aDownload (optional) if given, and if the download is private, the michael@0: * log message is suppressed michael@0: */ michael@0: logError: function dl_logError(aMessage, aDownload) { michael@0: if (!aDownload || !aDownload.isPrivate) { michael@0: console.log("Error: " + aMessage); michael@0: } michael@0: }, michael@0: michael@0: QueryInterface: function (aIID) { michael@0: if (!aIID.equals(Ci.nsIDownloadProgressListener) && michael@0: !aIID.equals(Ci.nsISupports)) michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: return this; michael@0: } michael@0: } michael@0: michael@0: document.addEventListener("DOMContentLoaded", Downloads.init.bind(Downloads), true); michael@0: window.addEventListener("unload", Downloads.uninit.bind(Downloads), false); michael@0: michael@0: