Reviewed by Zack
authorlars <lars@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Jun 2007 14:47:42 +0000 (14:47 +0000)
committerlars <lars@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Jun 2007 14:47:42 +0000 (14:47 +0000)
        Add an API to create and load plugins.
        Don't include moc files by hand anymore, rather let
        qmake handle them.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@22027 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
WebCore/ChangeLog
WebCore/WebCore.pro
WebCore/platform/qt/MimeTypeRegistryQt.cpp
WebCore/platform/qt/QWebPopup.cpp
WebCore/platform/qt/SharedTimerQt.cpp
WebKitQt/Api/qcookiejar.cpp
WebKitQt/Api/qwebframe.cpp
WebKitQt/Api/qwebnetworkinterface.cpp
WebKitQt/Api/qwebobjectplugin.cpp [new file with mode: 0644]
WebKitQt/Api/qwebobjectplugin.h [new file with mode: 0644]
WebKitQt/Api/qwebobjectplugin_p.h [new file with mode: 0644]
WebKitQt/Api/qwebpage.cpp
WebKitQt/ChangeLog
WebKitQt/WebCoreSupport/FrameLoaderClientQt.cpp

index d8f66e6dc4718a6b4f87922b1b8ae1d3fdb35e60..34ab1fd88ba14a5b9d6c252e3261ebb4e5943d8f 100644 (file)
@@ -1,3 +1,18 @@
+2007-06-06  Lars Knoll <lars@trolltech.com>
+
+        Reviewed by Zack
+
+        Add an API to create and load plugins.
+        Don't include moc files by hand anymore, rather let
+        qmake handle them.
+
+        * WebCore.pro:
+        * platform/qt/MimeTypeRegistryQt.cpp:
+        (WebCore::):
+        (WebCore::MimeTypeRegistry::getMIMETypeForExtension):
+        * platform/qt/QWebPopup.cpp:
+        * platform/qt/SharedTimerQt.cpp:
+
 2007-06-06  Mark Rowe  <mrowe@apple.com>
 
         Qt build fix.
index a444c48b598d3f95eb1e571b967d5e444175597a..148ea4faae0ec14261292abd77eb56274506b2b6 100644 (file)
@@ -59,6 +59,7 @@ macx {
     INCLUDEPATH += /usr/include/libxml2
     LIBS += -lxml2 -lxslt
 }
+
 qt-port {
 INCLUDEPATH += \
                 $$[QT_INSTALL_PREFIX]/src/3rdparty/sqlite/ \
@@ -134,17 +135,6 @@ SVGCSSVALUES = $$PWD/ksvg2/css/CSSValueKeywords.in
 
 STYLESHEETS_EMBED = $$PWD/css/html4.css
 
-MANUALMOC =
-qt-port:MANUALMOC += \
-    $$PWD/platform/qt/QWebPopup.h \
-    $$PWD/platform/qt/SharedTimerQt.h \
-    $$PWD/../WebKitQt/Api/qwebframe.h \
-    $$PWD/../WebKitQt/Api/qwebpage.h \
-    $$PWD/../WebKitQt/Api/qwebnetworkinterface.h \
-    $$PWD/../WebKitQt/Api/qwebnetworkinterface_p.h \
-    $$PWD/../WebKitQt/Api/qcookiejar.h \
-    $$PWD/../WebKitQt/WebCoreSupport/FrameLoaderClientQt.h
-
 LUT_FILES += \
     bindings/js/JSXMLHttpRequest.cpp \
     bindings/js/JSXSLTProcessor.cpp \
@@ -714,6 +704,18 @@ SOURCES += \
     xml/XSLStyleSheet.cpp \
     xml/XSLTProcessor.cpp
 
+qt-port:HEADERS += \
+    $$PWD/platform/qt/QWebPopup.h \
+    $$PWD/platform/qt/SharedTimerQt.h \
+    $$PWD/../WebKitQt/Api/qwebframe.h \
+    $$PWD/../WebKitQt/Api/qwebpage.h \
+    $$PWD/../WebKitQt/Api/qwebnetworkinterface.h \
+    $$PWD/../WebKitQt/Api/qwebnetworkinterface_p.h \
+    $$PWD/../WebKitQt/Api/qwebobjectplugin.h \
+    $$PWD/../WebKitQt/Api/qwebobjectplugin_p.h \
+    $$PWD/../WebKitQt/Api/qcookiejar.h \
+    $$PWD/../WebKitQt/WebCoreSupport/FrameLoaderClientQt.h
+
 qt-port:SOURCES += \
     page/qt/DragControllerQt.cpp \
     page/qt/EventHandlerQt.cpp \
@@ -781,7 +783,8 @@ qt-port:SOURCES += \
     ../WebKitQt/Api/qcookiejar.cpp \
     ../WebKitQt/Api/qwebpage.cpp \
     ../WebKitQt/Api/qwebpagehistory.cpp \
-    ../WebKitQt/Api/qwebsettings.cpp
+    ../WebKitQt/Api/qwebsettings.cpp \
+    ../WebKitQt/Api/qwebobjectplugin.cpp 
 
 gdk-port:SOURCES += \
         platform/TextCodecICU.cpp \
@@ -1388,13 +1391,6 @@ stylesheets.variable_out = GENERATED_SOURCES
 stylesheets.clean = ${QMAKE_FILE_OUT} tmp/UserAgentStyleSheets.h
 QMAKE_EXTRA_COMPILERS += stylesheets
 
-# GENERATOR M
-manual_moc.output = tmp/${QMAKE_FILE_BASE}.moc
-manual_moc.commands = $$QMAKE_MOC ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
-manual_moc.input = MANUALMOC
-manual_moc.CONFIG += target_predeps no_link
-QMAKE_EXTRA_COMPILERS += manual_moc
-
 # GENERATOR 10: XPATH grammar
 xpathbison.output = tmp/${QMAKE_FILE_BASE}.cpp
 xpathbison.commands = bison -d -p xpathyy ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_BASE}.tab.c && mv ${QMAKE_FILE_BASE}.tab.c tmp/${QMAKE_FILE_BASE}.cpp && mv ${QMAKE_FILE_BASE}.tab.h tmp/${QMAKE_FILE_BASE}.h
