1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/components/DownloadManagerUI.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const Ci = Components.interfaces; 1.9 +const Cr = Components.results; 1.10 + 1.11 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.12 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.13 + 1.14 +// ----------------------------------------------------------------------- 1.15 +// Download Manager UI 1.16 +// ----------------------------------------------------------------------- 1.17 + 1.18 +function DownloadManagerUI() { } 1.19 + 1.20 +DownloadManagerUI.prototype = { 1.21 + classID: Components.ID("{93db15b1-b408-453e-9a2b-6619e168324a}"), 1.22 + 1.23 + show: function show(aWindowContext, aDownload, aReason, aUsePrivateUI) { 1.24 + if (!aReason) 1.25 + aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED; 1.26 + 1.27 + this._getBrowserApp().selectOrOpenTab("about:downloads"); 1.28 + }, 1.29 + 1.30 + get visible() { 1.31 + let browserApp = this._getBrowserApp(); 1.32 + let downloadsTab = browserApp.getTabWithURL("about:downloads"); 1.33 + return (downloadsTab && downloadsTab == browserApp.selectedTab) ? true : false; 1.34 + }, 1.35 + 1.36 + getAttention: function getAttention() { 1.37 + if (this._getBrowserApp().getTabWithURL("about:downloads")) 1.38 + return; 1.39 + 1.40 + throw Cr.NS_ERROR_UNEXPECTED; 1.41 + }, 1.42 + 1.43 + _getBrowserApp: function getBrowserApp() { 1.44 + try { 1.45 + return Services.wm.getMostRecentWindow("navigator:browser").BrowserApp; 1.46 + } catch (e) { 1.47 + throw Cr.NS_ERROR_FAILURE; 1.48 + } 1.49 + }, 1.50 + 1.51 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIDownloadManagerUI]) 1.52 +}; 1.53 + 1.54 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DownloadManagerUI]);