Bug 103865 - [Qt] Don't rely on QMimeDatabase for essential MIME types
Summary: [Qt] Don't rely on QMimeDatabase for essential MIME types
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Pierre Rossi
URL:
Keywords:
Depends on:
Blocks: 103747
  Show dependency treegraph
 
Reported: 2012-12-03 00:46 PST by Pierre Rossi
Modified: 2012-12-05 04:38 PST (History)
3 users (show)

See Also:


Attachments
Patch (2.11 KB, patch)
2012-12-03 00:55 PST, Pierre Rossi
no flags Details | Formatted Diff | Diff
Patch (4.79 KB, patch)
2012-12-04 01:16 PST, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff
Patch (4.87 KB, patch)
2012-12-05 02:36 PST, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pierre Rossi 2012-12-03 00:46:20 PST
[Qt] Don't rely on QMimeDatabase for well-known extension to MIME type mapping.
Comment 1 Pierre Rossi 2012-12-03 00:55:45 PST
Created attachment 177202 [details]
Patch
Comment 2 Allan Sandfeld Jensen 2012-12-03 02:14:55 PST
Comment on attachment 177202 [details]
Patch

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

> Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp:87
>  String MIMETypeRegistry::getMIMETypeForPath(const String& path)
>  {
> +    size_t pos = path.reverseFind('.');
> +    if (pos != notFound) {
> +        String extension = path.substring(pos + 1);
> +        String result = getWellKnownMIMETypeForExtension(extension);
> +        if (result.length())
> +            return result;
> +    }
> +

Why is the change in getMIMETypeForPath? it is getMIMETypeForExtension that is used to determine if we should/can load content.
Comment 3 Allan Sandfeld Jensen 2012-12-03 02:18:13 PST
Btw, I think we should add all the aliases of the supported mime-types so that we don't end up in that situation.
Comment 4 Pierre Rossi 2012-12-03 04:39:29 PST
(In reply to comment #2)
> (From update of attachment 177202 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=177202&action=review
> 
> > Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp:87
> >  String MIMETypeRegistry::getMIMETypeForPath(const String& path)
> >  {
> > +    size_t pos = path.reverseFind('.');
> > +    if (pos != notFound) {
> > +        String extension = path.substring(pos + 1);
> > +        String result = getWellKnownMIMETypeForExtension(extension);
> > +        if (result.length())
> > +            return result;
> > +    }
> > +
> 
> Why is the change in getMIMETypeForPath? it is getMIMETypeForExtension that is used to determine if we should/can load content.

It's used in QNetworkReplyHandler::sendResponseIfNeeded when loading local files.
Comment 5 Allan Sandfeld Jensen 2012-12-04 01:01:04 PST
It seems some tools used for creating associating mimetypes to application will dynamical invent new mimetypes such as application/x-extension-html, which can confuse the mimedatabase because we only rely on the first match. 

We need to ensure users can not shoot themselves this hard with the basic mimetypes. For images and other types it can be potentially useful, but for html and other essential types it can only break stuff.
Comment 6 Allan Sandfeld Jensen 2012-12-04 01:16:56 PST
Created attachment 177443 [details]
Patch

A condensed version of Pierre's patch only detecting the essential mimetypes and doing it for both getMimetype functions
Comment 7 Jocelyn Turcotte 2012-12-05 02:06:55 PST
Comment on attachment 177443 [details]
Patch

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

> Source/WebCore/ChangeLog:9
> +        Extend the short static list to also include MIME types essential WebKit,

to WebKit

> Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp:59
> +    { "xls", ".xls", "text/xsl" },

I didn't know we supported Excel sheets with WebKit :P

> Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp:76
> +    // FIXME: We should get all the matched mimetypes with mimeTypesForFileName, and prefer one we support.

mimeTypesForFileName -> mimeTypesForFile?

> Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp:77
> +    // But initializeSupportedImageMIMETypes will first have to stop using getMIMETypeForExtension.

Could you write why? I don't have enough context to understand this part.
Comment 8 Allan Sandfeld Jensen 2012-12-05 02:28:37 PST
(In reply to comment #7)
> (From update of attachment 177443 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=177443&action=review
> > Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp:76
> > +    // FIXME: We should get all the matched mimetypes with mimeTypesForFileName, and prefer one we support.
> 
> mimeTypesForFileName -> mimeTypesForFile?
> 
Well, that is actually the name of this particular method in QMimeDatabase ;)

> > Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp:77
> > +    // But initializeSupportedImageMIMETypes will first have to stop using getMIMETypeForExtension.
> 
> Could you write why? I don't have enough context to understand this part.

Because to tell if a mime-type is supported we have to check against the supported mime-types, but we can not do that while we are still in the process of initializing the supported mime-types.
Comment 9 Allan Sandfeld Jensen 2012-12-05 02:36:14 PST
Created attachment 177707 [details]
Patch
Comment 10 Jocelyn Turcotte 2012-12-05 03:40:10 PST
Comment on attachment 177707 [details]
Patch

(In reply to comment #8)
> Well, that is actually the name of this particular method in QMimeDatabase ;)

Ah! I see what you mean, sorry about that.
Comment 11 WebKit Review Bot 2012-12-05 04:38:22 PST
Comment on attachment 177707 [details]
Patch

Clearing flags on attachment: 177707

Committed r136669: <http://trac.webkit.org/changeset/136669>
Comment 12 WebKit Review Bot 2012-12-05 04:38:25 PST
All reviewed patches have been landed.  Closing bug.