index dbd0efba17f0e9cae9a4aa5aca4b4e6564a74b11..c4f8573e1790933cb884006df15b1e1eaccc2d52 100644 (file)
@@ -29,7 +29,9 @@
 #include "MimeTypeRegistry.h"
 #include "NotImplemented.h"
 
-namespace WebCore 
+#include "qwebobjectplugin_p.h"
+
+namespace WebCore
 {
 
 struct ExtensionMap {
@@ -40,7 +42,7 @@ static const ExtensionMap extensionMap [] = {
     { "bmp", "image/bmp" },
     { "gif", "image/gif" },
     { "html", "text/html" },
-    { "ico", "image/x-icon" },   
+    { "ico", "image/x-icon" },
     { "jpeg", "image/jpeg" },
     { "jpg", "image/jpeg" },
     { "js", "application/x-javascript" },
@@ -63,18 +65,22 @@ static const ExtensionMap extensionMap [] = {
     { "xhtml", "application/xhtml+xml" },
     { 0, 0 }
 };
-    
+
 String MimeTypeRegistry::getMIMETypeForExtension(const String &ext)
 {
     String s = ext.lower();
+
     const ExtensionMap *e = extensionMap;
     while (e->extension) {
         if (s == e->extension)
             return e->mimeType;
         ++e;
     }
-    // unknown, let's just assume plain text
-    return "text/plain";
+    QString type = QWebFactoryLoader::self()->mimeTypeForExtension(ext);
+    if (!type.isEmpty())
+        return type;
+
+    return "application/octet-stream";
 }
 
 }
index fff439f8813f9fc75c1b32099fe9a1219012a5f9..c13825907247aefaae3817cd8c4e862b207644ab 100644 (file)
@@ -23,8 +23,6 @@
 #include <QCoreApplication>
 #include <QMouseEvent>
 
-#include "QWebPopup.moc"
-
 namespace WebCore {
 
 QWebPopup::QWebPopup(PopupMenuClient* client)
index 7d74e6d879b648a89a6cc3474f5ae7082496929f..95d406b53ac32c65f554924f1d6800ef87b27d8c 100644 (file)
@@ -50,6 +50,4 @@ void stopSharedTimer()
 
 }
 
-#include "SharedTimerQt.moc"
-
 // vim: ts=4 sw=4 et
index a2742a80ba506fa4791050fb695aebc039563ba6..3b8ae46dbdc48fa75ccb344310b4871c50567d20 100644 (file)
@@ -103,6 +103,3 @@ QCookieJar *QCookieJar::cookieJar()
     }
     return gJar;
 }
-
-
-#include "qcookiejar.moc"
index 4f65d7c982bfa467f95094831437ae607d0f4254..faccbe26602f4616facea3e820a6e9904cb34b7c 100644 (file)
@@ -322,5 +322,3 @@ void QWebFrame::scrollContentsBy(int dx, int dy)
 {
     viewport()->scroll(dx, dy);
 }
