Bug 465305 - Save page [r=mark.finkle]
authorVivien Nicolas <21@vingtetun.org>
Fri, 26 Mar 2010 15:06:58 -0400
changeset 66070 f34d064c7c8a2333a4131d728a1fa1b210f99c81
parent 66069 7fe22b827fad6309f8dac0f35a005cbc4a5c956b
child 66071 7511097145ca8fa775d059753b86527ec88629a0
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)
reviewersmark
bugs465305
Bug 465305 - Save page [r=mark.finkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
mobile/locales/en-US/chrome/browser.properties
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -932,16 +932,65 @@ var PageActions = {
       pm.remove(host.asciiHost, aType);
     });
 
     let lm = this._loginManager;
     if (!lm.getLoginSavingEnabled(host.prePath))
       lm.setLoginSavingEnabled(host.prePath, true);
   },
 
+  _savePageAsPDF: function saveAsPDF() {
+    let contentWindow = Browser.selectedBrowser.contentWindow;
+    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";
+    picker.defaultString = contentWindow.document.title + ".pdf";
+
+    let rv = picker.show();
+    if (rv == Ci.nsIFilePicker.returnCancel)
+      return;
+
+    let printSettings = Cc["@mozilla.org/gfx/printsettings-service;1"]
+                          .getService(Ci.nsIPrintSettingsService)
+                          .newPrintSettings;
+    printSettings.printSilent = true;
+    printSettings.showPrintProgress = false;
+    printSettings.printBGImages = true;
+    printSettings.printBGColors = true;
+    printSettings.printToFile = true;
+    printSettings.toFileName = picker.file.path;
+    printSettings.printFrameType = Ci.nsIPrintSettings.kFramesAsIs;
+    printSettings.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF;
+
+    //XXX we probably need a preference here, the header can be useful
+    printSettings.footerStrCenter = '';
+    printSettings.footerStrLeft   = '';
+    printSettings.footerStrRight  = '';
+    printSettings.headerStrCenter = '';
+    printSettings.headerStrLeft   = '';
+    printSettings.headerStrRight  = '';
+
+    let webBrowserPrint = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                                       .getInterface(Ci.nsIWebBrowserPrint);
+    webBrowserPrint.print(printSettings, null);
+  },
+
+  updatePageSaveAs: function updatePageSaveAs() {
+    if (Browser.selectedBrowser.contentDocument instanceof XULDocument)
+      return;
+
+    let strings = Elements.browserBundle;
+    let node = this.appendItem(strings.getString("pageactions.saveas.pdf"), "");
+    node.onclick = function(event) {
+      PageActions._savePageAsPDF();
+    }
+  },
+
   appendItem: function appendItem(aTitle, aDesc, aImage) {
     let container = document.getElementById("pageactions-container");
     let item = document.createElement("pageaction");
     item.setAttribute("title", aTitle);
     item.setAttribute("description", aDesc);
     if (aImage)
       item.setAttribute("image", aImage);
     container.appendChild(item);
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -2135,16 +2135,18 @@ IdentityHandler.prototype = {
     this._identityPopupContentHost.textContent = host;
     this._identityPopupContentOwner.textContent = owner;
     this._identityPopupContentSupp.textContent = supplemental;
     this._identityPopupContentVerif.textContent = verifier;
 
     // clean all the previous result
     PageActions.removeAllItems();
 
+    PageActions.updatePageSaveAs();
+
     // Update the search engines results
     BrowserSearch.updatePageSearchEngines();
 
     // Update the per site permissions results
     PageActions.updatePagePermissions();
   },
 
   show: function ih_show() {
--- a/mobile/locales/en-US/chrome/browser.properties
+++ b/mobile/locales/en-US/chrome/browser.properties
@@ -130,15 +130,16 @@ tabs.closeWarning=NOT USED;You are about
 
 tabs.closeButton=Close tabs
 tabs.closeWarningPromptMe=Warn me when I attempt to close multiple tabs
 
 # Homepage
 homepage.custom=Custom
 
 # Page Actions
+pageactions.saveas.pdf=Save As PDF
 pageactions.search.addNew=Add Search Engine
 pageactions.password.forget=Forget Password
 pageactions.reset=Clear Site Preferences
 pageactions.geo=Location
 pageactions.popup=Popups
 pageactions.offline-app=Offline Storage
 pageactions.password=Password