Commit 36b0aebb authored by Dawit Alemayehu's avatar Dawit Alemayehu
Browse files

Added an option, "DisableInternalPluginHandling", that allows the user to disable

the internal handling of flash and java applets.

Currently it lacks GUI configuration, but it can be activated by adding the
aforementioned option to the "General" section of $KDEHOME/share/config/kwebkitpartrc
and setting it to "true".

BUG: 232736
FIXED-IN: 4.9.0
parent b7a0448c
project(kwebkitpart)
# search packages used by KDE
find_package(KDE4 4.8.2 REQUIRED)
find_package(KDE4 4.8.3 REQUIRED)
include(KDE4Defaults)
include(MacroLibrary)
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
......
......@@ -10,6 +10,7 @@ set(kwebkit_LIB_SRCS
websslinfo.cpp
webhistoryinterface.cpp
networkaccessmanager.cpp
webpluginfactory.cpp
settings/webkitsettings.cpp
settings/webkit_filter.cpp
ui/searchbar.cpp
......
......@@ -139,6 +139,7 @@ KWebKitPart::KWebKitPart(QWidget *parentWidget, QObject *parent,
// Add text and html extensions...
new KWebKitTextExtension(this);
new KWebKitHtmlExtension(this);
new KWebKitScriptableExtension(this);
// Create the search bar...
m_searchBar = new KDEPrivate::SearchBar(mainWidget);
......
......@@ -46,6 +46,7 @@
#include <kdeversion.h>
#include <QtCore/QBuffer>
#include <QtCore/QMapIterator>
#include <QtCore/QCryptographicHash>
#include <QtGui/QClipboard>
#include <QtGui/QApplication>
......@@ -1047,4 +1048,88 @@ KWebKitPart* KWebKitHtmlExtension::part() const
return static_cast<KWebKitPart*>(parent());
}
KWebKitScriptableExtension::KWebKitScriptableExtension(KWebKitPart* part)
: ScriptableExtension(part)
{
}
QVariant KWebKitScriptableExtension::rootObject()
{
return QVariant::fromValue(KParts::ScriptableExtension::Object(this, reinterpret_cast<quint64>(this)));
}
bool KWebKitScriptableExtension::setException (KParts::ScriptableExtension* callerPrincipal, const QString& message)
{
return KParts::ScriptableExtension::setException (callerPrincipal, message);
}
QVariant KWebKitScriptableExtension::get (KParts::ScriptableExtension* callerPrincipal, quint64 objId, const QString& propName)
{
kDebug() << "caller:" << callerPrincipal << "id:" << objId << "propName:" << propName;
return callerPrincipal->get (0, objId, propName);
}
bool KWebKitScriptableExtension::put (KParts::ScriptableExtension* callerPrincipal, quint64 objId, const QString& propName, const QVariant& value)
{
return KParts::ScriptableExtension::put (callerPrincipal, objId, propName, value);
}
static QVariant exception(const char* msg)
{
kWarning(6031) << msg;
return QVariant::fromValue(KParts::ScriptableExtension::Exception(QString::fromLatin1(msg)));
}
QVariant KWebKitScriptableExtension::evaluateScript (KParts::ScriptableExtension* callerPrincipal,
quint64 contextObjectId,
const QString& code,
KParts::ScriptableExtension::ScriptLanguage lang)
{
kDebug() << "principal:" << callerPrincipal << "id:" << contextObjectId << "language:" << lang << "code:" << code;
if (lang != ECMAScript)
return exception("unsupported language");
KParts::ReadOnlyPart* part = callerPrincipal ? qobject_cast<KParts::ReadOnlyPart*>(callerPrincipal->parent()) : 0;
QWebFrame* frame = part ? qobject_cast<QWebFrame*>(part->parent()) : 0;
if (!frame)
return exception("failed to resolve principal");
QVariant result (frame->evaluateJavaScript(code));
if (result.type() == QVariant::Map) {
const QVariantMap map (result.toMap());
for (QVariantMap::const_iterator it = map.constBegin(), itEnd = map.constEnd(); it != itEnd; ++it) {
callerPrincipal->put(callerPrincipal, 0, it.key(), it.value());
}
} else {
const QString propName(code.contains(QLatin1String("__nsplugin")) ? QLatin1String("__nsplugin") : QString());
callerPrincipal->put(callerPrincipal, 0, propName, result.toString());
}
return QVariant::fromValue(ScriptableExtension::Null());
}
bool KWebKitScriptableExtension::isScriptLanguageSupported (KParts::ScriptableExtension::ScriptLanguage lang) const
{
return (lang == KParts::ScriptableExtension::ECMAScript);
}
QVariant KWebKitScriptableExtension::encloserForKid (KParts::ScriptableExtension* kid)
{
KParts::ReadOnlyPart* part = kid ? qobject_cast<KParts::ReadOnlyPart*>(kid->parent()) : 0;
QWebFrame* frame = part ? qobject_cast<QWebFrame*>(part->parent()) : 0;
if (frame) {
return QVariant::fromValue(KParts::ScriptableExtension::Object(kid, reinterpret_cast<quint64>(kid)));
}
return QVariant::fromValue(ScriptableExtension::Null());
}
KWebKitPart* KWebKitScriptableExtension::part()
{
return qobject_cast<KWebKitPart*>(parent());
}
#include "kwebkitpart_ext.moc"
......@@ -24,6 +24,7 @@
#include <KDE/KParts/BrowserExtension>
#include <KDE/KParts/TextExtension>
#include <KDE/KParts/HtmlExtension>
#include <kparts/scriptableextension.h>
class KUrl;
class KWebKitPart;
......@@ -166,4 +167,31 @@ private:
KWebKitPart* part() const;
};
class KWebKitScriptableExtension : public KParts::ScriptableExtension
{
Q_OBJECT
public:
KWebKitScriptableExtension(KWebKitPart* part);
virtual QVariant rootObject();
virtual QVariant get(ScriptableExtension* callerPrincipal, quint64 objId, const QString& propName);
virtual bool put(ScriptableExtension* callerPrincipal, quint64 objId, const QString& propName, const QVariant& value);
virtual bool setException(ScriptableExtension* callerPrincipal, const QString& message);
virtual QVariant evaluateScript(ScriptableExtension* callerPrincipal,
quint64 contextObjectId,
const QString& code,
ScriptLanguage language = ECMAScript);
virtual bool isScriptLanguageSupported(ScriptLanguage lang) const;
private:
virtual QVariant encloserForKid(KParts::ScriptableExtension* kid);
KWebKitPart* part();
};
#endif // WEBKITPART_EXT_H
......@@ -28,6 +28,7 @@
#include "sslinfodialog_p.h"
#include "networkaccessmanager.h"
#include "settings/webkitsettings.h"
#include "webpluginfactory.h"
#include <kdeversion.h>
#include <KDE/KMessageBox>
......@@ -81,6 +82,8 @@ WebPage::WebPage(KWebKitPart *part, QWidget *parent)
}
setNetworkAccessManager(manager);
setPluginFactory(new WebPluginFactory(part));
setSessionMetaData(QL1S("ssl_activate_warnings"), QL1S("TRUE"));
// Set font sizes accordingly...
......
/*
* This file is part of the KDE project.
*
* Copyright (C) 2012 Dawit Alemayehu <adawit@kde.org>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "webpluginfactory.h"
#include "webpage.h"
#include "kwebkitpart.h"
#include "settings/webkitsettings.h"
#include <KDE/KDebug>
#include <KDE/KConfigGroup>
#include <KDE/KSharedConfig>
#include <KDE/KParts/ReadOnlyPart>
#include <KDE/KParts/BrowserExtension>
#include <kparts/scriptableextension.h>
#include <QtWebKit/QWebFrame>
#include <QtWebKit/QWebView>
#define QL1S(x) QLatin1String(x)
WebPluginFactory::WebPluginFactory (KWebKitPart* parent)
: KWebPluginFactory (parent)
, mPart (parent)
{
}
QObject* WebPluginFactory::create (const QString& _mimeType, const QUrl& url, const QStringList& argumentNames, const QStringList& argumentValues) const
{
QString mimeType (_mimeType.trimmed());
if (mimeType.isEmpty()) {
extractGuessedMimeType (url, &mimeType);
}
KParts::ReadOnlyPart* part = 0;
QWebView* view = 0;
if (WebKitSettings::self()->isInternalPluginHandlingDisabled() || !excludedMimeType(mimeType)) {
view = mPart->view();
QWebFrame* frame = (view ? view->page()->currentFrame() : 0);
part = createPartInstanceFrom(mimeType, argumentNames, argumentValues, view, frame);
}
kDebug() << "Asked for" << mimeType << "plugin, got" << part;
if (part) {
connect (part->browserExtension(), SIGNAL (openUrlNotify()),
mPart->browserExtension(), SIGNAL (openUrlNotify()));
connect (part->browserExtension(), SIGNAL (openUrlRequest (KUrl, KParts::OpenUrlArguments, KParts::BrowserArguments)),
mPart->browserExtension(), SIGNAL (openUrlRequest (KUrl, KParts::OpenUrlArguments, KParts::BrowserArguments)));
// Check if this part is scriptable
KParts::ScriptableExtension* scriptExt = KParts::ScriptableExtension::childObject(part);
if (!scriptExt) {
// Try to fall back to LiveConnectExtension compat
KParts::LiveConnectExtension* lc = KParts::LiveConnectExtension::childObject(part);
if (lc) {
scriptExt = KParts::ScriptableExtension::adapterFromLiveConnect(part, lc);
}
}
if (scriptExt) {
scriptExt->setHost(KParts::ScriptableExtension::childObject(mPart));
}
QMap<QString, QString> metaData = part->arguments().metaData();
QString urlStr = url.toString (QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment);
metaData.insert ("PropagateHttpHeader", "true");
metaData.insert ("referrer", urlStr);
metaData.insert ("cross-domain", urlStr);
metaData.insert ("main_frame_request", "TRUE");
metaData.insert ("ssl_activate_warnings", "TRUE");
KWebPage *page = (view ? qobject_cast<KWebPage*>(view->page()) : 0);
if (page) {
const QString scheme = page->currentFrame()->url().scheme();
if (page && (QString::compare (scheme, QL1S ("https"), Qt::CaseInsensitive) == 0 ||
QString::compare (scheme, QL1S ("webdavs"), Qt::CaseInsensitive) == 0))
metaData.insert ("ssl_was_in_use", "TRUE");
else
metaData.insert ("ssl_was_in_use", "FALSE");
}
KParts::OpenUrlArguments openUrlArgs = part->arguments();
openUrlArgs.metaData() = metaData;
openUrlArgs.setMimeType(mimeType);
part->setArguments(openUrlArgs);
QMetaObject::invokeMethod(part, "openUrl", Qt::QueuedConnection, Q_ARG(KUrl, KUrl(url)));
return part->widget();
}
return 0;
}
/*
* This file is part of the KDE project.
*
* Copyright (C) 2012 Dawit Alemayehu <adawit@kde.org>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef WEBPLUGINFACTORY_H
#define WEBPLUGINFACTORY_H
#include <KDE/KWebPluginFactory>
class KWebKitPart;
class WebPluginFactory : public KWebPluginFactory
{
public:
WebPluginFactory (KWebKitPart* parent = 0);
virtual QObject* create (const QString&, const QUrl&, const QStringList&, const QStringList&) const;
private:
KWebKitPart* mPart;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment