2014-06-24 22:12:07 -07:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2013-11-04 10:21:13 -08:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
|
2012-04-17 04:35:09 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2013-11-04 10:21:13 -08:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-04-17 04:35:09 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This component implements the nsIDownloadManagerUI interface and opens the
|
2013-11-04 10:21:13 -08:00
|
|
|
* Downloads view for the most recent browser window when requested.
|
2012-04-17 04:35:09 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Globals
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
|
|
|
|
"resource:///modules/DownloadsCommon.jsm");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gBrowserGlue",
|
|
|
|
"@mozilla.org/browser/browserglue;1",
|
|
|
|
"nsIBrowserGlue");
|
2012-12-20 06:54:49 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
|
2013-03-18 08:46:17 -07:00
|
|
|
"resource:///modules/RecentWindow.jsm");
|
2012-12-31 09:17:36 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
2012-04-17 04:35:09 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// DownloadsUI
|
|
|
|
|
|
|
|
function DownloadsUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DownloadsUI.prototype = {
|
|
|
|
classID: Components.ID("{4d99321e-d156-455b-81f7-e7aa2308134f}"),
|
|
|
|
|
|
|
|
_xpcom_factory: XPCOMUtils.generateSingletonFactory(DownloadsUI),
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsISupports
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDownloadManagerUI]),
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIDownloadManagerUI
|
|
|
|
|
2013-01-21 08:11:45 -08:00
|
|
|
show: function DUI_show(aWindowContext, aDownload, aReason, aUsePrivateUI)
|
2012-04-17 04:35:09 -07:00
|
|
|
{
|
|
|
|
if (!aReason) {
|
|
|
|
aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aReason == Ci.nsIDownloadManagerUI.REASON_NEW_DOWNLOAD) {
|
2012-10-10 13:12:56 -07:00
|
|
|
const kMinimized = Ci.nsIDOMChromeWindow.STATE_MINIMIZED;
|
2012-08-25 02:37:55 -07:00
|
|
|
let browserWin = gBrowserGlue.getMostRecentBrowserWindow();
|
2012-10-10 13:12:56 -07:00
|
|
|
|
|
|
|
if (!browserWin || browserWin.windowState == kMinimized) {
|
2013-01-21 08:11:45 -08:00
|
|
|
this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
|
2012-10-10 13:12:56 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If the indicator is visible, then new download notifications are
|
|
|
|
// already handled by the panel service.
|
|
|
|
browserWin.DownloadsButton.checkIsVisible(function(isVisible) {
|
|
|
|
if (!isVisible) {
|
2013-01-21 08:11:45 -08:00
|
|
|
this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
|
2012-10-10 13:12:56 -07:00
|
|
|
}
|
|
|
|
}.bind(this));
|
2012-04-27 06:05:04 -07:00
|
|
|
}
|
2012-10-10 13:12:56 -07:00
|
|
|
} else {
|
2013-01-21 08:11:45 -08:00
|
|
|
this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
|
2012-04-17 04:35:09 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-04 10:21:13 -08:00
|
|
|
get visible() true,
|
2012-04-17 04:35:09 -07:00
|
|
|
|
2013-11-04 10:21:13 -08:00
|
|
|
getAttention: function () {},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Private
|
2012-12-20 06:54:49 -08:00
|
|
|
|
|
|
|
/**
|
2012-12-27 15:54:48 -08:00
|
|
|
* Helper function that opens the download manager UI.
|
2012-12-20 06:54:49 -08:00
|
|
|
*/
|
2013-11-04 10:21:13 -08:00
|
|
|
_showDownloadManagerUI: function (aWindowContext, aUsePrivateUI)
|
2012-12-20 06:54:49 -08:00
|
|
|
{
|
2012-12-31 09:17:36 -08:00
|
|
|
// If we weren't given a window context, try to find a browser window
|
|
|
|
// to use as our parent - and if that doesn't work, error out and give up.
|
|
|
|
let parentWindow = aWindowContext;
|
|
|
|
if (!parentWindow) {
|
2012-12-29 17:01:34 -08:00
|
|
|
parentWindow = RecentWindow.getMostRecentBrowserWindow({ private: !!aUsePrivateUI });
|
2012-12-20 06:54:49 -08:00
|
|
|
if (!parentWindow) {
|
2012-12-31 09:17:36 -08:00
|
|
|
Components.utils.reportError(
|
|
|
|
"Couldn't find a browser window to open the Places Downloads View " +
|
|
|
|
"from.");
|
|
|
|
return;
|
2012-12-20 06:54:49 -08:00
|
|
|
}
|
|
|
|
}
|
2012-12-31 09:17:36 -08:00
|
|
|
|
|
|
|
// If window is private then show it in a tab.
|
|
|
|
if (PrivateBrowsingUtils.isWindowPrivate(parentWindow)) {
|
2012-12-31 09:19:36 -08:00
|
|
|
parentWindow.openUILinkIn("about:downloads", "tab");
|
2012-12-31 09:17:36 -08:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
let organizer = Services.wm.getMostRecentWindow("Places:Organizer");
|
|
|
|
if (!organizer) {
|
|
|
|
parentWindow.openDialog("chrome://browser/content/places/places.xul",
|
|
|
|
"", "chrome,toolbar=yes,dialog=no,resizable",
|
|
|
|
"Downloads");
|
|
|
|
} else {
|
|
|
|
organizer.PlacesOrganizer.selectLeftPaneQuery("Downloads");
|
|
|
|
organizer.focus();
|
|
|
|
}
|
2012-12-20 06:54:49 -08:00
|
|
|
}
|
2012-04-17 04:35:09 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Module
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DownloadsUI]);
|