Bug 1281186 - Remove uses of nsIDownloadManager from DownloadsCommon.jsm, DownloadsViewUI.jsm, and allDownloadsViewOverlay.js. r=mak
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Fri, 05 May 2017 11:20:53 +0100
changeset 357029 e9adf0e056f76898658532ead3ef84965e8d5de3
parent 357028 5fa6bc617e2f81c82fa58e0e64f6b2352a9adc0d
child 357030 d85d25fa905b78dc22436245f99b97667ec466c0
push id90017
push userpaolo.mozmail@amadzone.org
push dateMon, 08 May 2017 14:04:12 +0000
treeherdermozilla-inbound@e9adf0e056f7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1281186
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1281186 - Remove uses of nsIDownloadManager from DownloadsCommon.jsm, DownloadsViewUI.jsm, and allDownloadsViewOverlay.js. r=mak MozReview-Commit-ID: 28nc8aTea5v
browser/components/downloads/DownloadsCommon.jsm
browser/components/downloads/DownloadsViewUI.jsm
browser/components/downloads/content/allDownloadsViewOverlay.js
browser/components/downloads/test/browser/browser_basic_functionality.js
browser/components/downloads/test/browser/browser_downloads_panel_block.js
browser/components/downloads/test/browser/browser_downloads_panel_footer.js
browser/components/downloads/test/browser/browser_downloads_panel_height.js
browser/components/downloads/test/browser/head.js
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -66,18 +66,16 @@ XPCOMUtils.defineLazyGetter(this, "Downl
   let { ConsoleAPI } = Cu.import("resource://gre/modules/Console.jsm", {});
   let consoleOptions = {
     maxLogLevelPref: "browser.download.loglevel",
     prefix: "Downloads"
   };
   return new ConsoleAPI(consoleOptions);
 });
 
