Bug 115487 - Move knowledge of PDF/PostScript MIME types into MIMETypeRegistry
Summary: Move knowledge of PDF/PostScript MIME types into MIMETypeRegistry
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Horton
URL:
Keywords:
Depends on:
Blocks: 75790
  Show dependency treegraph
 
Reported: 2013-05-01 13:12 PDT by Tim Horton
Modified: 2013-05-01 17:39 PDT (History)
7 users (show)

See Also:


Attachments
patch (16.81 KB, patch)
2013-05-01 13:17 PDT, Tim Horton
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Horton 2013-05-01 13:12:50 PDT
Right now we have this list of MIME types ineffectively and incorrectly duplicated in multiple places, and it's only going to get worse.

WebCore has a place to put this knowledge, so let's do it!
Comment 1 Tim Horton 2013-05-01 13:17:32 PDT
Created attachment 200237 [details]
patch
Comment 2 Darin Adler 2013-05-01 13:43:58 PDT
Comment on attachment 200237 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=200237&action=review

> Source/WebCore/platform/MIMETypeRegistry.cpp:361
> +    static const char* types[] = {
> +        "application/pdf",
> +        "text/pdf",
> +        "application/postscript",
> +    };

Why is this marked static? Since the function is called only once, I don’t know if that’s beneficial. Also could make this more const, const char* const, but that probably doesn’t matter; it’s usually not important if a local variable is const.

> Source/WebKit2/UIProcess/WebFrameProxy.cpp:118
> -    return WebContext::pdfAndPostScriptMIMETypes().contains(m_MIMEType);
> +    return MIMETypeRegistry::isPDFOrPostScriptMIMEType(m_MIMEType);

