From 158b1d0c6985dbfce442a60421c324fc94e26472 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Thu, 12 Jan 2012 15:16:31 -0500 Subject: [PATCH] Bug 717231 - Downloads are not added to the Download Manager (stock ICS 4.0.3) [r=mbrubeck] --- mobile/android/base/AndroidManifest.xml.in | 1 + mobile/android/chrome/content/browser.js | 6 +++++- mobile/android/chrome/content/downloads.js | 24 +++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/mobile/android/base/AndroidManifest.xml.in b/mobile/android/base/AndroidManifest.xml.in index 256a3cfc5a82..1fc6d64688a0 100644 --- a/mobile/android/base/AndroidManifest.xml.in +++ b/mobile/android/base/AndroidManifest.xml.in @@ -18,6 +18,7 @@ + diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index ef9463656445..eb347a957541 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -547,6 +547,10 @@ var BrowserApp = { printSettings.headerStrLeft = ""; printSettings.headerStrRight = ""; + // Create a valid mimeInfo for the PDF + let ms = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); + let mimeInfo = ms.getFromTypeAndExtension("application/pdf", "pdf"); + let webBrowserPrint = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebBrowserPrint); let cancelable = { @@ -556,7 +560,7 @@ var BrowserApp = { } let download = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD, aBrowser.currentURI, - Services.io.newFileURI(file), "", null, + Services.io.newFileURI(file), "", mimeInfo, Date.now() * 1000, null, cancelable); webBrowserPrint.print(printSettings, download); diff --git a/mobile/android/chrome/content/downloads.js b/mobile/android/chrome/content/downloads.js index b99d4f93b981..63bff73e4145 100644 --- a/mobile/android/chrome/content/downloads.js +++ b/mobile/android/chrome/content/downloads.js @@ -140,16 +140,20 @@ var Downloads = { } else if (aTopic == "dl-done") { msgKey = "alertDownloadsDone"; - let message = { - gecko: { - type: "Downloads:Done", - displayName: download.displayName, - path: download.targetFile.path, - size: download.size, - mimeType: download.MIMEInfo ? download.MIMEInfo.type : "" - } - }; - sendMessageToJava(message); + // In order to get the fileSize to be correct for "Save as PDF", we need + // let the local file be safely written before accessing it. + setTimeout(function() { + let message = { + gecko: { + type: "Downloads:Done", + displayName: download.displayName, + path: download.targetFile.path, + size: download.targetFile.fileSize, + mimeType: download.MIMEInfo ? download.MIMEInfo.type : "" + } + }; + sendMessageToJava(message); + }, 0); } if (msgKey)