Dmitry
Dmitry

Reputation: 35

Getting mime types array in Firefox Add-on script

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.

Upvotes: 2

Views: 550

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57651

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
  }
});

Upvotes: 1

Related Questions