browser/components/downloads/src/DownloadsUI.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /**
michael@0 8 * This component implements the nsIDownloadManagerUI interface and opens the
michael@0 9 * Downloads view for the most recent browser window when requested.
michael@0 10 */
michael@0 11
michael@0 12 "use strict";
michael@0 13
michael@0 14 ////////////////////////////////////////////////////////////////////////////////
michael@0 15 //// Globals
michael@0 16
michael@0 17 const Cc = Components.classes;
michael@0 18 const Ci = Components.interfaces;
michael@0 19 const Cu = Components.utils;
michael@0 20 const Cr = Components.results;
michael@0 21
michael@0 22 Cu.import("resource://gre/modules/Services.jsm");
michael@0 23 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 24
michael@0 25 XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
michael@0 26 "resource:///modules/DownloadsCommon.jsm");
michael@0 27 XPCOMUtils.defineLazyServiceGetter(this, "gBrowserGlue",
michael@0 28 "@mozilla.org/browser/browserglue;1",
michael@0 29 "nsIBrowserGlue");
michael@0 30 XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
michael@0 31 "resource:///modules/RecentWindow.jsm");
michael@0 32 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
michael@0 33 "resource://gre/modules/PrivateBrowsingUtils.jsm");
michael@0 34
michael@0 35 ////////////////////////////////////////////////////////////////////////////////
michael@0 36 //// DownloadsUI
michael@0 37
michael@0 38 function DownloadsUI()
michael@0 39 {
michael@0 40 }
michael@0 41
michael@0 42 DownloadsUI.prototype = {
michael@0 43 classID: Components.ID("{4d99321e-d156-455b-81f7-e7aa2308134f}"),
michael@0 44
michael@0 45 _xpcom_factory: XPCOMUtils.generateSingletonFactory(DownloadsUI),
michael@0 46
michael@0 47 //////////////////////////////////////////////////////////////////////////////
michael@0 48 //// nsISupports
michael@0 49
michael@0 50 QueryInterface: XPCOMUtils.generateQI([Ci.nsIDownloadManagerUI]),
michael@0 51
michael@0 52 //////////////////////////////////////////////////////////////////////////////
michael@0 53 //// nsIDownloadManagerUI
michael@0 54
michael@0 55 show: function DUI_show(aWindowContext, aDownload, aReason, aUsePrivateUI)
michael@0 56 {
michael@0 57 if (!aReason) {
michael@0 58 aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
michael@0 59 }
michael@0 60
michael@0 61 if (aReason == Ci.nsIDownloadManagerUI.REASON_NEW_DOWNLOAD) {
michael@0 62 const kMinimized = Ci.nsIDOMChromeWindow.STATE_MINIMIZED;
michael@0 63 let browserWin = gBrowserGlue.getMostRecentBrowserWindow();
michael@0 64
michael@0 65 if (!browserWin || browserWin.windowState == kMinimized) {
michael@0 66 this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
michael@0 67 }
michael@0 68 else {
michael@0 69 // If the indicator is visible, then new download notifications are
michael@0 70 // already handled by the panel service.
michael@0 71 browserWin.DownloadsButton.checkIsVisible(function(isVisible) {
michael@0 72 if (!isVisible) {
michael@0 73 this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
michael@0 74 }
michael@0 75 }.bind(this));
michael@0 76 }
michael@0 77 } else {
michael@0 78 this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
michael@0 79 }
michael@0 80 },
michael@0 81
michael@0 82 get visible() true,
michael@0 83
michael@0 84 getAttention: function () {},
michael@0 85
michael@0 86 //////////////////////////////////////////////////////////////////////////////
michael@0 87 //// Private
michael@0 88
michael@0 89 /**
michael@0 90 * Helper function that opens the download manager UI.
michael@0 91 */
michael@0 92 _showDownloadManagerUI: function (aWindowContext, aUsePrivateUI)
michael@0 93 {
michael@0 94 // If we weren't given a window context, try to find a browser window
michael@0 95 // to use as our parent - and if that doesn't work, error out and give up.
michael@0 96 let parentWindow = aWindowContext;
michael@0 97 if (!parentWindow) {
michael@0 98 parentWindow = RecentWindow.getMostRecentBrowserWindow({ private: !!aUsePrivateUI });
michael@0 99 if (!parentWindow) {
michael@0 100 Components.utils.reportError(
michael@0 101 "Couldn't find a browser window to open the Places Downloads View " +
michael@0 102 "from.");
michael@0 103 return;
michael@0 104 }
michael@0 105 }
michael@0 106
michael@0 107 // If window is private then show it in a tab.
michael@0 108 if (PrivateBrowsingUtils.isWindowPrivate(parentWindow)) {
michael@0 109 parentWindow.openUILinkIn("about:downloads", "tab");
michael@0 110 return;
michael@0 111 } else {
michael@0 112 let organizer = Services.wm.getMostRecentWindow("Places:Organizer");
michael@0 113 if (!organizer) {
michael@0 114 parentWindow.openDialog("chrome://browser/content/places/places.xul",
michael@0 115 "", "chrome,toolbar=yes,dialog=no,resizable",
michael@0 116 "Downloads");
michael@0 117 } else {
michael@0 118 organizer.PlacesOrganizer.selectLeftPaneQuery("Downloads");
michael@0 119 organizer.focus();
michael@0 120 }
michael@0 121 }
michael@0 122 }
michael@0 123 };
michael@0 124
michael@0 125 ////////////////////////////////////////////////////////////////////////////////
michael@0 126 //// Module
michael@0 127
michael@0 128 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DownloadsUI]);

mercurial