Old code was case folding, but the new function is not case folding. Is that OK? Does something ensure that the letters in m_MIMEType are lowercase?

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:559
> -        if ((parameters.mimeType == "application/pdf" || parameters.mimeType == "application/postscript")
> -            || (parameters.mimeType.isEmpty() && (path.endsWith(".pdf", false) || path.endsWith(".ps", false)))) {
> +        if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(parameters.mimeType) || (parameters.mimeType.isEmpty() && (path.endsWith(".pdf", false) || path.endsWith(".ps", false)))) {

Old code was case folding, but the new function is not case folding. Is that OK? Can someone pass WebPage::createPlugin a MIME type that contains uppercase letters?
Comment 3 Tim Horton 2013-05-01 15:46:30 PDT
(In reply to comment #2)
> (From update of attachment 200237 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=200237&action=review
> 
> > Source/WebCore/platform/MIMETypeRegistry.cpp:361
> > +    static const char* types[] = {
> > +        "application/pdf",
> > +        "text/pdf",
> > +        "application/postscript",
> > +    };
> 
> Why is this marked static? Since the function is called only once, I don’t know if that’s beneficial. Also could make this more const, const char* const, but that probably doesn’t matter; it’s usually not important if a local variable is const.

Good points.

> > Source/WebKit2/UIProcess/WebFrameProxy.cpp:118
> > -    return WebContext::pdfAndPostScriptMIMETypes().contains(m_MIMEType);
> > +    return MIMETypeRegistry::isPDFOrPostScriptMIMEType(m_MIMEType);
> 
> Old code was case folding, but the new function is not case folding. Is that OK? Does something ensure that the letters in m_MIMEType are lowercase?

I *think* it's OK. I don't think anything guarantees that m_MIMEType is lowercase -- in our case, it comes straight from NSURLResponse, never getting lowercased along the way. I have no idea if NSURLResponse guarantees lower-casing, but even if it did, I can't make a guarantee about other platforms.

Here's why I'm not horribly worried, though: everything else that compares against m_MIMEType compares in a case sensitive way (isDisplayingStandaloneImageDocument and isDisplayingMarkupDocument, specifically).

Do you think we should explicitly lowercase the characters earlier on?

> > Source/WebKit2/WebProcess/WebPage/WebPage.cpp:559
> > -        if ((parameters.mimeType == "application/pdf" || parameters.mimeType == "application/postscript")
> > -            || (parameters.mimeType.isEmpty() && (path.endsWith(".pdf", false) || path.endsWith(".ps", false)))) {
> > +        if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(parameters.mimeType) || (parameters.mimeType.isEmpty() && (path.endsWith(".pdf", false) || path.endsWith(".ps", false)))) {
> 
> Old code was case folding, but the new function is not case folding. Is that OK? Can someone pass WebPage::createPlugin a MIME type that contains uppercase letters?

WebPageProxy::FindPlugin (called from WebPage::createPlugin and handed that same MIME type) also compares in a case-sensitive way, so I think things would already be broken. In addition, before it gets to WebPage::createPlugin, it's compared in a case-sensitive way (in various places in SubframeLoader).

It looks like createPlugin eventually gets its mimeType argument from HTMLEmbedElement and HTMLObjectElement. HTMLEmbedElement explicitly lower-cases the MIME type. HTMLObjectElement appears to also lower case its MIMETypes *except* if they come from a data-URL. So that case might be broken, but it's already broken.

But, again, maybe we should improve the existing situation? Or maybe that should be a separate bug.
Comment 4 Tim Horton 2013-05-01 15:57:03 PDT
I think I'll make mine continue to be case-folding just to be safe, and file a fix me to investigate the other cases (especially the object-data-url case).
Comment 5 Tim Horton 2013-05-01 15:57:14 PDT
Err, leave a fixme and file a bug.
Comment 6 Tim Horton 2013-05-01 16:27:33 PDT
(In reply to comment #4)
> I think I'll make mine continue to be case-folding just to be safe, and file a fix me to investigate the other cases (especially the object-data-url case).

I'm actually just going to fix that, since it's easy (and is actually broken).
Comment 7 Tim Horton 2013-05-01 16:27:41 PDT
(In reply to comment #6)
> (In reply to comment #4)
> > I think I'll make mine continue to be case-folding just to be safe, and file a fix me to investigate the other cases (especially the object-data-url case).
> 
> I'm actually just going to fix that, since it's easy (and is actually broken).

https://bugs.webkit.org/show_bug.cgi?id=115494
Comment 8 Tim Horton 2013-05-01 16:34:20 PDT
(In reply to comment #4)
> I think I'll make mine continue to be case-folding just to be safe

Actually, I think this is wrong. We should fix cases where case-insensitive MIME types make it into WebCore, because there fewer of those than there are places that do The Wrong Thing(TM) and compare to lower-case strings.

I'm going to leave the patch as is, but we should keep looking out for things like https://bugs.webkit.org/show_bug.cgi?id=115494.

Thanks, Darin!
Comment 9 Tim Horton 2013-05-01 16:34:43 PDT
(In reply to comment #8)
> (In reply to comment #4)
> > I think I'll make mine continue to be case-folding just to be safe
> 
> Actually, I think this is wrong. We should fix cases where case-insensitive MIME types make it into

s/case-insensitive/non-lower-cased/
Comment 10 Tim Horton 2013-05-01 16:46:14 PDT
http://trac.webkit.org/changeset/149464
Comment 11 Darin Adler 2013-05-01 17:07:11 PDT
(In reply to comment #8)
> We should fix cases where case-insensitive MIME types make it into WebCore, because there fewer of those than there are places that do The Wrong Thing(TM) and compare to lower-case strings.

OK.
Comment 12 Darin Adler 2013-05-01 17:08:05 PDT
Comment on attachment 200237 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=200237&action=review

>>> Source/WebKit2/UIProcess/WebFrameProxy.cpp:118
>>> +    return MIMETypeRegistry::isPDFOrPostScriptMIMEType(m_MIMEType);
>> 
>> Old code was case folding, but the new function is not case folding. Is that OK? Does something ensure that the letters in m_MIMEType are lowercase?
> 
> I *think* it's OK. I don't think anything guarantees that m_MIMEType is lowercase -- in our case, it comes straight from NSURLResponse, never getting lowercased along the way. I have no idea if NSURLResponse guarantees lower-casing, but even if it did, I can't make a guarantee about other platforms.
> 
> Here's why I'm not horribly worried, though: everything else that compares against m_MIMEType compares in a case sensitive way (isDisplayingStandaloneImageDocument and isDisplayingMarkupDocument, specifically).
> 
> Do you think we should explicitly lowercase the characters earlier on?

I do not think that NSURLResponse guarantees lower-casing. We should figure out where to put the call to lower() to fix that.
Comment 13 Tim Horton 2013-05-01 17:09:11 PDT
(In reply to comment #12)
> (From update of attachment 200237 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=200237&action=review
> > Do you think we should explicitly lowercase the characters earlier on?
> 
> I do not think that NSURLResponse guarantees lower-casing. We should figure out where to put the call to lower() to fix that.

Agreed. Ideally, somewhere far enough away from NSURLResponse that it works for other platforms too.
Comment 14 Tim Horton 2013-05-01 17:39:36 PDT
(In reply to comment #12)
> (From update of attachment 200237 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=200237&action=review
> 
> >>> Source/WebKit2/UIProcess/WebFrameProxy.cpp:118
> >>> +    return MIMETypeRegistry::isPDFOrPostScriptMIMEType(m_MIMEType);
> >> 
> >> Old code was case folding, but the new function is not case folding. Is that OK? Does something ensure that the letters in m_MIMEType are lowercase?
> > 
> > I *think* it's OK. I don't think anything guarantees that m_MIMEType is lowercase -- in our case, it comes straight from NSURLResponse, never getting lowercased along the way. I have no idea if NSURLResponse guarantees lower-casing, but even if it did, I can't make a guarantee about other platforms.
> > 
> > Here's why I'm not horribly worried, though: everything else that compares against m_MIMEType compares in a case sensitive way (isDisplayingStandaloneImageDocument and isDisplayingMarkupDocument, specifically).
> > 
> > Do you think we should explicitly lowercase the characters earlier on?
> 
> I do not think that NSURLResponse guarantees lower-casing. We should figure out where to put the call to lower() to fix that.

Filed https://bugs.webkit.org/show_bug.cgi?id=115501.