File indexing completed on 2024-05-12 04:57:59

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2016  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #ifndef COOKIEJAR_H
0019 #define COOKIEJAR_H
0020 
0021 #include <QVector>
0022 #include <QStringList>
0023 #include <QWebEngineCookieStore>
0024 #include <QtWebEngineWidgetsVersion>
0025 
0026 #include "qzcommon.h"
0027 
0028 class AutoSaver;
0029 
0030 class FALKON_EXPORT CookieJar : public QObject
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     explicit CookieJar(QObject* parent = nullptr);
0036     ~CookieJar();
0037 
0038     void loadSettings();
0039 
0040     void setAllowCookies(bool allow);
0041 
0042     void deleteCookie(const QNetworkCookie &cookie);
0043 
0044     QVector<QNetworkCookie> getAllCookies() const;
0045     void deleteAllCookies(bool deleteAll = true);
0046 
0047 Q_SIGNALS:
0048     void cookieAdded(const QNetworkCookie &cookie);
0049     void cookieRemoved(const QNetworkCookie &cookie);
0050 
0051 protected:
0052     bool matchDomain(QString cookieDomain, QString siteDomain) const;
0053     bool listMatchesDomain(const QStringList &list, const QString &cookieDomain) const;
0054 
0055 private:
0056     void slotCookieAdded(const QNetworkCookie &cookie);
0057     void slotCookieRemoved(const QNetworkCookie &cookie);
0058 
0059     bool cookieFilter(const QWebEngineCookieStore::FilterRequest &request) const;
0060 
0061     bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) const;
0062     bool rejectCookie(const QString &domain, const QNetworkCookie &cookie, const QString &cookieDomain) const;
0063 
0064     bool m_allowCookies;
0065     bool m_filterTrackingCookie;
0066     bool m_filterThirdParty;
0067 
0068     QStringList m_whitelist;
0069     QStringList m_blacklist;
0070 
0071     QWebEngineCookieStore *m_client;
0072     QVector<QNetworkCookie> m_cookies;
0073 };
0074 
0075 #endif // COOKIEJAR_H