2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2013-03-11 14:42:23 +01:00
|
|
|
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "webpluginfactory.h"
|
|
|
|
#include "clicktoflash.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "pluginproxy.h"
|
2012-07-01 12:07:00 +02:00
|
|
|
#include "adblockmanager.h"
|
2011-10-27 14:26:40 +02:00
|
|
|
#include "webpage.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QDebug>
|
2012-07-01 12:07:00 +02:00
|
|
|
#include <QNetworkRequest>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-01-27 17:25:51 +01:00
|
|
|
WebPluginFactory::WebPluginFactory(WebPage* page)
|
|
|
|
: QWebPluginFactory(page)
|
|
|
|
, m_page(page)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
|
|
|
|
{
|
2012-04-17 15:11:26 +02:00
|
|
|
if (url.isEmpty()) {
|
2012-04-17 17:54:51 +02:00
|
|
|
return new QObject();
|
2012-04-17 15:11:26 +02:00
|
|
|
}
|
|
|
|
|
2013-03-11 14:42:23 +01:00
|
|
|
// AdBlock
|
|
|
|
AdBlockManager* manager = AdBlockManager::instance();
|
|
|
|
QNetworkRequest request(url);
|
|
|
|
request.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User + 150), QString("object"));
|
|
|
|
if (manager->isEnabled() && manager->block(request)) {
|
|
|
|
return new QObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString mime = mimeType.trimmed(); // Fixing bad behaviour when mimeType contains spaces
|
2011-11-06 17:01:23 +01:00
|
|
|
if (mime.isEmpty()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (url.toString().endsWith(QLatin1String(".swf"))) {
|
2012-02-11 14:19:41 +01:00
|
|
|
mime = "application/x-shockwave-flash";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-05-04 18:22:54 +02:00
|
|
|
|
2012-09-05 19:57:36 +02:00
|
|
|
if (mime != QLatin1String("application/x-shockwave-flash")) {
|
|
|
|
if (mime != QLatin1String("application/futuresplash") && mime != QLatin1String("application/x-java-applet")) {
|
2012-04-17 15:11:26 +02:00
|
|
|
qDebug() << "WebPluginFactory::create creating object of mimeType : " << mime;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2011-05-04 18:22:54 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!mApp->plugins()->c2f_isEnabled()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return 0;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-21 20:58:02 +01:00
|
|
|
// Click2Flash whitelist
|
2011-03-04 13:59:07 +01:00
|
|
|
QStringList whitelist = mApp->plugins()->c2f_getWhiteList();
|
2012-09-04 12:42:45 +02:00
|
|
|
if (whitelist.contains(url.host()) || whitelist.contains("www." + url.host()) || whitelist.contains(url.host().remove(QLatin1String("www.")))) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return 0;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-22 21:09:04 +01:00
|
|
|
|
2011-12-21 20:58:02 +01:00
|
|
|
// Click2Flash already accepted
|
|
|
|
if (ClickToFlash::isAlreadyAccepted(url, argumentNames, argumentValues)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-27 17:25:51 +01:00
|
|
|
ClickToFlash* ctf = new ClickToFlash(url, argumentNames, argumentValues, m_page);
|
2011-04-15 20:44:57 +02:00
|
|
|
return ctf;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<QWebPluginFactory::Plugin> WebPluginFactory::plugins() const
|
|
|
|
{
|
2012-02-11 12:52:23 +01:00
|
|
|
QList<Plugin> plugins;
|
|
|
|
return plugins;
|
2012-01-25 19:13:12 +01:00
|
|
|
|
2012-02-11 12:52:23 +01:00
|
|
|
// QList<QWebPluginFactory::Plugin> plugins;
|
2011-03-02 16:57:41 +01:00
|
|
|
// QWebPluginFactory::Plugin plugin;
|
2012-02-11 12:52:23 +01:00
|
|
|
// QWebPluginFactory::MimeType mimeType;
|
2012-01-25 19:13:12 +01:00
|
|
|
|
2012-02-11 12:52:23 +01:00
|
|
|
// mimeType.fileExtensions << "swf";
|
|
|
|
// mimeType.name = "application/x-shockwave-flash";
|
2012-01-25 19:13:12 +01:00
|
|
|
|
2012-02-11 12:52:23 +01:00
|
|
|
// plugin.name = "ClickToFlashPlugin";
|
|
|
|
// plugin.mimeTypes.append(mimeType);
|
|
|
|
// plugins.append(plugin);
|
|
|
|
// return plugins;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|