[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

commit-queue at webkit.org commit-queue at webkit.org
Wed Dec 22 14:39:35 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit bf7be4f14f1dc70ebda390e8237f5f84d82b271c
Author: commit-queue at webkit.org <commit-queue at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Oct 15 00:27:26 2010 +0000

    2010-09-27 Dawit Alemayehu  <adawit at 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):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69825 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/qt/Api/qwebpage.cpp b/WebKit/qt/Api/qwebpage.cpp
index a9ab02d..d4f0d63 100644
--- a/WebKit/qt/Api/qwebpage.cpp
+++ b/WebKit/qt/Api/qwebpage.cpp
@@ -93,6 +93,9 @@
 #include "PlatformTouchEvent.h"
 #include "WorkerThread.h"
 #include "wtf/Threading.h"
+#include "MIMETypeRegistry.h"
+#include "PluginDatabase.h"
+#include "PluginPackage.h"
 
 #include <QApplication>
 #include <QBasicTimer>
@@ -2019,6 +2022,63 @@ QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const Q
     return 0;
 }
 
+static void extractContentTypeFromHash(const HashSet<String>& types, QStringList* list)
+{
+    if (!list)
+        return;
+
+    HashSet<String>::const_iterator endIt = types.end();
+    for (HashSet<String>::const_iterator it = types.begin(); it != endIt; ++it)
+        *list << *it;
+}
+
+static void extractContentTypeFromPluginVector(const Vector<PluginPackage*>& plugins, QStringList* list)
+{
+    if (!list)
+        return;
+
+    for (unsigned int i = 0; i < plugins.size(); ++i) {
+        MIMEToDescriptionsMap::const_iterator map_it = plugins[i]->mimeToDescriptions().begin();
+        MIMEToDescriptionsMap::const_iterator map_end = plugins[i]->mimeToDescriptions().end();
+        for (; map_it != map_end; ++map_it)
+            *list << map_it->first;
+    }
+}
+
+/*!
+ *  Returns the list of all content types supported by QWebPage.
+ */
+QStringList QWebPage::supportedContentTypes() const
+{
+    QStringList mimeTypes;
+
+    extractContentTypeFromHash(MIMETypeRegistry::getSupportedImageMIMETypes(), &mimeTypes);
+    extractContentTypeFromHash(MIMETypeRegistry::getSupportedNonImageMIMETypes(), &mimeTypes);
+    if (d->page->settings() && d->page->settings()->arePluginsEnabled())
+        extractContentTypeFromPluginVector(PluginDatabase::installedPlugins()->plugins(), &mimeTypes);
+
+    return mimeTypes;
+}
+
+/*!
+ *  Returns true if QWebPage can handle the given \a mimeType; otherwise, returns false.
+ */
+bool QWebPage::supportsContentType(const QString& mimeType) const
+{
+    const String type = mimeType.toLower();
+    if (MIMETypeRegistry::isSupportedImageMIMEType(type))
+        return true;
+
+    if (MIMETypeRegistry::isSupportedNonImageMIMEType(type))
+        return true;
+
+    if (d->page->settings() && d->page->settings()->arePluginsEnabled()
+        && PluginDatabase::installedPlugins()->isMIMETypeRegistered(type))
+        return true;
+
+    return false;
+}
+
 static WebCore::FrameLoadRequest frameLoadRequest(const QUrl &url, WebCore::Frame *frame)
 {
     WebCore::ResourceRequest rr(url, frame->loader()->outgoingReferrer());
diff --git a/WebKit/qt/Api/qwebpage.h b/WebKit/qt/Api/qwebpage.h
index 410c689..a5df312 100644
--- a/WebKit/qt/Api/qwebpage.h
+++ b/WebKit/qt/Api/qwebpage.h
@@ -309,6 +309,9 @@ public:
 
     void setUserPermission(QWebFrame* frame, PermissionDomain domain, PermissionPolicy policy);
 
+    QStringList supportedContentTypes() const;
+    bool supportsContentType(const QString& mimeType) const;
+
     enum Extension {
         ChooseMultipleFilesExtension,
         ErrorPageExtension
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index a4be8fd..9d72edb 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,18 @@
+2010-09-27 Dawit Alemayehu  <adawit at 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):
+
 2010-10-14  Sheriff Bot  <webkit.review.bot at gmail.com>
 
         Unreviewed, rolling out r69795.
@@ -687,7 +702,6 @@
         (QWebSettings::QWebSettings):
         * Api/qwebsettings.h:
 
-
 2010-09-23  Tor Arne Vestbø  <tor.arne.vestbo at nokia.com>
 
         Reviewed by Simon Hausmann.
diff --git a/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp b/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
index 3ddbf4e..0462953 100644
--- a/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
+++ b/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
@@ -41,6 +41,7 @@
 #include <qwebpage.h>
 #include <qwebsecurityorigin.h>
 #include <qwebview.h>
+#include <qimagewriter.h>
 
 class EventSpy : public QObject, public QList<QEvent::Type>
 {
@@ -126,6 +127,7 @@ private slots:
     void showModalDialog();
     void testStopScheduledPageRefresh();
     void findText();
+    void supportedContentType();
     
 private:
     QWebView* m_view;
@@ -2203,5 +2205,80 @@ void tst_QWebPage::findText()
     }
 }
 
