Bug 645015 - Use correct filename when adding downloaded pdfs to the download manager [r=mfinkle]
authorWes Johnston <wjohnston@mozilla.com>
Tue, 29 Mar 2011 16:30:07 -0700
changeset 2947 650faad3682ff9397717fa3783c2d254a9420851
parent 2946 d402e973b4c9cc1aff687376e53cea097fa2e6f1
child 2948 6b9a963ef50592fc6c0cd7e85c29a778fa32f836
push id2484
push userwjohnston@mozilla.com
push dateTue, 29 Mar 2011 23:30:36 +0000
reviewersmfinkle
bugs645015
Bug 645015 - Use correct filename when adding downloaded pdfs to the download manager [r=mfinkle]
chrome/content/common-ui.js
--- a/chrome/content/common-ui.js
+++ b/chrome/content/common-ui.js
@@ -244,53 +244,52 @@ var PageActions = {
     this.hideItem(aEvent.target);
     aEvent.stopPropagation(); // Don't hide the site menu.
   },
 
   savePageAsPDF: function saveAsPDF() {
     let browser = Browser.selectedBrowser;
     let fileName = ContentAreaUtils.getDefaultFileName(browser.contentTitle, browser.documentURI, null, null);
     fileName = fileName.trim() + ".pdf";
-    let displayName = fileName;
 
     let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
     let downloadsDir = dm.defaultDownloadsDirectory;
 
 #ifdef ANDROID
     // Create the final destination file location
     let file = downloadsDir.clone();
     file.append(fileName);
     file.createUnique(file.NORMAL_FILE_TYPE, 0666);
-    fileName = file.leafName;
 #else
     let picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
     picker.init(window, Strings.browser.GetStringFromName("pageactions.saveas.pdf"), Ci.nsIFilePicker.modeSave);
     picker.appendFilter("PDF", "*.pdf");
     picker.defaultExtension = "pdf";
 
     picker.defaultString = fileName;
 
     picker.displayDirectory = downloadsDir;
     let rv = picker.show();
     if (rv == Ci.nsIFilePicker.returnCancel)
       return;
 
     let file = picker.file;
 #endif
+    fileName = file.leafName;
 
     // We must manually add this to the download system
     let db = dm.DBConnection;
 
     let stmt = db.createStatement(
       "INSERT INTO moz_downloads (name, source, target, startTime, endTime, state, referrer) " +
       "VALUES (:name, :source, :target, :startTime, :endTime, :state, :referrer)"
     );
 
     let current = browser.currentURI.spec;
-    stmt.params.name = displayName;
+    stmt.params.name = fileName;
     stmt.params.source = current;
     stmt.params.target = Services.io.newFileURI(file).spec;
     stmt.params.startTime = Date.now() * 1000;
     stmt.params.endTime = Date.now() * 1000;
     stmt.params.state = Ci.nsIDownloadManager.DOWNLOAD_NOTSTARTED;
     stmt.params.referrer = current;
     stmt.execute();
     stmt.finalize();