File indexing completed on 2024-05-12 04:57:50
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2014-2017 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 ADBLOCKMATCHER_H 0019 #define ADBLOCKMATCHER_H 0020 0021 #include <QUrl> 0022 #include <QObject> 0023 0024 #include "qzcommon.h" 0025 #include "adblocksearchtree.h" 0026 0027 class QWebEngineUrlRequestInfo; 0028 0029 class AdBlockManager; 0030 0031 class FALKON_EXPORT AdBlockMatcher : public QObject 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 explicit AdBlockMatcher(AdBlockManager* manager); 0037 ~AdBlockMatcher(); 0038 0039 const AdBlockRule* match(const QWebEngineUrlRequestInfo &request, const QString &urlDomain, const QString &urlString) const; 0040 0041 bool adBlockDisabledForUrl(const QUrl &url) const; 0042 bool elemHideDisabledForUrl(const QUrl &url) const; 0043 bool genericElemHideDisabledForUrl(const QUrl &url) const; 0044 0045 QString elementHidingRules() const; 0046 QString elementHidingRulesForDomain(const QString &domain) const; 0047 0048 public Q_SLOTS: 0049 void update(); 0050 void clear(); 0051 0052 private: 0053 AdBlockManager* m_manager; 0054 0055 QVector<AdBlockRule*> m_createdRules; 0056 QVector<const AdBlockRule*> m_networkExceptionRules; 0057 QVector<const AdBlockRule*> m_networkBlockRules; 0058 QVector<const AdBlockRule*> m_domainRestrictedCssRules; 0059 QVector<const AdBlockRule*> m_documentRules; 0060 QVector<const AdBlockRule*> m_elemhideRules; 0061 QVector<const AdBlockRule*> m_generichideRules; 0062 0063 QString m_elementHidingRules; 0064 AdBlockSearchTree m_networkBlockTree; 0065 AdBlockSearchTree m_networkExceptionTree; 0066 }; 0067 0068 #endif // ADBLOCKMATCHER_H