mozilla/pdf.js — Issue #1236: Investigate Thunderbird compatibility
Author: protz
Created: 2012-02-17 09:49:59+00:00
State: open

Another area where it'd be worthwhile to have pdf.js running is Thunderbird. PDF attachments are really common, and opening them in a tab would really bring additional value to Thunderbird. In Thunderbird Conversations (see the [blog post](http://blog.xulforum.org/index.php?post/2011/12/03/Leveraging-pdf.js-in-Thunderbird)), I bundle pdf.js and I have hacked up a small viewer that displays a PDF attachment in a tab. Here's some information:

* the addon SDK doesn't have support for Thunderbird (officially) but i) you can pass a path to the thunderbird binary (when doing cfx run) and ii) you can edit the install.rdf in the generated xpi (with cfx build I think)
* the URL to an attachment in Thunderbird is `imap-message://`; the cross-origin test fails when PDF.js tries to do its XMLHttpRequest, here's how I worked around it: from privileged code, I download the contents of the attachment as a bunch of JS strings [1](https://github.com/protz/GMail-Conversation-View/blob/master/content/pdfviewer/wrapper.js#L67) then I pass them into the `window` object of `viewer.xhtml` which is itself run from a resource:// URL. The `viewer.js` creates an `ArrayBuffer` [2](https://github.com/protz/GMail-Conversation-View/blob/master/content/pdfviewer/viewer.js#L122) and pdf.js takes it from then on.
* Thunderbird has its own way of opening tabs (namely, there's a function called `openTab` in the global scope that you can use like so:

```
openTab("contentTab", { contentPage: "http://www.google.com" });
```

Prefix with `top.opener.` to run this snippet in Thunderbird's error console.

I don't know how much work is required, and I do wish that somehow pdf.js would magically intercept any request to load an `application/pdf` attachment, and then manage to open the tab and make all things work together. In the short run, we may just want to have pdf.js be opened by, say, Thunderbird Conversations (if it detects that it's installed)...