From a84af542ab6be14403816276aefae980f83c5c21 Mon Sep 17 00:00:00 2001 From: nowrep Date: Fri, 15 Apr 2011 20:44:57 +0200 Subject: [PATCH] Fixed bug in click2flash when some flash's won't be loaded --- src/plugins/clicktoflash.cpp | 100 +++++++++++++++++++++++-------- src/plugins/clicktoflash.h | 3 - src/plugins/webpluginfactory.cpp | 15 ++--- src/plugins/webpluginfactory.h | 8 +-- 4 files changed, 79 insertions(+), 47 deletions(-) diff --git a/src/plugins/clicktoflash.cpp b/src/plugins/clicktoflash.cpp index 60c470a66..07d8ad70c 100644 --- a/src/plugins/clicktoflash.cpp +++ b/src/plugins/clicktoflash.cpp @@ -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(parent)) { +// view = aView; +// break; +// } +// parent = parent->parentWidget(); +// } +// if (!view) +// return; + +// const QString selector = "%1[type=\"application/x-shockwave-flash\"]"; +// hide(); + +// QList 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(parent)) { + if (QWebView *aView = qobject_cast(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 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; } diff --git a/src/plugins/clicktoflash.h b/src/plugins/clicktoflash.h index 91aa5aba0..0c38a979b 100644 --- a/src/plugins/clicktoflash.h +++ b/src/plugins/clicktoflash.h @@ -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); diff --git a/src/plugins/webpluginfactory.cpp b/src/plugins/webpluginfactory.cpp index 1b526d1c2..6e8464158 100644 --- a/src/plugins/webpluginfactory.cpp +++ b/src/plugins/webpluginfactory.cpp @@ -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 WebPluginFactory::plugins() const diff --git a/src/plugins/webpluginfactory.h b/src/plugins/webpluginfactory.h index 48a2f72d2..7415a5065 100644 --- a/src/plugins/webpluginfactory.h +++ b/src/plugins/webpluginfactory.h @@ -30,13 +30,7 @@ public: virtual QObject* create (const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const; QList 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