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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Constants michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cr = Components.results; michael@0: const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul"; michael@0: const PREF_FLASH_COUNT = "browser.download.manager.flashCount"; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// nsDownloadManagerUI class michael@0: michael@0: function nsDownloadManagerUI() {} michael@0: michael@0: nsDownloadManagerUI.prototype = { michael@0: classID: Components.ID("7dfdf0d1-aff6-4a34-bad1-d0fe74601642"), michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// nsIDownloadManagerUI michael@0: michael@0: show: function show(aWindowContext, aDownload, aReason, aUsePrivateUI) michael@0: { michael@0: if (!aReason) michael@0: aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED; michael@0: michael@0: // First we see if it is already visible michael@0: let window = this.recentWindow; michael@0: if (window) { michael@0: window.focus(); michael@0: michael@0: // If we are being asked to show again, with a user interaction reason, michael@0: // set the appropriate variable. michael@0: if (aReason == Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED) michael@0: window.gUserInteracted = true; michael@0: return; michael@0: } michael@0: michael@0: let parent = null; michael@0: // We try to get a window to use as the parent here. If we don't have one, michael@0: // the download manager will close immediately after opening if the pref michael@0: // browser.download.manager.closeWhenDone is set to true. michael@0: try { michael@0: if (aWindowContext) michael@0: parent = aWindowContext.getInterface(Ci.nsIDOMWindow); michael@0: } catch (e) { /* it's OK to not have a parent window */ } michael@0: michael@0: // We pass the download manager and the nsIDownload we want selected (if any) michael@0: var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); michael@0: params.appendElement(aDownload, false); michael@0: michael@0: // Pass in the reason as well michael@0: let reason = Cc["@mozilla.org/supports-PRInt16;1"]. michael@0: createInstance(Ci.nsISupportsPRInt16); michael@0: reason.data = aReason; michael@0: params.appendElement(reason, false); michael@0: michael@0: var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. michael@0: getService(Ci.nsIWindowWatcher); michael@0: ww.openWindow(parent, michael@0: DOWNLOAD_MANAGER_URL, michael@0: "Download:Manager", michael@0: "chrome,dialog=no,resizable", michael@0: params); michael@0: }, michael@0: michael@0: get visible() { michael@0: return (null != this.recentWindow); michael@0: }, michael@0: michael@0: getAttention: function getAttention() michael@0: { michael@0: if (!this.visible) michael@0: throw Cr.NS_ERROR_UNEXPECTED; michael@0: michael@0: var prefs = Cc["@mozilla.org/preferences-service;1"]. michael@0: getService(Ci.nsIPrefBranch); michael@0: // This preference may not be set, so defaulting to two. michael@0: let flashCount = 2; michael@0: try { michael@0: flashCount = prefs.getIntPref(PREF_FLASH_COUNT); michael@0: } catch (e) { } michael@0: michael@0: var win = this.recentWindow.QueryInterface(Ci.nsIDOMChromeWindow); michael@0: win.getAttentionWithCycleCount(flashCount); michael@0: }, michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// nsDownloadManagerUI michael@0: michael@0: get recentWindow() { michael@0: var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. michael@0: getService(Ci.nsIWindowMediator); michael@0: return wm.getMostRecentWindow("Download:Manager"); michael@0: }, michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// nsISupports michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIDownloadManagerUI]) michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Module michael@0: michael@0: let components = [nsDownloadManagerUI]; michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components); michael@0: