1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Close all tabs but current now don't close pinned tabs, added some fixes

to click2flash
This commit is contained in:
nowrep 2011-04-18 21:35:57 +02:00
parent 71d5091533
commit 379ff8cd96
5 changed files with 71 additions and 100 deletions

View File

@ -45,9 +45,11 @@
#include "adblockmanager.h"
#include "adblocksubscription.h"
ClickToFlash::ClickToFlash(const QUrl &pluginUrl, QWidget* parent)
ClickToFlash::ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNames, const QStringList &argumentValues, QWidget* parent)
: QWidget(parent)
, m_url(pluginUrl)
, m_argumentNames(argumentNames)
, m_argumentValues(argumentValues)
{
//AdBlock
AdBlockManager* manager = AdBlockManager::instance();
@ -136,48 +138,12 @@ void ClickToFlash::toWhitelist()
load();
}
void ClickToFlash::load()
{
// 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;
void ClickToFlash::findElement()
{
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;
}
@ -186,63 +152,62 @@ void ClickToFlash::load()
if (!view)
return;
// 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());
m_mainFrame = view->page()->mainFrame();
frames.append(m_mainFrame);
while (!frames.isEmpty()) {
QWebFrame *frame = frames.takeFirst();
QWebFrame* frame = frames.takeFirst();
QWebElement docElement = frame->documentElement();
QWebElementCollection elements;
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"))));
elements.append(docElement.findAll(QLatin1String("object")));
QWebElement element;
foreach (element, elements) {
if (!checkElement(element))
if (!checkElement(element) && !checkUrlOnElement(element))
continue;
QWebElement substitute = element.clone();
substitute.setAttribute(QLatin1String("type"), mime);
element.replace(substitute);
m_element = element;
return;
}
frames += frame->childFrames();
}
}
void ClickToFlash::load()
{
findElement();
if (m_element.isNull()) {
} else {
QWebElement substitute = m_element.clone();
substitute.setAttribute(QLatin1String("type"), "application/futuresplash");
m_element.replace(substitute);
}
}
bool ClickToFlash::checkUrlOnElement(QWebElement el)
{
QString checkString = QUrl(el.attribute("src")).toString(QUrl::RemoveQuery);
if (checkString.isEmpty())
checkString = QUrl(el.attribute("data")).toString(QUrl::RemoveQuery);
if (checkString.isEmpty())
checkString = QUrl(el.attribute("value")).toString(QUrl::RemoveQuery);
if (m_url.toEncoded().contains(checkString.toAscii()))
return true;
return false;
}
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))
if (m_argumentNames == el.attributeNames()) {
foreach (QString name, m_argumentNames) {
if (m_argumentValues.indexOf(el.attribute(name)) == -1)
return false;
}
return true;
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;
}

View File

@ -61,15 +61,21 @@ class ClickToFlash : public QWidget
Q_OBJECT
public:
explicit ClickToFlash(const QUrl &pluginUrl, QWidget* parent = 0);
explicit ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNames, const QStringList &argumentValues, QWidget* parent = 0);
private slots:
void load();
void customContextMenuRequested(const QPoint &pos);
void toWhitelist();
void findElement();
private:
bool checkElement(QWebElement el);
bool checkUrlOnElement(QWebElement el);
QStringList m_argumentNames;
QStringList m_argumentValues;
QWebElement m_element;
QWebFrame* m_mainFrame;
/**
used to find the right QWebElement between the ones of the different plugins

View File

@ -27,9 +27,6 @@ WebPluginFactory::WebPluginFactory(QObject* parent)
QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
{
Q_UNUSED(argumentNames)
Q_UNUSED(argumentValues)
if (mimeType != "application/x-shockwave-flash") {
if (mimeType != "application/futuresplash")
qDebug() << mimeType;
@ -43,7 +40,7 @@ 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;
ClickToFlash* ctf = new ClickToFlash(url);
ClickToFlash* ctf = new ClickToFlash(url, argumentNames, argumentValues);
return ctf;
}

View File

@ -310,22 +310,12 @@ void TabWidget::reloadAllTabs()
void TabWidget::closeAllButCurrent(int index)
{
WebView* akt = qobject_cast<WebView*>(widget(index));
WebTab* akt = qobject_cast<WebTab*>(widget(index));
int cycleCounter = 0; // Only tab count * 1.6 attempts to
int maxCycles = count()*1.6; // close tabs -> it sometimes hangs here
while(count()!=1) {
for (int i = 0;i<=count();i++) {
if (widget(i) == akt)
continue;
closeTab(i);
cycleCounter++;
if (cycleCounter >= maxCycles)
break;
}
if (cycleCounter >= maxCycles)
break;
foreach (WebTab* tab, allTabs(false)) {
if (akt == widget(tab->view()->tabIndex()))
continue;
closeTab(tab->view()->tabIndex());
}
}
@ -352,6 +342,18 @@ void TabWidget::restoreClosedTab()
m_canRestoreTab = false;
}
QList<WebTab*> TabWidget::allTabs(bool withPinned)
{
QList<WebTab*> allTabs;
for (int i = 0; i < count(); i++) {
WebTab* tab = qobject_cast<WebTab*>(widget(i));
if (!tab || (!withPinned && tab->isPinned()) )
continue;
allTabs.append(tab);
}
return allTabs;
}
void TabWidget::savePinnedTabs()
{
QByteArray data;

View File

@ -51,6 +51,7 @@ public:
inline TabBar* getTabBar() { return m_tabBar; }
inline bool canRestoreTab() { return m_canRestoreTab; }
QList<WebTab*> allTabs(bool withPinned = true);
public slots: