From 4a556a4adc33aeafd332548ead9cb1f8b9c9885c Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 5 Nov 2011 15:04:29 +0100 Subject: [PATCH] Improved cookies filtering + fixed crash Improved cookies filtering for domain mismatch and for tracking cookies, it is now fully (i hope) working and ready to use in everyday browsing. Please test it by yourself and report any issues. Also fixed crash when closing cookies manager window with "Close" in title bar or with Alt+F4 --- src/app/qupzilla.cpp | 2 +- src/autofill/autofillmodel.cpp | 1 + src/cookies/cookiejar.cpp | 23 ++++++++++++----------- src/cookies/cookiemanager.cpp | 1 - src/webview/tabbar.cpp | 10 ++++++++++ src/webview/tabbar.h | 3 +++ 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index 77c652669..b81744bbc 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -176,7 +176,7 @@ void QupZilla::postLaunch() aboutToShowHistoryMenu(false); aboutToShowBookmarksMenu(); - if (m_tabWidget->count() == 0) //Something went really wrong .. add one tab + if (m_tabWidget->getTabBar()->normalTabsCount() <= 0) //Something went really wrong .. add one tab m_tabWidget->addView(m_homepage); setUpdatesEnabled(true); diff --git a/src/autofill/autofillmodel.cpp b/src/autofill/autofillmodel.cpp index 3522ade70..791b19069 100644 --- a/src/autofill/autofillmodel.cpp +++ b/src/autofill/autofillmodel.cpp @@ -163,6 +163,7 @@ void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgo //Dont save in private browsing if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) return; + m_lastOutgoingData = outgoingData; QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); diff --git a/src/cookies/cookiejar.cpp b/src/cookies/cookiejar.cpp index 7a12ad386..8e5cdc3d4 100644 --- a/src/cookies/cookiejar.cpp +++ b/src/cookies/cookiejar.cpp @@ -17,24 +17,24 @@ * ============================================================ */ #include "cookiejar.h" #include "qupzilla.h" -#define COOKIE_DEBUG +//#define COOKIE_DEBUG //TODO: black/white listing -CookieJar::CookieJar(QupZilla* mainClass, QObject* parent) : - QNetworkCookieJar(parent) - ,p_QupZilla(mainClass) +CookieJar::CookieJar(QupZilla* mainClass, QObject* parent) + : QNetworkCookieJar(parent) + , p_QupZilla(mainClass) { - loadSettings(); m_activeProfil = mApp->getActiveProfilPath(); + loadSettings(); } void CookieJar::loadSettings() { - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); settings.beginGroup("Web-Browser-Settings"); - m_allowCookies = settings.value("allowCookies",true).toBool(); - m_allowCookiesFromDomain = settings.value("allowCookiesFromVisitedDomainOnly",false).toBool(); - m_filterTrackingCookie = settings.value("filterTrackingCookie",false).toBool(); + m_allowCookies = settings.value("allowCookies", true).toBool(); + m_allowCookiesFromDomain = settings.value("allowCookiesFromVisitedDomainOnly", false).toBool(); + m_filterTrackingCookie = settings.value("filterTrackingCookie", false).toBool(); m_deleteOnClose = settings.value("deleteCookiesOnClose", false).toBool(); } @@ -52,14 +52,15 @@ bool CookieJar::setCookiesFromUrl(const QList &cookieList, const QDateTime now = QDateTime::currentDateTime(); foreach (QNetworkCookie cok, newList) { - if (m_allowCookiesFromDomain && !url.toString().contains(cok.domain())) { + if (m_allowCookiesFromDomain && !QString("." + url.host()).contains(cok.domain().remove("www."))) { #ifdef COOKIE_DEBUG qDebug() << "purged for domain mismatch" << cok; #endif newList.removeOne(cok); continue; } - if (m_filterTrackingCookie && cok.expirationDate() > now.addYears(2)) { + + if (m_filterTrackingCookie && (cok.name().startsWith("__utm") || cok.expirationDate() > now.addYears(1).addMonths(6)) ) { #ifdef COOKIE_DEBUG qDebug() << "purged as tracking " << cok; #endif diff --git a/src/cookies/cookiemanager.cpp b/src/cookies/cookiemanager.cpp index bd310cb82..f67a7fe66 100644 --- a/src/cookies/cookiemanager.cpp +++ b/src/cookies/cookiemanager.cpp @@ -26,7 +26,6 @@ CookieManager::CookieManager(QWidget* parent) : QWidget(parent) , ui(new Ui::CookieManager) { - setAttribute(Qt::WA_DeleteOnClose); setWindowModality(Qt::WindowModal); ui->setupUi(this); diff --git a/src/webview/tabbar.cpp b/src/webview/tabbar.cpp index c1e7b1b2b..8108664b5 100644 --- a/src/webview/tabbar.cpp +++ b/src/webview/tabbar.cpp @@ -279,6 +279,16 @@ void TabBar::pinnedTabAdded() m_pinnedTabsCount++; } +int TabBar::pinnedTabsCount() +{ + return m_pinnedTabsCount; +} + +int TabBar::normalTabsCount() +{ + return count() - m_pinnedTabsCount; +} + void TabBar::mouseDoubleClickEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton && tabAt(event->pos()) == -1) { diff --git a/src/webview/tabbar.h b/src/webview/tabbar.h index bdda15beb..e557c30a3 100644 --- a/src/webview/tabbar.h +++ b/src/webview/tabbar.h @@ -44,6 +44,9 @@ public: void setVisible(bool visible); void updateVisibilityWithFullscreen(bool visible); + int pinnedTabsCount(); + int normalTabsCount(); + signals: void reloadTab(int index); void stopTab(int index);