Bug 1275289 - Add try catch to DownloadLegacy.js since aRequest.responseStatus does not exist in the case of a failed download;r?paolo draft
authorJimmy Wang <jimmyw22@gmail.com>
Tue, 24 May 2016 14:37:42 -0400
changeset 403726 066b7df14d37e1197e8481bf574aefb2747e9dc9
parent 403581 f97a056ae6235de7855fd8aaa04fb1c8d183bd06
child 403727 28b1510923caed796b46510d04848742e26d29fe
push id26991
push userjimmyw22@gmail.com
push dateMon, 22 Aug 2016 01:16:40 +0000
reviewerspaolo
bugs1275289
milestone51.0a1
Bug 1275289 - Add try catch to DownloadLegacy.js since aRequest.responseStatus does not exist in the case of a failed download;r?paolo MozReview-Commit-ID: HbN86Ef3Okv
toolkit/components/jsdownloads/src/DownloadLegacy.js
--- a/toolkit/components/jsdownloads/src/DownloadLegacy.js
+++ b/toolkit/components/jsdownloads/src/DownloadLegacy.js
@@ -85,20 +85,30 @@ DownloadLegacyTransfer.prototype = {
   {
     if (!Components.isSuccessCode(aStatus)) {
       this._componentFailed = true;
     }
 
     if ((aStateFlags & Ci.nsIWebProgressListener.STATE_START) &&
         (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK)) {
 
-      // If the request's response has been blocked by Windows Parental Controls
-      // with an HTTP 450 error code, we must cancel the request synchronously.
-      let blockedByParentalControls = aRequest instanceof Ci.nsIHttpChannel &&
+      let blockedByParentalControls = false;
+      // If it is a failed download, aRequest.responseStatus doesn't exist.
+      // (missing file on the server, network failure to download)
+      try {
+        // If the request's response has been blocked by Windows Parental Controls
+        // with an HTTP 450 error code, we must cancel the request synchronously.
+        blockedByParentalControls = aRequest instanceof Ci.nsIHttpChannel &&
                                       aRequest.responseStatus == 450;
+      } catch (e) {
+        if (e.result == Cr.NS_ERROR_NOT_AVAILABLE) {
+          aRequest.cancel(Cr.NS_BINDING_ABORTED);
+        }
+      }
+
       if (blockedByParentalControls) {
         aRequest.cancel(Cr.NS_BINDING_ABORTED);
       }
 
       // The main request has just started.  Wait for the associated Download
       // object to be available before notifying.
       this._deferDownload.promise.then(download => {
         // If the request was blocked, now that we have the download object we