Comment 7 for bug 1981163

Revision history for this message
In , 9-henry (9-henry) wrote :

## Steps to Reproduce

Compose or Edit a message with a pdf attachment.

Open the pdf attachment (through double click or context menu).

## Result

Get popup message

```
You have chosen to open:
    <file>.pdf
    which is: HTML document
```

So the type is HTML, which means you'll likely get a recommendation to open in a browser, rather than the default pdf reader.

Also get the printed error message

```
JavaScript error: resource://pdf.js/PdfStreamConverter.jsm, line 140: TypeError: can't access property "getInterface", requestor is null
```

*Note: opening attachments when viewing a message (not composition), in either a tab or a separate window works fine.*

## Expected

The file to be treated as a PDF and no error message.

## Origin?

Looking in `PdfStreamConverter.jsm`, the error is from `getDOMWindow` (https://searchfox.org/mozilla-central/rev/9ae77e4ce3378bd683ac9a86b729ea6b6bd22cb8/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#136), which is called by `proxy.onStopRequest`. The problem seems to be that both `aChannel.notificationCallbacks` and `aChannel.loadGroup.notificationCallbacks` are `null`.

*Note: opening an attachment in a viewed message (not composing), does not seem to pass through the same code.*

On the the thunderbird side, I've tracked down the trigger for the error to `openURI` in `MsgComposeCommands.js` (https://searchfox.org/comm-central/rev/9bc3ba1480090c4e89d5152e458f19c79b3d6ac4/mail/components/compose/content/MsgComposeCommands.js#7171).

I couldn't really pinpoint the origin much beyond this because the code is passing through interfaces (and probably between c++ and javascript), and I'm not familiar enough to navigate this.

#### Why is it treated as HTML instead?

I think the reason the document is treated as as HTML is a side effect of the JavaScript error. Also in `PdfStreamConverter.jsm`, the `onStartRequest` method changes the `contentType` from `application/pdf` to `text/html` (https://searchfox.org/mozilla-central/rev/9ae77e4ce3378bd683ac9a86b729ea6b6bd22cb8/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#1231). Supposedly, this is done to break some loop. My guess is that it is meant to be set back to `application/pdf` during `onStopRequest`, but this method errors before it can do so.