Bug 1243445 - Pasting an invalid URL breaks the Downloads View in the Library. r=jaws a=ritu
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 22 Aug 2016 14:22:18 +0100
changeset 348053 d7b3e0350c056327bc3e33deb02f3756cc021c0d
parent 348052 e6b75b2a627bbdfb83893a6ee5ed1091896373e4
child 348054 3cad1bde8677e1ed9d33ab3e3589df816f6e829a
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, ritu
bugs1243445
milestone50.0a2
Bug 1243445 - Pasting an invalid URL breaks the Downloads View in the Library. r=jaws a=ritu MozReview-Commit-ID: DCPhxiB1i0Y
browser/components/downloads/content/allDownloadsViewOverlay.js
toolkit/content/contentAreaUtils.js
toolkit/mozapps/downloads/DownloadUtils.jsm
toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
--- a/browser/components/downloads/content/allDownloadsViewOverlay.js
+++ b/browser/components/downloads/content/allDownloadsViewOverlay.js
@@ -1230,16 +1230,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();
 }