Bug 1552449 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

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.

 * 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.
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.

Back to Bug 1552449 Comment 0