Bug 875731 - Replace callers of nsIDownloadManager.usersDownloadsDirectory with Downloads.getUserDownloadsDirectory mobile/andriod/. r=mfinkle
authorRaymond Lee <raymond@raysquare.com>
Fri, 27 Sep 2013 07:05:46 +0800
changeset 149082 41701d2c03414fb308a4233f5f69a0416008bf9c
parent 149081 a00aba84b699ea26bc3e90428938124d8dae6d26
child 149083 d725f6930fbd5b61a360d694ccbb25a270eb93ec
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmfinkle
bugs875731
milestone27.0a1
Bug 875731 - Replace callers of nsIDownloadManager.usersDownloadsDirectory with Downloads.getUserDownloadsDirectory mobile/andriod/. r=mfinkle
mobile/android/components/HelperAppDialog.js
--- a/mobile/android/components/HelperAppDialog.js
+++ b/mobile/android/components/HelperAppDialog.js
@@ -8,16 +8,21 @@ const Cu = Components.utils;
 const Cr = Components.results;
 
 const PREF_BD_USEDOWNLOADDIR = "browser.download.useDownloadDir";
 const URI_GENERIC_ICON_DOWNLOAD = "drawable://alert_download";
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
+                                  "resource://gre/modules/Downloads.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+                                  "resource://gre/modules/Task.jsm");
+
 // -----------------------------------------------------------------------
 // HelperApp Launcher Dialog
 // -----------------------------------------------------------------------
 
 function HelperAppLauncherDialog() { }
 
 HelperAppLauncherDialog.prototype = {
   classID: Components.ID("{e9d277a0-268a-4ec2-bb8c-10fdf3e44611}"),
@@ -25,25 +30,26 @@ HelperAppLauncherDialog.prototype = {
 
   show: function hald_show(aLauncher, aContext, aReason) {
     // Save everything by default
     aLauncher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.useSystemDefault;
     aLauncher.saveToDisk(null, false);
   },
 
   promptForSaveToFile: function hald_promptForSaveToFile(aLauncher, aContext, aDefaultFile, aSuggestedFileExt, aForcePrompt) {
-    // Retrieve the user's default download directory
-    let dnldMgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
-    let defaultFolder = dnldMgr.userDownloadsDirectory;
+    return Task.spawn(function() {
+      // Retrieve the user's default download directory
+      let defaultFolder = yield Downloads.getPreferredDownloadsDirectory();
 
-    try {
-      file = this.validateLeafName(defaultFolder, aDefaultFile, aSuggestedFileExt);
-    } catch (e) { }
+      try {
+        file = this.validateLeafName(defaultFolder, aDefaultFile, aSuggestedFileExt);
+      } catch (e) { }
 
-    return file;
+      throw new Task.Result(file);
+    }.bind(this));
   },
 
   validateLeafName: function hald_validateLeafName(aLocalFile, aLeafName, aFileExt) {
     if (!(aLocalFile && this.isUsableDirectory(aLocalFile)))
       return null;
 
     // Remove any leading periods, since we don't want to save hidden files
     // automatically.