mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Fixed bug with duplicated history entries
Added AdBlock cleanup after loading page which removes blocked objects from page
This commit is contained in:
parent
3c6eee9964
commit
0279018f17
@ -57,6 +57,8 @@ AdBlockDialog::AdBlockDialog(QWidget *parent)
|
|||||||
adblockCheckBox->setChecked(m_manager->isEnabled());
|
adblockCheckBox->setChecked(m_manager->isEnabled());
|
||||||
|
|
||||||
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
treeWidget->setDefaultItemShowMode(TreeWidget::ItemsExpanded);
|
||||||
|
|
||||||
connect(adblockCheckBox, SIGNAL(toggled(bool)), m_manager, SLOT(setEnabled(bool)));
|
connect(adblockCheckBox, SIGNAL(toggled(bool)), m_manager, SLOT(setEnabled(bool)));
|
||||||
connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule()));
|
connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule()));
|
||||||
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));
|
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));
|
||||||
|
@ -209,9 +209,7 @@ static QString convertPatternToRegExp(const QString &wildcardPattern) {
|
|||||||
|
|
||||||
void AdBlockRule::setPattern(const QString &pattern, bool isRegExp)
|
void AdBlockRule::setPattern(const QString &pattern, bool isRegExp)
|
||||||
{
|
{
|
||||||
if (isRegExp)
|
Q_UNUSED(isRegExp)
|
||||||
qDebug() << pattern;
|
m_regExp = QRegExp(convertPatternToRegExp(pattern), Qt::CaseInsensitive, QRegExp::RegExp);
|
||||||
m_regExp = QRegExp(isRegExp ? pattern : convertPatternToRegExp(pattern),
|
|
||||||
Qt::CaseInsensitive, QRegExp::RegExp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,28 +520,14 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QupZilla::refreshHistory(int index)
|
void QupZilla::refreshHistory()
|
||||||
{
|
{
|
||||||
if (mApp->isClosing())
|
if (mApp->isClosing())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QWebHistory* history;
|
QWebHistory* history = weView()->page()->history();
|
||||||
if (index == -1)
|
m_buttonBack->setEnabled(history->canGoBack());
|
||||||
history = weView()->page()->history();
|
m_buttonNext->setEnabled(history->canGoForward());
|
||||||
else
|
|
||||||
history = weView()->page()->history();
|
|
||||||
|
|
||||||
if (history->canGoBack()) {
|
|
||||||
m_buttonBack->setEnabled(true);
|
|
||||||
} else {
|
|
||||||
m_buttonBack->setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (history->canGoForward()) {
|
|
||||||
m_buttonNext->setEnabled(true);
|
|
||||||
} else {
|
|
||||||
m_buttonNext->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QupZilla::goAtHistoryIndex()
|
void QupZilla::goAtHistoryIndex()
|
||||||
@ -559,13 +545,13 @@ void QupZilla::aboutToShowHistoryBackMenu()
|
|||||||
m_menuBack->clear();
|
m_menuBack->clear();
|
||||||
QWebHistory* history = weView()->history();
|
QWebHistory* history = weView()->history();
|
||||||
int curindex = history->currentItemIndex();
|
int curindex = history->currentItemIndex();
|
||||||
for (int i = curindex-1;i>=0;i--) {
|
for (int i = curindex-1; i >= 0; i--) {
|
||||||
QWebHistoryItem item = history->itemAt(i);
|
QWebHistoryItem item = history->itemAt(i);
|
||||||
if (item.isValid()) {
|
if (item.isValid()) {
|
||||||
QString title = item.title();
|
QString title = item.title();
|
||||||
if (title.length()>40) {
|
if (title.length() > 40) {
|
||||||
title.truncate(40);
|
title.truncate(40);
|
||||||
title+="..";
|
title += "..";
|
||||||
}
|
}
|
||||||
QAction* action = m_menuBack->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex()));
|
QAction* action = m_menuBack->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex()));
|
||||||
action->setData(i);
|
action->setData(i);
|
||||||
@ -580,13 +566,13 @@ void QupZilla::aboutToShowHistoryNextMenu()
|
|||||||
m_menuForward->clear();
|
m_menuForward->clear();
|
||||||
QWebHistory* history = weView()->history();
|
QWebHistory* history = weView()->history();
|
||||||
int curindex = history->currentItemIndex();
|
int curindex = history->currentItemIndex();
|
||||||
for (int i = curindex+1;i<history->count();i++) {
|
for (int i = curindex+1; i < history->count(); i++) {
|
||||||
QWebHistoryItem item = history->itemAt(i);
|
QWebHistoryItem item = history->itemAt(i);
|
||||||
if (item.isValid()) {
|
if (item.isValid()) {
|
||||||
QString title = item.title();
|
QString title = item.title();
|
||||||
if (title.length()>40) {
|
if (title.length() > 40) {
|
||||||
title.truncate(40);
|
title.truncate(40);
|
||||||
title+="..";
|
title += "..";
|
||||||
}
|
}
|
||||||
QAction* action = m_menuForward->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex()));
|
QAction* action = m_menuForward->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex()));
|
||||||
action->setData(i);
|
action->setData(i);
|
||||||
@ -877,6 +863,12 @@ void QupZilla::loadActionUrl()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QupZilla::loadAddress(const QUrl &url)
|
||||||
|
{
|
||||||
|
weView()->load(url);
|
||||||
|
locationBar()->setText(url.toEncoded());
|
||||||
|
}
|
||||||
|
|
||||||
void QupZilla::urlEnter()
|
void QupZilla::urlEnter()
|
||||||
{
|
{
|
||||||
if (locationBar()->text().isEmpty())
|
if (locationBar()->text().isEmpty())
|
||||||
|
@ -123,10 +123,10 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showBookmarksToolbar();
|
void showBookmarksToolbar();
|
||||||
void refreshHistory(int index=-1);
|
void refreshHistory();
|
||||||
void loadActionUrl();
|
void loadActionUrl();
|
||||||
void bookmarkPage();
|
void bookmarkPage();
|
||||||
void loadAddress(QUrl url) { weView()->load(url); locationBar()->setText(url.toEncoded()); }
|
void loadAddress(const QUrl &url);
|
||||||
void showSource(const QString& selectedHtml = "");
|
void showSource(const QString& selectedHtml = "");
|
||||||
void showPageInfo();
|
void showPageInfo();
|
||||||
void receiveMessage(MainApplication::MessageType mes, bool state);
|
void receiveMessage(MainApplication::MessageType mes, bool state);
|
||||||
|
@ -38,6 +38,7 @@ WebPage::WebPage(WebView* parent, QupZilla* mainClass)
|
|||||||
{
|
{
|
||||||
setForwardUnsupportedContent(true);
|
setForwardUnsupportedContent(true);
|
||||||
setPluginFactory(new WebPluginFactory(this));
|
setPluginFactory(new WebPluginFactory(this));
|
||||||
|
history()->setMaximumItemCount(20);
|
||||||
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), SLOT(handleUnsupportedContent(QNetworkReply*)));
|
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), SLOT(handleUnsupportedContent(QNetworkReply*)));
|
||||||
connect(this, SIGNAL(loadStarted()), this, SLOT(loadingStarted()));
|
connect(this, SIGNAL(loadStarted()), this, SLOT(loadingStarted()));
|
||||||
connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int)));
|
connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int)));
|
||||||
@ -199,29 +200,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
|
|||||||
break;
|
break;
|
||||||
case QNetworkReply::ContentAccessDenied:
|
case QNetworkReply::ContentAccessDenied:
|
||||||
if (exOption->errorString.startsWith("AdBlockRule")) {
|
if (exOption->errorString.startsWith("AdBlockRule")) {
|
||||||
QString rule = exOption->errorString;
|
if (exOption->frame != exOption->frame->page()->mainFrame()) { //Content in <iframe>
|
||||||
rule.remove("AdBlockRule:");
|
|
||||||
|
|
||||||
QFile file(":/html/adblockPage.html");
|
|
||||||
file.open(QFile::ReadOnly);
|
|
||||||
QString errString = file.readAll();
|
|
||||||
errString.replace("%TITLE%", tr("AdBlocked Content"));
|
|
||||||
|
|
||||||
//QPixmap pixmap = QIcon::fromTheme("dialog-warning").pixmap(45,45);
|
|
||||||
QPixmap pixmap(":/html/adblock_big.png");
|
|
||||||
QByteArray bytes;
|
|
||||||
QBuffer buffer(&bytes);
|
|
||||||
buffer.open(QIODevice::WriteOnly);
|
|
||||||
if (pixmap.save(&buffer, "PNG")) {
|
|
||||||
errString.replace("%IMAGE%", buffer.buffer().toBase64());
|
|
||||||
errString.replace("%FAVICON%", buffer.buffer().toBase64());
|
|
||||||
}
|
|
||||||
|
|
||||||
errString.replace("%RULE%", tr("Blocked by rule <i>%1</i>").arg(rule));
|
|
||||||
|
|
||||||
exReturn->baseUrl = exOption->url.toString();
|
|
||||||
exReturn->content = errString.toUtf8();
|
|
||||||
if (exOption->frame != exOption->frame->page()->mainFrame()) {
|
|
||||||
QWebElement docElement = exOption->frame->page()->mainFrame()->documentElement();
|
QWebElement docElement = exOption->frame->page()->mainFrame()->documentElement();
|
||||||
|
|
||||||
QWebElementCollection elements;
|
QWebElementCollection elements;
|
||||||
@ -231,18 +210,40 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
|
|||||||
if (exOption->url.toString().contains(src))
|
if (exOption->url.toString().contains(src))
|
||||||
element.setAttribute("style", "display:none;");
|
element.setAttribute("style", "display:none;");
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
|
} else { //The whole page is blocked
|
||||||
|
QString rule = exOption->errorString;
|
||||||
|
rule.remove("AdBlockRule:");
|
||||||
|
|
||||||
return true;
|
QFile file(":/html/adblockPage.html");
|
||||||
break;
|
file.open(QFile::ReadOnly);
|
||||||
|
QString errString = file.readAll();
|
||||||
|
errString.replace("%TITLE%", tr("AdBlocked Content"));
|
||||||
|
|
||||||
|
//QPixmap pixmap = QIcon::fromTheme("dialog-warning").pixmap(45,45);
|
||||||
|
QPixmap pixmap(":/html/adblock_big.png");
|
||||||
|
QByteArray bytes;
|
||||||
|
QBuffer buffer(&bytes);
|
||||||
|
buffer.open(QIODevice::WriteOnly);
|
||||||
|
if (pixmap.save(&buffer, "PNG")) {
|
||||||
|
errString.replace("%IMAGE%", buffer.buffer().toBase64());
|
||||||
|
errString.replace("%FAVICON%", buffer.buffer().toBase64());
|
||||||
|
}
|
||||||
|
|
||||||
|
errString.replace("%RULE%", tr("Blocked by rule <i>%1</i>").arg(rule));
|
||||||
|
|
||||||
|
exReturn->baseUrl = exOption->url.toString();
|
||||||
|
exReturn->content = errString.toUtf8();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
errorString = tr("Content Access Denied");
|
errorString = tr("Content Access Denied");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//errorString = exOption->error;
|
qDebug() << "Content error: " << exOption->errorString;
|
||||||
if (errorString.isEmpty())
|
return false;
|
||||||
errorString = tr("Unknown error");
|
// if (errorString.isEmpty())
|
||||||
break;
|
// errorString = tr("Unknown error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (exOption->domain == QWebPage::Http) {
|
else if (exOption->domain == QWebPage::Http) {
|
||||||
@ -286,6 +287,19 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebPage::adBlockCleanup()
|
||||||
|
{
|
||||||
|
QWebElement docElement = mainFrame()->documentElement();
|
||||||
|
|
||||||
|
foreach (AdBlockedEntry entry, m_adBlockedEntries) {
|
||||||
|
QWebElementCollection elements;
|
||||||
|
elements.append(docElement.findAll("*[src=\"" + entry.url.toString() + "\"]"));
|
||||||
|
foreach (QWebElement element, elements)
|
||||||
|
// element.setAttribute("style", "display:none;");
|
||||||
|
element.removeFromDocument();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool WebPage::javaScriptPrompt(QWebFrame* originatingFrame, const QString &msg, const QString &defaultValue, QString* result)
|
bool WebPage::javaScriptPrompt(QWebFrame* originatingFrame, const QString &msg, const QString &defaultValue, QString* result)
|
||||||
{
|
{
|
||||||
WebView* _view = (WebView*)originatingFrame->page()->view();
|
WebView* _view = (WebView*)originatingFrame->page()->view();
|
||||||
|
@ -56,6 +56,7 @@ public:
|
|||||||
|
|
||||||
void addAdBlockRule(const QString &filter, const QUrl &url);
|
void addAdBlockRule(const QString &filter, const QUrl &url);
|
||||||
QList<AdBlockedEntry> adBlockedEntries() { return m_adBlockedEntries; }
|
QList<AdBlockedEntry> adBlockedEntries() { return m_adBlockedEntries; }
|
||||||
|
void adBlockCleanup();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void privacyChanged(bool status);
|
void privacyChanged(bool status);
|
||||||
|
@ -241,6 +241,7 @@ void WebView::loadFinished(bool state)
|
|||||||
titleChanged();
|
titleChanged();
|
||||||
mApp->autoFill()->completePage(this);
|
mApp->autoFill()->completePage(this);
|
||||||
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
|
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
|
||||||
|
m_page->adBlockCleanup();
|
||||||
|
|
||||||
if (isCurrent()) {
|
if (isCurrent()) {
|
||||||
p_QupZilla->progressBar()->setVisible(false);
|
p_QupZilla->progressBar()->setVisible(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user