Bug 717231 - Downloads are not added to the Download Manager (stock ICS 4.0.3) [r=mbrubeck]
authorMark Finkle <mfinkle@mozilla.com>
Thu, 12 Jan 2012 15:16:31 -0500
changeset 84361 67fe34d2c8afddec0f83cafe279362565a31d88e
parent 84360 4b0fd441c9c70767a253f2b437b1d2aabb6840e0
child 84362 c04fb55118f84b2fe83f09ea4eedbfa1b07df491
push id21842
push usermak77@bonardo.net
push dateFri, 13 Jan 2012 08:56:37 +0000
treeherdermozilla-central@8d4638feec54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs717231
milestone12.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 717231 - Downloads are not added to the Download Manager (stock ICS 4.0.3) [r=mbrubeck]
mobile/android/base/AndroidManifest.xml.in
mobile/android/chrome/content/browser.js
mobile/android/chrome/content/downloads.js
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -13,16 +13,17 @@
               android:targetSdkVersion="11"/>
 
 #include ../sync/manifests/SyncAndroidManifest_permissions.xml.in
 
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>
     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
 
     <uses-permission android:name="android.permission.WAKE_LOCK"/>
     <uses-permission android:name="android.permission.VIBRATE"/>
 
     <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/> 
     <uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/> 
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -542,26 +542,30 @@ var BrowserApp = {
     //XXX we probably need a preference here, the header can be useful
     printSettings.footerStrCenter = "";
     printSettings.footerStrLeft   = "";
     printSettings.footerStrRight  = "";
     printSettings.headerStrCenter = "";
     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 = {
       cancel: function (aReason) {
         webBrowserPrint.cancel();
       }
     }
     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);
   },
 
   getPreferences: function getPreferences(aPrefNames) {
     try {
       let json = JSON.parse(aPrefNames);
--- a/mobile/android/chrome/content/downloads.js
+++ b/mobile/android/chrome/content/downloads.js
@@ -135,26 +135,30 @@ var Downloads = {
         this._progressAlert = new AlertDownloadProgressListener();
         this._dlmgr.addListener(this._progressAlert);
       }
 
       NativeWindow.toast.show(Strings.browser.GetStringFromName("alertDownloadsToast"), "long");
     } 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)
       this.showAlert(download, Strings.browser.formatStringFromName(msgKey, [download.displayName], 1));
   },
 
   QueryInterface: function (aIID) {
     if (!aIID.equals(Ci.nsIObserver) &&