Bug 595737 - Don't show file picker for "Save As PDF" on Android [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 13 Sep 2010 14:56:17 -0700
changeset 66576 04b83261231cc7b7507b4a475165e5f073f0fb43
parent 66575 0b7392ed33f19ed4a0bd98919af49db84f468659
child 66577 a9db71caa4e759f8249775d0e137022006cf322e
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs595737
Bug 595737 - Don't show file picker for "Save As PDF" on Android [r=mfinkle]
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1187,48 +1187,58 @@ var PageActions = {
     });
 
     let lm = this._loginManager;
     if (!lm.getLoginSavingEnabled(host.prePath))
       lm.setLoginSavingEnabled(host.prePath, true);
   },
 
   savePageAsPDF: function saveAsPDF() {
+    let browser = Browser.selectedBrowser;
+    let fileName = getDefaultFileName(browser.contentTitle, browser.documentURI, null, null);
+    fileName = fileName.trim() + ".pdf";
+#ifdef MOZ_PLATFORM_MAEMO
+    fileName = fileName.replace(/[\*\:\?]+/g, " ");
+#endif
+
+    let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
+    let downloadsDir = dm.defaultDownloadsDirectory;
+
+#ifdef ANDROID
+    let file = downloadsDir.clone();
+    file.append(fileName);
+#else
     let strings = Elements.browserBundle;
     let picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
     picker.init(window, strings.getString("pageactions.saveas.pdf"), Ci.nsIFilePicker.modeSave);
     picker.appendFilter("PDF", "*.pdf");
     picker.defaultExtension = "pdf";
 
-    let browser = Browser.selectedBrowser;
-    let fileName = getDefaultFileName(browser.contentTitle, browser.documentURI, null, null);
-    fileName = fileName.trim();
-#ifdef MOZ_PLATFORM_MAEMO
-    fileName = fileName.replace(/[\*\:\?]+/g, " ");
-#endif
-    picker.defaultString = fileName + ".pdf";
-
-    let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
-    picker.displayDirectory = dm.defaultDownloadsDirectory;
+    picker.defaultString = fileName;
+
+    picker.displayDirectory = downloadsDir;
     let rv = picker.show();
     if (rv == Ci.nsIFilePicker.returnCancel)
       return;
 
+    let file = picker.file;
+#endif
+
     // 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.selectedBrowser.currentURI.spec;
-    stmt.params.name = picker.file.leafName;
+    let current = browser.currentURI.spec;
+    stmt.params.name = file.leafName;
     stmt.params.source = current;
-    stmt.params.target = Services.io.newFileURI(picker.file).spec;
+    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();
 
     let newItemId = db.lastInsertRowID;
@@ -1238,17 +1248,17 @@ var PageActions = {
     }
     catch(e) {}
     Services.obs.notifyObservers(download, "dl-start", null);
 
     let data = {
       type: Ci.nsIPrintSettings.kOutputFormatPDF,
       id: newItemId,
       referrer: current,
-      filePath: picker.file.path
+      filePath: file.path
     };
 
     Browser.selectedBrowser.messageManager.sendAsyncMessage("Browser:SaveAs", data);
   },
 
   updatePageSaveAs: function updatePageSaveAs(aNode) {
     // Check for local XUL content
     let contentDocument = Browser.selectedBrowser.contentDocument;