mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Close all tabs but current now don't close pinned tabs, added some fixes
to click2flash
This commit is contained in:
parent
71d5091533
commit
379ff8cd96
@ -45,9 +45,11 @@
|
|||||||
#include "adblockmanager.h"
|
#include "adblockmanager.h"
|
||||||
#include "adblocksubscription.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)
|
: QWidget(parent)
|
||||||
, m_url(pluginUrl)
|
, m_url(pluginUrl)
|
||||||
|
, m_argumentNames(argumentNames)
|
||||||
|
, m_argumentValues(argumentValues)
|
||||||
{
|
{
|
||||||
//AdBlock
|
//AdBlock
|
||||||
AdBlockManager* manager = AdBlockManager::instance();
|
AdBlockManager* manager = AdBlockManager::instance();
|
||||||
@ -136,48 +138,12 @@ void ClickToFlash::toWhitelist()
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClickToFlash::load()
|
void ClickToFlash::findElement()
|
||||||
{
|
{
|
||||||
// QWidget* parent = parentWidget();
|
QWidget* parent = parentWidget();
|
||||||
// QWebView* view = 0;
|
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) {
|
while (parent) {
|
||||||
if (QWebView *aView = qobject_cast<QWebView*>(parent)) {
|
if (QWebView* aView = qobject_cast<QWebView*>(parent)) {
|
||||||
view = aView;
|
view = aView;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -186,63 +152,62 @@ void ClickToFlash::load()
|
|||||||
if (!view)
|
if (!view)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// const QString selector = QLatin1String("%1[type=\"application/x-shockwave-flash\"]");
|
|
||||||
const QString mime = QLatin1String("application/futuresplash");
|
|
||||||
|
|
||||||
hide();
|
|
||||||
QList<QWebFrame*> frames;
|
QList<QWebFrame*> frames;
|
||||||
frames.append(view->page()->mainFrame());
|
m_mainFrame = view->page()->mainFrame();
|
||||||
|
frames.append(m_mainFrame);
|
||||||
|
|
||||||
while (!frames.isEmpty()) {
|
while (!frames.isEmpty()) {
|
||||||
QWebFrame *frame = frames.takeFirst();
|
QWebFrame* frame = frames.takeFirst();
|
||||||
QWebElement docElement = frame->documentElement();
|
QWebElement docElement = frame->documentElement();
|
||||||
|
|
||||||
QWebElementCollection elements;
|
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(QLatin1String("embed")));
|
||||||
// elements.append(docElement.findAll(selector.arg(QLatin1String("embed"))));
|
elements.append(docElement.findAll(QLatin1String("object")));
|
||||||
|
|
||||||
QWebElement element;
|
QWebElement element;
|
||||||
foreach (element, elements) {
|
foreach (element, elements) {
|
||||||
if (!checkElement(element))
|
if (!checkElement(element) && !checkUrlOnElement(element))
|
||||||
continue;
|
continue;
|
||||||
QWebElement substitute = element.clone();
|
m_element = element;
|
||||||
substitute.setAttribute(QLatin1String("type"), mime);
|
|
||||||
element.replace(substitute);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
frames += frame->childFrames();
|
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)
|
bool ClickToFlash::checkElement(QWebElement el)
|
||||||
{
|
{
|
||||||
QString checkString;
|
if (m_argumentNames == el.attributeNames()) {
|
||||||
QString urlString;
|
foreach (QString name, m_argumentNames) {
|
||||||
checkString = QUrl(el.attribute("src")).toString(QUrl::RemoveQuery);
|
if (m_argumentValues.indexOf(el.attribute(name)) == -1)
|
||||||
if (checkString.isEmpty())
|
return false;
|
||||||
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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -61,15 +61,21 @@ class ClickToFlash : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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:
|
private slots:
|
||||||
void load();
|
void load();
|
||||||
void customContextMenuRequested(const QPoint &pos);
|
void customContextMenuRequested(const QPoint &pos);
|
||||||
void toWhitelist();
|
void toWhitelist();
|
||||||
|
void findElement();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool checkElement(QWebElement el);
|
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
|
used to find the right QWebElement between the ones of the different plugins
|
||||||
|
@ -27,9 +27,6 @@ WebPluginFactory::WebPluginFactory(QObject* parent)
|
|||||||
|
|
||||||
QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
|
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/x-shockwave-flash") {
|
||||||
if (mimeType != "application/futuresplash")
|
if (mimeType != "application/futuresplash")
|
||||||
qDebug() << mimeType;
|
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.")))
|
if (whitelist.contains(url.host()) || whitelist.contains("www."+url.host()) || whitelist.contains(url.host().remove("www.")))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ClickToFlash* ctf = new ClickToFlash(url);
|
ClickToFlash* ctf = new ClickToFlash(url, argumentNames, argumentValues);
|
||||||
return ctf;
|
return ctf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,22 +310,12 @@ void TabWidget::reloadAllTabs()
|
|||||||
|
|
||||||
void TabWidget::closeAllButCurrent(int index)
|
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
|
foreach (WebTab* tab, allTabs(false)) {
|
||||||
int maxCycles = count()*1.6; // close tabs -> it sometimes hangs here
|
if (akt == widget(tab->view()->tabIndex()))
|
||||||
while(count()!=1) {
|
continue;
|
||||||
for (int i = 0;i<=count();i++) {
|
closeTab(tab->view()->tabIndex());
|
||||||
if (widget(i) == akt)
|
|
||||||
continue;
|
|
||||||
closeTab(i);
|
|
||||||
cycleCounter++;
|
|
||||||
|
|
||||||
if (cycleCounter >= maxCycles)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (cycleCounter >= maxCycles)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,6 +342,18 @@ void TabWidget::restoreClosedTab()
|
|||||||
m_canRestoreTab = false;
|
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()
|
void TabWidget::savePinnedTabs()
|
||||||
{
|
{
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
|
@ -51,6 +51,7 @@ public:
|
|||||||
|
|
||||||
inline TabBar* getTabBar() { return m_tabBar; }
|
inline TabBar* getTabBar() { return m_tabBar; }
|
||||||
inline bool canRestoreTab() { return m_canRestoreTab; }
|
inline bool canRestoreTab() { return m_canRestoreTab; }
|
||||||
|
QList<WebTab*> allTabs(bool withPinned = true);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
Loading…
Reference in New Issue
Block a user