Bug 833015 Update Suite Download Manager UI for Private Browsing changes r=IanN f=Ratty

This commit is contained in:
Neil Rashbrook 2013-01-26 23:58:12 +00:00
Родитель ecf003737e
Коммит 8646c8e60c
8 изменённых файлов: 156 добавлений и 169 удалений

Просмотреть файл

@ -129,37 +129,22 @@ function sortDownloads(aEventTarget)
}
}
function pauseDownload(aDownloadID)
function retryDownload(aDownload)
{
gDownloadManager.pauseDownload(aDownloadID);
}
function resumeDownload(aDownloadID)
{
gDownloadManager.resumeDownload(aDownloadID);
}
function retryDownload(aDownloadID)
{
gDownloadManager.retryDownload(aDownloadID);
aDownload.retry();
if (gDownloadTreeView)
gDownloadTreeView.removeDownload(aDownloadID);
gDownloadTreeView.removeDownload(aDownload.guid);
}
function cancelDownload(aDownload)
{
gDownloadManager.cancelDownload(aDownload.id);
aDownload.cancel();
// delete the file if it exists
var file = aDownload.targetFile;
if (file.exists())
file.remove(false);
}
function removeDownload(aDownloadID)
{
gDownloadManager.removeDownload(aDownloadID);
}
function openDownload(aDownload)
{
var name = aDownload.displayName;
@ -240,11 +225,11 @@ function showDownload(aDownload)
}
}
function showProperties(aDownloadID)
function showProperties(aDownload)
{
var dmui = Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.nsISuiteDownloadManagerUI);
dmui.showProgress(window, aDownloadID);
dmui.showProgress(window, aDownload);
}
function onTreeSelect(aEvent)
@ -456,7 +441,7 @@ var dlTreeController = {
case "cmd_play":
if (!selectionCount)
return false;
for each (let dldata in selItemData) {
for (let dldata of selItemData) {
if (dldata.state != nsIDownloadManager.DOWNLOAD_CANCELED &&
dldata.state != nsIDownloadManager.DOWNLOAD_FAILED &&
(!dldata.resumable ||
@ -468,7 +453,7 @@ var dlTreeController = {
case "cmd_pause":
if (!selectionCount)
return false;
for each (let dldata in selItemData) {
for (let dldata of selItemData) {
if (!dldata.isActive ||
dldata.state == nsIDownloadManager.DOWNLOAD_PAUSED ||
!dldata.resumable)
@ -478,7 +463,7 @@ var dlTreeController = {
case "cmd_resume":
if (!selectionCount)
return false;
for each (let dldata in selItemData) {
for (let dldata of selItemData) {
if (dldata.state != nsIDownloadManager.DOWNLOAD_PAUSED ||
!dldata.resumable)
return false;
@ -494,7 +479,7 @@ var dlTreeController = {
case "cmd_cancel":
if (!selectionCount)
return false;
for each (let dldata in selItemData) {
for (let dldata of selItemData) {
if (!dldata.isActive)
return false;
}
@ -502,7 +487,7 @@ var dlTreeController = {
case "cmd_retry":
if (!selectionCount)
return false;
for each (let dldata in selItemData) {
for (let dldata of selItemData) {
if (dldata.state != nsIDownloadManager.DOWNLOAD_CANCELED &&
dldata.state != nsIDownloadManager.DOWNLOAD_FAILED)
return false;
@ -511,7 +496,7 @@ var dlTreeController = {
case "cmd_remove":
if (!selectionCount)
return false;
for each (let dldata in selItemData) {
for (let dldata of selItemData) {
if (dldata.isActive)
return false;
}
@ -554,59 +539,54 @@ var dlTreeController = {
switch (aCommand) {
case "cmd_play":
for each (let dldata in selItemData) {
for (let dldata of selItemData) {
switch (dldata.state) {
case nsIDownloadManager.DOWNLOAD_DOWNLOADING:
pauseDownload(dldata.dlid);
dldata.dld.pause();
break;
case nsIDownloadManager.DOWNLOAD_PAUSED:
resumeDownload(dldata.dlid);
dldata.dld.resume();
break;
case nsIDownloadManager.DOWNLOAD_FAILED:
case nsIDownloadManager.DOWNLOAD_CANCELED:
retryDownload(dldata.dlid);
retryDownload(dldata.dld);
break;
}
}
break;
case "cmd_pause":
for each (let dldata in selItemData)
pauseDownload(dldata.dlid);
for (let dldata of selItemData)
dldata.dld.pause();
break;
case "cmd_resume":
for each (let dldata in selItemData)
resumeDownload(dldata.dlid);
for (let dldata of selItemData)
dldata.dld.resume();
break;
case "cmd_retry":
for each (let dldata in selItemData)
retryDownload(dldata.dlid);
for (let dldata of selItemData)
retryDownload(dldata.dld);
break;
case "cmd_cancel":
for each (let dldata in selItemData)
// fake an nsIDownload with the properties needed by that function
cancelDownload({id: dldata.dlid,
targetFile: GetFileFromString(dldata.file)});
for (let dldata of selItemData)
cancelDownload(dldata.dld);
break;
case "cmd_remove":
for each (let dldata in selItemData)
removeDownload(dldata.dlid);
for (let dldata of selItemData)
dldata.dld.remove();
break;
case "cmd_stop":
for each (let dldata in selItemData) {
for (let dldata of selItemData) {
if (dldata.isActive)
// fake an nsIDownload with the properties needed by that function
cancelDownload({id: dldata.dlid,
targetFile: GetFileFromString(dldata.file)});
cancelDownload(dldata.dld);
else
removeDownload(dldata.dlid);
dldata.dld.remove();
}
break;
case "cmd_open":
openDownload(gDownloadManager.getDownload(selItemData[0].dlid));
openDownload(selItemData[0].dld);
break;
case "cmd_show":
// fake an nsIDownload with the properties needed by that function
showDownload({targetFile: GetFileFromString(selItemData[0].file)});
showDownload(selItemData[0].dld);
break;
case "cmd_openReferrer":
openUILink(selItemData[0].referrer);
@ -615,12 +595,12 @@ var dlTreeController = {
var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper);
var uris = [];
for each (let dldata in selItemData)
for (let dldata of selItemData)
uris.push(dldata.uri);
clipboard.copyString(uris.join("\n"), document);
break;
case "cmd_properties":
showProperties(selItemData[0].dlid);
showProperties(selItemData[0].dld);
break;
case "cmd_selectAll":
gDownloadTreeView.selection.selectAll();
@ -637,7 +617,7 @@ var dlTreeController = {
for (let idx = gDownloadTreeView.rowCount - 1; idx >= 0; idx--) {
let dldata = gDownloadTreeView.getRowData(idx);
if (!dldata.isActive) {
removeDownload(dldata.dlid);
dldata.dld.remove();
}
}

Просмотреть файл

@ -32,7 +32,7 @@ function progressStartup() {
if (recentDMWindow && recentDMWindow.gDownloadTreeView.rowCount > 0) {
// we have been opened by a download manager, get the end time from there
let dmtree = recentDMWindow.gDownloadTreeView;
let dldata = dmtree.getRowData(dmtree._getIdxForID(gDownload.id));
let dldata = dmtree.getRowData(dmtree._getIdxForGUID(gDownload.guid));
gEndTime = dldata.endTime;
}
@ -336,14 +336,14 @@ var ProgressDlgController = {
doCommand: function(aCommand) {
switch (aCommand) {
case "cmd_pause":
pauseDownload(gDownload.id);
gDownload.pause();
break;
case "cmd_resume":
resumeDownload(gDownload.id);
gDownload.resume();
break;
case "cmd_retry":
gRetrying = true;
retryDownload(gDownload.id);
retryDownload(gDownload);
break;
case "cmd_cancel":
cancelDownload(gDownload);

Просмотреть файл

@ -5,19 +5,19 @@
function test_visibility_open()
{
var dmui = Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.nsIDownloadManagerUI);
is(dmui.visible, true,
.getService(Components.interfaces.nsISuiteDownloadManagerUI);
isnot(dmui.recentWindow, null,
"nsIDownloadManagerUI indicates that the UI is visible");
}
function test_visibility_closed(aWin)
{
var dmui = Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.nsIDownloadManagerUI);
.getService(Components.interfaces.nsISuiteDownloadManagerUI);
function dmWindowClosedListener() {
aWin.removeEventListener("unload", dmWindowClosedListener, false);
is(dmui.visible, false,
is(dmui.recentWindow, null,
"nsIDownloadManagerUI indicates that the UI is not visible");
finish();
}

Просмотреть файл

@ -11,11 +11,13 @@ const nsITreeView = Components.interfaces.nsITreeView;
function DownloadTreeView(aDownloadManager) {
this._dm = aDownloadManager;
this._dlList = [];
this._dlMap = {};
this._searchTerms = [];
}
DownloadTreeView.prototype = {
QueryInterface: XPCOMUtils.generateQI([nsITreeView]),
QueryInterface: XPCOMUtils.generateQI([nsITreeView,
Components.interfaces.nsIDownloadManagerResult]),
// ***** nsITreeView attributes and methods *****
get rowCount() {
@ -135,7 +137,7 @@ DownloadTreeView.prototype = {
return dl.progress;
case "TimeRemaining":
if (dl.isActive) {
var dld = this._dm.getDownload(dl.dlid);
var dld = dl.dld;
var lastSec = (dl.lastSec == null) ? Infinity : dl.lastSec;
// Calculate the time remaining if we have valid values
var seconds = (dld.speed > 0) && (dl.maxBytes > 0)
@ -151,7 +153,7 @@ DownloadTreeView.prototype = {
case "TransferRate":
switch (dl.state) {
case nsIDownloadManager.DOWNLOAD_DOWNLOADING:
var speed = this._dm.getDownload(dl.dlid).speed;
var speed = dl.dld.speed;
this._dlList[aRow]._speed = speed; // used for sorting
var [rate, unit] = DownloadUtils.convertByteUnits(speed);
return this._dlbundle.getFormattedString("speedFormat", [rate, unit]);
@ -202,24 +204,22 @@ DownloadTreeView.prototype = {
case "ActionPlay":
switch (dl.state) {
case nsIDownloadManager.DOWNLOAD_DOWNLOADING:
pauseDownload(dl.dlid);
dl.dld.pause();
break;
case nsIDownloadManager.DOWNLOAD_PAUSED:
resumeDownload(dl.dlid);
dl.dld.resume();
break;
case nsIDownloadManager.DOWNLOAD_FAILED:
case nsIDownloadManager.DOWNLOAD_CANCELED:
retryDownload(dl.dlid);
retryDownload(dl.dld);
break;
}
break;
case "ActionStop":
if (dl.isActive)
// fake an nsIDownload with the properties needed by that function
cancelDownload({id: dl.dlid,
targetFile: GetFileFromString(dl.file)});
cancelDownload(dl.dld);
else
removeDownload(dl.dlid);
dl.dld.remove();
break;
}
},
@ -235,7 +235,7 @@ DownloadTreeView.prototype = {
addDownload: function(aDownload) {
var attrs = {
dlid: aDownload.id,
guid: aDownload.guid,
file: aDownload.target.spec,
target: aDownload.displayName,
uri: aDownload.source.spec,
@ -249,6 +249,7 @@ DownloadTreeView.prototype = {
currBytes: aDownload.amountTransferred,
maxBytes: aDownload.size,
lastSec: Infinity, // For calculations of remaining time
dld: aDownload
};
switch (attrs.state) {
case nsIDownloadManager.DOWNLOAD_DOWNLOADING:
@ -276,6 +277,7 @@ DownloadTreeView.prototype = {
// Prepend data to the download list
this._dlList.unshift(attrs);
this._dlMap[attrs.guid] = attrs;
// Tell the tree we added 1 row at index 0
this._tree.rowCountChanged(0, 1);
@ -287,7 +289,7 @@ DownloadTreeView.prototype = {
},
updateDownload: function(aDownload) {
var row = this._getIdxForID(aDownload.id);
var row = this._getIdxForGUID(aDownload.guid);
if (row == -1) {
// No download row found to update, but as it's obviously going on,
// add it to the list now (can happen with very fast, e.g. local dls)
@ -337,8 +339,8 @@ DownloadTreeView.prototype = {
window.updateCommands("tree-select");
},
removeDownload: function(aDownloadID) {
var row = this._getIdxForID(aDownloadID);
removeDownload: function(aGUID) {
var row = this._getIdxForGUID(aGUID);
// Make sure we have an item to remove
if (row < 0) return;
@ -347,6 +349,7 @@ DownloadTreeView.prototype = {
// Remove data from the download list
this._dlList.splice(row, 1);
delete this._dlMap[aGUID];
// Tell the tree we removed 1 row at the given row index
this._tree.rowCountChanged(row, -1);
@ -368,6 +371,7 @@ DownloadTreeView.prototype = {
// or because we need to recreate it
this._tree.beginUpdateBatch();
this._dlList = [];
this._dlMap = {};
this._lastListIndex = 0;
this.selection.clearSelection();
@ -375,8 +379,8 @@ DownloadTreeView.prototype = {
// sort in reverse and prepend to the list to get continuous list indexes
// with increasing negative numbers for default-sort in ascending order
var statement = this._dm.DBConnection.createStatement(
"SELECT id, target, name, source, state, startTime, endTime, referrer, " +
"currBytes, maxBytes, state IN (?1, ?2, ?3, ?4, ?5) AS isActive " +
"SELECT guid, target, name, source, state, startTime, endTime, referrer" +
", currBytes, maxBytes, state IN (?1, ?2, ?3, ?4, ?5) AS isActive " +
"FROM moz_downloads " +
"ORDER BY isActive ASC, endTime ASC, startTime ASC, id DESC");
@ -389,37 +393,25 @@ DownloadTreeView.prototype = {
while (statement.executeStep()) {
// Try to get the attribute values from the statement
let attrs = {
dlid: statement.getInt64(0),
guid: statement.getString(0),
file: statement.getString(1),
target: statement.getString(2),
uri: statement.getString(3),
state: statement.getInt32(4),
progress: 100,
progressMode: nsITreeView.PROGRESS_NONE,
resumable: false,
startTime: Math.round(statement.getInt64(5) / 1000),
endTime: Math.round(statement.getInt64(6) / 1000),
referrer: statement.getString(7),
currBytes: statement.getInt64(8),
maxBytes: statement.getInt64(9),
isActive: statement.getInt32(10),
lastSec: Infinity, // For calculations of remaining time
dld: null
};
// If the download is active, grab the real progress, otherwise default 100
attrs.isActive = statement.getInt32(10);
if (attrs.isActive) {
let dld = this._dm.getDownload(attrs.dlid);
attrs.progress = dld.percentComplete;
attrs.progressMode = attrs.progress == -1 ?
nsITreeView.PROGRESS_UNDETERMINED :
nsITreeView.PROGRESS_NORMAL;
attrs.resumable = dld.resumable;
}
else {
attrs.progress = 100;
attrs.progressMode = nsITreeView.PROGRESS_NONE;
attrs.resumable = false;
}
// Only actually add item to the tree if it's active or matching search
let matchSearch = true;
if (this._searchTerms) {
// Search through the download attributes that are shown to the user and
@ -430,7 +422,7 @@ DownloadTreeView.prototype = {
combinedSearch = combinedSearch + " " + attrs.target.toLowerCase();
if (!attrs.isActive)
for each (let term in this._searchTerms)
for (let term of this._searchTerms)
if (combinedSearch.indexOf(term) == -1)
matchSearch = false;
}
@ -439,9 +431,25 @@ DownloadTreeView.prototype = {
if (matchSearch) {
attrs.listIndex = this._lastListIndex--;
this._dlList.unshift(attrs);
this._dlMap[attrs.guid] = attrs;
}
}
statement.finalize();
// now read active downloads
var downloads = this._dm.activeDownloads;
while (downloads.hasMoreElements()) {
let dld = downloads.getNext()
.QueryInterface(Components.interfaces.nsIDownload);
if (dld.guid in this._dlMap) {
var dl = this._dlMap[dld.guid];
dl.progress = dld.percentComplete;
dl.progressMode = dl.progress == -1 ?
nsITreeView.PROGRESS_UNDETERMINED :
nsITreeView.PROGRESS_NORMAL;
dl.resumable = dld.resumable;
dl.dld = dld;
}
}
// find sorted column and sort the tree
var sortedColumn = this._tree.columns.getSortedColumn();
if (sortedColumn) {
@ -452,11 +460,21 @@ DownloadTreeView.prototype = {
window.updateCommands("tree-select");
// ask for nsIDownload objects for finished downloads
for (let dl of this._dlList)
if (!dl.dld)
this._dm.getDownloadByGUID(dl.guid, this);
// Send a notification that we finished
setTimeout(function()
Services.obs.notifyObservers(window, "download-manager-ui-done", null), 0);
},
handleResult: function(aStatus, aDownload) {
if (aDownload)
this._dlMap[aDownload.guid].dld = aDownload;
},
searchView: function(aInput) {
// Stringify the previous search
var prevSearch = this._searchTerms.join(" ");
@ -609,12 +627,9 @@ DownloadTreeView.prototype = {
},
// Get array index in _dlList for a given download ID
_getIdxForID: function(aDlID) {
var len = this._dlList.length;
for (let idx = 0; idx < len; idx++) {
if (this._dlList[idx].dlid == aDlID)
return idx;
}
_getIdxForGUID: function(aGUID) {
if (aGUID in this._dlMap)
return this._dlList.indexOf(this._dlMap[aGUID]);
return -1;
},
@ -635,7 +650,7 @@ DownloadTreeView.prototype = {
for (let rg = 0; rg < numRanges; rg++){
this.selection.getRangeAt(rg, start, end);
for (let row = start.value; row <= end.value; row++){
this._selectionCache.push(this._dlList[row].dlid);
this._selectionCache.push(this._dlList[row].guid);
}
}
},
@ -647,9 +662,9 @@ DownloadTreeView.prototype = {
return;
this.selection.clearSelection();
for each (let dlid in this._selectionCache) {
for (let guid of this._selectionCache) {
// Find out what row this is now and if possible, add it to the selection
var row = this._getIdxForID(dlid);
var row = this._getIdxForGUID(guid);
if (row != -1)
this.selection.rangedSelect(row, row, true);
}

Просмотреть файл

@ -16,12 +16,12 @@
script="chrome://communicator/content/pref/pref-download.js">
<preferences>
<preference id="browser.download.manager.focusWhenStarting"
name="browser.download.manager.focusWhenStarting"
type="bool" inverted="true"/>
<preference id="browser.download.manager.behavior"
name="browser.download.manager.behavior"
type="int"/>
<preference id="browser.download.manager.focusWhenStarting"
name="browser.download.manager.focusWhenStarting"
type="bool" inverted="true"/>
<preference id="browser.download.useDownloadDir"
name="browser.download.useDownloadDir"
type="bool"/>
@ -49,23 +49,23 @@
<groupbox>
<caption label="&downloadBehavior.label;"/>
<checkbox id="focusWhenStarting"
label="&focusWhenStarting.label;"
preference="browser.download.manager.focusWhenStarting"
accesskey="&focusWhenStarting.accesskey;"/>
<radiogroup id="downloadBehavior"
class="indent"
preference="browser.download.manager.behavior">
<radio value="0"
label="&openDM.label;"
accesskey="&openDM.accesskey;"/>
<radio value="1"
label="&openProgressDialog.label;"
accesskey="&openProgressDialog.accesskey;"/>
<radio value="2"
label="&doNothing.label;"
accesskey="&doNothing.accesskey;"/>
<radio value="1"
label="&openProgressDialog.label;"
accesskey="&openProgressDialog.accesskey;"/>
<radio value="0"
label="&openDM.label;"
accesskey="&openDM.accesskey;"/>
</radiogroup>
<checkbox id="focusWhenStarting"
class="indent"
preference="browser.download.manager.focusWhenStarting"
label="&flashWhenOpen.label;"
accesskey="&flashWhenOpen.accesskey;"/>
</groupbox>
<groupbox>

Просмотреть файл

@ -4,14 +4,16 @@
#include "nsISupports.idl"
#include "nsIDownloadManagerUI.idl"
interface nsIDOMWindow;
[scriptable, uuid(b2180611-e56e-4831-9770-15a53aacb36a)]
[scriptable, uuid(23e0112d-2924-4e74-8886-157b60c4af24)]
interface nsISuiteDownloadManagerUI : nsIDownloadManagerUI
{
readonly attribute nsIDOMWindow recentWindow;
void showManager([optional] in nsIInterfaceRequestor aWindowContext,
[optional] in unsigned long aID,
[optional] in short aReason);
[optional] in nsIDownload aDownload,
[optional] in short aReason);
void showProgress([optional] in nsIInterfaceRequestor aWindowContext,
[optional] in unsigned long aID,
[optional] in short aReason);
[optional] in nsIDownload aDownload,
[optional] in short aReason);
};

Просмотреть файл

@ -12,6 +12,7 @@ const Ci = Components.interfaces;
const Cr = Components.results;
const TOOLKIT_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul";
const DOWNLOAD_MANAGER_URL = "chrome://communicator/content/downloads/downloadmanager.xul";
const PREF_FOCUS_WHEN_STARTING = "browser.download.manager.focusWhenStarting";
const PREF_FLASH_COUNT = "browser.download.manager.flashCount";
const PREF_DM_BEHAVIOR = "browser.download.manager.behavior";
const PREF_FORCE_TOOLKIT_UI = "browser.download.manager.useToolkitUI";
@ -27,11 +28,13 @@ nsDownloadManagerUI.prototype = {
//////////////////////////////////////////////////////////////////////////////
//// nsIDownloadManagerUI
show: function show(aWindowContext, aID, aReason)
show: function show(aWindowContext, aDownload, aReason, aUsePrivateUI)
{
var behavior = 0;
if (aReason != Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED) {
try {
if (aUsePrivateUI)
behavior = 1;
else try {
var prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
behavior = prefs.getIntPref(PREF_DM_BEHAVIOR);
@ -42,22 +45,21 @@ nsDownloadManagerUI.prototype = {
switch (behavior) {
case 0:
this.showManager(aWindowContext, aID, aReason);
this.showManager(aWindowContext, aDownload, aReason);
break;
case 1:
this.showProgress(aWindowContext, aID, aReason);
this.showProgress(aWindowContext, aDownload, aReason);
}
return; // No UI for behavior >= 2
},
get visible() {
return this.recentWindow != null;
},
visible: false, // needed for private downloads to work
getAttention: function getAttention()
{
if (!this.visible)
var window = this.recentWindow;
if (!window)
throw Cr.NS_ERROR_UNEXPECTED;
var prefs = Cc["@mozilla.org/preferences-service;1"].
@ -68,11 +70,11 @@ nsDownloadManagerUI.prototype = {
flashCount = prefs.getIntPref(PREF_FLASH_COUNT);
} catch (e) { }
this.recentWindow.getAttentionWithCycleCount(flashCount);
window.getAttentionWithCycleCount(flashCount);
},
//////////////////////////////////////////////////////////////////////////////
//// nsDownloadManagerUI
//// nsISuiteDownloadManagerUI
get recentWindow() {
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
@ -80,19 +82,18 @@ nsDownloadManagerUI.prototype = {
return wm.getMostRecentWindow("Download:Manager");
},
//////////////////////////////////////////////////////////////////////////////
//// nsISuiteDownloadManagerUI
showManager: function showManager(aWindowContext, aID, aReason)
showManager: function showManager(aWindowContext, aDownload, aReason)
{
// First we see if it is already visible
let window = this.recentWindow;
if (window) {
window.focus();
// If we are being asked to show again, with a user interaction reason,
// set the appropriate variable.
if (aReason == Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED)
window.gUserInteracted = true;
var prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
var focus = prefs.getBoolPref(PREF_FOCUS_WHEN_STARTING);
if (focus || aReason == Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED)
window.focus();
else
this.getAttention();
return;
}
@ -108,15 +109,7 @@ nsDownloadManagerUI.prototype = {
// We pass the download manager and the nsIDownload we want selected (if any)
var params = Cc["@mozilla.org/array;1"].
createInstance(Ci.nsIMutableArray);
// Don't fail if our passed in ID is invalid
var download = null;
try {
let dm = Cc["@mozilla.org/download-manager;1"].
getService(Ci.nsIDownloadManager);
download = dm.getDownload(aID);
} catch (ex) {}
params.appendElement(download, false);
params.appendElement(aDownload, false);
// Pass in the reason as well
let reason = Cc["@mozilla.org/supports-PRInt16;1"].
@ -141,9 +134,11 @@ nsDownloadManagerUI.prototype = {
params);
},
showProgress: function showProgress(aWindowContext, aID, aReason)
showProgress: function showProgress(aWindowContext, aDownload, aReason)
{
var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
// Fail if our passed in download is invalid
if (!aDownload)
return;
var parent = null;
// We try to get a window to use as the parent here. If we don't have one,
@ -154,11 +149,8 @@ nsDownloadManagerUI.prototype = {
parent = aWindowContext.getInterface(Ci.nsIDOMWindow);
} catch (e) { /* it's OK to not have a parent window */ }
// Fail if our passed in ID is invalid
var download = Cc["@mozilla.org/download-manager;1"].
getService(Ci.nsIDownloadManager).
getDownload(aID);
params.appendElement(download, false);
var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
params.appendElement(aDownload, false);
// Pass in the reason as well
let reason = Cc["@mozilla.org/supports-PRInt16;1"].
@ -184,6 +176,4 @@ nsDownloadManagerUI.prototype = {
////////////////////////////////////////////////////////////////////////////////
//// Module
let components = [nsDownloadManagerUI];
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
var NSGetFactory = XPCOMUtils.generateNSGetFactory([nsDownloadManagerUI]);

Просмотреть файл

@ -5,14 +5,14 @@
<!ENTITY pref.download.title "Downloads">
<!ENTITY downloadBehavior.label "When starting a download">
<!ENTITY focusWhenStarting.label "Flash the download manager if it is already open, otherwise:">
<!ENTITY focusWhenStarting.accesskey "F">
<!ENTITY openDM.label "Open the download manager">
<!ENTITY openDM.accesskey "m">
<!ENTITY openProgressDialog.label "Open a progress dialog">
<!ENTITY openProgressDialog.accesskey "O">
<!ENTITY doNothing.label "Don't open anything">
<!ENTITY doNothing.accesskey "D">
<!ENTITY openProgressDialog.label "Open a progress dialog">
<!ENTITY openProgressDialog.accesskey "O">
<!ENTITY openDM.label "Open the download manager">
<!ENTITY openDM.accesskey "m">
<!ENTITY flashWhenOpen.label "Just flash the download manager if it is already open">
<!ENTITY flashWhenOpen.accesskey "f">
<!ENTITY downloadLocation.label "When saving a file">
<!ENTITY saveTo.label "Save files to">