Changeset 69825 in webkit


Ignore:
Timestamp:
Oct 14, 2010 5:27:26 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-09-27 Dawit Alemayehu <adawit@kde.org>

Reviewed by Andreas Kling.

[Qt] Added functions for obtaining and checking the supported content types.
http://webkit.org/b/37880

  • Api/qwebpage.cpp: (extractContentTypeFromHash): (extractContentTypeFromPluginVector): (QWebPage::supportedContentTypes): (QWebPage::supportsContentType):
  • tests/qwebpage/tst_qwebpage.cpp: (tst_QWebPage::supportedContentType):
Location:
trunk/WebKit/qt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/qt/Api/qwebpage.cpp

    r69331 r69825  
    9494#include "WorkerThread.h"
    9595#include "wtf/Threading.h"
     96#include "MIMETypeRegistry.h"
     97#include "PluginDatabase.h"
     98#include "PluginPackage.h"
    9699
    97100#include <QApplication>
     
    20202023}
    20212024
     2025static void extractContentTypeFromHash(const HashSet<String>& types, QStringList* list)
     2026{
     2027    if (!list)
     2028        return;
     2029
     2030    HashSet<String>::const_iterator endIt = types.end();
     2031    for (HashSet<String>::const_iterator it = types.begin(); it != endIt; ++it)
     2032        *list << *it;
     2033}
     2034
     2035static void extractContentTypeFromPluginVector(const Vector<PluginPackage*>& plugins, QStringList* list)
     2036{
     2037    if (!list)
     2038        return;
     2039
     2040    for (unsigned int i = 0; i < plugins.size(); ++i) {
     2041        MIMEToDescriptionsMap::const_iterator map_it = plugins[i]->mimeToDescriptions().begin();
     2042        MIMEToDescriptionsMap::const_iterator map_end = plugins[i]->mimeToDescriptions().end();
     2043        for (; map_it != map_end; ++map_it)
     2044            *list << map_it->first;
     2045    }
     2046}
     2047
     2048/*!
     2049 *  Returns the list of all content types supported by QWebPage.
     2050 */
     2051QStringList QWebPage::supportedContentTypes() const
     2052{
     2053    QStringList mimeTypes;
     2054
     2055    extractContentTypeFromHash(MIMETypeRegistry::getSupportedImageMIMETypes(), &mimeTypes);
     2056    extractContentTypeFromHash(MIMETypeRegistry::getSupportedNonImageMIMETypes(), &mimeTypes);
     2057    if (d->page->settings() && d->page->settings()->arePluginsEnabled())
     2058        extractContentTypeFromPluginVector(PluginDatabase::installedPlugins()->plugins(), &mimeTypes);
     2059
     2060    return mimeTypes;
     2061}
     2062
     2063/*!
     2064 *  Returns true if QWebPage can handle the given \a mimeType; otherwise, returns false.
     2065 */
     2066bool QWebPage::supportsContentType(const QString& mimeType) const
     2067{
     2068    const String type = mimeType.toLower();
     2069    if (MIMETypeRegistry::isSupportedImageMIMEType(type))
     2070        return true;
     2071
     2072    if (MIMETypeRegistry::isSupportedNonImageMIMEType(type))
     2073        return true;
     2074
     2075    if (d->page->settings() && d->page->settings()->arePluginsEnabled()
     2076        && PluginDatabase::installedPlugins()->isMIMETypeRegistered(type))
     2077        return true;
     2078
     2079    return false;
     2080}
     2081
    20222082static WebCore::FrameLoadRequest frameLoadRequest(const QUrl &url, WebCore::Frame *frame)
    20232083{
  • trunk/WebKit/qt/Api/qwebpage.h

    r69331 r69825  
    310310    void setUserPermission(QWebFrame* frame, PermissionDomain domain, PermissionPolicy policy);
    311311
     312    QStringList supportedContentTypes() const;
     313    bool supportsContentType(const QString& mimeType) const;
     314
    312315    enum Extension {
    313316        ChooseMultipleFilesExtension,
  • trunk/WebKit/qt/ChangeLog

    r69803 r69825  
     12010-09-27 Dawit Alemayehu  <adawit@kde.org>
     2
     3        Reviewed by Andreas Kling.
     4
     5        [Qt] Added functions for obtaining and checking the supported content types.
     6        http://webkit.org/b/37880
     7
     8        * Api/qwebpage.cpp:
     9        (extractContentTypeFromHash):
     10        (extractContentTypeFromPluginVector):
     11        (QWebPage::supportedContentTypes):
     12        (QWebPage::supportsContentType):
     13        * tests/qwebpage/tst_qwebpage.cpp:
     14        (tst_QWebPage::supportedContentType):
     15
    1162010-10-14  Sheriff Bot  <webkit.review.bot@gmail.com>
    217
     
    687702        (QWebSettings::QWebSettings):
    688703        * Api/qwebsettings.h:
    689 
    690704
    6917052010-09-23  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
  • trunk/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp

    r68760 r69825  
    4242#include <qwebsecurityorigin.h>
    4343#include <qwebview.h>
     44#include <qimagewriter.h>
    4445
    4546class EventSpy : public QObject, public QList<QEvent::Type>
     
    127128    void testStopScheduledPageRefresh();
    128129    void findText();
     130    void supportedContentType();
    129131   
    130132private:
     
    22042206}
    22052207
     2208struct ImageExtensionMap {
     2209    const char* extension;
     2210    const char* mimeType;
     2211};
     2212
     2213static const ImageExtensionMap extensionMap[] = {
     2214    { "bmp", "image/bmp" },
     2215    { "css", "text/css" },
     2216    { "gif", "image/gif" },
     2217    { "html", "text/html" },
     2218    { "htm", "text/html" },
     2219    { "ico", "image/x-icon" },
     2220    { "jpeg", "image/jpeg" },
     2221    { "jpg", "image/jpeg" },
     2222    { "js", "application/x-javascript" },
     2223    { "mng", "video/x-mng" },
     2224    { "pbm", "image/x-portable-bitmap" },
     2225    { "pgm", "image/x-portable-graymap" },
     2226    { "pdf", "application/pdf" },
     2227    { "png", "image/png" },
     2228    { "ppm", "image/x-portable-pixmap" },
     2229    { "rss", "application/rss+xml" },
     2230    { "svg", "image/svg+xml" },
     2231    { "text", "text/plain" },
     2232    { "tif", "image/tiff" },
     2233    { "tiff", "image/tiff" },
     2234    { "txt", "text/plain" },
     2235    { "xbm", "image/x-xbitmap" },
     2236    { "xml", "text/xml" },
     2237    { "xpm", "image/x-xpm" },
     2238    { "xsl", "text/xsl" },
     2239    { "xhtml", "application/xhtml+xml" },
     2240    { "wml", "text/vnd.wap.wml" },
     2241    { "wmlc", "application/vnd.wap.wmlc" },
     2242    { 0, 0 }
     2243};
     2244
     2245static QString getMimeTypeForExtension(const QString &ext)
     2246{
     2247    const ImageExtensionMap *e = extensionMap;
     2248    while (e->extension) {
     2249        if (ext.compare(QLatin1String(e->extension), Qt::CaseInsensitive) == 0)
     2250            return QLatin1String(e->mimeType);
     2251        ++e;
     2252    }
     2253
     2254    return QString();
     2255}
     2256
     2257void tst_QWebPage::supportedContentType()
     2258{
     2259   QStringList contentTypes;
     2260
     2261   // Add supported non image types...
     2262   contentTypes << "text/html" << "text/xml" << "text/xsl" << "text/plain" << "text/"
     2263                << "application/xml" << "application/xhtml+xml" << "application/vnd.wap.xhtml+xml"
     2264                << "application/rss+xml" << "application/atom+xml" << "application/json";
     2265
     2266   // Add supported image types...
     2267   Q_FOREACH(const QByteArray& imageType, QImageWriter::supportedImageFormats()) {
     2268      const QString mimeType = getMimeTypeForExtension(imageType);
     2269      if (!mimeType.isEmpty())
     2270          contentTypes << mimeType;
     2271   }
     2272
     2273   // Get the mime types supported by webkit...
     2274   const QStringList supportedContentTypes = m_page->supportedContentTypes();
     2275
     2276   Q_FOREACH(const QString& mimeType, contentTypes)
     2277      QVERIFY2(supportedContentTypes.contains(mimeType), QString("'%1' is not a supported content type!").arg(mimeType).toLatin1());
     2278     
     2279   Q_FOREACH(const QString& mimeType, contentTypes)
     2280      QVERIFY2(m_page->supportsContentType(mimeType), QString("Cannot handle content types '%1'!").arg(mimeType).toLatin1());
     2281}
     2282
    22062283QTEST_MAIN(tst_QWebPage)
    22072284#include "tst_qwebpage.moc"
Note: See TracChangeset for help on using the changeset viewer.