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