+struct ImageExtensionMap {
+    const char* extension;
+    const char* mimeType;
+};
+
+static const ImageExtensionMap extensionMap[] = {
+    { "bmp", "image/bmp" },
+    { "css", "text/css" },
+    { "gif", "image/gif" },
+    { "html", "text/html" },
+    { "htm", "text/html" },
+    { "ico", "image/x-icon" },
+    { "jpeg", "image/jpeg" },
+    { "jpg", "image/jpeg" },
+    { "js", "application/x-javascript" },
+    { "mng", "video/x-mng" },
+    { "pbm", "image/x-portable-bitmap" },
+    { "pgm", "image/x-portable-graymap" },
+    { "pdf", "application/pdf" },
+    { "png", "image/png" },
+    { "ppm", "image/x-portable-pixmap" },
+    { "rss", "application/rss+xml" },
+    { "svg", "image/svg+xml" },
+    { "text", "text/plain" },
+    { "tif", "image/tiff" },
+    { "tiff", "image/tiff" },
+    { "txt", "text/plain" },
+    { "xbm", "image/x-xbitmap" },
+    { "xml", "text/xml" },
+    { "xpm", "image/x-xpm" },
+    { "xsl", "text/xsl" },
+    { "xhtml", "application/xhtml+xml" },
+    { "wml", "text/vnd.wap.wml" },
+    { "wmlc", "application/vnd.wap.wmlc" },
+    { 0, 0 }
+};
+
+static QString getMimeTypeForExtension(const QString &ext)
+{
+    const ImageExtensionMap *e = extensionMap;
+    while (e->extension) {
+        if (ext.compare(QLatin1String(e->extension), Qt::CaseInsensitive) == 0)
+            return QLatin1String(e->mimeType);
+        ++e;
+    }
+
+    return QString();
+}
+
+void tst_QWebPage::supportedContentType()
+{
+   QStringList contentTypes;
+
+   // Add supported non image types...
+   contentTypes << "text/html" << "text/xml" << "text/xsl" << "text/plain" << "text/"
+                << "application/xml" << "application/xhtml+xml" << "application/vnd.wap.xhtml+xml"
+                << "application/rss+xml" << "application/atom+xml" << "application/json";
+
+   // Add supported image types...
+   Q_FOREACH(const QByteArray& imageType, QImageWriter::supportedImageFormats()) {
+      const QString mimeType = getMimeTypeForExtension(imageType);
+      if (!mimeType.isEmpty())
+          contentTypes << mimeType;
+   }
+
+   // Get the mime types supported by webkit...
+   const QStringList supportedContentTypes = m_page->supportedContentTypes();
+
+   Q_FOREACH(const QString& mimeType, contentTypes)
+      QVERIFY2(supportedContentTypes.contains(mimeType), QString("'%1' is not a supported content type!").arg(mimeType).toLatin1());
+      
+   Q_FOREACH(const QString& mimeType, contentTypes)
+      QVERIFY2(m_page->supportsContentType(mimeType), QString("Cannot handle content types '%1'!").arg(mimeType).toLatin1());
+}
+
 QTEST_MAIN(tst_QWebPage)
 #include "tst_qwebpage.moc"

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list