From c9813c11a0c8a928d8fac4eb63efd29eec50047d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 4 Mar 2010 15:37:18 +0100 Subject: Fix Click to Flash. In my tests it doesn't crash anymore and works ever well :) (Please, don't wake up me if this is just aa dream..) --- src/clicktoflash.cpp | 54 ++++++++++++++++++++++++++++++------------------ src/clicktoflash.h | 3 +++ src/webpluginfactory.cpp | 2 +- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/clicktoflash.cpp b/src/clicktoflash.cpp index 24f8740e..3c284b3f 100644 --- a/src/clicktoflash.cpp +++ b/src/clicktoflash.cpp @@ -31,6 +31,7 @@ // KDE Includes #include +#include // Qt Includes #include @@ -89,28 +90,11 @@ void ClickToFlash::load() elements.append(docElement.findAll(selector.arg(QLatin1String("object")))); elements.append(docElement.findAll(selector.arg(QLatin1String("embed")))); - bool isRightElement = false; foreach (QWebElement element, elements) { - // TODO : find a proper solution to compare a QWebElement with a plugin - // With this "manual" test, it's probably not working everywhere - if(QUrl(element.attribute("data")) == m_url - || QUrl(element.attribute("src")) == m_url) - isRightElement = true; - else - { - QWebElementCollection collec = element.findAll("param"); - int i = 0; - while(i < collec.count() && isRightElement == false) - { - if(QUrl(collec.at(i).attribute("value")) == m_url) - isRightElement = true; - i++; - } - } - - if(isRightElement) + if( checkElement(element) ) { + kDebug() << "RETURNED TRUE ..........................."; QWebElement substitute = element.clone(); emit signalLoadClickToFlash(true); element.replace(substitute); @@ -118,9 +102,39 @@ void ClickToFlash::load() return; } } - frames += frame->childFrames(); } } +bool ClickToFlash::checkElement(QWebElement el) +{ + kDebug() << "src: " << QUrl(el.attribute("src")); + kDebug() << "url: " << m_url; + + QString checkString; + QString urlString; + + checkString = QUrl(el.attribute("src")).toString( QUrl::RemoveQuery ); + 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++; + } + + return false; +} diff --git a/src/clicktoflash.h b/src/clicktoflash.h index 2284ec7e..7d6c4e05 100644 --- a/src/clicktoflash.h +++ b/src/clicktoflash.h @@ -35,6 +35,7 @@ // Qt Includes #include #include +#include // Forward Declarations class WebPluginFactory; @@ -54,6 +55,8 @@ private slots: void load(); private: + bool checkElement(QWebElement el); + /** used to find the right QWebElement between the ones of the different plugins */ diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp index c8060969..9e4b8ba3 100644 --- a/src/webpluginfactory.cpp +++ b/src/webpluginfactory.cpp @@ -79,7 +79,7 @@ QObject *WebPluginFactory::create(const QString &mimeType, if( _loadClickToFlash ) { emit signalLoadClickToFlash(false); - return KWebPluginFactory::create(mimeType, url, argumentNames, argumentValues); + return 0; //KWebPluginFactory::create(mimeType, url, argumentNames, argumentValues); } else { -- cgit v1.2.1