-
-#include "qwebframe.moc"
index 1b3e20f33e66b26a80bcee09a97e35ce635fcd75..98fd41f47abaeed7541adc5a38746c9bbd6ae36f 100644 (file)
@@ -793,6 +793,3 @@ HostInfo::HostInfo(const QUrl& url)
     }
 }
 
-#include "qwebnetworkinterface_p.moc"
-#include "qwebnetworkinterface.moc"
-
diff --git a/WebKitQt/Api/qwebobjectplugin.cpp b/WebKitQt/Api/qwebobjectplugin.cpp
new file mode 100644 (file)
index 0000000..ff757de
--- /dev/null
@@ -0,0 +1,89 @@
+#include "qwebobjectplugin_p.h"
+#include <qcoreapplication.h>
+    
+#ifndef QT_NO_LIBRARY
+Q_GLOBAL_STATIC_WITH_ARGS(QWebFactoryLoader, loader,
+                          (QWebObjectPluginFactoryInterface_iid, QCoreApplication::libraryPaths(), QLatin1String("/webplugins")))
+#endif
+
+
+QWebFactoryLoader::QWebFactoryLoader(const char *iid, const QStringList &paths, const QString &suffix, Qt::CaseSensitivity)
+    : QFactoryLoader(iid, paths, suffix)
+{
+    QStringList plugins = keys();
+    foreach(QString k, plugins) {
+        QWebObjectPlugin *plugin = qobject_cast<QWebObjectPlugin *>(instance(k));
+        if (!plugin)
+            continue;
+        QStringList extensions = plugin->extensionsForMimetype(k);
+        foreach(QString ext, extensions) {
+            m_extensions.append(ext);
+            m_mimeTypesForExtension.append(k);
+        }
+    }
+}
+
+QWebFactoryLoader *QWebFactoryLoader::self()
+{
+    return loader();
+}
+    
+QString QWebFactoryLoader::mimeTypeForExtension(const QString &extension)
+{
+    int idx = m_extensions.indexOf(extension);
+    if (idx > 0)
+        return m_mimeTypesForExtension.at(idx);
+    return QString();
+}
+
+QObject *QWebFactoryLoader::create(QWidget *parent,
+                                   const QString &mimeType,
+                                   const QStringList &argumentNames,
+                                   const QStringList &argumentValues)
+{
+    QWebObjectPlugin *plugin = qobject_cast<QWebObjectPlugin *>(instance(mimeType));
+    if (!plugin)
+        return 0;
+    return plugin->create(parent, mimeType, argumentNames, argumentValues);
+}
+
+
+
+/*! \class QWebObjectPlugin
+
+  This class is a plugin for the HTML object tag. It can be used to embed arbitrary content in a web page.
+*/
+
+
+QWebObjectPlugin::QWebObjectPlugin(QObject *parent)
+    : QObject(parent)
+{
+}
+
+QWebObjectPlugin::~QWebObjectPlugin()
+{
+}
+
+/*!
+  \fn QStringList QWebObjectPlugin::keys() const
+
+  The keys are the mimetypes the plugin can handle
+*/
+
+/*!
+  \fn QStringList QWebObjectPlugin::extensionsForMimetype() const
+
+  Should return a list of extensions that are recognised to match the \a mimeType.
+*/
+QStringList QWebObjectPlugin::extensionsForMimetype(const QString &mimeType) const
+{
+    return QStringList();
+}
+
+/*!
+  \fn QObject *QWebObjectPlugin::create(QWidget *parent, const QString &mimeType, const QStringList &argumentNames, const QStringList &argumentValues) const
+
+  Creates a QObject with \a parent to handle \a mimeType. \a argumentNames and \a argumentValues are a set of key-value pairs passed directly
+  from the &lt;param&gt; elements contained in the HTML object tag.
+*/
+
diff --git a/WebKitQt/Api/qwebobjectplugin.h b/WebKitQt/Api/qwebobjectplugin.h
new file mode 100644 (file)
index 0000000..47442e5
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef QWEBOBJECTPLUGIN_H
+#define QWEBOBJECTPLUGIN_H
+
+#include <qwebkitglobal.h>
+#include <QtCore/qplugin.h>
+#include <QtCore/qfactoryinterface.h>
+
+struct QWEBKIT_EXPORT QWebObjectPluginFactoryInterface : public QFactoryInterface
+{
+    virtual QObject *create(QWidget *parent,
+                            const QString &mimeType,
+                            const QStringList &argumentNames,
+                            const QStringList &argumentValues) const = 0;
+};
+
+#define QWebObjectPluginFactoryInterface_iid "com.trolltech.Qt.QWebObjectPluginFactoryInterface"
+Q_DECLARE_INTERFACE(QWebObjectPluginFactoryInterface, QWebObjectPluginFactoryInterface_iid)
+
+class QWEBKIT_EXPORT QWebObjectPlugin : public QObject, public QWebObjectPluginFactoryInterface
+{
+    Q_OBJECT
+    Q_INTERFACES(QWebObjectPluginFactoryInterface:QFactoryInterface)
+public:
+    explicit QWebObjectPlugin(QObject *parent = 0);
+    virtual ~QWebObjectPlugin();
+
+    virtual QStringList keys() const = 0;
+    virtual QStringList extensionsForMimetype(const QString &mimeType) const;
+    virtual QObject *create(QWidget *parent,
+                            const QString &mimeType,
+                            const QStringList &argumentNames,
+                            const QStringList &argumentValues) const = 0;
+};
+    
+#endif
diff --git a/WebKitQt/Api/qwebobjectplugin_p.h b/WebKitQt/Api/qwebobjectplugin_p.h
new file mode 100644 (file)
index 0000000..7c1a07d
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef QWEBOBJECTPLUGIN_P_H
+#define QWEBOBJECTPLUGIN_P_H
+
+#include <qglobal.h>
+#include <qwebobjectplugin.h>
+
+#include <private/qfactoryloader_p.h>
+
+class QWebFactoryLoader : public QFactoryLoader
+{
+    Q_OBJECT
+public:
+    QWebFactoryLoader(const char *iid,
+                      const QStringList &paths = QStringList(),
+                      const QString &suffix = QString(),
+                      Qt::CaseSensitivity = Qt::CaseSensitive);
+
+    static QWebFactoryLoader *self();
+
+    QStringList mimeTypes() { return keys(); }
+    QStringList extensions() { return m_extensions; }
+
+    QString mimeTypeForExtension(const QString &extension);
+    bool supportsMimeType(const QString &mimeType) { return keys().contains(mimeType); }
+    
+    QObject *create(QWidget *parent,
+                    const QString &mimeType,
+                    const QStringList &argumentNames,
+                    const QStringList &argumentValues);
+
+private:
+    QStringList m_extensions;
+    QStringList m_mimeTypesForExtension;
+};
+
+#endif
index 0d03e68ef9780f3c5d989900a591dc4056bdb550..ae197d1648b836a6f18803221f1867d74eb31617 100644 (file)
@@ -357,6 +357,3 @@ QWebSettings QWebPage::settings() const
 
     return settings;
 }
