From 021c377f983dcaa771a72f5b78c974bb9b48a315 Mon Sep 17 00:00:00 2001 From: Felipe Gomes Date: Mon, 1 Apr 2013 03:16:13 -0300 Subject: [PATCH] Bug 854299. Part 5. Make nsHelperAppDlg.promptForSaveToFileAsync actually async. r=bz --- toolkit/mozapps/downloads/nsHelperAppDlg.js | 61 ++++++++++----------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/toolkit/mozapps/downloads/nsHelperAppDlg.js b/toolkit/mozapps/downloads/nsHelperAppDlg.js index 66010f0f77b6..534de784e947 100644 --- a/toolkit/mozapps/downloads/nsHelperAppDlg.js +++ b/toolkit/mozapps/downloads/nsHelperAppDlg.js @@ -279,44 +279,39 @@ nsUnknownContentTypeDialog.prototype = { .getService(Components.interfaces.nsIDownloadManager); picker.displayDirectory = dnldMgr.userDownloadsDirectory; - // The last directory preference may not exist, which will throw. - try { - var lastDir = gDownloadLastDir.getFile(aLauncher.source); - if (isUsableDirectory(lastDir)) + gDownloadLastDir.getFileAsync(aLauncher.source, function LastDirCallback(lastDir) { + if (lastDir && isUsableDirectory(lastDir)) picker.displayDirectory = lastDir; - } - catch (ex) { - } - if (picker.show() == nsIFilePicker.returnCancel) { - // null result means user cancelled. - aLauncher.saveDestinationAvailable(null); - return; - } - - // Be sure to save the directory the user chose through the Save As... - // dialog as the new browser.download.dir since the old one - // didn't exist. - result = picker.file; - - if (result) { - try { - // Remove the file so that it's not there when we ensure non-existence later; - // this is safe because for the file to exist, the user would have had to - // confirm that he wanted the file overwritten. - if (result.exists()) - result.remove(false); + if (picker.show() == nsIFilePicker.returnCancel) { + // null result means user cancelled. + aLauncher.saveDestinationAvailable(null); + return; } - catch (e) { } - var newDir = result.parent.QueryInterface(Components.interfaces.nsILocalFile); - // Do not store the last save directory as a pref inside the private browsing mode - gDownloadLastDir.setFile(aLauncher.source, newDir); + // Be sure to save the directory the user chose through the Save As... + // dialog as the new browser.download.dir since the old one + // didn't exist. + result = picker.file; - result = this.validateLeafName(newDir, result.leafName, null); - } - aLauncher.saveDestinationAvailable(result); - return; + if (result) { + try { + // Remove the file so that it's not there when we ensure non-existence later; + // this is safe because for the file to exist, the user would have had to + // confirm that he wanted the file overwritten. + if (result.exists()) + result.remove(false); + } + catch (e) { } + var newDir = result.parent.QueryInterface(Components.interfaces.nsILocalFile); + + // Do not store the last save directory as a pref inside the private browsing mode + gDownloadLastDir.setFile(aLauncher.source, newDir); + + result = this.validateLeafName(newDir, result.leafName, null); + } + aLauncher.saveDestinationAvailable(result); + }.bind(this)); }, /**