From f073b0e08bae3ddd861bef8c8101c95919f30d40 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Thu, 8 Jan 2015 20:57:18 -0800 Subject: [PATCH] Bug 1114586 - Replace nsIDownloadManager.defaultDownloadsDirectory with Downloads.getSystemDownloadsDirectory; r=margaret --HG-- extra : amend_source : 029c30cccaa48d0153bc297be9b976858b98e52b --- mobile/android/modules/WebappManager.jsm | 38 ++++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/mobile/android/modules/WebappManager.jsm b/mobile/android/modules/WebappManager.jsm index 84b08dcb625..f8ddb66bddd 100644 --- a/mobile/android/modules/WebappManager.jsm +++ b/mobile/android/modules/WebappManager.jsm @@ -11,6 +11,7 @@ const { classes: Cc, interfaces: Ci, utils: Cu } = Components; const UPDATE_URL_PREF = "browser.webapps.updateCheckUrl"; Cu.import("resource://gre/modules/AppsUtils.jsm"); +Cu.import("resource://gre/modules/Downloads.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); @@ -137,30 +138,29 @@ this.WebappManager = { [p + "=" + encodeURIComponent(params[p]) for (p in params)].join("&"); debug("downloading APK from " + generatorUrl.spec); - let file = Cc["@mozilla.org/download-manager;1"]. - getService(Ci.nsIDownloadManager). - defaultDownloadsDirectory. - clone(); - file.append(aManifestUrl.replace(/[^a-zA-Z0-9]/gi, "") + ".apk"); - file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); - debug("downloading APK to " + file.path); + Downloads.getSystemDownloadsDirectory().then(function(downloadsDir) { + let file = new FileUtils.File(downloadsDir); + file.append(aManifestUrl.replace(/[^a-zA-Z0-9]/gi, "") + ".apk"); + file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); + debug("downloading APK to " + file.path); - let worker = new ChromeWorker("resource://gre/modules/WebappManagerWorker.js"); - worker.onmessage = function(event) { - let { type, message } = event.data; + let worker = new ChromeWorker("resource://gre/modules/WebappManagerWorker.js"); + worker.onmessage = function(event) { + let { type, message } = event.data; - worker.terminate(); + worker.terminate(); - if (type == "success") { - deferred.resolve(file.path); - } else { // type == "failure" - debug("error downloading APK: " + message); - deferred.reject(message); + if (type == "success") { + deferred.resolve(file.path); + } else { // type == "failure" + debug("error downloading APK: " + message); + deferred.reject(message); + } } - } - // Trigger the download. - worker.postMessage({ url: generatorUrl.spec, path: file.path }); + // Trigger the download. + worker.postMessage({ url: generatorUrl.spec, path: file.path }); + }); return deferred.promise; },