-
-
-#include "qwebpage.moc"
index 9e1592f106173cb920735bfdef7318a7f5c7390d..74ca4930b3d8284efcbf005edc5a4c5f6b96516d 100644 (file)
@@ -1,3 +1,37 @@
+2007-06-06  Lars Knoll <lars@trolltech.com>
+
+        Reviewed by Zack
+
+        Add an API to create and load plugins.
+        Don't include moc files by hand anymore, rather let
+        qmake handle them.
+
+        * Api/qcookiejar.cpp:
+        (QCookieJar::cookieJar):
+        * Api/qwebframe.cpp:
+        (QWebFrame::scrollContentsBy):
+        * Api/qwebnetworkinterface.cpp:
+        * Api/qwebobjectplugin.cpp: Added.
+        (QWebFactoryLoader::QWebFactoryLoader):
+        (QWebFactoryLoader::self):
+        (QWebFactoryLoader::mimeTypeForExtension):
+        (QWebFactoryLoader::create):
+        (QWebObjectPlugin::QWebObjectPlugin):
+        (QWebObjectPlugin::~QWebObjectPlugin):
+        (QWebObjectPlugin::extensionsForMimetype):
+        * Api/qwebobjectplugin.h: Added.
+        * Api/qwebobjectplugin_p.h: Added.
+        (QWebFactoryLoader::mimeTypes):
+        (QWebFactoryLoader::extensions):
+        (QWebFactoryLoader::supportsMimeType):
+        * Api/qwebpage.cpp:
+        (QWebPage::settings):
+        * WebCoreSupport/FrameLoaderClientQt.cpp:
+        (WebCore::FrameLoaderClientQt::dispatchDidHandleOnloadEvents):
+        (WebCore::FrameLoaderClientQt::postProgressEstimateChangedNotification):
+        (WebCore::FrameLoaderClientQt::objectContentType):
+        (WebCore::FrameLoaderClientQt::createPlugin):
+
 2007-05-28  Zack Rusin  <zrusin@trolltech.com>
 
         Reviewed by andersca and simon
