Bug 561765 - PDF create from the 'Save Page As PDF' menu should appear into the downloads panel [r=mfinkle]
--- a/mobile/chrome/content/bindings/downloads.xml
+++ b/mobile/chrome/content/bindings/downloads.xml
@@ -51,16 +51,47 @@
state == this.nsIDLMgr.DOWNLOAD_DIRTY ||
state == this.nsIDLMgr.DOWNLOAD_FAILED;
]]>
</getter>
</property>
</implementation>
</binding>
+ <binding id="download-not-started" extends="#download-base">
+ <content orient="horizontal" align="start">
+ <xul:image validate="always" xbl:inherits="src=iconURL"/>
+ <xul:vbox flex="1">
+ <xul:hbox align="center">
+ <xul:label class="title" xbl:inherits="value=target" crop="center" flex="1"/>
+ <xul:label class="normal" xbl:inherits="value=datetime"/>
+ </xul:hbox>
+ <xul:hbox>
+ <xul:label class="normal" xbl:inherits="value=status"/>
+ </xul:hbox>
+ <xul:hbox class="show-on-select" align="center">
+ <xul:button anonid="showpage-button" label="&downloadShowPage.label;"
+ oncommand="DownloadsView.showPage(document.getBindingParent(this));"/>
+ <xul:spacer flex="1"/>
+ </xul:hbox>
+ </xul:vbox>
+ </content>
+
+ <implementation>
+ <constructor>
+ <![CDATA[
+ let referrer = this.hasAttribute("referrer");
+ if (!referrer)
+ document.getAnonymousElementByAttribute(this, "anonid", "showpage-button").setAttribute("disabled", "true");
+ ]]>
+ </constructor>
+ </implementation>
+ </binding>
+
+
<binding id="download-downloading" extends="#download-base">
<content orient="horizontal" align="start">
<xul:image validate="always" xbl:inherits="src=iconURL"/>
<xul:vbox flex="1">
<xul:hbox align="center">
<xul:label class="title" xbl:inherits="value=target" crop="center" flex="1"/>
<xul:label class="normal" xbl:inherits="value=datetime"/>
</xul:hbox>
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -994,19 +994,78 @@ var PageActions = {
//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);
+ // We must manually add this to the download system
+ let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
+ 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;
+ stmt.params.source = current;
+ stmt.params.target = gIOService.newFileURI(picker.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 newId = db.lastInsertRowID;
+ let listener = {
+ onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
+ if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
+ let stmt = db.createStatement("UPDATE moz_downloads SET endTime = :endTime, state = :state WHERE id = :id");
+ stmt.params.endTime = Date.now() * 1000;
+ stmt.params.state = Ci.nsIDownloadManager.DOWNLOAD_FINISHED;
+ stmt.params.id = newId;
+ stmt.execute();
+ stmt.finalize();
+
+ let download = dm.getDownload(newId);
+ try {
+ DownloadsView.downloadCompleted(download);
+ let element = DownloadsView.getElementForDownload(newId);
+ element.setAttribute("state", Ci.nsIDownloadManager.DOWNLOAD_FINISHED);
+ element.setAttribute("endTime", Date.now());
+ element.setAttribute("referrer", current);
+ DownloadsView._updateTime(element);
+ DownloadsView._updateStatus(element);
+ }
+ catch(e) {}
+ gObserverService.notifyObservers(download, "dl-done", null);
+ }
+ },
+ onProgressChange : function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
+
+ // stubs for the nsIWebProgressListener interfaces which nsIWebBrowserPrint doesn't use.
+ onLocationChange : function() { throw "Unexpected onLocationChange"; },
+ onStatusChange : function() { throw "Unexpected onStatusChange"; },
+ onSecurityChange : function() { throw "Unexpected onSecurityChange"; }
+ };
+
+ let download = dm.getDownload(newId);
+ try {
+ DownloadsView.downloadStarted(download);
+ }
+ catch(e) {}
+ gObserverService.notifyObservers(download, "dl-start", null);
+
+ let webBrowserPrint = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebBrowserPrint);
+ webBrowserPrint.print(printSettings, listener);
},
updatePageSaveAs: function updatePageSaveAs() {
this.removeItems("saveas");
if (Browser.selectedBrowser.contentDocument instanceof XULDocument)
return;
let strings = Elements.browserBundle;
--- a/mobile/chrome/content/browser.css
+++ b/mobile/chrome/content/browser.css
@@ -133,16 +133,20 @@ richlistitem[typeName="search"] hbox.add
richlistitem[typeName="message"] {
-moz-binding: url("chrome://browser/content/bindings/extensions.xml#extension-message");
}
richlistitem[typeName="showmore"] {
-moz-binding: url("chrome://browser/content/bindings/extensions.xml#extension-search-showmore");
}
+richlistitem[typeName="download"][state="-1"] {
+ -moz-binding: url("chrome://browser/content/bindings/downloads.xml#download-not-started");
+}
+
richlistitem[typeName="download"] {
-moz-binding: url("chrome://browser/content/bindings/downloads.xml#download-downloading");
}
richlistitem[typeName="download"][state="1"] {
-moz-binding: url("chrome://browser/content/bindings/downloads.xml#download-done");
}