Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-42595

Unable to create WebPlugin for pdf extension file

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • P3: Somewhat important
    • None
    • 5.4.0 Beta
    • WebKit
    • None
    • Windows 7

    Description

      I'm trying to create a web plugin to display pdf in a custom pdf viewer using QWebPluginFactory, but whatever the QWidget* I returned, it crash with the following assertion and callstack.

      ASSERTION FAILED: !widget || widget->isPluginView()
      C:\QtCustom\Qt5.4.0\5.4\Src\qtwebkit\Source\WebCore/plugins/PluginView.h(458) : WebCore::toPluginView
      

      Stack:

      0	WTFCrash	Assertions.cpp	345	0x11139ab7	
      1	WebCore::toPluginView	PluginView.h	459	0xfd2804e	
      2	WebCore::FrameLoaderClientQt::redirectDataToPlugin	FrameLoaderClientQt.cpp	1562	0xfd24c50	
      3	WebCore::PluginDocumentParser::appendBytes	PluginDocument.cpp	132	0x105f19fb	
      4	WebCore::DocumentWriter::addData	DocumentWriter.cpp	226	0x104e887f	
      5	WebCore::DocumentLoader::commitData	DocumentLoader.cpp	804	0x101bc0f8	
      6	WebCore::FrameLoaderClientQt::committedLoad	FrameLoaderClientQt.cpp	882	0xfd22835	
      7	WebCore::DocumentLoader::commitLoad	DocumentLoader.cpp	746	0x101bc747	
      8	WebCore::DocumentLoader::dataReceived	DocumentLoader.cpp	856	0x101bd983	
      9	WebCore::CachedRawResource::notifyClientsDataWasReceived	CachedRawResource.cpp	110	0x109b7716	
      10	WebCore::CachedRawResource::addDataBuffer	CachedRawResource.cpp	67	0x109b6ec0	
      11	WebCore::SubresourceLoader::didReceiveDataOrBuffer	SubresourceLoader.cpp	251	0x10901688	
      12	WebCore::SubresourceLoader::didReceiveData	SubresourceLoader.cpp	227	0x10900e9d	
      13	WebCore::ResourceLoader::didReceiveData	ResourceLoader.cpp	476	0x1062927b	
      14	WebCore::QNetworkReplyHandler::forwardData	QNetworkReplyHandler.cpp	691	0x1059d4f8	
      15	WebCore::QNetworkReplyHandlerCallQueue::flush	QNetworkReplyHandler.cpp	256	0x1059c394	
      16	WebCore::QNetworkReplyHandlerCallQueue::unlock	QNetworkReplyHandler.cpp	237	0x1059c339	
      17	WebCore::QueueLocker::~QueueLocker	QNetworkReplyHandler.cpp	264	0x1059fae1	
      18	WebCore::QNetworkReplyWrapper::emitMetaDataChanged	QNetworkReplyHandler.cpp	402	0x1059ce06	
      19	WebCore::QNetworkReplyWrapper::receiveSniffedMIMEType	QNetworkReplyHandler.cpp	366	0x1059cbb9	
      ...	<plus>				
      

      I could reproduce the problem with Qt Browser (Webkit) and the following class:

      mywebpluginfactory.h

      #include <QWebPluginFactory>
      
      class MyWebPluginFactory : public QWebPluginFactory
      {
      public:
          MyWebPluginFactory(QObject *parent);
      
      protected:
          QObject* create(
                  const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const;
          QList<Plugin> plugins() const;
      };
      

      mywebpluginfactory.cpp

      #include "mywebpluginfactory.h"
      
      MyWebPluginFactory::MyWebPluginFactory(QObject *parent) :
          QWebPluginFactory(parent)
      {}
      
      QList<QWebPluginFactory::Plugin> MyWebPluginFactory::plugins() const
      {
          QWebPluginFactory::MimeType mimeType;
          mimeType.name = "application/pdf";
          mimeType.description = "PDF document";
          mimeType.fileExtensions = QStringList() << "pdf";
      
          QWebPluginFactory::Plugin plugin;
          plugin.name = "PDF file viewer";
          plugin.description = "A PDF file plugin.";
          plugin.mimeTypes = QList<MimeType>() << mimeType;
      
          return QList<QWebPluginFactory::Plugin>() << plugin;
      }
      
      QObject *MyWebPluginFactory::create(
                  const QString &mimeType, const QUrl &, const QStringList &, const QStringList &) const
      {
          if (mimeType == "application/pdf")
          {
              QWidget *myWidget = new QWidget();
              return myWidget;
          }
      
          return nullptr;
      }
      

      And this in WebView constructor:

      MyWebPluginFactory *pluginFactory = new MyWebPluginFactory(this);
      page()->setPluginFactory(pluginFactory);
      

      The example of QWebPluginFactory present in Qt 4.8 disappeared from Qt 5.4 examples, so I can't test it.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            annulen Konstantin Tokarev
            johnlamericain Jonathan Courtois
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes