Closed Bug 73847 Opened 24 years ago Closed 23 years ago

Need a way of determining the MIME type of the current document from chrome JS

Categories

(SeaMonkey :: UI Design, defect)

defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

Details

Attachments

(2 files, 2 obsolete files)

Some context menu things could be improved if we had a way of telling when we are viewing an image URL. The best way to do this is to look at the content-type. Also, page info could use being able to tell what the content-type of the current document is (since we will be trying to show it, like NS 4.x). The MIME service just looks at the extension of the URL, and so is unreliable. This could possibly be done by making the nsIDocument or nsIHTMLDocument interfaces scriptable and then calling the GetContentType methods of those interfaces... but if there is a better way of doing it, I'm all for it.
Blocks: 52730, autoresize
OS: Linux → All
Hardware: PC → All
Blocks: 67544
The way it's done in the new page info stuff reports whatever the server returns in the HTTP headers, and doesn't base if off of the file name. As an example, grab a copy of my latest work from db48x.hypermart.net/pageinfo/, and check out something from lxr, it does weird stuff to the mime type :). db48x
Daniel, Unless I am completely missing something, you use nsIMIMEService to get the mime type... this just looks at the extension.
Blocks: 75338
could bug 46655 be related to this?
Only in that 46655 also uses the MIME service...
No longer blocks: 52730
Blocks: 92901
Blocks: 92902
mscott: any idea when you might get to this? It's blocking several bugs for bits of UI that need to know what sort of content we are viewing. Gerv
Attached patch Patch to fix this (obsolete) — Splinter Review
ccing jst for comments (he seems to be fairly well represented in the code I'm touching). Not sure who should be doing r= for this.... The fact that nsIDocument declares GetContentType as |const| sucks. Otherwise I could implement all this in nsDocument.cpp....
Assignee: mscott → bzbarsky
um. really ccing jst for review. :)
Keywords: patch, review
ccing vidur and peterl as well. Comments?
This bothers me a bit since this will block global variables named 'contentType' in scripts on the web from bing accessed from event handlers within the document. I'm not sure that this will cause enough problems for us to worry about, and I don't have a better suggestion for the name of this property, so I'm leaning towards letting this in. As for the patch: - You will have merge conflicts when you update, I changed nsIDOMNSDocument.idl today and it looks like we'll conflict, so look out for that. - Make add mContentType to nsDocument in stead of adding it to both nsHTMLDocument and nsXMLDocument, and make it an nsString, not an nsString*. This will let you move GetContentType() into nsDocument too. - Why add nsIHTMLDocument::SetContentType()? I don't see that called anywhere other than from within classes that inherit nsIHTMLDocument, which will inherit nsHTMLDocument which means they can just set mContentType (which is trivial once you make it a nsString and not a nsString*). - Use FindCharInReadable() to find the ';' you're looking for in a few places: + nsString::const_iterator start, end; + contentType.BeginReading(start); + contentType.EndReading(end); + + if(FindCharInReadable(';', start, end)) { + SetContentType(Substring(start, iter)); + } else { + SetContentType(contentType); + } Fix that and I'll have one more look.
Er, make that: + SetContentType(Substring(start, iter));
No, I meant: + SetContentType(Substring(start, end));
Attached patch updated patch. (obsolete) — Splinter Review
Attachment #50159 - Attachment is obsolete: true
Attachment #50287 - Attachment is obsolete: true
- In nsRange.cpp, there's no need for the if (document) check, do_QueryInterface() is null safe. Take out the if check and remove one of the text/html assignments... - In nsRootAccessible.cpp, same as above, no need for the if (mDocument) before do_QueryInterface(). - Why add #include "nsIDOMNSDocument.h" to nsRootAccessible.h and not nsRootAccessible.cpp, it's not needed in the header file, right? Fix those when checking in, sr=jst
Attachment #50329 - Flags: superreview+
vidur? peterl? Would you care to r=?
Blocks: 88918
Comment on attachment 50433 [details] [diff] [review] Updated patch. jst's changes and fix my mistyping of CopyASCIItoUCS2 r=peterv
Attachment #50433 - Flags: review+
checked in
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
rs vrfy --unless there are particular places you'd like me to test with!
Status: RESOLVED → VERIFIED
Blocks: 122144
Product: Core → Mozilla Application Suite
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: