1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 var EXPORTED_SYMBOLS = ["PrintingParent"];
9 let gTestListener = null;
11 class PrintingParent extends JSWindowActorParent {
12 static setTestListener(listener) {
13 gTestListener = listener;
16 getPrintPreviewToolbar(browser) {
17 return browser.ownerDocument.getElementById("print-preview-toolbar");
20 receiveMessage(message) {
21 let browser = this.browsingContext.top.embedderElement;
22 let PrintUtils = browser.ownerGlobal.PrintUtils;
24 if (message.name == "Printing:Error") {
25 PrintUtils._displayPrintingError(
26 message.data.nsresult,
27 message.data.isPrinting
32 if (this.ignoreListeners) {
36 let listener = PrintUtils._webProgressPP.value;
37 let data = message.data;
39 switch (message.name) {
40 case "Printing:Preview:Entered": {
41 // This message is sent by the content process once it has completed
42 // putting the content into print preview mode. We must wait for that to
43 // to complete before switching the chrome UI to print preview mode,
44 // otherwise we have layout issues.
47 gTestListener(browser);
50 PrintUtils.printPreviewEntered(browser, message.data);
54 case "Printing:Preview:ReaderModeReady": {
55 PrintUtils.readerModeReady(browser);
59 case "Printing:Preview:UpdatePageCount": {
60 let toolbar = this.getPrintPreviewToolbar(browser);
61 toolbar.updatePageCount(message.data.totalPages);
65 case "Printing:Preview:ProgressChange": {
66 if (!PrintUtils._webProgressPP.value) {
67 // We somehow didn't get a nsIWebProgressListener to be updated...
68 // I guess there's nothing to do.
72 return listener.onProgressChange(
77 data.curTotalProgress,
82 case "Printing:Preview:StateChange": {
83 if (!PrintUtils._webProgressPP.value) {
84 // We somehow didn't get a nsIWebProgressListener to be updated...
85 // I guess there's nothing to do.
89 if (data.stateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
90 // Strangely, the printing engine sends 2 STATE_STOP messages when
91 // print preview is finishing. One has the STATE_IS_DOCUMENT flag,
92 // the other has the STATE_IS_NETWORK flag. However, the webProgressPP
93 // listener stops listening once the first STATE_STOP is sent.
94 // Any subsequent messages result in NS_ERROR_FAILURE errors getting
95 // thrown. This should all get torn out once bug 1088061 is fixed.
97 // Enable toobar elements that we disabled during update.
98 let printPreviewTB = this.getPrintPreviewToolbar(browser);
99 printPreviewTB.disableUpdateTriggers(false);
102 return listener.onStateChange(null, null, data.stateFlags, data.status);