view tests/41701d2c0341.diff @ 15:77118f83b5b7

almost does somethign
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 28 Sep 2013 09:20:14 -0700
parents 7ae60d2ff1c2
children
line wrap: on
line source


# HG changeset patch
# User Raymond Lee <raymond@raysquare.com>
# Date 1380236746 -28800
# Node ID 41701d2c03414fb308a4233f5f69a0416008bf9c
# Parent  a00aba84b699ea26bc3e90428938124d8dae6d26
Bug 875731 - Replace callers of nsIDownloadManager.usersDownloadsDirectory with Downloads.getUserDownloadsDirectory mobile/andriod/. r=mfinkle

diff --git a/mobile/android/components/HelperAppDialog.js b/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.