Closed Bug 1558067 Opened 6 years ago Closed 6 years ago

Prevent mozPrintCallback being invoked with the wrong <canvas> element

Categories

(Core :: Printing: Setup, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla69
Tracking Status
firefox69 --- fixed

People

(Reporter: jwatt, Assigned: jwatt)

Details

Attachments

(1 file)

No description provided.

Since the Firefox print preview code creates a static clone from the existing print preview static clone for any print preview settings changes, for enabling of simplified mode, and for a print from a print preview document, HTMLCanvasElement::CopyInnerTo may be invoked on an existing static clone. In that case, the mozPrintCallback's printState.context.canvas would previously have ended up using the canvas in the previous print preview static clone, which is wrong.

This is actually not as straightforward to trigger as you might think, since for settings changes the previous static clone is discarded, so any mozPrintCallback mutations to it are not seen. It is visible however if you print while in print preview, since the original print preview document is kept and keeps displaying after the print static clone is created and printed. It's also visible when switching to/from simplified mode since that uses two tabs (one for normal print preview, another for the simplified print preview).

For example, open about:blank and use the web console to invoke the following:

let p = document.createElement("p");
p.id = "myp"
p.textContent = "original"
document.body.append(p)
let c = document.createElement("canvas");
c.mozPrintCallback=(printState)=>{printState.context.canvas.ownerDocument.querySelector("#myp").textContent+=" mutated"}
document.body.append(c)

Now print preview it, and print from the print preview window. On finishing the actual print, the print preview window will now be displaying "original mutated" instead of just "original".

Since the Firefox print preview code creates a static clone from the existing
print preview static clone for any print preview settings changes, for enabling
of simplified mode, and for a print from a print preview document,
HTMLCanvasElement::CopyInnerTo may be invoked on an existing static clone.
In that case, the mozPrintCallback's printState.context.canvas would previously
have ended up using the canvas in the previous print preview static clone,
which is wrong, and allow the callback to modify the static clone document.

Pushed by jwatt@jwatt.org: https://hg.mozilla.org/integration/mozilla-inbound/rev/5b55f2d60ad7 Prevent mozPrintCallback being invoked with the wrong <canvas> element. r=bobowen
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla69
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: