mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-19 18:26:34 +01:00
AdBlock: Fixed $third-party option when Referer header is empty
- should fix a lot of false positives with $third-party rules see #444
This commit is contained in:
parent
b0e741447d
commit
14e0040a9f
@ -302,7 +302,8 @@ bool AdBlockRule::matchDomain(const QString &domain) const
|
||||
|
||||
bool AdBlockRule::matchThirdParty(const QNetworkRequest &request) const
|
||||
{
|
||||
const QString &referer = request.rawHeader("Referer");
|
||||
const QString &referer = request.attribute(QNetworkRequest::Attribute(QNetworkRequest::User + 151), QString()).toString();
|
||||
|
||||
if (referer.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -193,7 +193,10 @@ void QupZilla::postLaunch()
|
||||
}
|
||||
|
||||
if (addTab) {
|
||||
m_tabWidget->addView(startUrl, Qz::NT_CleanSelectedTabAtTheEnd);
|
||||
QNetworkRequest request(startUrl);
|
||||
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
||||
|
||||
m_tabWidget->addView(request, Qz::NT_CleanSelectedTabAtTheEnd);
|
||||
|
||||
if (startUrl.isEmpty() || startUrl.toString() == "qupzilla:speeddial") {
|
||||
locationBar()->setFocus();
|
||||
@ -202,7 +205,10 @@ void QupZilla::postLaunch()
|
||||
|
||||
if (m_tabWidget->getTabBar()->normalTabsCount() <= 0 && m_startBehaviour != Qz::BW_OtherRestoredWindow) {
|
||||
//Something went really wrong .. add one tab
|
||||
m_tabWidget->addView(m_homepage, Qz::NT_SelectedTabAtTheEnd);
|
||||
QNetworkRequest request(m_homepage);
|
||||
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
||||
|
||||
m_tabWidget->addView(request, Qz::NT_SelectedTabAtTheEnd);
|
||||
}
|
||||
|
||||
aboutToHideEditMenu();
|
||||
|
@ -361,6 +361,14 @@ QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op
|
||||
return reply;
|
||||
}
|
||||
|
||||
if (req.rawHeader("X-QupZilla-UserLoadAction") == QByteArray("1")) {
|
||||
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray());
|
||||
req.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User + 151), QString());
|
||||
}
|
||||
else {
|
||||
req.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User + 151), req.rawHeader("Referer"));
|
||||
}
|
||||
|
||||
if (m_doNotTrack) {
|
||||
req.setRawHeader("DNT", QByteArray("1"));
|
||||
}
|
||||
@ -372,9 +380,9 @@ QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op
|
||||
req.setRawHeader("Accept-Language", m_acceptLanguage);
|
||||
|
||||
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
|
||||
if (req.attribute(QNetworkRequest::CacheLoadControlAttribute).toInt() == QNetworkRequest::PreferNetwork) {
|
||||
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
||||
}
|
||||
// if (req.attribute(QNetworkRequest::CacheLoadControlAttribute).toInt() == QNetworkRequest::PreferNetwork) {
|
||||
// req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
||||
// }
|
||||
|
||||
// Adblock
|
||||
if (op == QNetworkAccessManager::GetOperation) {
|
||||
|
@ -67,6 +67,7 @@ void PopupWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag posi
|
||||
if (window) {
|
||||
QNetworkRequest req(urla);
|
||||
req.setRawHeader("Referer", url().toEncoded());
|
||||
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
||||
|
||||
window->tabWidget()->addView(req, Qz::NT_SelectedTab);
|
||||
window->raise();
|
||||
|
@ -138,6 +138,14 @@ void TabbedWebView::loadProgress(int prog)
|
||||
}
|
||||
}
|
||||
|
||||
void TabbedWebView::userLoadAction(const QUrl &url)
|
||||
{
|
||||
QNetworkRequest request(url);
|
||||
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
||||
|
||||
load(request);
|
||||
}
|
||||
|
||||
void TabbedWebView::slotLoadStarted()
|
||||
{
|
||||
m_rssChecked = false;
|
||||
@ -280,6 +288,7 @@ void TabbedWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag pos
|
||||
{
|
||||
QNetworkRequest req(urla);
|
||||
req.setRawHeader("Referer", url().toEncoded());
|
||||
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
||||
|
||||
m_tabWidget->addView(req, position);
|
||||
}
|
||||
|
@ -65,6 +65,8 @@ public slots:
|
||||
void slotLoadStarted();
|
||||
void loadProgress(int prog);
|
||||
|
||||
void userLoadAction(const QUrl &url);
|
||||
|
||||
void closeView();
|
||||
void openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position);
|
||||
void openNewTab();
|
||||
|
@ -314,7 +314,6 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT
|
||||
connect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
|
||||
|
||||
if (url.isValid()) {
|
||||
req.setUrl(url);
|
||||
webView->load(req);
|
||||
}
|
||||
|
||||
@ -553,6 +552,7 @@ int TabWidget::duplicateTab(int index)
|
||||
|
||||
QNetworkRequest req(url);
|
||||
req.setRawHeader("Referer", url.toEncoded());
|
||||
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
||||
|
||||
int id = addView(req, title, Qz::NT_CleanNotSelectedTab);
|
||||
weTab(id)->setHistoryData(history);
|
||||
|
@ -453,6 +453,8 @@ QSslCertificate WebPage::sslCertificate()
|
||||
bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type)
|
||||
{
|
||||
m_lastRequestType = type;
|
||||
m_lastRequestUrl = request.url();
|
||||
|
||||
const QString &scheme = request.url().scheme();
|
||||
|
||||
if (scheme == "mailto" || scheme == "ftp") {
|
||||
@ -480,7 +482,13 @@ void WebPage::populateNetworkRequest(QNetworkRequest &request)
|
||||
|
||||
QVariant variant = qVariantFromValue((void*) pagePointer);
|
||||
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), variant);
|
||||
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101), m_lastRequestType);
|
||||
|
||||
if (m_lastRequestUrl == request.url()) {
|
||||
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101), m_lastRequestType);
|
||||
if (m_lastRequestType == NavigationTypeLinkClicked) {
|
||||
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
|
||||
|
@ -124,15 +124,17 @@ private:
|
||||
|
||||
QupZilla* p_QupZilla;
|
||||
NetworkManagerProxy* m_networkProxy;
|
||||
QWebPage::NavigationType m_lastRequestType;
|
||||
TabbedWebView* m_view;
|
||||
SpeedDial* m_speedDial;
|
||||
QFileSystemWatcher* m_fileWatcher;
|
||||
QEventLoop* m_runningLoop;
|
||||
|
||||
QSslCertificate m_sslCert;
|
||||
QList<QSslCertificate> m_rejectedSslCerts;
|
||||
QList<AdBlockedEntry> m_adBlockedEntries;
|
||||
QFileSystemWatcher* m_fileWatcher;
|
||||
|
||||
QEventLoop* m_runningLoop;
|
||||
QWebPage::NavigationType m_lastRequestType;
|
||||
QUrl m_lastRequestUrl;
|
||||
|
||||
int m_loadProgress;
|
||||
bool m_blockAlerts;
|
||||
|
@ -93,7 +93,7 @@ WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar)
|
||||
connect(m_view, SIGNAL(urlChanged(QUrl)), m_locationBar.data(), SLOT(showUrl(QUrl)));
|
||||
connect(m_view, SIGNAL(rssChanged(bool)), m_locationBar.data(), SLOT(showRSSIcon(bool)));
|
||||
connect(m_view, SIGNAL(privacyChanged(bool)), m_locationBar.data(), SLOT(setPrivacy(bool)));
|
||||
connect(m_locationBar.data(), SIGNAL(loadUrl(QUrl)), m_view, SLOT(load(QUrl)));
|
||||
connect(m_locationBar.data(), SIGNAL(loadUrl(QUrl)), m_view, SLOT(userLoadAction(QUrl)));
|
||||
}
|
||||
|
||||
TabbedWebView* WebTab::view() const
|
||||
|
@ -38,7 +38,7 @@ PluginSpec GM_Plugin::pluginSpec()
|
||||
spec.name = "GreaseMonkey";
|
||||
spec.info = "Userscripts for QupZilla";
|
||||
spec.description = "Provides support for userscripts (www.userscripts.org)";
|
||||
spec.version = "0.1.1";
|
||||
spec.version = "0.2.1";
|
||||
spec.author = "David Rosca <nowrep@gmail.com>";
|
||||
spec.icon = QPixmap(":gm/data/icon.png");
|
||||
spec.hasSettings = true;
|
||||
@ -81,9 +81,7 @@ QNetworkReply* GM_Plugin::createRequest(QNetworkAccessManager::Operation op, con
|
||||
{
|
||||
Q_UNUSED(outgoingData)
|
||||
|
||||
int type = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101), -1).toInt();
|
||||
|
||||
if (op == QNetworkAccessManager::GetOperation && QWebPage::NavigationType(type) == QWebPage::NavigationTypeLinkClicked) {
|
||||
if (op == QNetworkAccessManager::GetOperation && request.rawHeader("X-QupZilla-UserLoadAction") == QByteArray("1")) {
|
||||
const QString &urlString = request.url().toString(QUrl::RemoveFragment | QUrl::RemoveQuery);
|
||||
|
||||
if (urlString.endsWith(".user.js")) {
|
||||
|
Loading…
Reference in New Issue
Block a user