Application/pdf XPCOM stream converter registering but not activating

(Miguel Guedes) #1

I am developing an addon that exposes a custom PDF viewer based on the awesome pdf.js library.

Unfortunately, part of the requirements are that the addon must work on Firefox 49, which rules out the WebExtensions API. The problem I’m facing is that I am able to register the custom PDF viewer’s application/pdf stream converter but it is never instantiated, which results in the custom viewer never loading in Firefox 49. No errors or notifications are produced.

The custom PDF viewer registers an XPCOM stream converter component where its contract IDs are ';1?from=application/pdf&to=*/*' and;1?from=application/pdf&to=test/html, just like pdf.js’s.

Strangely, my code works in Firefox 48 but something seems to have changed in 49. At this point I’m considering all sorts of options. Could it be that Firefox 49 does not allow stream converters on application/pdf?

I’ve even attempted (but failed) to unregister the existing two factories set up by the internal pdf.js viewer, like so:

function unregisterFactoryByContractID(contractID) {
  const cid = contractIDToCID(contractID);
  const factory = Cm.getClassObjectByContractID(contractID, Ci.nsIFactory);
  console.error('contract ID registered?', isContractIDRegistered(contractID));
  console.error('cid registered?', isCIDRegistered(cid));
  console.error('Unregistering', contractID, cid, factory);
  unregisterFactory(cid, factory);

The above fails with a factory not registered error even though both the contract ID and CID seem to be registered.

Here’s how I’m setting up a test stream converter factory on application/pdf streams:

    contract: StreamConverter.contractID,
    //    id: components.ID('{5948f77a-cad0-4eea-9520-f7ace5462dad}'),
    Component: StreamConverter,

    contract: StreamConverter.contractID2,
    //    id: components.ID('{5948f77a-cad0-4eea-9520-f7ace5462dac}'),
    Component: StreamConverter,

The StreamConverter component above is simply an empty shell at the moment that logs messages to the console on instantiation and invocation of the asyncConvertData method.

Why does my code work in Firefox 48 but not 49? Is it because it is silently disallowing application/pdf stream converters? Would unregistering the existing stream converters help and, if so, am I doing it wrong above?

Any help would be greatly appreciated!