index 857bb6117259576526d04b9c842b56e9c71164cd..c3371eb3773fe0f6a1dbc8071a82cb554d71af9b 100644 (file)
@@ -44,6 +44,7 @@
 #include "qwebpage.h"
 #include "qwebframe.h"
 #include "qwebframe_p.h"
+#include "qwebobjectplugin_p.h"
 
 #include <qfileinfo.h>
 
@@ -288,7 +289,7 @@ void FrameLoaderClientQt::loadedFromCachedPage()
 
 void FrameLoaderClientQt::dispatchDidHandleOnloadEvents()
 {
-    
+    // don't need this one
 }
 
 
@@ -424,7 +425,7 @@ void FrameLoaderClientQt::postProgressStartedNotification()
 void FrameLoaderClientQt::postProgressEstimateChangedNotification()
 {
     if (m_webFrame && m_frame->page())
-        emit loadProgressChanged(m_frame->page()->progress()->estimatedProgress() * 100);
+        emit loadProgressChanged(qRound(m_frame->page()->progress()->estimatedProgress() * 100));
 }
 
 void FrameLoaderClientQt::postProgressFinishedNotification()
@@ -503,7 +504,6 @@ bool FrameLoaderClientQt::canShowMIMEType(const String& MIMEType) const
     return false;
 }
 
-
 bool FrameLoaderClientQt::representationExistsForURLScheme(const String& URLScheme) const
 {
     notImplemented();
@@ -863,23 +863,57 @@ Frame* FrameLoaderClientQt::createFrame(const KURL& url, const String& name, HTM
     return childFrame.get();
 }
 
-ObjectContentType FrameLoaderClientQt::objectContentType(const KURL& url, const String& mimeType)
+ObjectContentType FrameLoaderClientQt::objectContentType(const KURL& url, const String& _mimeType)
 {
+    //qDebug()<<" ++++++++++++++++ url is "<<url.prettyURL()<<", mime = "<<mimeType;
     if (!url.isValid())
-        return ObjectContentType();
-    
-    //This is not really correct. it works because getMIMETypeForExtension
-    //  currently returns only the mimetypes that frames can handle
-    QFileInfo fi(url.path());
-    String rtype = MimeTypeRegistry::getMIMETypeForExtension(fi.suffix());
-    if (!rtype.isEmpty())
+        return ObjectContentNone;
+
+    String mimeType = _mimeType;
+    if (!mimeType.length()) {
+        QFileInfo fi(url.path());
+        mimeType = MimeTypeRegistry::getMIMETypeForExtension(fi.suffix());
+    }
+
+    if (!mimeType.length())
+        return ObjectContentFrame;
+
+    if (MimeTypeRegistry::isSupportedImageMIMEType(mimeType))
+        return ObjectContentImage;
+
+    if (QWebFactoryLoader::self()->supportsMimeType(mimeType))
+        return ObjectContentPlugin;
+
+    if (MimeTypeRegistry::isSupportedNonImageMIMEType(mimeType))
         return ObjectContentFrame;
-    return ObjectContentType();
+    
+    return ObjectContentNone;
 }
 
-Widget* FrameLoaderClientQt::createPlugin(Element*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool)
+Widget* FrameLoaderClientQt::createPlugin(Element* element, const KURL& url, const Vector<String>& paramNames,
+                                          const Vector<String>& paramValues, const String& mimeType, bool loadManually)
 {
-    notImplemented();
+    //qDebug()<<"------ Creating plugin in FrameLoaderClientQt::createPlugin for "<<mimeType;
+    //qDebug()<<"------\t url = "<<url.prettyURL();
+    QStringList params;
+    QStringList values;
+    for (int i = 0; i < paramNames.size(); ++i)
+        params.append(paramNames[i]);
+    for (int i = 0; i < paramValues.size(); ++i) 
+        values.append(paramValues[i]);
+    
+    QObject *object = QWebFactoryLoader::self()->create(m_webFrame->viewport(), mimeType, params, values);
+    if (object) {
+        QWidget *widget = qobject_cast<QWidget *>(object);
+        if (widget) {
+            Widget* w= new Widget();
+            w->setQWidget(widget);
+            return w;
+        }
+        // FIXME: make things work for widgetless plugins as well
+        delete object;
+    }
+
     return 0;
 }
 
@@ -903,5 +937,3 @@ String FrameLoaderClientQt::overrideMediaType() const
 }
 
 }
-
-#include "FrameLoaderClientQt.moc"