| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #ifndef _PLUGIN_FILTER_H_ | 18 #ifndef _PLUGIN_FILTER_H_ |
| 19 #define _PLUGIN_FILTER_H_ | 19 #define _PLUGIN_FILTER_H_ |
| 20 | 20 |
| 21 | 21 |
| 22 #include "PluginTypedef.h" | 22 #include "PluginTypedef.h" |
| 23 #include <memory> | 23 #include <memory> |
| 24 #include <AdblockPlus/FilterEngine.h> |
| 24 | 25 |
| 25 enum CFilterElementHideAttrPos | 26 enum CFilterElementHideAttrPos |
| 26 { | 27 { |
| 27 POS_NONE = 0, STARTING, ENDING, ANYWHERE, EXACT | 28 POS_NONE = 0, STARTING, ENDING, ANYWHERE, EXACT |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 enum CFilterElementHideAttrType | 31 enum CFilterElementHideAttrType |
| 31 { | 32 { |
| 32 TYPE_NONE = 0, STYLE, ID, CLASS | 33 TYPE_NONE = 0, STYLE, ID, CLASS |
| 33 }; | 34 }; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 91 |
| 91 // ============================================================================ | 92 // ============================================================================ |
| 92 // CFilter | 93 // CFilter |
| 93 // ============================================================================ | 94 // ============================================================================ |
| 94 | 95 |
| 95 class CFilter | 96 class CFilter |
| 96 { | 97 { |
| 97 | 98 |
| 98 public: | 99 public: |
| 99 | 100 |
| 100 enum EContentType | |
| 101 { | |
| 102 contentTypeUnknown = 0, | |
| 103 contentTypeOther = 1, | |
| 104 contentTypeScript = 2, | |
| 105 contentTypeImage = 4, | |
| 106 contentTypeStyleSheet = 8, | |
| 107 contentTypeObject = 16, | |
| 108 contentTypeSubdocument = 32, | |
| 109 contentTypeDocument = 64, | |
| 110 contentTypeBackground = 256, | |
| 111 contentTypeXbl = 512, | |
| 112 contentTypePing = 1024, | |
| 113 contentTypeXmlHttpRequest = 2048, | |
| 114 contentTypeObjectSubrequest = 4096, | |
| 115 contentTypeDtd = 8192, | |
| 116 contentTypeAny = 65535 | |
| 117 } contentType; | |
| 118 | 101 |
| 119 enum EFilterType | 102 enum EFilterType |
| 120 { | 103 { |
| 121 filterTypeBlocking = 0, | 104 filterTypeBlocking = 0, |
| 122 filterTypeWhiteList = 1, | 105 filterTypeWhiteList = 1, |
| 123 filterTypeElementHide = 2, | 106 filterTypeElementHide = 2, |
| 124 filterTypeUnknown = 3 | 107 filterTypeUnknown = 3 |
| 125 } filterType; | 108 } filterType; |
| 126 | 109 |
| 127 int m_contentType; | 110 AdblockPlus::FilterEngine::ContentType m_contentType; |
| 128 enum EFilterType m_filterType; | 111 enum EFilterType m_filterType; |
| 129 bool m_isMatchCase; | 112 bool m_isMatchCase; |
| 130 bool m_isFirstParty; | 113 bool m_isFirstParty; |
| 131 bool m_isThirdParty; | 114 bool m_isThirdParty; |
| 132 bool m_isFromStart; | 115 bool m_isFromStart; |
| 133 bool m_isFromEnd; | 116 bool m_isFromEnd; |
| 134 int m_hitCount; | 117 int m_hitCount; |
| 135 CString m_filterText; | 118 CString m_filterText; |
| 136 | 119 |
| 137 CFilter(const CFilter&); | 120 CFilter(const CFilter&); |
| 138 CFilter(); | 121 CFilter(); |
| 139 }; | 122 }; |
| 140 | 123 |
| 141 // ============================================================================ | 124 // ============================================================================ |
| 142 // CPluginFilter | 125 // CPluginFilter |
| 143 // ============================================================================ | 126 // ============================================================================ |
| 144 | 127 |
| 145 class CPluginFilter | 128 class CPluginFilter |
| 146 { | 129 { |
| 147 | 130 |
| 148 private: | 131 private: |
| 149 | 132 |
| 150 CString m_dataPath; | 133 CString m_dataPath; |
| 151 | 134 |
| 152 std::map<int, CString> m_contentMapText; | |
| 153 | |
| 154 typedef std::map<DWORD, CFilter> TFilterMap; | 135 typedef std::map<DWORD, CFilter> TFilterMap; |
| 155 typedef std::vector<CFilter> TFilterMapDefault; | 136 typedef std::vector<CFilter> TFilterMapDefault; |
| 156 | 137 |
| 157 // (Tag,Name) -> Filter | 138 // (Tag,Name) -> Filter |
| 158 typedef std::multimap<std::pair<CString,CString>, CFilterElementHide> TFilterE
lementHideTagsNamed; | 139 typedef std::multimap<std::pair<CString,CString>, CFilterElementHide> TFilterE
lementHideTagsNamed; |
| 159 | 140 |
| 160 // Tag -> Filter | 141 // Tag -> Filter |
| 161 typedef std::multimap<CString, CFilterElementHide> TFilterElementHideTags; | 142 typedef std::multimap<CString, CFilterElementHide> TFilterElementHideTags; |
| 162 | 143 |
| 163 | 144 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 175 CPluginFilter(const CString& dataPath = ""); | 156 CPluginFilter(const CString& dataPath = ""); |
| 176 | 157 |
| 177 bool LoadHideFilters(std::vector<std::wstring> filters); | 158 bool LoadHideFilters(std::vector<std::wstring> filters); |
| 178 | 159 |
| 179 bool AddFilterElementHide(CString filter); | 160 bool AddFilterElementHide(CString filter); |
| 180 | 161 |
| 181 | 162 |
| 182 bool IsElementHidden(const std::wstring& tag, IHTMLElement* pEl, const std::ws
tring& domain, const std::wstring& indent) const; | 163 bool IsElementHidden(const std::wstring& tag, IHTMLElement* pEl, const std::ws
tring& domain, const std::wstring& indent) const; |
| 183 | 164 |
| 184 | 165 |
| 185 bool ShouldBlock(const std::wstring& src, int contentType, const std::wstring&
domain, bool addDebug=false) const; | 166 bool ShouldBlock(const std::wstring& src, AdblockPlus::FilterEngine::ContentTy
pe contentType, const std::wstring& domain, bool addDebug=false) const; |
| 186 | 167 |
| 187 HANDLE hideFiltersLoadedEvent; | 168 HANDLE hideFiltersLoadedEvent; |
| 188 }; | 169 }; |
| 189 | 170 |
| 190 | 171 |
| 191 #endif // _PLUGIN_FILTER_H_ | 172 #endif // _PLUGIN_FILTER_H_ |
| OLD | NEW |