~ubuntu-branches/ubuntu/utopic/kde4libs/utopic

« back to all changes in this revision

Viewing changes to kdewebkit/kwebpluginfactory.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-05-13 15:42:30 UTC
  • mfrom: (1.14.17)
  • Revision ID: package-import@ubuntu.com-20120513154230-2xv2bsi52w6x5lue
Tags: 4:4.8.3-0ubuntu1
* New upstream release
  - Drop kubuntu_fix_nepomuk_utils_crash.diff, applied upstream
  - Add new symbols to libkdecore5.symbols and libkdewebkit5.symbols
  - Update kdelibs5-dev.install and kdelibs5-experimental-dev.install
  - update symbol files for gcc 4.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <kdebug.h>
33
33
 
34
34
#include <kio/job.h>
35
 
#include <kio/scheduler.h>
36
35
#include <kparts/part.h>
37
36
 
38
37
#include <QtCore/QListIterator>
46
45
#define QL1S(x)  QLatin1String(x)
47
46
#define QL1C(x)  QLatin1Char(x)
48
47
 
49
 
static bool excludedMimeType(const QString &type)
50
 
{
51
 
    if (type.startsWith(QL1S("inode/"), Qt::CaseInsensitive))
52
 
        return true;
53
 
 
54
 
    if (type.startsWith(QL1S("application/x-java"), Qt::CaseInsensitive))
55
 
        return true;
56
 
 
57
 
    if (type == QL1S("application/x-shockwave-flash") ||
58
 
        type == QL1S("application/futuresplash"))
59
 
      return true;
60
 
 
61
 
    return false;
62
 
}
63
48
 
64
49
KWebPluginFactory::KWebPluginFactory(QObject *parent)
65
50
                  :QWebPluginFactory(parent),d(0)
72
57
 
73
58
QObject* KWebPluginFactory::create(const QString& _mimeType, const QUrl& url, const QStringList& argumentNames, const QStringList& argumentValues) const
74
59
{
75
 
    // Only attempt to find a KPart for the supported mime types...
76
 
    QVariantList arguments;
77
 
    const int count = argumentNames.count();
78
 
 
79
 
    for (int i = 0; i < count; ++i) {
80
 
        arguments << QString(argumentNames.at(i) + QL1S("=\"") + argumentValues.at(i) + QL1C('\"'));
81
 
    }
82
 
 
83
60
    QString mimeType (_mimeType.trimmed());
84
61
    // If no mimetype is provided, we do our best to correctly determine it here...
85
62
    if (mimeType.isEmpty()) {
86
 
      kDebug(800) << "Looking up missing mimetype for plugin resource:" << url;
87
 
      const KUrl reqUrl (url);
88
 
      KMimeType::Ptr ptr = KMimeType::findByUrl(reqUrl, 0, reqUrl.isLocalFile());
89
 
      if (ptr->isDefault())
90
 
          mimeType = ptr->name();
91
 
 
92
 
       // Disregard inode/* mime-types...
93
 
       if (mimeType.startsWith(QLatin1String("inode/"), Qt::CaseInsensitive))
94
 
          mimeType.clear();
95
 
       kDebug(800) << "Updated mimetype to" << mimeType;
 
63
        kDebug(800) << "Looking up missing mimetype for plugin resource:" << url;
 
64
        extractGuessedMimeType(url, &mimeType);
 
65
        kDebug(800) << "Updated mimetype to" << mimeType;
96
66
    }
97
67
 
98
 
    KParts::ReadOnlyPart* part = 0;
99
 
 
100
68
    // Defer handling of flash content to QtWebKit's builtin viewer.
101
69
    // If you want to use/test KDE's nspluginviewer, comment out the
102
70
    // if statement below.
103
 
    if (!mimeType.isEmpty() && !excludedMimeType(mimeType))
104
 
        part = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType, 0, parent(), QString(), arguments);
 
71
    KParts::ReadOnlyPart* part = (excludedMimeType(mimeType) ? 0 : createPartInstanceFrom(mimeType, argumentNames, argumentValues, 0, parent()));
105
72
 
106
73
    kDebug(800) << "Asked for" << mimeType << "plugin, got" << part;
107
74
 
117
84
        KWebPage *page = qobject_cast<KWebPage *>(parent());
118
85
 
119
86
        if (page) {
120
 
            const QString scheme = page->mainFrame()->url().scheme();
 
87
            const QString scheme = page->currentFrame()->url().scheme();
121
88
            if (page && (QString::compare(scheme, QL1S("https"), Qt::CaseInsensitive) == 0 ||
122
89
                         QString::compare(scheme, QL1S("webdavs"), Qt::CaseInsensitive) == 0))
123
90
              metaData.insert("ssl_was_in_use", "TRUE");
142
109
    return plugins;
143
110
}
144
111
 
 
112
static bool isHttpProtocol(const QUrl& url)
 
113
{
 
114
    const QString scheme (url.scheme());
 
115
    return (scheme.startsWith(QL1S("http"), Qt::CaseInsensitive)
 
116
         || scheme.startsWith(QL1S("webdav"), Qt::CaseInsensitive));
 
117
}
 
118
 
 
119
void KWebPluginFactory::extractGuessedMimeType (const QUrl& url, QString* mimeType) const
 
120
{
 
121
    if (mimeType) {
 
122
        const KUrl reqUrl ((isHttpProtocol(url) ? url.path() : url));
 
123
        KMimeType::Ptr ptr = KMimeType::findByUrl(reqUrl, 0, reqUrl.isLocalFile(), true);
 
124
        if (!ptr->isDefault() && !ptr->name().startsWith(QL1S("inode/"), Qt::CaseInsensitive)) {
 
125
            *mimeType = ptr->name();
 
126
        }
 
127
    }
 
128
}
 
129
 
 
130
KParts::ReadOnlyPart* KWebPluginFactory::createPartInstanceFrom(const QString& mimeType,
 
131
                                                                const QStringList& argumentNames,
 
132
                                                                const QStringList& argumentValues,
 
133
                                                                QWidget* parentWidget,
 
134
                                                                QObject* parentObj) const
 
135
{
 
136
    KParts::ReadOnlyPart* part = 0;
 
137
 
 
138
    if (!mimeType.isEmpty()) {
 
139
        // Only attempt to find a KPart for the supported mime types...
 
140
        QVariantList arguments;
 
141
        const int count = argumentNames.count();
 
142
 
 
143
        for (int i = 0; i < count; ++i) {
 
144
            arguments << QString(argumentNames.at(i) + QL1S("=\"") + argumentValues.at(i) + QL1C('\"'));
 
145
        }
 
146
        part = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType, parentWidget, parentObj, QString(), arguments);
 
147
    }
 
148
 
 
149
    return part;
 
150
}
 
151
 
 
152
bool KWebPluginFactory::excludedMimeType (const QString& mimeType) const
 
153
{
 
154
    if (mimeType.startsWith(QL1S("inode/"), Qt::CaseInsensitive))
 
155
        return true;
 
156
 
 
157
    if (mimeType.startsWith(QL1S("application/x-java"), Qt::CaseInsensitive))
 
158
        return true;
 
159
 
 
160
    if (mimeType == QL1S("application/x-shockwave-flash") ||
 
161
        mimeType == QL1S("application/futuresplash"))
 
162
      return true;
 
163
 
 
164
    return false;
 
165
}
 
166
 
145
167
#include "kwebpluginfactory.moc"