QtPlatformPlugin.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this library; see the file COPYING.LIB. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #include "config.h"
  21. #include "QtPlatformPlugin.h"
  22. #include "qwebkitplatformplugin.h"
  23. #include <QCoreApplication>
  24. #include <QDir>
  25. #include <QPluginLoader>
  26. namespace WebCore {
  27. bool QtPlatformPlugin::load(const QString& file)
  28. {
  29. m_loader.setFileName(file);
  30. if (!m_loader.load())
  31. return false;
  32. QObject* obj = m_loader.instance();
  33. if (obj) {
  34. m_plugin = qobject_cast<QWebKitPlatformPlugin*>(obj);
  35. if (m_plugin)
  36. return true;
  37. }
  38. m_loader.unload();
  39. return false;
  40. }
  41. bool QtPlatformPlugin::load()
  42. {
  43. const QLatin1String suffix("/webkit/");
  44. const QStringList paths = QCoreApplication::libraryPaths();
  45. for (int i = 0; i < paths.count(); ++i) {
  46. const QDir dir(paths[i] + suffix);
  47. if (!dir.exists())
  48. continue;
  49. const QStringList files = dir.entryList(QDir::Files);
  50. for (int j = 0; j < files.count(); ++j) {
  51. if (load(dir.absoluteFilePath(files.at(j))))
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. QtPlatformPlugin::~QtPlatformPlugin()
  58. {
  59. m_loader.unload();
  60. }
  61. bool QtPlatformPlugin::loadStaticallyLinkedPlugin()
  62. {
  63. QObjectList objs = QPluginLoader::staticInstances();
  64. for (int i = 0; i < objs.size(); ++i) {
  65. m_plugin = qobject_cast<QWebKitPlatformPlugin*>(objs[i]);
  66. if (m_plugin)
  67. return true;
  68. }
  69. return false;
  70. }
  71. QWebKitPlatformPlugin* QtPlatformPlugin::plugin()
  72. {
  73. if (m_loaded)
  74. return m_plugin;
  75. m_loaded = true;
  76. if (loadStaticallyLinkedPlugin())
  77. return m_plugin;
  78. // Plugin path is stored in a static variable to avoid searching for the plugin
  79. // more then once.
  80. static QString pluginPath;
  81. if (pluginPath.isNull()) {
  82. if (load())
  83. pluginPath = m_loader.fileName();
  84. } else
  85. load(pluginPath);
  86. return m_plugin;
  87. }
  88. PassOwnPtr<QWebSelectMethod> QtPlatformPlugin::createSelectInputMethod()
  89. {
  90. QWebKitPlatformPlugin* p = plugin();
  91. return adoptPtr(p ? static_cast<QWebSelectMethod*>(p->createExtension(QWebKitPlatformPlugin::MultipleSelections)) : 0);
  92. }
  93. PassOwnPtr<QWebNotificationPresenter> QtPlatformPlugin::createNotificationPresenter()
  94. {
  95. QWebKitPlatformPlugin* p = plugin();
  96. return adoptPtr(p ? static_cast<QWebNotificationPresenter*>(p->createExtension(QWebKitPlatformPlugin::Notifications)) : 0);
  97. }
  98. PassOwnPtr<QWebHapticFeedbackPlayer> QtPlatformPlugin::createHapticFeedbackPlayer()
  99. {
  100. QWebKitPlatformPlugin* p = plugin();
  101. return adoptPtr(p ? static_cast<QWebHapticFeedbackPlayer*>(p->createExtension(QWebKitPlatformPlugin::Haptics)) : 0);
  102. }
  103. PassOwnPtr<QWebTouchModifier> QtPlatformPlugin::createTouchModifier()
  104. {
  105. QWebKitPlatformPlugin* p = plugin();
  106. return adoptPtr(p ? static_cast<QWebTouchModifier*>(p->createExtension(QWebKitPlatformPlugin::TouchInteraction)) : 0);
  107. }
  108. #if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
  109. PassOwnPtr<QWebFullScreenVideoHandler> QtPlatformPlugin::createFullScreenVideoHandler()
  110. {
  111. QWebKitPlatformPlugin* p = plugin();
  112. return adoptPtr(p ? static_cast<QWebFullScreenVideoHandler*>(p->createExtension(QWebKitPlatformPlugin::FullScreenVideoPlayer)) : 0);
  113. }
  114. #endif
  115. PassOwnPtr<QWebSpellChecker> QtPlatformPlugin::createSpellChecker()
  116. {
  117. QWebKitPlatformPlugin* p = plugin();
  118. return adoptPtr(p ? static_cast<QWebSpellChecker*>(p->createExtension(QWebKitPlatformPlugin::SpellChecker)) : 0);
  119. }
  120. }