Closed Bug 1552449 Opened 6 months ago Closed 6 months ago

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

Categories

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

defect

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: jwatt, Assigned: jwatt)

Details

Attachments

(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
    viewer.

  • 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:

docShell.initOrReusePrintPreviewViewer().exitPrintPreview()

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 jwatt@jwatt.org:
https://hg.mozilla.org/integration/mozilla-inbound/rev/73c9f2d6d3a0
Make the nsIDocShell interface to print preview less susceptible to inadvertent misuse. r=bobowen
Status: NEW → RESOLVED
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.