-const nsIDM = Ci.nsIDownloadManager;
-
 const kDownloadsStringBundleUrl =
   "chrome://browser/locale/downloads/downloads.properties";
 
 const kDownloadsStringsRequiringFormatting = {
   sizeWithUnits: true,
   shortTimeLeftSeconds: true,
   shortTimeLeftMinutes: true,
   shortTimeLeftHours: true,
@@ -134,16 +132,29 @@ PrefObserver.register({
 
 // DownloadsCommon
 
 /**
  * This object is exposed directly to the consumers of this JavaScript module,
  * and provides shared methods for all the instances of the user interface.
  */
 this.DownloadsCommon = {
+  // The following legacy constants are still returned by stateOfDownload, but
+  // individual properties of the Download object should normally be used.
+  DOWNLOAD_NOTSTARTED: -1,
+  DOWNLOAD_DOWNLOADING: 0,
+  DOWNLOAD_FINISHED: 1,
+  DOWNLOAD_FAILED: 2,
+  DOWNLOAD_CANCELED: 3,
+  DOWNLOAD_PAUSED: 4,
+  DOWNLOAD_BLOCKED_PARENTAL: 6,
+  DOWNLOAD_DIRTY: 8,
+  DOWNLOAD_BLOCKED_POLICY: 9,
+
+  // The following are the possible values of the "attention" property.
   ATTENTION_NONE: "",
   ATTENTION_SUCCESS: "success",
   ATTENTION_WARNING: "warning",
   ATTENTION_SEVERE: "severe",
 
   /**
    * This can be used by add-on experiments as a killswitch for the new style
    * progress indication. This will be removed in bug 1329109 after the new
@@ -292,37 +303,37 @@ this.DownloadsCommon = {
   _privateSummary: null,
 
   /**
    * Returns the legacy state integer value for the provided Download object.
    */
   stateOfDownload(download) {
     // Collapse state using the correct priority.
     if (!download.stopped) {
-      return nsIDM.DOWNLOAD_DOWNLOADING;
+      return DownloadsCommon.DOWNLOAD_DOWNLOADING;
     }
     if (download.succeeded) {
-      return nsIDM.DOWNLOAD_FINISHED;
+      return DownloadsCommon.DOWNLOAD_FINISHED;
     }
     if (download.error) {
       if (download.error.becauseBlockedByParentalControls) {
-        return nsIDM.DOWNLOAD_BLOCKED_PARENTAL;
+        return DownloadsCommon.DOWNLOAD_BLOCKED_PARENTAL;
       }
       if (download.error.becauseBlockedByReputationCheck) {
-        return nsIDM.DOWNLOAD_DIRTY;
+        return DownloadsCommon.DOWNLOAD_DIRTY;
       }
-      return nsIDM.DOWNLOAD_FAILED;
+      return DownloadsCommon.DOWNLOAD_FAILED;
     }
     if (download.canceled) {
       if (download.hasPartialData) {
-        return nsIDM.DOWNLOAD_PAUSED;
+        return DownloadsCommon.DOWNLOAD_PAUSED;
       }
-      return nsIDM.DOWNLOAD_CANCELED;
+      return DownloadsCommon.DOWNLOAD_CANCELED;
     }
-    return nsIDM.DOWNLOAD_NOTSTARTED;
+    return DownloadsCommon.DOWNLOAD_NOTSTARTED;
   },
 
   /**
    * Helper function required because the Downloads Panel and the Downloads View
    * don't share the controller yet.
    */
   removeAndFinalizeDownload(download) {
     Downloads.getList(Downloads.ALL)
--- a/browser/components/downloads/DownloadsViewUI.jsm
+++ b/browser/components/downloads/DownloadsViewUI.jsm
@@ -320,28 +320,28 @@ this.DownloadsViewUI.DownloadElementShel
   /**
    * Returns the name of the default command to use for the current state of the
    * download, when there is a double click or another default interaction. If
    * there is no default command for the current state, returns an empty string.
    * The commands are implemented as functions on this object or derived ones.
    */
   get currentDefaultCommandName() {
     switch (DownloadsCommon.stateOfDownload(this.download)) {
-      case Ci.nsIDownloadManager.DOWNLOAD_NOTSTARTED:
+      case DownloadsCommon.DOWNLOAD_NOTSTARTED:
         return "downloadsCmd_cancel";
-      case Ci.nsIDownloadManager.DOWNLOAD_FAILED:
-      case Ci.nsIDownloadManager.DOWNLOAD_CANCELED:
+      case DownloadsCommon.DOWNLOAD_FAILED:
+      case DownloadsCommon.DOWNLOAD_CANCELED:
         return "downloadsCmd_retry";
-      case Ci.nsIDownloadManager.DOWNLOAD_PAUSED:
+      case DownloadsCommon.DOWNLOAD_PAUSED:
         return "downloadsCmd_pauseResume";
-      case Ci.nsIDownloadManager.DOWNLOAD_FINISHED:
+      case DownloadsCommon.DOWNLOAD_FINISHED:
         return "downloadsCmd_open";
-      case Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL:
+      case DownloadsCommon.DOWNLOAD_BLOCKED_PARENTAL:
         return "downloadsCmd_openReferrer";
-      case Ci.nsIDownloadManager.DOWNLOAD_DIRTY:
+      case DownloadsCommon.DOWNLOAD_DIRTY:
         return "downloadsCmd_showBlockedInfo";
     }
     return "";
   },
 
   /**
    * Returns true if the specified command can be invoked on the current item.
    * The commands are implemented as functions on this object or derived ones.
--- a/browser/components/downloads/content/allDownloadsViewOverlay.js
+++ b/browser/components/downloads/content/allDownloadsViewOverlay.js
@@ -25,18 +25,16 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/Promise.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
                                   "resource:///modules/RecentWindow.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
                                   "resource://gre/modules/Task.jsm");
 
-const nsIDM = Ci.nsIDownloadManager;
-
 const DESTINATION_FILE_URI_ANNO  = "downloads/destinationFileURI";
 const DOWNLOAD_META_DATA_ANNO    = "downloads/metaData";
 
 /**
  * Represents a download from the browser history. It implements part of the
  * interface of the Download object.
  *
  * @param aPlacesNode
@@ -67,27 +65,27 @@ HistoryDownload.prototype = {
       this.target.path = Cc["@mozilla.org/network/protocol;1?name=file"]
                            .getService(Ci.nsIFileProtocolHandler)
                            .getFileFromURLSpec(metaData.targetFileSpec).path;
     } catch (ex) {
       this.target.path = undefined;
     }
 
     if ("state" in metaData) {
-      this.succeeded = metaData.state == nsIDM.DOWNLOAD_FINISHED;
-      this.canceled = metaData.state == nsIDM.DOWNLOAD_CANCELED ||
-                      metaData.state == nsIDM.DOWNLOAD_PAUSED;
+      this.succeeded = metaData.state == DownloadsCommon.DOWNLOAD_FINISHED;
+      this.canceled = metaData.state == DownloadsCommon.DOWNLOAD_CANCELED ||
+                      metaData.state == DownloadsCommon.DOWNLOAD_PAUSED;
       this.endTime = metaData.endTime;
 
       // Recreate partial error information from the state saved in history.
-      if (metaData.state == nsIDM.DOWNLOAD_FAILED) {
+      if (metaData.state == DownloadsCommon.DOWNLOAD_FAILED) {
         this.error = { message: "History download failed." };
-      } else if (metaData.state == nsIDM.DOWNLOAD_BLOCKED_PARENTAL) {
+      } else if (metaData.state == DownloadsCommon.DOWNLOAD_BLOCKED_PARENTAL) {
         this.error = { becauseBlockedByParentalControls: true };
-      } else if (metaData.state == nsIDM.DOWNLOAD_DIRTY) {
+      } else if (metaData.state == DownloadsCommon.DOWNLOAD_DIRTY) {
         this.error = {
           becauseBlockedByReputationCheck: true,
           reputationCheckVerdict: metaData.reputationCheckVerdict || "",
         };
       } else {
         this.error = null;
       }
 
--- a/browser/components/downloads/test/browser/browser_basic_functionality.js
+++ b/browser/components/downloads/test/browser/browser_basic_functionality.js
@@ -9,21 +9,21 @@ registerCleanupFunction(function*() {
 
 /**
  * Make sure the downloads panel can display items in the right order and
  * contains the expected data.
  */
 add_task(function* test_basic_functionality() {
   // Display one of each download state.
   const DownloadData = [
-    { state: nsIDM.DOWNLOAD_NOTSTARTED },
-    { state: nsIDM.DOWNLOAD_PAUSED },
-    { state: nsIDM.DOWNLOAD_FINISHED },
-    { state: nsIDM.DOWNLOAD_FAILED },
-    { state: nsIDM.DOWNLOAD_CANCELED },
+    { state: DownloadsCommon.DOWNLOAD_NOTSTARTED },
+    { state: DownloadsCommon.DOWNLOAD_PAUSED },
+    { state: DownloadsCommon.DOWNLOAD_FINISHED },
+    { state: DownloadsCommon.DOWNLOAD_FAILED },
+    { state: DownloadsCommon.DOWNLOAD_CANCELED },
   ];
 
   // Wait for focus first
   yield promiseFocus();
 
   // Ensure that state is reset in case previous tests didn't finish.
   yield task_resetState();
 
--- a/browser/components/downloads/test/browser/browser_downloads_panel_block.js
+++ b/browser/components/downloads/test/browser/browser_downloads_panel_block.js
@@ -134,17 +134,17 @@ function promisePanelHidden() {
     DownloadsPanel.panel.addEventListener("popuphidden", function() {
       setTimeout(resolve, 0);
     }, {once: true});
   });
 }
 
 function makeDownload(verdict) {
   return {
-    state: nsIDM.DOWNLOAD_DIRTY,
+    state: DownloadsCommon.DOWNLOAD_DIRTY,
     hasBlockedData: true,
     errorObj: {
       result: Components.results.NS_ERROR_FAILURE,
       message: "Download blocked.",
       becauseBlocked: true,
       becauseBlockedByReputationCheck: true,
       reputationCheckVerdict:  verdict,
     },
--- a/browser/components/downloads/test/browser/browser_downloads_panel_footer.js
+++ b/browser/components/downloads/test/browser/browser_downloads_panel_footer.js
@@ -29,36 +29,36 @@ add_task(function* test_openDownloadsFol
   });
 
   yield task_resetState();
 });
 
 add_task(function* test_clearList() {
   const kTestCases = [{
     downloads: [
-      { state: nsIDM.DOWNLOAD_NOTSTARTED },
-      { state: nsIDM.DOWNLOAD_FINISHED },
-      { state: nsIDM.DOWNLOAD_FAILED },
-      { state: nsIDM.DOWNLOAD_CANCELED },
+      { state: DownloadsCommon.DOWNLOAD_NOTSTARTED },
+      { state: DownloadsCommon.DOWNLOAD_FINISHED },
+      { state: DownloadsCommon.DOWNLOAD_FAILED },
+      { state: DownloadsCommon.DOWNLOAD_CANCELED },
     ],
     expectClearListShown: true,
     expectedItemNumber: 0,
   }, {
     downloads: [
-      { state: nsIDM.DOWNLOAD_NOTSTARTED },
-      { state: nsIDM.DOWNLOAD_FINISHED },
-      { state: nsIDM.DOWNLOAD_FAILED },
-      { state: nsIDM.DOWNLOAD_PAUSED },
-      { state: nsIDM.DOWNLOAD_CANCELED },
+      { state: DownloadsCommon.DOWNLOAD_NOTSTARTED },
+      { state: DownloadsCommon.DOWNLOAD_FINISHED },
+      { state: DownloadsCommon.DOWNLOAD_FAILED },
+      { state: DownloadsCommon.DOWNLOAD_PAUSED },
+      { state: DownloadsCommon.DOWNLOAD_CANCELED },
     ],
     expectClearListShown: true,
     expectedItemNumber: 1,
   }, {
     downloads: [
-      { state: nsIDM.DOWNLOAD_PAUSED },
+      { state: DownloadsCommon.DOWNLOAD_PAUSED },
     ],
     expectClearListShown: false,
     expectedItemNumber: 1,
   }];
 
   for (let testCase of kTestCases) {
     yield verify_clearList(testCase);
   }
--- a/browser/components/downloads/test/browser/browser_downloads_panel_height.js
+++ b/browser/components/downloads/test/browser/browser_downloads_panel_height.js
@@ -5,17 +5,17 @@
 
 /**
  * This test exists because we use a <panelmultiview> element and it handles
  * some of the height changes for us. We need to verify that the height is
  * updated correctly if downloads are removed while the panel is hidden.
  */
 add_task(function* test_height_reduced_after_removal() {
   yield task_addDownloads([
-    { state: nsIDM.DOWNLOAD_FINISHED },
+    { state: DownloadsCommon.DOWNLOAD_FINISHED },
   ]);
 
   yield task_openPanel();
   let panel = document.getElementById("downloadsPanel");
   let heightBeforeRemoval = panel.getBoundingClientRect().height;
 
   // We want to close the panel before we remove the download from the list.
   DownloadsPanel.hidePanel();
--- a/browser/components/downloads/test/browser/head.js
+++ b/browser/components/downloads/test/browser/head.js
@@ -19,18 +19,16 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/Promise.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
                                   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "HttpServer",
     "resource://testing-common/httpd.js");
 
-const nsIDM = Ci.nsIDownloadManager;
-
 var gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]);
 gTestTargetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
 
 // Load mocking/stubbing library, sinon
 // docs: http://sinonjs.org/docs/
 /* global sinon:false */
 Services.scriptloader.loadSubScript("resource://testing-common/sinon-1.16.1.js");
 
@@ -158,21 +156,22 @@ function* task_addDownloads(aItems) {
   for (let item of aItems) {
     let download = {
       source: {
         url: "http://www.example.com/test-download.txt",
       },
       target: {
         path: gTestTargetFile.path,
       },
-      succeeded: item.state == nsIDM.DOWNLOAD_FINISHED,
-      canceled: item.state == nsIDM.DOWNLOAD_CANCELED ||
-                item.state == nsIDM.DOWNLOAD_PAUSED,
-      error: item.state == nsIDM.DOWNLOAD_FAILED ? new Error("Failed.") : null,
-      hasPartialData: item.state == nsIDM.DOWNLOAD_PAUSED,
+      succeeded: item.state == DownloadsCommon.DOWNLOAD_FINISHED,
+      canceled: item.state == DownloadsCommon.DOWNLOAD_CANCELED ||
+                item.state == DownloadsCommon.DOWNLOAD_PAUSED,
+      error: item.state == DownloadsCommon.DOWNLOAD_FAILED ?
+             new Error("Failed.") : null,
+      hasPartialData: item.state == DownloadsCommon.DOWNLOAD_PAUSED,
       hasBlockedData: item.hasBlockedData || false,
       startTime: new Date(startTimeMs++),
     };
     // `"errorObj" in download` must be false when there's no error.
     if (item.errorObj) {
       download.errorObj = item.errorObj;
     }
     yield publicList.add(yield Downloads.createDownload(download));