Changeset 49440 in webkit


Ignore:
Timestamp:
Oct 12, 2009 8:05:59 AM (15 years ago)
Author:
eric@webkit.org
Message:

2009-10-12 Jedrzej Nowacki <jedrzej.nowacki@nokia.com>

Reviewed by Simon Hausmann.

QWebPage's createViewlessPlugin autotest crash fix.

It is possible that plugins that are QWidgets or QGraphicsWidgets
are created before a view has been assigned to a QWebPage. The
plug-ins won't be fully functional, as by design, they should
visualise something, but they won't crash and will stay in memory.

An autotest that covers this use-case, is included.

https://bugs.webkit.org/show_bug.cgi?id=30118

  • WebCoreSupport/FrameLoaderClientQt.cpp: (WebCore::FrameLoaderClientQt::createPlugin):
  • tests/qwebpage/tst_qwebpage.cpp: (PluginTrackedPageWidget::PluginTrackedPageWidget): (PluginTrackedPageGraphicsWidget::PluginTrackedPageGraphicsWidget): (PluginTrackedPageGraphicsWidget::createPlugin): (tst_QWebPage::destroyPlugin): (tst_QWebPage::createViewlessPlugin):
Location:
trunk/WebKit/qt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/qt/ChangeLog

    r49397 r49440  
     12009-10-12  Jedrzej Nowacki  <jedrzej.nowacki@nokia.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        QWebPage's createViewlessPlugin autotest crash fix.
     6       
     7        It is possible that plugins that are QWidgets or QGraphicsWidgets
     8        are created before a view has been assigned to a QWebPage. The
     9        plug-ins won't be fully functional, as by design, they should
     10        visualise something, but they won't crash and will stay in memory.
     11
     12        An autotest that covers this use-case, is included.
     13
     14        https://bugs.webkit.org/show_bug.cgi?id=30118
     15
     16        * WebCoreSupport/FrameLoaderClientQt.cpp:
     17        (WebCore::FrameLoaderClientQt::createPlugin):
     18        * tests/qwebpage/tst_qwebpage.cpp:
     19        (PluginTrackedPageWidget::PluginTrackedPageWidget):
     20        (PluginTrackedPageGraphicsWidget::PluginTrackedPageGraphicsWidget):
     21        (PluginTrackedPageGraphicsWidget::createPlugin):
     22        (tst_QWebPage::destroyPlugin):
     23        (tst_QWebPage::createViewlessPlugin):
     24
    1252009-10-09  Joe Ligman  <joseph.ligman@nokia.com>
    226
  • trunk/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp

    r49284 r49440  
    12311231            QWidget* widget = qobject_cast<QWidget*>(object);
    12321232            if (widget) {
    1233                 QWidget* parentWidget = qobject_cast<QWidget*>(m_webFrame->page()->d->client->pluginParent());
    1234                 if (parentWidget)
    1235                     widget->setParent(parentWidget);
     1233                QWidget* parentWidget;
     1234                if (m_webFrame->page()->d->client)
     1235                    parentWidget = qobject_cast<QWidget*>(m_webFrame->page()->d->client->pluginParent());
     1236                else
     1237                    parentWidget = 0;  // The plug-in won't be fully functional because the QWebView doesn't exist.
     1238                widget->setParent(parentWidget);
    12361239                RefPtr<QtPluginWidget> w = adoptRef(new QtPluginWidget());
    12371240                w->setPlatformWidget(widget);
     
    12431246            QGraphicsWidget* graphicsWidget = qobject_cast<QGraphicsWidget*>(object);
    12441247            if (graphicsWidget) {
     1248                QGraphicsObject* parentWidget;
     1249                if (m_webFrame->page()->d->client)
     1250                    parentWidget = qobject_cast<QGraphicsObject*>(m_webFrame->page()->d->client->pluginParent());
     1251                else
     1252                    parentWidget = 0;  // The plug-in won't be fully functional because the QWebView doesn't exist.
    12451253                graphicsWidget->hide();
    1246                 graphicsWidget->setParentItem(qobject_cast<QGraphicsObject*>(m_webFrame->page()->d->client->pluginParent()));
     1254                graphicsWidget->setParentItem(parentWidget);
    12471255                RefPtr<QtPluginGraphicsWidget> w = QtPluginGraphicsWidget::create(graphicsWidget);
    12481256                // Make sure it's invisible until properly placed into the layout
  • trunk/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp

    r49397 r49440  
    2424#include <qwebpage.h>
    2525#include <qwidget.h>
     26#include <QGraphicsWidget>
    2627#include <qwebview.h>
    2728#include <qwebframe.h>
     
    102103    void database();
    103104    void createPlugin();
     105    void destroyPlugin_data();
    104106    void destroyPlugin();
     107    void createViewlessPlugin_data();
    105108    void createViewlessPlugin();
    106109    void multiplePageGroupsAndLocalStorage();
     
    622625}
    623626
    624 class PluginTrackedPage : public QWebPage
    625 {
     627
     628// Standard base class for template PluginTracerPage. In tests it is used as interface.
     629class PluginCounterPage : public QWebPage {
    626630public:
    627 
    628     int count;
    629     QPointer<QWidget> widget;
    630 
    631     PluginTrackedPage(QWidget *parent = 0) : QWebPage(parent), count(0) {
     631    int m_count;
     632    QPointer<QObject> m_widget;
     633    PluginCounterPage(QObject* parent = 0) : QWebPage(parent), m_count(0), m_widget(0)
     634    {
    632635       settings()->setAttribute(QWebSettings::PluginsEnabled, true);
    633636    }
    634 
    635     virtual QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&) {
    636        count++;
    637        QWidget *w = new QWidget;
    638        widget = w;
    639        return w;
    640     }
    641637};
    642638
     639template<class T>
     640class PluginTracerPage : public PluginCounterPage {
     641public:
     642    PluginTracerPage(QObject* parent = 0) : PluginCounterPage(parent) {}
     643    virtual QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&)
     644    {
     645        m_count++;
     646        return m_widget = new T();
     647    }
     648};
     649
     650class PluginFactory {
     651public:
     652    enum FactoredType {QWidgetType, QGraphicsWidgetType};
     653    static PluginCounterPage* create(FactoredType type, QObject* parent = 0)
     654    {
     655        PluginCounterPage* result = 0;
     656        switch (type) {
     657        case QWidgetType:
     658            result = new PluginTracerPage<QWidget>(parent);
     659            break;
     660        case QGraphicsWidgetType:
     661            result = new PluginTracerPage<QGraphicsWidget>(parent);
     662            break;
     663        default: {/*Oops*/};
     664        }
     665        return result;
     666    }
     667
     668    static void prepareTestData()
     669    {
     670        QTest::addColumn<int>("type");
     671        QTest::newRow("QWidget") << (int)PluginFactory::QWidgetType;
     672        QTest::newRow("QGraphicsWidget") << (int)PluginFactory::QGraphicsWidgetType;
     673    }
     674};
     675
     676void tst_QWebPage::destroyPlugin_data()
     677{
     678    PluginFactory::prepareTestData();
     679}
     680
    643681void tst_QWebPage::destroyPlugin()
    644682{
    645     PluginTrackedPage* page = new PluginTrackedPage(m_view);
     683    QFETCH(int, type);
     684    PluginCounterPage* page = PluginFactory::create((PluginFactory::FactoredType)type, m_view);
    646685    m_view->setPage(page);
    647686
     
    649688    QString content("<html><body><object type=\"application/x-qt-plugin\" classid=\"QProgressBar\"></object></body></html>");
    650689    m_view->setHtml(content);
    651     QVERIFY(page->widget != 0);
    652     QCOMPARE(page->count, 1);
     690    QVERIFY(page->m_widget);
     691    QCOMPARE(page->m_count, 1);
    653692
    654693    // navigate away, the plugin widget should be destructed
    655694    m_view->setHtml("<html><body>Hi</body></html>");
    656695    QTestEventLoop::instance().enterLoop(1);
    657     QVERIFY(page->widget == 0);
     696    QVERIFY(!page->m_widget);
     697}
     698
     699void tst_QWebPage::createViewlessPlugin_data()
     700{
     701    PluginFactory::prepareTestData();
    658702}
    659703
    660704void tst_QWebPage::createViewlessPlugin()
    661705{
    662     PluginTrackedPage* page = new PluginTrackedPage;
     706    QFETCH(int, type);
     707    PluginCounterPage* page = PluginFactory::create((PluginFactory::FactoredType)type);
    663708    QString content("<html><body><object type=\"application/x-qt-plugin\" classid=\"QProgressBar\"></object></body></html>");
    664709    page->mainFrame()->setHtml(content);
    665     QCOMPARE(page->count, 1);
    666     QVERIFY(page->widget != 0);
     710    QCOMPARE(page->m_count, 1);
     711    QVERIFY(page->m_widget);
    667712    delete page;
     713
    668714}
    669715
Note: See TracChangeset for help on using the changeset viewer.