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