Changeset 135507 in webkit


Ignore:
Timestamp:
Nov 22, 2012 5:23:28 AM (11 years ago)
Author:
allan.jensen@digia.com
Message:

[Qt] Lookup mimetypes using QMimeDatabase
https://bugs.webkit.org/show_bug.cgi?id=102667

Reviewed by Simon Hausmann.

The Qt backend of MIMETypeRegistry now looks up using QMimeDatabase.

  • loader/archive/ArchiveFactory.cpp:

(WebCore::archiveMIMETypes):

Also map the preferred freedesktop mimetype for MIME archives to MIME archive constructor.

  • platform/MIMETypeRegistry.cpp:

(WebCore::MIMETypeRegistry::getNormalizedMIMEType):

  • platform/qt/MIMETypeRegistryQt.cpp:

(WebCore::MIMETypeRegistry::getMIMETypeForExtension):
(WebCore::MIMETypeRegistry::getMIMETypeForPath):
(WebCore::MIMETypeRegistry::getNormalizedMIMEType):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r135503 r135507  
     12012-11-22  Allan Sandfeld Jensen  <allan.jensen@digia.com>
     2
     3        [Qt] Lookup mimetypes using QMimeDatabase
     4        https://bugs.webkit.org/show_bug.cgi?id=102667
     5
     6        Reviewed by Simon Hausmann.
     7
     8        The Qt backend of MIMETypeRegistry now looks up using QMimeDatabase.
     9
     10        * loader/archive/ArchiveFactory.cpp:
     11        (WebCore::archiveMIMETypes):
     12            Also map the preferred freedesktop mimetype for MIME archives to MIME archive constructor.
     13        * platform/MIMETypeRegistry.cpp:
     14        (WebCore::MIMETypeRegistry::getNormalizedMIMEType):
     15        * platform/qt/MIMETypeRegistryQt.cpp:
     16        (WebCore::MIMETypeRegistry::getMIMETypeForExtension):
     17        (WebCore::MIMETypeRegistry::getMIMETypeForPath):
     18        (WebCore::MIMETypeRegistry::getNormalizedMIMEType):
     19
    1202012-11-22  Cosmin Truta  <ctruta@rim.com>
    221
  • trunk/Source/WebCore/loader/archive/ArchiveFactory.cpp

    r130612 r135507  
    7171#if PLATFORM(GTK)
    7272    mimeTypes.set("message/rfc822", archiveFactoryCreate<MHTMLArchive>);
     73#elif PLATFORM(QT)
     74    mimeTypes.set("application/x-mimearchive", archiveFactoryCreate<MHTMLArchive>);
    7375#endif
    7476#endif
  • trunk/Source/WebCore/platform/MIMETypeRegistry.cpp

    r131826 r135507  
    492492}
    493493
     494#if !PLATFORM(QT)
    494495String MIMETypeRegistry::getMIMETypeForPath(const String& path)
    495496{
     
    501502            return result;
    502503    }
    503     return "application/octet-stream";
    504 }
     504    return defaultMIMEType();
     505}
     506#endif
    505507
    506508bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
     
    638640    return defaultMIMEType;
    639641}
     642
     643#if !PLATFORM(QT) && !PLATFORM(BLACKBERRY)
     644String MIMETypeRegistry::getNormalizedMIMEType(const String& mimeType)
     645{
     646    return mimeType;
     647}
     648#endif
    640649
    641650#if PLATFORM(BLACKBERRY)
     
    697706    return *mimeTypeMap;
    698707}
    699 #endif
    700708
    701709String MIMETypeRegistry::getNormalizedMIMEType(const String& mimeType)
    702710{
    703 #if PLATFORM(BLACKBERRY)
    704711    MIMETypeAssociationMap::const_iterator it = mimeTypeAssociationMap().find(mimeType);
    705712
    706713    if (it != mimeTypeAssociationMap().end())
    707714        return it->value;
    708 #endif
     715
    709716    return mimeType;
    710717}
    711 
     718#endif
    712719
    713720} // namespace WebCore
  • trunk/Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp

    r134214 r135507  
    3030#include "MIMETypeRegistry.h"
    3131
     32#include <QMimeDatabase>
    3233#include <wtf/Assertions.h>
    3334#include <wtf/MainThread.h>
     
    3536namespace WebCore {
    3637
    37 struct ExtensionMap {
    38     const char* extension;
    39     const char* mimeType;
    40 };
    41 
    42 static const ExtensionMap extensionMap[] = {
    43     { "bmp", "image/bmp" },
    44     { "css", "text/css" },
    45     { "gif", "image/gif" },
    46     { "html", "text/html" },
    47     { "htm", "text/html" },
    48     { "ico", "image/x-icon" },
    49     { "jpeg", "image/jpeg" },
    50     { "jpg", "image/jpeg" },
    51     { "js", "application/x-javascript" },
    52     { "mng", "video/x-mng" },
    53     { "mp4", "video/mp4" },
    54     { "m4v", "video/mp4" },
    55     { "m4a", "audio/x-m4a" },
    56     { "mht", "multipart/related" },
    57     { "mhtml", "multipart/related" },
    58     { "mp3", "audio/mp3" },
    59     { "ogv", "video/ogg" },
    60     { "oga", "audio/ogg" },
    61     { "ogm", "audio/ogg" },
    62     { "ogg", "audio/ogg" },
    63     { "webm", "video/webm" },
    64     { "webm", "audio/webm" },
    65     { "wav", "audio/wav" },
    66     { "mov", "video/quicktime" },
    67     { "pbm", "image/x-portable-bitmap" },
    68     { "pgm", "image/x-portable-graymap" },
    69     { "pdf", "application/pdf" },
    70     { "png", "image/png" },
    71     { "ppm", "image/x-portable-pixmap" },
    72     { "rss", "application/rss+xml" },
    73     { "svg", "image/svg+xml" },
    74     { "text", "text/plain" },
    75     { "tif", "image/tiff" },
    76     { "tiff", "image/tiff" },
    77     { "txt", "text/plain" },
    78     { "xbm", "image/x-xbitmap" },
    79     { "xml", "text/xml" },
    80     { "xpm", "image/x-xpm" },
    81     { "xsl", "text/xsl" },
    82     { "xhtml", "application/xhtml+xml" },
    83     { "wml", "text/vnd.wap.wml" },
    84     { "wmlc", "application/vnd.wap.wmlc" },
    85     { 0, 0 }
    86 };
    87 
    8838String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
    8939{
    90     ASSERT(isMainThread());
     40    // QMimeDatabase lacks the ability to query by extension alone, so we create a fake filename to lookup.
     41    const QString filename = QStringLiteral("filename.") + QString(ext.lower());
    9142
    92     String s = ext.lower();
    93 
    94     const ExtensionMap *e = extensionMap;
    95     while (e->extension) {
    96         if (s == e->extension)
    97             return e->mimeType;
    98         ++e;
    99     }
     43    QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
     44    if (mimeType.isValid() && !mimeType.isDefault())
     45        return mimeType.name();
    10046
    10147    return String();
     48}
     49
     50String MIMETypeRegistry::getMIMETypeForPath(const String& path)
     51{
     52    QMimeType type = QMimeDatabase().mimeTypeForFile(path, QMimeDatabase::MatchExtension);
     53    if (type.isValid())
     54        return type.name();
     55
     56    return defaultMIMEType();
     57}
     58
     59String MIMETypeRegistry::getNormalizedMIMEType(const String& mimeTypeName)
     60{
     61    // This looks up the mime type object by preferred name or alias, and returns the preferred name.
     62    QMimeType mimeType = QMimeDatabase().mimeTypeForName(mimeTypeName);
     63    if (mimeType.isValid() && !mimeType.isDefault())
     64        return mimeType.name();
     65
     66    return mimeTypeName;
    10267}
    10368
Note: See TracChangeset for help on using the changeset viewer.