46
45
#define QL1S(x) QLatin1String(x)
47
46
#define QL1C(x) QLatin1Char(x)
49
static bool excludedMimeType(const QString &type)
51
if (type.startsWith(QL1S("inode/"), Qt::CaseInsensitive))
54
if (type.startsWith(QL1S("application/x-java"), Qt::CaseInsensitive))
57
if (type == QL1S("application/x-shockwave-flash") ||
58
type == QL1S("application/futuresplash"))
64
49
KWebPluginFactory::KWebPluginFactory(QObject *parent)
65
50
:QWebPluginFactory(parent),d(0)
73
58
QObject* KWebPluginFactory::create(const QString& _mimeType, const QUrl& url, const QStringList& argumentNames, const QStringList& argumentValues) const
75
// Only attempt to find a KPart for the supported mime types...
76
QVariantList arguments;
77
const int count = argumentNames.count();
79
for (int i = 0; i < count; ++i) {
80
arguments << QString(argumentNames.at(i) + QL1S("=\"") + argumentValues.at(i) + QL1C('\"'));
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());
90
mimeType = ptr->name();
92
// Disregard inode/* mime-types...
93
if (mimeType.startsWith(QLatin1String("inode/"), Qt::CaseInsensitive))
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;
98
KParts::ReadOnlyPart* part = 0;
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()));
106
73
kDebug(800) << "Asked for" << mimeType << "plugin, got" << part;
117
84
KWebPage *page = qobject_cast<KWebPage *>(parent());
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");
112
static bool isHttpProtocol(const QUrl& url)
114
const QString scheme (url.scheme());
115
return (scheme.startsWith(QL1S("http"), Qt::CaseInsensitive)
116
|| scheme.startsWith(QL1S("webdav"), Qt::CaseInsensitive));
119
void KWebPluginFactory::extractGuessedMimeType (const QUrl& url, QString* mimeType) const
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();
130
KParts::ReadOnlyPart* KWebPluginFactory::createPartInstanceFrom(const QString& mimeType,
131
const QStringList& argumentNames,
132
const QStringList& argumentValues,
133
QWidget* parentWidget,
134
QObject* parentObj) const
136
KParts::ReadOnlyPart* part = 0;
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();
143
for (int i = 0; i < count; ++i) {
144
arguments << QString(argumentNames.at(i) + QL1S("=\"") + argumentValues.at(i) + QL1C('\"'));
146
part = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType, parentWidget, parentObj, QString(), arguments);
152
bool KWebPluginFactory::excludedMimeType (const QString& mimeType) const
154
if (mimeType.startsWith(QL1S("inode/"), Qt::CaseInsensitive))
157
if (mimeType.startsWith(QL1S("application/x-java"), Qt::CaseInsensitive))
160
if (mimeType == QL1S("application/x-shockwave-flash") ||
161
mimeType == QL1S("application/futuresplash"))
145
167
#include "kwebpluginfactory.moc"