Description based on a discussion with Boris elsewhere (thank you!):
In particular, if we are given a type and an extension, and that extension is a valid extension for that type, and Windows does helper app lookup by extension, then we should be doing that lookup based on that extension.
nsOSHelperAppService::GetMIMEInfoFromOS does right now is:
- Get the default extension for the given type.
- Look up the handler for that default extension.
- If we found something, and the given extension is valid for the given type, add it to the MIME info.
- If we found nothing for the default extension, look up info for the given extension.
or so (there are some more complications). It seems like the logic should be more like:
- Look up the type for the given extension.
- If this matches the given type, look up handlers by the given extension, since that's the extension we will end up using. We can use the existing
nsOSHelperAppService::typeFromExtEquals thing on Windows for this, I bet.
- Otherwise look up the default extension for the type and look up based on that [Gijs: note, and set the default extension as the extension for the mime info object. This is useful e.g. when we've determined the extension from the URL, and it's actually related to e.g. the server-side programming language (
.cgi, etc.). ]
- If none of that found anything useful, continue to look up by the given extension, I guess, as now? I'm not sure what exactly should happen here if the given extension does not match the given MIME type in any sort of useful way and there is no handler for the default exension for the given MIME type.
I have a patch that switches us to the second set of steps. I'm not changing what we do for (4) for now.
What should get stored in our prefs in terms of how to handle things in the future, given all that, is an interesting question.
Yeah. This is difficult. It's tempting to only store information where the extension is also the mimetype's primary extension, but unfortunately that breaks relatively common cases where a single mimetype commonly has one of several extensions (e.g.
.jpeg). I'm not changing pref storage in this bug. As noted in bug 393504, there's something to be said for storing the file extension in prefs too, but I'd like to limit the scope here.