mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
AdBlock: Subscription downloading now follows redirects.
- fixed related possible crash
This commit is contained in:
parent
935cf7b40b
commit
adac699cc9
@ -47,6 +47,7 @@
|
||||
#include "mainapplication.h"
|
||||
#include "networkmanager.h"
|
||||
#include "globalfunctions.h"
|
||||
#include "followredirectreply.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
@ -58,6 +59,7 @@ AdBlockSubscription::AdBlockSubscription(const QString &title, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_reply(0)
|
||||
, m_title(title)
|
||||
, m_updated(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -129,7 +131,7 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
|
||||
populateCache();
|
||||
|
||||
// Initial update
|
||||
if (m_rules.isEmpty()) {
|
||||
if (m_rules.isEmpty() && !m_updated) {
|
||||
QTimer::singleShot(0, this, SLOT(updateSubscription()));
|
||||
}
|
||||
}
|
||||
@ -144,21 +146,20 @@ void AdBlockSubscription::updateSubscription()
|
||||
return;
|
||||
}
|
||||
|
||||
QNetworkRequest request(m_url);
|
||||
m_reply = mApp->networkManager()->get(request);
|
||||
m_reply = new FollowRedirectReply(m_url, mApp->networkManager());
|
||||
|
||||
connect(m_reply, SIGNAL(finished()), this, SLOT(subscriptionDownloaded()));
|
||||
}
|
||||
|
||||
void AdBlockSubscription::subscriptionDownloaded()
|
||||
{
|
||||
if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
|
||||
if (m_reply != qobject_cast<FollowRedirectReply*>(sender())) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray response = m_reply->readAll();
|
||||
|
||||
if (m_reply->error() == QNetworkReply::NoError && !response.isEmpty()) {
|
||||
if (m_reply->error() == QNetworkReply::NoError && response.startsWith("[Adblock")) {
|
||||
// Prepend subscription info
|
||||
response.prepend(QString("Title: %1\nUrl: %2\n").arg(title(), url().toString()).toUtf8());
|
||||
|
||||
@ -168,7 +169,6 @@ void AdBlockSubscription::subscriptionDownloaded()
|
||||
emit subscriptionUpdated();
|
||||
}
|
||||
|
||||
m_reply->close();
|
||||
m_reply->deleteLater();
|
||||
m_reply = 0;
|
||||
}
|
||||
|
@ -56,6 +56,8 @@ class QNetworkRequest;
|
||||
class QNetworkReply;
|
||||
class QUrl;
|
||||
|
||||
class FollowRedirectReply;
|
||||
|
||||
class QT_QUPZILLA_EXPORT AdBlockSubscription : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -105,7 +107,7 @@ protected:
|
||||
|
||||
void populateCache();
|
||||
|
||||
QNetworkReply* m_reply;
|
||||
FollowRedirectReply* m_reply;
|
||||
|
||||
QList<AdBlockRule> m_rules;
|
||||
QString m_elementHidingRules;
|
||||
@ -120,6 +122,7 @@ private:
|
||||
QString m_filePath;
|
||||
|
||||
QUrl m_url;
|
||||
bool m_updated;
|
||||
};
|
||||
|
||||
class AdBlockEasyList : public AdBlockSubscription
|
||||
|
@ -312,7 +312,7 @@ void RSSManager::finished()
|
||||
QString titleString;
|
||||
|
||||
QXmlStreamReader xml;
|
||||
xml.addData(reply->reply()->readAll());
|
||||
xml.addData(reply->readAll());
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "followredirectreply.h"
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
FollowRedirectReply::FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager)
|
||||
: QObject()
|
||||
@ -30,6 +28,26 @@ FollowRedirectReply::FollowRedirectReply(const QUrl &url, QNetworkAccessManager*
|
||||
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
|
||||
}
|
||||
|
||||
QNetworkReply* FollowRedirectReply::reply() const
|
||||
{
|
||||
return m_reply;
|
||||
}
|
||||
|
||||
QUrl FollowRedirectReply::url() const
|
||||
{
|
||||
return m_reply->url();
|
||||
}
|
||||
|
||||
QNetworkReply::NetworkError FollowRedirectReply::error() const
|
||||
{
|
||||
return m_reply->error();
|
||||
}
|
||||
|
||||
QByteArray FollowRedirectReply::readAll()
|
||||
{
|
||||
return m_reply->readAll();
|
||||
}
|
||||
|
||||
void FollowRedirectReply::replyFinished()
|
||||
{
|
||||
int replyStatus = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
@ -38,6 +56,7 @@ void FollowRedirectReply::replyFinished()
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
|
||||
m_redirectCount++;
|
||||
|
||||
QUrl redirectUrl = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define FOLLOWREDIRECTREPLY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
|
||||
@ -34,7 +35,11 @@ public:
|
||||
explicit FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager);
|
||||
~FollowRedirectReply();
|
||||
|
||||
QNetworkReply* reply() { return m_reply; }
|
||||
QNetworkReply* reply() const;
|
||||
QUrl url() const;
|
||||
|
||||
QNetworkReply::NetworkError error() const;
|
||||
QByteArray readAll();
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
@ -44,8 +44,8 @@ void IconFetcher::pageDownloaded()
|
||||
return;
|
||||
}
|
||||
|
||||
QString html = reply->reply()->readAll();
|
||||
QUrl replyUrl = reply->reply()->url();
|
||||
QString html = reply->readAll();
|
||||
QUrl replyUrl = reply->url();
|
||||
reply->deleteLater();
|
||||
|
||||
QRegExp rx("<link(.*)>", Qt::CaseInsensitive);
|
||||
@ -91,7 +91,7 @@ void IconFetcher::iconDownloaded()
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray response = reply->reply()->readAll();
|
||||
QByteArray response = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if (!response.isEmpty()) {
|
||||
|
@ -152,7 +152,7 @@ void WebPage::addRejectedCerts(const QList<QSslCertificate> &certs)
|
||||
}
|
||||
}
|
||||
|
||||
bool WebPage::containsRejectedCerts(const QList<QSslCertificate> &certs) const
|
||||
bool WebPage::containsRejectedCerts(const QList<QSslCertificate> &certs)
|
||||
{
|
||||
int matches = 0;
|
||||
|
||||
@ -160,6 +160,10 @@ bool WebPage::containsRejectedCerts(const QList<QSslCertificate> &certs) const
|
||||
if (m_rejectedSslCerts.contains(cert)) {
|
||||
++matches;
|
||||
}
|
||||
|
||||
if (m_sslCert == cert) {
|
||||
m_sslCert.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return matches == certs.count();
|
||||
@ -434,18 +438,16 @@ bool WebPage::event(QEvent* event)
|
||||
void WebPage::setSSLCertificate(const QSslCertificate &cert)
|
||||
{
|
||||
// if (cert != m_SslCert)
|
||||
m_SslCert = cert;
|
||||
m_sslCert = cert;
|
||||
}
|
||||
|
||||
QSslCertificate WebPage::sslCertificate()
|
||||
{
|
||||
if (url().scheme() == "https" &&
|
||||
m_SslCert.subjectInfo(QSslCertificate::CommonName).remove('*').contains(QRegExp(url().host()))) {
|
||||
return m_SslCert;
|
||||
}
|
||||
else {
|
||||
return QSslCertificate();
|
||||
if (url().scheme() == "https" && m_sslCert.isValid()) {
|
||||
return m_sslCert;
|
||||
}
|
||||
|
||||
return QSslCertificate();
|
||||
}
|
||||
|
||||
bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type)
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
void populateNetworkRequest(QNetworkRequest &request);
|
||||
|
||||
TabbedWebView* getView() { return m_view; }
|
||||
|
||||
void setSSLCertificate(const QSslCertificate &cert);
|
||||
QSslCertificate sslCertificate();
|
||||
|
||||
@ -71,7 +72,7 @@ public:
|
||||
bool loadingError() const;
|
||||
|
||||
void addRejectedCerts(const QList<QSslCertificate> &certs);
|
||||
bool containsRejectedCerts(const QList<QSslCertificate> &certs) const;
|
||||
bool containsRejectedCerts(const QList<QSslCertificate> &certs);
|
||||
|
||||
static void setUserAgent(const QString &agent);
|
||||
QString userAgentForUrl(const QUrl &url) const;
|
||||
@ -126,7 +127,7 @@ private:
|
||||
QWebPage::NavigationType m_lastRequestType;
|
||||
TabbedWebView* m_view;
|
||||
SpeedDial* m_speedDial;
|
||||
QSslCertificate m_SslCert;
|
||||
QSslCertificate m_sslCert;
|
||||
QList<QSslCertificate> m_rejectedSslCerts;
|
||||
QList<AdBlockedEntry> m_adBlockedEntries;
|
||||
QFileSystemWatcher* m_fileWatcher;
|
||||
|
Loading…
Reference in New Issue
Block a user