Closed Bug 1552449 Opened 6 months ago Closed 6 months ago

Make the nsIDocShell interface to print preview less susceptible to inadvertent misuse


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




Tracking Status
firefox68 --- fixed


(Reporter: jwatt, Assigned: jwatt)



(1 file)

I'm concerned about the frontend code that does does docShell.printPreview.printPreview(...). This looks like the docShell has a single, unchanging "printPreview" object. There are a bunch of things that are not immediately clear about this object though:

  • It is created on first access, and it is actually a document viewer,
    meaning that initialization changes the docShell's current document

  • It should only be initialized on a docShell that has been created
    specifically for creating this document viewer. (Not, for example,
    on the docShell of a document that the user wants to see a print
    preview of.)

  • Navigating the docShell would be bad since a lot of code assumes this
    document viewer is never changed once created, and it could result in
    multiple print preview document viewers being created under the same
    docShell, breaking things even more.

I think the name of nsIDocShell.printPreview should be changed to make these things clearer. Making it a method (as opposed to an attribute) called initOrReusePrintPreviewViewer seems better. That would mean that we then have code that does this though:


which looks confusing. I think we should therefore add an exitPrintPreview() method to nsIDocShell that asserts that we have a print preview viewer, and propagates the exit call to it.

Pushed by
Make the nsIDocShell interface to print preview less susceptible to inadvertent misuse. r=bobowen
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
You need to log in before you can comment on or make changes to this bug.