qwebpluginfactory.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include "config.h"
  17. #include "qwebpluginfactory.h"
  18. /*!
  19. \class QWebPluginFactory
  20. \since 4.4
  21. \brief The QWebPluginFactory class is used to embed custom data types in web pages.
  22. \inmodule QtWebKit
  23. The HTML \c{<object>} tag is used to embed arbitrary content into a web page,
  24. for example:
  25. \code
  26. <object type="application/x-pdf" data="http://qt.nokia.com/document.pdf" width="500" height="400"></object>
  27. \endcode
  28. Qt WebKit will natively handle the most basic data types like \c{text/html} and
  29. \c{image/jpeg}, but for any advanced or custom data types you will need to
  30. provide a handler yourself.
  31. QWebPluginFactory is a factory for creating plugins for QWebPage, where each
  32. plugin provides support for one or more data types. A plugin factory can be
  33. installed on a QWebPage using QWebPage::setPluginFactory().
  34. \note The plugin factory is only used if plugins are enabled through QWebSettings.
  35. You provide a QWebPluginFactory by implementing the plugins() and the
  36. create() methods. For plugins() it is necessary to describe the plugins the
  37. factory can create, including a description and the supported MIME types.
  38. The MIME types each plugin can handle should match the ones specified in
  39. in the HTML \c{<object>} tag of your content.
  40. The create() method is called if the requested MIME type is supported. The
  41. implementation has to return a new instance of the plugin requested for the
  42. given MIME type and the specified URL.
  43. The plugins themselves are subclasses of QObject, but currently only plugins
  44. based on either QWidget or QGraphicsWidget are supported.
  45. */
  46. /*!
  47. \class QWebPluginFactory::Plugin
  48. \since 4.4
  49. \brief The QWebPluginFactory::Plugin structure describes the properties of a plugin a QWebPluginFactory can create.
  50. \inmodule QtWebKit
  51. */
  52. /*!
  53. \variable QWebPluginFactory::Plugin::name
  54. The name of the plugin.
  55. */
  56. /*!
  57. \variable QWebPluginFactory::Plugin::description
  58. The description of the plugin.
  59. */
  60. /*!
  61. \variable QWebPluginFactory::Plugin::mimeTypes
  62. The list of mime types supported by the plugin.
  63. */
  64. /*!
  65. \class QWebPluginFactory::MimeType
  66. \since 4.4
  67. \brief The QWebPluginFactory::MimeType structure describes a mime type supported by a plugin.
  68. \inmodule QtWebKit
  69. */
  70. /*!
  71. Returns true if this mimetype is the same as the \a other mime type.
  72. */
  73. bool QWebPluginFactory::MimeType::operator==(const MimeType& other) const
  74. {
  75. return name == other.name
  76. && description == other.description
  77. && fileExtensions == other.fileExtensions;
  78. }
  79. /*!
  80. \fn bool QWebPluginFactory::MimeType::operator!=(const MimeType& other) const
  81. Returns true if this mimetype is different from the \a other mime type.
  82. */
  83. /*!
  84. \variable QWebPluginFactory::MimeType::name
  85. The full name of the MIME type; e.g., \c{text/plain} or \c{image/png}.
  86. */
  87. /*!
  88. \variable QWebPluginFactory::MimeType::description
  89. The description of the mime type.
  90. */
  91. /*!
  92. \variable QWebPluginFactory::MimeType::fileExtensions
  93. The list of file extensions that are used by this mime type.
  94. For example, a mime type for PDF documents would return "pdf" as its file extension.
  95. */
  96. /*!
  97. Constructs a QWebPluginFactory with parent \a parent.
  98. */
  99. QWebPluginFactory::QWebPluginFactory(QObject *parent)
  100. : QObject(parent)
  101. {
  102. }
  103. /*!
  104. Destructor.
  105. */
  106. QWebPluginFactory::~QWebPluginFactory()
  107. {
  108. }
  109. /*!
  110. \fn QList<Plugin> QWebPluginFactory::plugins() const = 0
  111. This function is reimplemented in subclasses to return a list of
  112. supported plugins the factory can create.
  113. \note Currently, this function is only called when JavaScript programs
  114. access the global \c plugins or \c mimetypes objects.
  115. */
  116. /*!
  117. This function is called to refresh the list of supported plugins. It may be called after a new plugin
  118. has been installed in the system.
  119. */
  120. void QWebPluginFactory::refreshPlugins()
  121. {
  122. }
  123. /*!
  124. \fn QObject *QWebPluginFactory::create(const QString &mimeType, const QUrl &url,
  125. const QStringList &argumentNames, const QStringList &argumentValues) const = 0
  126. Implemented in subclasses to create a new plugin that can display content of
  127. the MIME type given by \a mimeType. The URL of the content is provided in \a url.
  128. The returned object should be a QWidget.
  129. The HTML object element can provide parameters through the \c{<param>} tag.
  130. The name and the value attributes of these tags are specified by the
  131. \a argumentNames and \a argumentValues string lists.
  132. For example:
  133. \code
  134. <object type="application/x-pdf" data="http://qt.nokia.com/document.pdf" width="500" height="400">
  135. <param name="showTableOfContents" value="true" />
  136. <param name="hideThumbnails" value="false" />
  137. </object>
  138. \endcode
  139. The above object element will result in a call to create() with the following arguments:
  140. \table
  141. \header \li Parameter
  142. \li Value
  143. \row \li mimeType
  144. \li "application/x-pdf"
  145. \row \li url
  146. \li "http://qt.nokia.com/document.pdf"
  147. \row \li argumentNames
  148. \li "showTableOfContents" "hideThumbnails"
  149. \row \li argumentVaues
  150. \li "true" "false"
  151. \endtable
  152. \note Ownership of the returned object will be transferred to the caller.
  153. */
  154. /*!
  155. \enum QWebPluginFactory::Extension
  156. \internal
  157. This enum describes the types of extensions that the plugin factory can support. Before using these extensions, you
  158. should verify that the extension is supported by calling supportsExtension().
  159. Currently there are no extensions.
  160. */
  161. /*!
  162. \class QWebPluginFactory::ExtensionOption
  163. \internal
  164. \since 4.4
  165. \brief The ExtensionOption class provides an extended input argument to QWebPluginFactory's extension support.
  166. \inmodule QtWebKit
  167. \sa QWebPluginFactory::extension()
  168. */
  169. /*!
  170. \class QWebPluginFactory::ExtensionReturn
  171. \internal
  172. \since 4.4
  173. \brief The ExtensionOption class provides an extended output argument to QWebPluginFactory's extension support.
  174. \inmodule QtWebKit
  175. \sa QWebPluginFactory::extension()
  176. */
  177. /*!
  178. This virtual function can be reimplemented in a QWebPluginFactory subclass to provide support for extensions. The \a option
  179. argument is provided as input to the extension; the output results can be stored in \a output.
  180. \internal
  181. The behaviour of this function is determined by \a extension.
  182. You can call supportsExtension() to check if an extension is supported by the factory.
  183. By default, no extensions are supported, and this function returns false.
  184. \sa supportsExtension(), Extension
  185. */
  186. bool QWebPluginFactory::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output)
  187. {
  188. Q_UNUSED(extension)
  189. Q_UNUSED(option)
  190. Q_UNUSED(output)
  191. return false;
  192. }
  193. /*!
  194. This virtual function returns true if the plugin factory supports \a extension; otherwise false is returned.
  195. \internal
  196. \sa extension()
  197. */
  198. bool QWebPluginFactory::supportsExtension(Extension extension) const
  199. {
  200. Q_UNUSED(extension)
  201. return false;
  202. }