Title: [136669] trunk/Source/WebCore
Revision
136669
Author
[email protected]
Date
2012-12-05 04:37:27 -0800 (Wed, 05 Dec 2012)

Log Message

[Qt] Don't rely on QMimeDatabase for essential MIME types
https://bugs.webkit.org/show_bug.cgi?id=103865

Based on patch by Pierre Rossi.
Reviewed by Jocelyn Turcotte.

Extend the short static list to also include MIME types essential to WebKit,
and detect these first before checking the system mimedatabase.

* platform/qt/MIMETypeRegistryQt.cpp:
(WebCore::MIMETypeRegistry::getMIMETypeForExtension):
(WebCore::MIMETypeRegistry::getMIMETypeForPath):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (136668 => 136669)


--- trunk/Source/WebCore/ChangeLog	2012-12-05 12:32:00 UTC (rev 136668)
+++ trunk/Source/WebCore/ChangeLog	2012-12-05 12:37:27 UTC (rev 136669)
@@ -1,3 +1,18 @@
+2012-12-05  Allan Sandfeld Jensen  <[email protected]>
+
+        [Qt] Don't rely on QMimeDatabase for essential MIME types
+        https://bugs.webkit.org/show_bug.cgi?id=103865
+
+        Based on patch by Pierre Rossi.
+        Reviewed by Jocelyn Turcotte.
+
+        Extend the short static list to also include MIME types essential to WebKit,
+        and detect these first before checking the system mimedatabase.
+
+        * platform/qt/MIMETypeRegistryQt.cpp:
+        (WebCore::MIMETypeRegistry::getMIMETypeForExtension):
+        (WebCore::MIMETypeRegistry::getMIMETypeForPath):
+
 2012-12-05  Zoltan Herczeg  <[email protected]>
 
         Optimize ColorMatrix filter

Modified: trunk/Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp (136668 => 136669)


--- trunk/Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp	2012-12-05 12:32:00 UTC (rev 136668)
+++ trunk/Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp	2012-12-05 12:37:27 UTC (rev 136669)
@@ -41,21 +41,41 @@
     const char* mimeType;
 };
 
-// This is a short list of extensions not recognized by the freedesktop shared mimetype database 1.0.
+// This is a short list of extensions that are either not recognized by the freedesktop shared mimetype database 1.0,
+// or too essential for QtWebKit that we can not allow a user configuration to potentially override it.
+// Any extension that has to be recognized for the layout-tests to run should be added here.
 static const ExtensionMap extensionMap[] = {
-    { "mht", ".mht", "application/x-mimearchive" },
-    { "mhtml", ".mhtml", "application/x-mimearchive" },
-    { "text", ".text", "text/plain" },
-    { "wmlc", ".wmlc", "application/vnd.wap.wmlc" },
+    { "htm", ".htm", "text/html" },
+    { "html", ".html", "text/html" },
+    { "js", ".js", "application/_javascript_" },
+    { "mht", ".mht", "application/x-mimearchive" }, // Not in shared mimetype database
+    { "mhtml", ".mhtml", "application/x-mimearchive" }, // Not in shared mimetype database
+    { "svg", ".svg", "image/svg+xml" },
+    { "text", ".text", "text/plain" }, // Not in shared mimetype database
+    { "txt", ".txt", "text/plain"},
+    { "wmlc", ".wmlc", "application/vnd.wap.wmlc" }, // Not in shared mimetype database
+    { "xht", ".xht", "application/xhtml+xml" },
+    { "xhtml", ".xhtml", "application/xhtml+xml" },
+    { "xsl", ".xsl", "text/xsl" },
     { 0, 0, 0 }
 };
 
 String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
 {
+    String suffix = ext.lower();
+    const ExtensionMap *e = extensionMap;
+    while (e->extension) {
+        if (suffix == e->extension)
+            return e->mimeType;
+        ++e;
+    }
+
     // QMimeDatabase lacks the ability to query by extension alone, so we create a fake filename to lookup.
-    String suffix = ext.lower();
     const QString filename = QStringLiteral("filename.") + QString(suffix);
 
+    // FIXME: We should get all the matched mimetypes with mimeTypesForFileName, and prefer one we support.
+    // But initializeSupportedImageMIMETypes will first have to stop using getMIMETypeForExtension, or we
+    // would be checking against an uninitialized set of supported mimetypes.
     QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
     if (mimeType.isValid() && !mimeType.isDefault()) {
         // getMIMETypeForExtension is used for preload mimetype check, so image looking files can not be loaded as anything but images.
@@ -65,29 +85,23 @@
         return mimeType.name();
     }
 
-    const ExtensionMap *e = extensionMap;
-    while (e->extension) {
-        if (suffix == e->extension)
-            return e->mimeType;
-        ++e;
-    }
-
     return String();
 }
 
 String MIMETypeRegistry::getMIMETypeForPath(const String& path)
 {
-    QMimeType type = QMimeDatabase().mimeTypeForFile(path, QMimeDatabase::MatchExtension);
-    if (type.isValid() && !type.isDefault())
-        return type.name();
-
     const ExtensionMap *e = extensionMap;
     while (e->extension) {
-        if (path.endsWith(e->dotExtension))
+        if (path.endsWith(e->dotExtension, /* caseSensitive */ false))
             return e->mimeType;
         ++e;
     }
 
+    // FIXME: See comment in getMIMETypeForExtension.
+    QMimeType type = QMimeDatabase().mimeTypeForFile(path, QMimeDatabase::MatchExtension);
+    if (type.isValid() && !type.isDefault())
+        return type.name();
+
     return defaultMIMEType();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to