Closed
Bug 1144204
Opened 10 years ago
Closed 9 years ago
navigator.mimeTypes should only consider things supported via plug-ins
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
FIXED
mozilla48
Tracking | Status | |
---|---|---|
firefox48 | --- | fixed |
People
(Reporter: April, Assigned: bzbarsky)
References
Details
Attachments
(2 files)
(deleted),
text/html
|
Details | |
(deleted),
patch
|
smaug
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:36.0) Gecko/20100101 Firefox/36.0
Build ID: 20150305021524
Steps to reproduce:
Firefox Mobile always reports that a particular object is in navigator.mimeTypes, no matter what MIME type you actually search for. I have an application that does real-time PDF previews, but I have to write special code for Firefox Mobile only:
function detectPDFPreviewSupport() {
showpreview = false;
// Safari and Chrome have application/pdf in navigator.mimeTypes
if (navigator.mimeTypes["application/pdf"] != undefined) { showpreview = true; }
// Firefox desktop uses pdf.js, but not mobile or tablet
if (navigator.userAgent.indexOf("Firefox") != -1) {
if ((navigator.userAgent.indexOf("Mobile") == -1) && (navigator.userAgent.indexOf("Tablet") == -1)) { showpreview = true; }
else { showpreview = false; } // have to reset it, as FF Mobile application/pdf listed, but not supported (wtf?)
}
}
Actual results:
< 'application/pdf' in navigator.mimeTypes;
> true
(this is not true, Firefox Mobile does not natively support PDF)
< navigator.mimeTypes['blah/foo']
> MimeType { description: "", enabledPlugin: null, suffixes: "", type: "blah/foo" }
"blah/foo" isn't actually a real MIME type. Oh no!
Expected results:
Firefox (Desktop), as well as other desktop and mobile browsers behave properly. Here is the output from Firefox (Desktop):
< 'blah/foo' in navigator.mimeTypes
> false
< navigator.mimeTypes['blah/foo']
> undefined
Similarly, here is the output from Chrome (Mobile), which also behaves as expected:
< navigator.mimeTypes['application/pdf']
> undefined
< 'blah/foo' in navigator.mimeTypes
> false
< navigator.mimeTypes["blah/foo"]
> undefined
Reporter | ||
Updated•10 years ago
|
OS: Mac OS X → Android
Hardware: x86 → ARM
Comment 1•9 years ago
|
||
This breaks a nasa.gov page as reported in https://webcompat.com/issues/1984
Comment 2•9 years ago
|
||
See http://hallvord.com/temp/moz/bug/wc1984.htm for a crazy demo - will also attach it here.
Strange. I can reproduce it here too, but not on desktop. I'll dig deeper.
Assignee: nobody → snorp
Flags: needinfo?(snorp)
OK, I figured this out. We always count the Android chooser as an option for any mime type, so any mime type could be "handled". Whether that's right or not could be argued I guess, but that's why we have this behavior.
Comment 6•9 years ago
|
||
Right. We should stop doing that. On Desktop most of us have another application capable of opening *.docx but it doesn't mean we advertise support for it in navigator.mimeTypes.
It seems that navigator.mimeTypes is not part of any spec. Do we know exactly what it is supposed to represent? Is it mime types that the browser itself can handle, or the system as a whole? We can easily remove the chooser shenanigans.
Flags: needinfo?(hsteen)
Flags: needinfo?(bugs)
Comment 8•9 years ago
|
||
navigator.mimeTypes is part of HTML spec, https://html.spec.whatwg.org/#navigatorplugins
Flags: needinfo?(bugs)
Ah, so it's specifically supposed to be mimetypes that *plugins* support? We can most likely always return a false result then.
Comment 10•9 years ago
|
||
well, looks like browsers behave differently.
Would be worth to test different browsers, both desktop and mobile
Comment 11•9 years ago
|
||
I guess we should change Gecko to follow what other browsers do.
But isn't still clear to me why desktop works on that page and mobile doesn't.
(In reply to Olli Pettay [:smaug] (expect slower than usual review time for couple of days) from comment #11)
> I guess we should change Gecko to follow what other browsers do.
> But isn't still clear to me why desktop works on that page and mobile
> doesn't.
The reason is because Android has a default handler for any mime type, representing the Android activity chooser. Desktop has no such thing, but will return valid results for things like 'application/pdf' if you have a PDF viewer installed.
I actually think the best thing to do here is to remove the chooser as a default handler, and just query the system for the mime types directly.
Comment 13•9 years ago
|
||
and I think we should just follow the spec, so deal with plugins only.
Updated•9 years ago
|
Flags: needinfo?(hsteen)
Updated•9 years ago
|
Assignee | ||
Comment 14•9 years ago
|
||
> On Desktop most of us have another application capable of opening *.docx but it doesn't mean we advertise
> support for it in navigator.mimeTypes.
Actually, we probably do. For example, navigator.mimeTypes["application/msword"] returns a thing for me, on desktop.
I think I agree with Olli here, but we should check what other UAs do. Chrome and Safari seem to only return plug-in stuff here. What does IE do?
Assignee | ||
Comment 15•9 years ago
|
||
I guess IE at least has undefined for navigator.mimeTypes["text/html"].
Component: General → DOM
Product: Firefox for Android → Core
Summary: navigator.mimeTypes always returns a MimeType object, even for unsupported MIME types → navigator.mimeTypes should only consider things supported via plug-ins
Assignee | ||
Comment 16•9 years ago
|
||
Attachment #8732690 -
Flags: review?(bugs)
Assignee | ||
Updated•9 years ago
|
Assignee: snorp → bzbarsky
Status: NEW → ASSIGNED
Comment 18•9 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #14)
> > *.docx ... in navigator.mimeTypes.
>
> For example,
> navigator.mimeTypes["application/msword"] returns a thing for me, on desktop.
Interesting - so what does
navigator.mimeTypes["application/msword"].enabledPlugin
return? I have no such mimeType registered in my Firefox so I assume that some Word/MSOffice viewer plug-in has snuck into your instance.
Assignee | ||
Comment 19•9 years ago
|
||
> navigator.mimeTypes["application/msword"].enabledPlugin
Returns null, of course. ;)
> I have no such mimeType registered in my Firefox
Try navigator.mimeTypes["text/html"]? Also, what happens if you try to actually open an application/msword thing? Is an application suggested in the dialog that comes up?
> so I assume that some Word/MSOffice viewer plug-in has snuck into your instance
Most definitely not.
Comment 20•9 years ago
|
||
Comment on attachment 8732690 [details] [diff] [review]
Stop returning things for non-plug-in MIME types from the navigator.mimeTypes getter
> nsMimeType::GetEnabledPlugin() const
> {
>- if (!mPluginElement || !mPluginElement->PluginTag()->IsEnabled()) {
>+ if (!mPluginElement->PluginTag()->IsEnabled()) {
I wouldn't mind keeping the null check just for the sake of missing unlink
Attachment #8732690 -
Flags: review?(bugs) → review+
Comment 21•9 years ago
|
||
Comment 22•9 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #19)
> > navigator.mimeTypes["application/msword"].enabledPlugin
>
> Returns null, of course. ;)
Raises an interesting question: if you at some point did have a plugin that told Firefox it would handle application/msword, and the plugin is no longer installed - what happens to navigator.mimeType? Is it "live", or more like a DB that remains cluttered when a plugin is uninstalled? Not something I have time to research right now..
> > I have no such mimeType registered in my Firefox
>
> Try navigator.mimeTypes["text/html"]? Also, what happens if you try to
> actually open an application/msword thing? Is an application suggested in
> the dialog that comes up?
If I download Word-documents, Fx suggests LibreOffice. I checked the MIME type, it's correct.
> > so I assume that some Word/MSOffice viewer plug-in has snuck into your instance
>
> Most definitely not.
Never ever? What happens on a clean profile? ;)
Anyway, I'm sure you agree in principle that it's somewhere between unpractical and undoable to really create a mimeTypes entry for every single file type some software on the machine can handle - not to mention that it would be a bad fingerprinting risk..
Assignee | ||
Comment 23•9 years ago
|
||
> and the plugin is no longer installed - what happens to navigator.mimeType?
We basically cache the info in MimeTypeArray on a per-page basis. So if you uninstall (or just disable), the value of .enabledPlugin will go null, afaict, but the entry will still be there for that page. A new pageload should get a MimeTypeArray without that entry.
> If I download Word-documents, Fx suggests LibreOffice. I checked the MIME type, it's correct.
Huh. Weird...
> Never ever? What happens on a clean profile? ;)
In a clean profile, on Mac, in the console:
navigator.mimeTypes["application/msword"]
MimeType { description: "", enabledPlugin: null, suffixes: "", type: "application/msword" }
> I'm sure you agree in principle that it's somewhere between unpractical and undoable to
> really create a mimeTypes entry for every single file type some software on the machine can handle
Well. The non-plugin ones are created lazily when you ask via the named getter and we find that either the OS has an application registered for the type or we do in mimeTypes.rdf. Otherwise the Android behavior would be totally impossible.
But I certainly agree we should drop the non-plugin bits from the list here. I mean, I wrote and landed a patch to do that.... ;)
Comment 24•9 years ago
|
||
bugherder |
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
status-firefox48:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla48
Would it be worth uplifting this patch to ship it sooner? As far as I can tell, all versions back to at least 36 are affected.
Flags: needinfo?(bzbarsky)
Assignee | ||
Comment 26•9 years ago
|
||
That's a call for the Android folks to make. If we _do_ uplift, I think we should uplift Android-only. The risk does not justify the (nonexistent) reward for other platforms.
Flags: needinfo?(bzbarsky)
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•