mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Fixed bug in click2flash when some flash's won't be loaded
This commit is contained in:
parent
d3ef260c12
commit
a84af542ab
|
@ -138,10 +138,46 @@ void ClickToFlash::toWhitelist()
|
|||
|
||||
void ClickToFlash::load()
|
||||
{
|
||||
QWidget* parent = parentWidget();
|
||||
QWebView* view = 0;
|
||||
// QWidget* parent = parentWidget();
|
||||
// QWebView* view = 0;
|
||||
// while (parent) {
|
||||
// if (QWebView* aView = qobject_cast<QWebView*>(parent)) {
|
||||
// view = aView;
|
||||
// break;
|
||||
// }
|
||||
// parent = parent->parentWidget();
|
||||
// }
|
||||
// if (!view)
|
||||
// return;
|
||||
|
||||
// const QString selector = "%1[type=\"application/x-shockwave-flash\"]";
|
||||
// hide();
|
||||
|
||||
// QList<QWebFrame*> frames;
|
||||
// frames.append(view->page()->mainFrame());
|
||||
// while (!frames.isEmpty()) {
|
||||
// QWebFrame* frame = frames.takeFirst();
|
||||
// QWebElement docElement = frame->documentElement();
|
||||
|
||||
// QWebElementCollection elements;
|
||||
// elements.append(docElement.findAll(selector.arg("object")));
|
||||
// elements.append(docElement.findAll(selector.arg("embed")));
|
||||
|
||||
// foreach(QWebElement element, elements) {
|
||||
// if (checkElement(element)) {
|
||||
// QWebElement substitute = element.clone();
|
||||
// emit signalLoadClickToFlash(true);
|
||||
// element.replace(substitute);
|
||||
// deleteLater();
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// frames += frame->childFrames();
|
||||
// }
|
||||
QWidget *parent = parentWidget();
|
||||
QWebView *view = 0;
|
||||
while (parent) {
|
||||
if (QWebView* aView = qobject_cast<QWebView*>(parent)) {
|
||||
if (QWebView *aView = qobject_cast<QWebView*>(parent)) {
|
||||
view = aView;
|
||||
break;
|
||||
}
|
||||
|
@ -150,28 +186,32 @@ void ClickToFlash::load()
|
|||
if (!view)
|
||||
return;
|
||||
|
||||
const QString selector = "%1[type=\"application/x-shockwave-flash\"]";
|
||||
hide();
|
||||
// const QString selector = QLatin1String("%1[type=\"application/x-shockwave-flash\"]");
|
||||
const QString mime = QLatin1String("application/futuresplash");
|
||||
|
||||
hide();
|
||||
QList<QWebFrame*> frames;
|
||||
frames.append(view->page()->mainFrame());
|
||||
while (!frames.isEmpty()) {
|
||||
QWebFrame* frame = frames.takeFirst();
|
||||
QWebFrame *frame = frames.takeFirst();
|
||||
QWebElement docElement = frame->documentElement();
|
||||
|
||||
QWebElementCollection elements;
|
||||
elements.append(docElement.findAll(selector.arg("object")));
|
||||
elements.append(docElement.findAll(selector.arg("embed")));
|
||||
elements.append(docElement.findAll(QLatin1String("object")));
|
||||
// elements.append(docElement.findAll(selector.arg(QLatin1String("object"))));
|
||||
elements.append(docElement.findAll(QLatin1String("embed")));
|
||||
// elements.append(docElement.findAll(selector.arg(QLatin1String("embed"))));
|
||||
|
||||
foreach(QWebElement element, elements) {
|
||||
if (checkElement(element)) {
|
||||
QWebElement substitute = element.clone();
|
||||
emit signalLoadClickToFlash(true);
|
||||
element.replace(substitute);
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
QWebElement element;
|
||||
foreach (element, elements) {
|
||||
if (!checkElement(element))
|
||||
continue;
|
||||
QWebElement substitute = element.clone();
|
||||
substitute.setAttribute(QLatin1String("type"), mime);
|
||||
element.replace(substitute);
|
||||
return;
|
||||
}
|
||||
|
||||
frames += frame->childFrames();
|
||||
}
|
||||
}
|
||||
|
@ -182,19 +222,27 @@ bool ClickToFlash::checkElement(QWebElement el)
|
|||
QString checkString;
|
||||
QString urlString;
|
||||
checkString = QUrl(el.attribute("src")).toString(QUrl::RemoveQuery);
|
||||
if (checkString.isEmpty())
|
||||
checkString = QUrl(el.attribute("data")).toString(QUrl::RemoveQuery);
|
||||
|
||||
if (checkString.isEmpty())
|
||||
return false;
|
||||
urlString = m_url.toString(QUrl::RemoveQuery);
|
||||
|
||||
if (urlString.contains(checkString))
|
||||
return true;
|
||||
QWebElementCollection collec = el.findAll("*");
|
||||
int i = 0;
|
||||
while (i < collec.count()) {
|
||||
QWebElement el = collec.at(i);
|
||||
checkString = QUrl(el.attribute("src")).toString(QUrl::RemoveQuery);
|
||||
urlString = m_url.toString(QUrl::RemoveQuery);
|
||||
if (urlString.contains(checkString))
|
||||
return true;
|
||||
i++;
|
||||
}
|
||||
|
||||
qDebug() << checkString << m_url;
|
||||
|
||||
// QWebElementCollection collec = el.findAll("*");
|
||||
// int i = 0;
|
||||
// while (i < collec.count()) {
|
||||
// QWebElement el = collec.at(i);
|
||||
// checkString = QUrl(el.attribute("src")).toString(QUrl::RemoveQuery);
|
||||
// urlString = m_url.toString(QUrl::RemoveQuery);
|
||||
// if (urlString.contains(checkString))
|
||||
// return true;
|
||||
// i++;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -63,9 +63,6 @@ class ClickToFlash : public QWidget
|
|||
public:
|
||||
explicit ClickToFlash(const QUrl &pluginUrl, QWidget* parent = 0);
|
||||
|
||||
signals:
|
||||
void signalLoadClickToFlash(bool);
|
||||
|
||||
private slots:
|
||||
void load();
|
||||
void customContextMenuRequested(const QPoint &pos);
|
||||
|
|
|
@ -22,9 +22,7 @@
|
|||
|
||||
WebPluginFactory::WebPluginFactory(QObject* parent)
|
||||
: QWebPluginFactory(parent)
|
||||
,m_loadClickToFlash(false)
|
||||
{
|
||||
connect(this, SIGNAL(signalLoadClickToFlash(bool)), SLOT(setLoadClickToFlash(bool)));
|
||||
}
|
||||
|
||||
QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
|
||||
|
@ -33,7 +31,8 @@ QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, cons
|
|||
Q_UNUSED(argumentValues)
|
||||
|
||||
if (mimeType != "application/x-shockwave-flash") {
|
||||
qDebug() << mimeType;
|
||||
if (mimeType != "application/futuresplash")
|
||||
qDebug() << mimeType;
|
||||
return 0;
|
||||
}
|
||||
if (!mApp->plugins()->c2f_isEnabled())
|
||||
|
@ -44,14 +43,8 @@ QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, cons
|
|||
if (whitelist.contains(url.host()) || whitelist.contains("www."+url.host()) || whitelist.contains(url.host().remove("www.")))
|
||||
return 0;
|
||||
|
||||
if (m_loadClickToFlash) {
|
||||
emit signalLoadClickToFlash(false);
|
||||
return 0;
|
||||
} else {
|
||||
ClickToFlash* ctf = new ClickToFlash(url);
|
||||
connect(ctf, SIGNAL(signalLoadClickToFlash(bool)), this, SLOT(setLoadClickToFlash(bool)));
|
||||
return ctf;
|
||||
}
|
||||
ClickToFlash* ctf = new ClickToFlash(url);
|
||||
return ctf;
|
||||
}
|
||||
|
||||
QList<QWebPluginFactory::Plugin> WebPluginFactory::plugins() const
|
||||
|
|
|
@ -30,13 +30,7 @@ public:
|
|||
virtual QObject* create (const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const;
|
||||
QList<QWebPluginFactory::Plugin> plugins() const;
|
||||
|
||||
signals:
|
||||
void signalLoadClickToFlash(bool) const;
|
||||
|
||||
public slots:
|
||||
void setLoadClickToFlash(bool load) { m_loadClickToFlash = load; }
|
||||
|
||||
private:
|
||||
bool m_loadClickToFlash;
|
||||
|
||||
};
|
||||
#endif // WEB_PLUGIN_FACTORY_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user