Bug 465305 - Save page [r=mark.finkle]
--- 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