OLD | NEW |
1 #ifndef _PLUGIN_FILTER_H_ | 1 #ifndef _PLUGIN_FILTER_H_ |
2 #define _PLUGIN_FILTER_H_ | 2 #define _PLUGIN_FILTER_H_ |
3 | 3 |
4 | 4 |
5 #include "PluginTypedef.h" | 5 #include "PluginTypedef.h" |
6 #include <memory> | 6 #include <memory> |
7 | 7 |
8 enum CFilterElementHideAttrPos | 8 enum CFilterElementHideAttrPos |
9 { | 9 { |
10 POS_NONE = 0, STARTING, ENDING, ANYWHERE, EXACT | 10 POS_NONE = 0, STARTING, ENDING, ANYWHERE, EXACT |
11 }; | 11 }; |
12 | 12 |
13 enum CFilterElementHideAttrType | 13 enum CFilterElementHideAttrType |
14 { | 14 { |
15 TYPE_NONE = 0, STYLE, ID, CLASS | 15 TYPE_NONE = 0, STYLE, ID, CLASS |
16 }; | 16 }; |
17 // ============================================================================ | 17 // ============================================================================ |
18 // CFilterElementHideAttrSelector | 18 // CFilterElementHideAttrSelector |
19 // ============================================================================ | 19 // ============================================================================ |
20 | 20 |
21 class CFilterElementHideAttrSelector | 21 class CFilterElementHideAttrSelector |
22 { | 22 { |
23 | 23 |
24 public: | 24 public: |
25 | 25 |
26 CFilterElementHideAttrPos m_pos; | 26 CFilterElementHideAttrPos m_pos; |
27 | 27 |
28 CFilterElementHideAttrType m_type; | 28 CFilterElementHideAttrType m_type; |
29 | 29 |
30 CComBSTR m_bstrAttr; | 30 std::wstring m_attr_name; |
31 CString m_value; | 31 std::wstring m_value; |
32 | 32 |
33 CFilterElementHideAttrSelector(); | 33 CFilterElementHideAttrSelector(); |
34 CFilterElementHideAttrSelector(const CFilterElementHideAttrSelector& filter); | 34 CFilterElementHideAttrSelector(const CFilterElementHideAttrSelector& filter); |
35 ~CFilterElementHideAttrSelector(); | 35 ~CFilterElementHideAttrSelector(); |
36 }; | 36 }; |
37 | 37 |
38 | 38 |
39 | 39 |
40 // ============================================================================ | 40 // ============================================================================ |
41 // CFilterElementHide | 41 // CFilterElementHide |
42 // ============================================================================ | 42 // ============================================================================ |
43 class CFilterElementHide | 43 class CFilterElementHide |
44 { | 44 { |
45 | 45 |
46 public: | 46 public: |
47 | 47 |
48 enum ETraverserComplexType | 48 enum ETraverserComplexType |
49 { | 49 { |
50 TRAVERSER_TYPE_PARENT, | 50 TRAVERSER_TYPE_PARENT, |
51 TRAVERSER_TYPE_IMMEDIATE, | 51 TRAVERSER_TYPE_IMMEDIATE, |
52 TRAVERSER_TYPE_ERROR | 52 TRAVERSER_TYPE_ERROR |
53 }; | 53 }; |
54 | 54 |
55 | 55 |
56 CString m_filterText; | 56 std::wstring m_filterText; |
57 | 57 |
58 // For domain specific filters only | 58 // For domain specific filters only |
59 CString m_tagId; | 59 std::wstring m_tagId; |
60 CString m_tagClassName; | 60 std::wstring m_tagClassName; |
61 CString m_tag; | 61 std::wstring m_tag; |
62 | 62 |
63 std::vector<CFilterElementHideAttrSelector> m_attributeSelectors; | 63 std::vector<CFilterElementHideAttrSelector> m_attributeSelectors; |
64 std::shared_ptr<CFilterElementHide> m_predecessor; | 64 std::shared_ptr<CFilterElementHide> m_predecessor; |
65 | 65 |
66 CFilterElementHide(const CString& filterText=""); | 66 CFilterElementHide(const std::wstring & filterText=L""); |
67 CFilterElementHide(const CFilterElementHide& filter); | 67 CFilterElementHide(const CFilterElementHide& filter); |
68 ETraverserComplexType m_type; | 68 ETraverserComplexType m_type; |
69 | 69 |
70 bool IsMatchFilterElementHide(IHTMLElement* pEl) const; | 70 bool IsMatchFilterElementHide(IHTMLElement* pEl) const; |
71 | 71 |
72 }; | 72 }; |
73 | 73 |
74 // ============================================================================ | 74 // ============================================================================ |
75 // CFilter | 75 // CFilter |
76 // ============================================================================ | 76 // ============================================================================ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } filterType; | 108 } filterType; |
109 | 109 |
110 int m_contentType; | 110 int m_contentType; |
111 enum EFilterType m_filterType; | 111 enum EFilterType m_filterType; |
112 bool m_isMatchCase; | 112 bool m_isMatchCase; |
113 bool m_isFirstParty; | 113 bool m_isFirstParty; |
114 bool m_isThirdParty; | 114 bool m_isThirdParty; |
115 bool m_isFromStart; | 115 bool m_isFromStart; |
116 bool m_isFromEnd; | 116 bool m_isFromEnd; |
117 int m_hitCount; | 117 int m_hitCount; |
118 CString m_filterText; | 118 std::wstring m_filterText; |
119 | 119 |
120 CFilter(const CFilter&); | 120 CFilter(const CFilter&); |
121 CFilter(); | 121 CFilter(); |
122 }; | 122 }; |
123 | 123 |
124 // ============================================================================ | 124 // ============================================================================ |
125 // CPluginFilter | 125 // CPluginFilter |
126 // ============================================================================ | 126 // ============================================================================ |
127 | 127 |
128 class CPluginFilter | 128 class CPluginFilter |
129 { | 129 { |
130 | 130 |
131 private: | 131 private: |
132 | 132 |
133 CString m_dataPath; | 133 std::map< int, std::wstring > m_contentMapText; |
134 | |
135 std::map<int, CString> m_contentMapText; | |
136 | 134 |
137 typedef std::map<DWORD, CFilter> TFilterMap; | 135 typedef std::map<DWORD, CFilter> TFilterMap; |
138 typedef std::vector<CFilter> TFilterMapDefault; | 136 typedef std::vector<CFilter> TFilterMapDefault; |
139 | 137 |
140 // (Tag,Name) -> Filter | 138 // (Tag,Name) -> Filter |
141 typedef std::multimap<std::pair<CString,CString>, CFilterElementHide> TFilterE
lementHideTagsNamed; | 139 typedef std::multimap<std::pair< std::wstring, std::wstring >, CFilterElementH
ide> TFilterElementHideTagsNamed; |
142 | 140 |
143 // Tag -> Filter | 141 // Tag -> Filter |
144 typedef std::multimap<CString, CFilterElementHide> TFilterElementHideTags; | 142 typedef std::multimap< std::wstring, CFilterElementHide> TFilterElementHideTag
s; |
145 | 143 |
146 | 144 |
147 TFilterElementHideTagsNamed m_elementHideTagsId; | 145 TFilterElementHideTagsNamed m_elementHideTagsId; |
148 TFilterElementHideTagsNamed m_elementHideTagsClass; | 146 TFilterElementHideTagsNamed m_elementHideTagsClass; |
149 TFilterElementHideTags m_elementHideTags; | 147 TFilterElementHideTags m_elementHideTags; |
150 | 148 |
151 TFilterMap m_filterMap[2][2]; | 149 TFilterMap m_filterMap[2][2]; |
152 TFilterMapDefault m_filterMapDefault[2]; | 150 TFilterMapDefault m_filterMapDefault[2]; |
153 | 151 |
154 void ClearFilters(); | 152 void ClearFilters(); |
155 | 153 |
156 public: | 154 public: |
157 | 155 |
158 CPluginFilter(const CString& dataPath = ""); | 156 CPluginFilter(); |
159 | 157 |
160 bool LoadHideFilters(std::vector<std::wstring> filters); | 158 bool LoadHideFilters(std::vector<std::wstring> filters); |
161 | 159 |
162 bool AddFilterElementHide(CString filter); | 160 bool AddFilterElementHide( std::wstring filter); |
163 | 161 |
164 | 162 |
165 bool IsElementHidden(const CString& tag, IHTMLElement* pEl, const CString& dom
ain, const CString& indent) const; | 163 bool IsElementHidden(const std::wstring & tag, IHTMLElement* pEl, const std::w
string & domain, const std::wstring & indent) const; |
166 | 164 |
167 | 165 |
168 bool ShouldBlock(CString src, int contentType, const CString& domain, bool add
Debug=false) const; | 166 bool ShouldBlock( std::wstring src, int contentType, const std::wstring & doma
in, bool addDebug=false) const; |
169 | 167 |
170 HANDLE hideFiltersLoadedEvent; | 168 HANDLE hideFiltersLoadedEvent; |
171 }; | 169 }; |
172 | 170 |
173 | 171 |
174 #endif // _PLUGIN_FILTER_H_ | 172 #endif // _PLUGIN_FILTER_H_ |
OLD | NEW |