2

I'm trying to get MIME types list on a firefox extension side.

There is navigator object in browser JavaScript context. It has mimeTypes property - list of MIME types recognized by the browser. I need to get that list in add-on script using Add-On SDK or XPCOM. How can I do that? I cannot find any appropriate methods in XPCOM or SDK.

Thanks in advance for help.

Dmitry
  • 35
  • 5

1 Answers1

1

It has mimeTypes property - list of MIME types recognized by the browser.

No, it isn't - it is merely the list of MIME types that have a plugin (Flash & Co.) registered for them. If you need to get plugin information I would normally recommend using nsIPluginHost.getPluginTags() method. Unfortunately, the plugin tags don't have information on MIME types associated with the plugins.

So you cannot avoid getting hold of a navigator object that is only available in the window context. You can do that using page-worker module:

require("page-worker").Page({
  contentScript: "var result = [];" +
                 "for (var i = 0; i < navigator.mimeTypes.length; i++)" +
                   "result.push(navigator.mimeTypes[i].type);" +
                 "self.postMessage(result);",
  contentURL: "about:blank",
  onMessage: function(mimeTypes) {
    // Do something with the MIME types
  }
});
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Thanks a lot! Are there any sirializer constraints? I cannot transmit object **navigator** itself, for example. – Dmitry Aug 29 '12 at 14:35
  • @Dmitry: It's a [JSON serializer](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify). – Wladimir Palant Aug 29 '12 at 16:55