1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +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:
nowrep 2011-07-31 00:50:40 +02:00
parent 3c6eee9964
commit 0279018f17
7 changed files with 68 additions and 60 deletions

View File

@ -57,6 +57,8 @@ AdBlockDialog::AdBlockDialog(QWidget *parent)
adblockCheckBox->setChecked(m_manager->isEnabled());
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
treeWidget->setDefaultItemShowMode(TreeWidget::ItemsExpanded);
connect(adblockCheckBox, SIGNAL(toggled(bool)), m_manager, SLOT(setEnabled(bool)));
connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule()));
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));

View File

@ -209,9 +209,7 @@ static QString convertPatternToRegExp(const QString &wildcardPattern) {
void AdBlockRule::setPattern(const QString &pattern, bool isRegExp)
{
if (isRegExp)
qDebug() << pattern;
m_regExp = QRegExp(isRegExp ? pattern : convertPatternToRegExp(pattern),
Qt::CaseInsensitive, QRegExp::RegExp);
Q_UNUSED(isRegExp)
m_regExp = QRegExp(convertPatternToRegExp(pattern), Qt::CaseInsensitive, QRegExp::RegExp);
}

View File

@ -520,28 +520,14 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
}
}
void QupZilla::refreshHistory(int index)
void QupZilla::refreshHistory()
{
if (mApp->isClosing())
return;
QWebHistory* history;
if (index == -1)
history = weView()->page()->history();
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);
}
QWebHistory* history = weView()->page()->history();
m_buttonBack->setEnabled(history->canGoBack());
m_buttonNext->setEnabled(history->canGoForward());
}
void QupZilla::goAtHistoryIndex()
@ -559,13 +545,13 @@ void QupZilla::aboutToShowHistoryBackMenu()
m_menuBack->clear();
QWebHistory* history = weView()->history();
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);
if (item.isValid()) {
QString title = item.title();
if (title.length()>40) {
if (title.length() > 40) {
title.truncate(40);
title+="..";
title += "..";
}
QAction* action = m_menuBack->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex()));
action->setData(i);
@ -580,13 +566,13 @@ void QupZilla::aboutToShowHistoryNextMenu()
m_menuForward->clear();
QWebHistory* history = weView()->history();
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);
if (item.isValid()) {
QString title = item.title();
if (title.length()>40) {
if (title.length() > 40) {
title.truncate(40);
title+="..";
title += "..";
}
QAction* action = m_menuForward->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex()));
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()
{
if (locationBar()->text().isEmpty())

View File

@ -123,10 +123,10 @@ signals:
public slots:
void showBookmarksToolbar();
void refreshHistory(int index=-1);
void refreshHistory();
void loadActionUrl();
void bookmarkPage();
void loadAddress(QUrl url) { weView()->load(url); locationBar()->setText(url.toEncoded()); }
void loadAddress(const QUrl &url);
void showSource(const QString& selectedHtml = "");
void showPageInfo();
void receiveMessage(MainApplication::MessageType mes, bool state);

View File

@ -38,6 +38,7 @@ WebPage::WebPage(WebView* parent, QupZilla* mainClass)
{
setForwardUnsupportedContent(true);
setPluginFactory(new WebPluginFactory(this));
history()->setMaximumItemCount(20);
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), SLOT(handleUnsupportedContent(QNetworkReply*)));
connect(this, SIGNAL(loadStarted()), this, SLOT(loadingStarted()));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int)));
@ -199,29 +200,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
break;
case QNetworkReply::ContentAccessDenied:
if (exOption->errorString.startsWith("AdBlockRule")) {
QString rule = exOption->errorString;
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()) {
if (exOption->frame != exOption->frame->page()->mainFrame()) { //Content in <iframe>
QWebElement docElement = exOption->frame->page()->mainFrame()->documentElement();
QWebElementCollection elements;
@ -231,18 +210,40 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
if (exOption->url.toString().contains(src))
element.setAttribute("style", "display:none;");
}
}
return false;
} else { //The whole page is blocked
QString rule = exOption->errorString;
rule.remove("AdBlockRule:");
return true;
break;
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();
return true;
}
}
errorString = tr("Content Access Denied");
break;
default:
//errorString = exOption->error;
if (errorString.isEmpty())
errorString = tr("Unknown error");
break;
qDebug() << "Content error: " << exOption->errorString;
return false;
// if (errorString.isEmpty())
// errorString = tr("Unknown error");
}
}
else if (exOption->domain == QWebPage::Http) {
@ -286,6 +287,19 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
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)
{
WebView* _view = (WebView*)originatingFrame->page()->view();

View File

@ -56,6 +56,7 @@ public:
void addAdBlockRule(const QString &filter, const QUrl &url);
QList<AdBlockedEntry> adBlockedEntries() { return m_adBlockedEntries; }
void adBlockCleanup();
signals:
void privacyChanged(bool status);

View File

@ -241,6 +241,7 @@ void WebView::loadFinished(bool state)
titleChanged();
mApp->autoFill()->completePage(this);
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
m_page->adBlockCleanup();
if (isCurrent()) {
p_QupZilla->progressBar()->setVisible(false);