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 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 message >> description.listed; | 111 message >> description.listed; |
112 result.push_back(description); | 112 result.push_back(description); |
113 } | 113 } |
114 return result; | 114 return result; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; | 118 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; |
119 CComAutoCriticalSection CAdblockPlusClient::s_criticalSectionLocal; | 119 CComAutoCriticalSection CAdblockPlusClient::s_criticalSectionLocal; |
120 | 120 |
121 CAdblockPlusClient::CAdblockPlusClient() | |
122 { | |
123 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); | |
124 } | |
125 | |
126 bool CAdblockPlusClient::CallEngine(Communication::OutputBuffer& message, Commun
ication::InputBuffer& inputBuffer) | 121 bool CAdblockPlusClient::CallEngine(Communication::OutputBuffer& message, Commun
ication::InputBuffer& inputBuffer) |
127 { | 122 { |
128 DEBUG_GENERAL("CallEngine start"); | 123 DEBUG_GENERAL("CallEngine start"); |
129 CriticalSection::Lock lock(enginePipeLock); | 124 CriticalSection::Lock lock(enginePipeLock); |
130 try | 125 try |
131 { | 126 { |
132 if (!enginePipe) | 127 if (!enginePipe) |
133 enginePipe.reset(OpenEnginePipe()); | 128 enginePipe.reset(OpenEnginePipe()); |
134 enginePipe->WriteMessage(message); | 129 enginePipe->WriteMessage(message); |
135 inputBuffer = enginePipe->ReadMessage(); | 130 inputBuffer = enginePipe->ReadMessage(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 s_instance = client; | 164 s_instance = client; |
170 } | 165 } |
171 | 166 |
172 instance = s_instance; | 167 instance = s_instance; |
173 } | 168 } |
174 s_criticalSectionLocal.Unlock(); | 169 s_criticalSectionLocal.Unlock(); |
175 | 170 |
176 return instance; | 171 return instance; |
177 } | 172 } |
178 | 173 |
| 174 namespace |
| 175 { |
| 176 bool ShouldBlockLocal(const std::wstring& src, AdblockPlus::FilterEngine::Cont
entType contentType, const std::wstring& domain, bool addDebug) |
| 177 { |
| 178 std::wstring srcTrimmed = TrimString(src); |
| 179 |
| 180 // We should not block the empty string, so all filtering does not make sens
e |
| 181 // Therefore we just return |
| 182 if (srcTrimmed.empty()) |
| 183 { |
| 184 return false; |
| 185 } |
| 186 |
| 187 CPluginSettings* settings = CPluginSettings::GetInstance(); |
| 188 |
| 189 CPluginClient* client = CPluginClient::GetInstance(); |
| 190 bool result = client->Matches(srcTrimmed, contentType, domain); |
| 191 |
| 192 #ifdef ENABLE_DEBUG_RESULT |
| 193 if (addDebug) |
| 194 { |
| 195 std::wstring type = ToUtf16String(AdblockPlus::FilterEngine::ContentTypeTo
String(contentType)); |
| 196 if (result) |
| 197 { |
| 198 CPluginDebug::DebugResultBlocking(type, srcTrimmed, domain); |
| 199 } |
| 200 else |
| 201 { |
| 202 CPluginDebug::DebugResultIgnoring(type, srcTrimmed, domain); |
| 203 } |
| 204 } |
| 205 #endif |
| 206 return result; |
| 207 } |
| 208 } |
| 209 |
179 bool CAdblockPlusClient::ShouldBlock(const std::wstring& src, AdblockPlus::Filte
rEngine::ContentType contentType, const std::wstring& domain, bool addDebug) | 210 bool CAdblockPlusClient::ShouldBlock(const std::wstring& src, AdblockPlus::Filte
rEngine::ContentType contentType, const std::wstring& domain, bool addDebug) |
180 { | 211 { |
181 bool isBlocked = false; | 212 bool isBlocked = false; |
182 bool isCached = false; | 213 bool isCached = false; |
183 m_criticalSectionCache.Lock(); | 214 m_criticalSectionCache.Lock(); |
184 { | 215 { |
185 auto it = m_cacheBlockedSources.find(src); | 216 auto it = m_cacheBlockedSources.find(src); |
186 | 217 |
187 isCached = it != m_cacheBlockedSources.end(); | 218 isCached = it != m_cacheBlockedSources.end(); |
188 if (isCached) | 219 if (isCached) |
189 { | 220 { |
190 isBlocked = it->second; | 221 isBlocked = it->second; |
191 } | 222 } |
192 } | 223 } |
193 m_criticalSectionCache.Unlock(); | 224 m_criticalSectionCache.Unlock(); |
194 | 225 |
195 if (!isCached) | 226 if (!isCached) |
196 { | 227 { |
197 m_criticalSectionFilter.Lock(); | 228 m_criticalSectionFilter.Lock(); |
198 { | 229 { |
199 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug); | 230 isBlocked = ShouldBlockLocal(src, contentType, domain, addDebug); |
200 } | 231 } |
201 m_criticalSectionFilter.Unlock(); | 232 m_criticalSectionFilter.Unlock(); |
202 | 233 |
203 // Cache result, if content type is defined | 234 // Cache result, if content type is defined |
204 if (contentType != AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_OTHE
R) | 235 if (contentType != AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_OTHE
R) |
205 { | 236 { |
206 m_criticalSectionCache.Lock(); | 237 m_criticalSectionCache.Lock(); |
207 { | 238 { |
208 m_cacheBlockedSources[src] = isBlocked; | 239 m_cacheBlockedSources[src] = isBlocked; |
209 } | 240 } |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 DEBUG_GENERAL("CompareVersions"); | 564 DEBUG_GENERAL("CompareVersions"); |
534 Communication::OutputBuffer request; | 565 Communication::OutputBuffer request; |
535 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S
tring(v2); | 566 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S
tring(v2); |
536 Communication::InputBuffer response; | 567 Communication::InputBuffer response; |
537 if (!CallEngine(request, response)) | 568 if (!CallEngine(request, response)) |
538 return 0; | 569 return 0; |
539 int result; | 570 int result; |
540 response >> result; | 571 response >> result; |
541 return result; | 572 return result; |
542 } | 573 } |
OLD | NEW |