Bug 945707 - Pausing a download fails when done after a retry. r=paolo

This commit is contained in:
Marco Bonardo 2014-01-29 17:00:17 -05:00
Родитель 34594fb0bf
Коммит 3a79e9b75a
3 изменённых файлов: 66 добавлений и 22 удалений

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

@ -40,22 +40,6 @@ const DOWNLOAD_VIEW_SUPPORTED_COMMANDS =
const NOT_AVAILABLE = Number.MAX_VALUE;
/**
* Download a URL.
*
* @param aURL
* the url to download (nsIURI object)
* @param [optional] aFileName
* the destination file name
*/
function DownloadURL(aURL, aFileName) {
// For private browsing, try to get document out of the most recent browser
// window, or provide our own if there's no browser window.
let browserWin = RecentWindow.getMostRecentBrowserWindow();
let initiatingDoc = browserWin ? browserWin.document : document;
saveURL(aURL, aFileName, null, true, true, undefined, initiatingDoc);
}
/**
* A download element shell is responsible for handling the commands and the
* displayed data for a single download view element. The download element
@ -645,7 +629,10 @@ DownloadElementShell.prototype = {
// In future we may try to download into the same original target uri, when
// we have it. Though that requires verifying the path is still valid and
// may surprise the user if he wants to be requested every time.
DownloadURL(this.downloadURI, this.getDownloadMetaData().fileName);
let browserWin = RecentWindow.getMostRecentBrowserWindow();
let initiatingDoc = browserWin ? browserWin.document : document;
DownloadURL(this.downloadURI, this.getDownloadMetaData().fileName,
initiatingDoc);
},
/* nsIController */
@ -1433,7 +1420,9 @@ DownloadsPlacesView.prototype = {
_downloadURLFromClipboard: function DPV__downloadURLFromClipboard() {
let [url, name] = this._getURLFromClipboardData();
DownloadURL(url, name);
let browserWin = RecentWindow.getMostRecentBrowserWindow();
let initiatingDoc = browserWin ? browserWin.document : document;
DownloadURL(url, name, initiatingDoc);
},
doCommand: function DPV_doCommand(aCommand) {
@ -1487,6 +1476,11 @@ DownloadsPlacesView.prototype = {
else
contextMenu.removeAttribute("state");
if (state == nsIDM.DOWNLOAD_DOWNLOADING) {
// The resumable property of a download may change at any time, so
// ensure we update the related command now.
goUpdateCommand("downloadsCmd_pauseResume");
}
return true;
},
@ -1579,8 +1573,11 @@ DownloadsPlacesView.prototype = {
let name = { };
let url = Services.droppedLinkHandler.dropLink(aEvent, name);
if (url)
DownloadURL(url, name.value);
if (url) {
let browserWin = RecentWindow.getMostRecentBrowserWindow();
let initiatingDoc = browserWin ? browserWin.document : document;
DownloadURL(url, name.value, initiatingDoc);
}
}
};

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

@ -505,8 +505,7 @@ const DownloadsPanel = {
let uri = NetUtil.newURI(url);
DownloadsCommon.log("Pasted URL seems valid. Starting download.");
saveURL(uri.spec, name || uri.spec, null, true, true,
undefined, document);
DownloadURL(uri.spec, name, document);
} catch (ex) {}
},

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

@ -679,6 +679,54 @@ function uniqueFile(aLocalFile)
return aLocalFile;
}
#ifdef MOZ_JSDOWNLOADS
/**
* Download a URL using the new jsdownloads API.
*
* @param aURL
* the url to download
* @param [optional] aFileName
* the destination file name, if omitted will be obtained from the url.
* @param aInitiatingDocument
* The document from which the download was initiated.
*/
function DownloadURL(aURL, aFileName, aInitiatingDocument) {
// For private browsing, try to get document out of the most recent browser
// window, or provide our own if there's no browser window.
let isPrivate = aInitiatingDocument.defaultView
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsILoadContext)
.usePrivateBrowsing;
let fileInfo = new FileInfo(aFileName);
initFileInfo(fileInfo, aURL, null, null, null, null);
let filepickerParams = {
fileInfo: fileInfo,
saveMode: SAVEMODE_FILEONLY
};
Task.spawn(function* () {
let accepted = yield promiseTargetFile(filepickerParams, true, fileInfo.uri);
if (!accepted)
return;
let file = filepickerParams.file;
let download = yield Downloads.createDownload({
source: { url: aURL, isPrivate: isPrivate },
target: { path: file.path, partFilePath: file.path + ".part" }
});
download.tryToKeepPartialData = true;
download.start();
// Add the download to the list, allowing it to be managed.
let list = yield Downloads.getList(Downloads.ALL);
list.add(download);
}).then(null, Components.utils.reportError);
}
#endif
// We have no DOM, and can only save the URL as is.
const SAVEMODE_FILEONLY = 0x00;
// We have a DOM and can save as complete.