~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/qt/WebCoreSupport/QtPlatformPlugin.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
21
#include "config.h"
 
22
#include "QtPlatformPlugin.h"
 
23
 
 
24
#include "qwebkitplatformplugin.h"
 
25
 
 
26
#include <QCoreApplication>
 
27
#include <QDir>
 
28
#include <QPluginLoader>
 
29
 
 
30
namespace WebCore {
 
31
 
 
32
bool QtPlatformPlugin::load(const QString& file)
 
33
{
 
34
    m_loader.setFileName(file);
 
35
    if (!m_loader.load())
 
36
        return false;
 
37
 
 
38
    QObject* obj = m_loader.instance();
 
39
    if (obj) {
 
40
        m_plugin = qobject_cast<QWebKitPlatformPlugin*>(obj);
 
41
        if (m_plugin)
 
42
            return true;
 
43
    }
 
44
 
 
45
    m_loader.unload();
 
46
    return false;
 
47
}
 
48
 
 
49
bool QtPlatformPlugin::load()
 
50
{
 
51
    const QLatin1String suffix("/webkit/");
 
52
    const QStringList paths = QCoreApplication::libraryPaths();
 
53
 
 
54
    for (int i = 0; i < paths.count(); ++i) {
 
55
        const QDir dir(paths[i] + suffix);
 
56
        if (!dir.exists())
 
57
            continue;
 
58
        const QStringList files = dir.entryList(QDir::Files);
 
59
        for (int j = 0; j < files.count(); ++j) {
 
60
            if (load(dir.absoluteFilePath(files.at(j))))
 
61
                return true;
 
62
        }
 
63
    }
 
64
    return false;
 
65
}
 
66
 
 
67
QtPlatformPlugin::~QtPlatformPlugin()
 
68
{
 
69
    m_loader.unload();
 
70
}
 
71
 
 
72
bool QtPlatformPlugin::loadStaticallyLinkedPlugin()
 
73
{
 
74
    QObjectList objs = QPluginLoader::staticInstances();
 
75
    for (int i = 0; i < objs.size(); ++i) {
 
76
        m_plugin = qobject_cast<QWebKitPlatformPlugin*>(objs[i]);
 
77
        if (m_plugin)
 
78
            return true;
 
79
    }
 
80
    return false;
 
81
}
 
82
 
 
83
QWebKitPlatformPlugin* QtPlatformPlugin::plugin()
 
84
{
 
85
    if (m_loaded)
 
86
        return m_plugin;
 
87
    m_loaded = true;
 
88
 
 
89
    if (loadStaticallyLinkedPlugin())
 
90
        return m_plugin;
 
91
 
 
92
    // Plugin path is stored in a static variable to avoid searching for the plugin
 
93
    // more then once.
 
94
    static QString pluginPath;
 
95
 
 
96
    if (pluginPath.isNull()) {
 
97
        if (load())
 
98
            pluginPath = m_loader.fileName();
 
99
    } else
 
100
        load(pluginPath);
 
101
 
 
102
    return m_plugin;
 
103
}
 
104
 
 
105
PassOwnPtr<QWebSelectMethod> QtPlatformPlugin::createSelectInputMethod()
 
106
{
 
107
    QWebKitPlatformPlugin* p = plugin();
 
108
    return adoptPtr(p ? static_cast<QWebSelectMethod*>(p->createExtension(QWebKitPlatformPlugin::MultipleSelections)) : 0);
 
109
}
 
110
 
 
111
PassOwnPtr<QWebNotificationPresenter> QtPlatformPlugin::createNotificationPresenter()
 
112
{
 
113
    QWebKitPlatformPlugin* p = plugin();
 
114
    return adoptPtr(p ? static_cast<QWebNotificationPresenter*>(p->createExtension(QWebKitPlatformPlugin::Notifications)) : 0);
 
115
}
 
116
 
 
117
PassOwnPtr<QWebHapticFeedbackPlayer> QtPlatformPlugin::createHapticFeedbackPlayer()
 
118
{
 
119
    QWebKitPlatformPlugin* p = plugin();
 
120
    return adoptPtr(p ? static_cast<QWebHapticFeedbackPlayer*>(p->createExtension(QWebKitPlatformPlugin::Haptics)) : 0);
 
121
}
 
122
 
 
123
PassOwnPtr<QWebTouchModifier> QtPlatformPlugin::createTouchModifier()
 
124
{
 
125
    QWebKitPlatformPlugin* p = plugin();
 
126
    return adoptPtr(p ? static_cast<QWebTouchModifier*>(p->createExtension(QWebKitPlatformPlugin::TouchInteraction)) : 0);
 
127
}
 
128
 
 
129
#if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
 
130
PassOwnPtr<QWebFullScreenVideoHandler> QtPlatformPlugin::createFullScreenVideoHandler()
 
131
{
 
132
    QWebKitPlatformPlugin* p = plugin();
 
133
    return adoptPtr(p ? static_cast<QWebFullScreenVideoHandler*>(p->createExtension(QWebKitPlatformPlugin::FullScreenVideoPlayer)) : 0);
 
134
}
 
135
#endif
 
136
 
 
137
PassOwnPtr<QWebSpellChecker> QtPlatformPlugin::createSpellChecker()
 
138
{
 
139
    QWebKitPlatformPlugin* p = plugin();
 
140
    return adoptPtr(p ? static_cast<QWebSpellChecker*>(p->createExtension(QWebKitPlatformPlugin::SpellChecker)) : 0);
 
141
}
 
142
 
 
143
}