Bug 115487

Summary: Move knowledge of PDF/PostScript MIME types into MIMETypeRegistry
Product: WebKit Reporter: Tim Horton <thorton>
Component: WebCore Misc.Assignee: Tim Horton <thorton>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, ap, commit-queue, darin, esprehn+autocc, sam, simon.fraser
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 75790    
Attachments:
Description Flags
patch darin: review+

Tim Horton
Reported 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!
Attachments
patch (16.81 KB, patch)
2013-05-01 13:17 PDT, Tim Horton
darin: review+
Tim Horton
Comment 1 2013-05-01 13:17:32 PDT
Darin Adler
Comment 2 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?
Tim Horton
Comment 3 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.
Tim Horton
Comment 4 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).
Tim Horton
Comment 5 2013-05-01 15:57:14 PDT
Err, leave a fixme and file a bug.
Tim Horton
Comment 6 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).
Tim Horton
Comment 7 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
Tim Horton
Comment 8 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!
Tim Horton
Comment 9 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/
Tim Horton
Comment 10 2013-05-01 16:46:14 PDT
Darin Adler
Comment 11 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.
Darin Adler
Comment 12 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.
Tim Horton
Comment 13 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.
Tim Horton
Comment 14 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.
Note You need to log in before you can comment on or make changes to this bug.