Bug 1243445 - Pasting an invalid URL breaks the Downloads View in the Library. r=mak
MozReview-Commit-ID: DCPhxiB1i0Y
--- a/browser/components/downloads/content/allDownloadsViewOverlay.js
+++ b/browser/components/downloads/content/allDownloadsViewOverlay.js
@@ -1231,16 +1231,21 @@ DownloadsPlacesView.prototype = {
let [url, name] = this._getURLFromClipboardData();
let browserWin = RecentWindow.getMostRecentBrowserWindow();
let initiatingDoc = browserWin ? browserWin.document : document;
DownloadURL(url, name, initiatingDoc);
},
// nsIController
doCommand(aCommand) {
+ // Commands may be invoked with keyboard shortcuts even if disabled.
+ if (!this.isCommandEnabled(aCommand)) {
+ return;
+ }
+
// If this command is not selection-specific, execute it.
if (aCommand in this) {
this[aCommand]();
return;
}
// Cloning the nodelist into an array to get a frozen list of selected items.
// Otherwise, the selectedItems nodelist is live and doCommand may alter the
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -831,17 +831,19 @@ function DownloadURL(aURL, aFileName, aI
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();
+
+ // Ignore errors because failures are reported through the download list.
+ download.start().catch(() => {});
// 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);
}
// We have no DOM, and can only save the URL as is.
--- a/toolkit/mozapps/downloads/DownloadUtils.jsm
+++ b/toolkit/mozapps/downloads/DownloadUtils.jsm
@@ -404,17 +404,22 @@ this.DownloadUtils = {
let ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
let eTLDService = Cc["@mozilla.org/network/effective-tld-service;1"].
getService(Ci.nsIEffectiveTLDService);
let idnService = Cc["@mozilla.org/network/idn-service;1"].
getService(Ci.nsIIDNService);
// Get a URI that knows about its components
- let uri = ioService.newURI(aURIString, null, null);
+ let uri;
+ try {
+ uri = ioService.newURI(aURIString, null, null);
+ } catch (ex) {
+ return ["", ""];
+ }
// Get the inner-most uri for schemes like jar:
if (uri instanceof Ci.nsINestedURI)
uri = uri.innermostURI;
let fullHost;
try {
// Get the full host name; some special URIs fail (data: jar:)
--- a/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
+++ b/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
@@ -210,11 +210,12 @@ function run_test()
testURI("jar:http://www.mozilla.com/file!/magic", "mozilla.com", "www.mozilla.com");
testURI("file:///C:/Cool/Stuff/", "local file", "local file");
// Don't test for moz-icon if we don't have a protocol handler for it (e.g. b2g):
if ("@mozilla.org/network/protocol;1?name=moz-icon" in Components.classes) {
testURI("moz-icon:file:///test.extension", "local file", "local file");
testURI("moz-icon://.extension", "moz-icon resource", "moz-icon resource");
}
testURI("about:config", "about resource", "about resource");
+ testURI("invalid.uri", "", "");
testAllGetReadableDates();
}