LEFT | RIGHT |
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 message >> description.title; | 138 message >> description.title; |
139 message >> description.specialization; | 139 message >> description.specialization; |
140 message >> description.listed; | 140 message >> description.listed; |
141 result.push_back(description); | 141 result.push_back(description); |
142 } | 142 } |
143 return result; | 143 return result; |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; | 147 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; |
148 | 148 CComAutoCriticalSection CAdblockPlusClient::s_criticalSectionLocal; |
149 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() | 149 |
| 150 CAdblockPlusClient::CAdblockPlusClient() |
150 { | 151 { |
151 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); | 152 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); |
152 } | 153 } |
153 | 154 |
154 bool CAdblockPlusClient::CallEngine(Communication::OutputBuffer& message, Commun
ication::InputBuffer& inputBuffer) | 155 bool CAdblockPlusClient::CallEngine(Communication::OutputBuffer& message, Commun
ication::InputBuffer& inputBuffer) |
155 { | 156 { |
156 DEBUG_GENERAL("CallEngine start"); | 157 DEBUG_GENERAL("CallEngine start"); |
157 CriticalSection::Lock lock(enginePipeLock); | 158 CriticalSection::Lock lock(enginePipeLock); |
158 try | 159 try |
159 { | 160 { |
160 if (!enginePipe) | 161 if (!enginePipe) |
161 enginePipe.reset(OpenEnginePipe()); | 162 enginePipe.reset(OpenEnginePipe()); |
162 enginePipe->WriteMessage(message); | 163 enginePipe->WriteMessage(message); |
163 inputBuffer = enginePipe->ReadMessage(); | 164 inputBuffer = enginePipe->ReadMessage(); |
164 } | 165 } |
165 catch (const std::exception& e) | 166 catch (const std::exception& ex) |
166 { | 167 { |
167 DEBUG_GENERAL(e.what()); | 168 DEBUG_EXCEPTION(ex); |
168 return false; | 169 return false; |
169 } | 170 } |
170 DEBUG_GENERAL("CallEngine end"); | 171 DEBUG_GENERAL("CallEngine end"); |
171 return true; | 172 return true; |
172 } | 173 } |
173 | 174 |
174 bool CAdblockPlusClient::CallEngine(Communication::ProcType proc, Communication:
:InputBuffer& inputBuffer) | 175 bool CAdblockPlusClient::CallEngine(Communication::ProcType proc, Communication:
:InputBuffer& inputBuffer) |
175 { | 176 { |
176 Communication::OutputBuffer message; | 177 Communication::OutputBuffer message; |
177 message << proc; | 178 message << proc; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 m_criticalSectionFilter.Lock(); | 248 m_criticalSectionFilter.Lock(); |
248 { | 249 { |
249 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent); | 250 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent); |
250 } | 251 } |
251 m_criticalSectionFilter.Unlock(); | 252 m_criticalSectionFilter.Unlock(); |
252 return isHidden; | 253 return isHidden; |
253 } | 254 } |
254 | 255 |
255 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) | 256 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) |
256 { | 257 { |
257 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str()); | 258 return !GetWhitelistingFilter(url).empty(); |
258 Communication::OutputBuffer request; | 259 } |
259 request << Communication::PROC_IS_WHITELISTED_URL << url; | 260 |
260 | 261 std::string CAdblockPlusClient::GetWhitelistingFilter(const std::wstring& url) |
261 Communication::InputBuffer response; | 262 { |
262 if (!CallEngine(request, response)) | 263 DEBUG_GENERAL((L"GetWhitelistingFilter: " + url + L" start").c_str()); |
263 return false; | 264 Communication::OutputBuffer request; |
264 | 265 request << Communication::PROC_GET_WHITELISTING_FITER << url; |
265 bool isWhitelisted; | 266 |
266 response >> isWhitelisted; | 267 Communication::InputBuffer response; |
267 | 268 if (!CallEngine(request, response)) |
268 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str()); | 269 return ""; |
269 return isWhitelisted; | 270 |
| 271 std::string filterText; |
| 272 response >> filterText; |
| 273 |
| 274 DEBUG_GENERAL((L"GetWhitelistingFilter: " + url + L" end").c_str()); |
| 275 return filterText; |
270 } | 276 } |
271 | 277 |
272 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url) | 278 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url) |
273 { | 279 { |
274 Communication::OutputBuffer request; | 280 Communication::OutputBuffer request; |
275 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << url; | 281 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << url; |
276 | 282 |
277 Communication::InputBuffer response; | 283 Communication::InputBuffer response; |
278 if (!CallEngine(request, response)) | 284 if (!CallEngine(request, response)) |
279 return false; | 285 return false; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 397 } |
392 | 398 |
393 void CAdblockPlusClient::AddFilter(const std::wstring& text) | 399 void CAdblockPlusClient::AddFilter(const std::wstring& text) |
394 { | 400 { |
395 Communication::OutputBuffer request; | 401 Communication::OutputBuffer request; |
396 request << Communication::PROC_ADD_FILTER << text; | 402 request << Communication::PROC_ADD_FILTER << text; |
397 CallEngine(request); | 403 CallEngine(request); |
398 } | 404 } |
399 | 405 |
400 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) | 406 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) |
| 407 { |
| 408 RemoveFilter(ToUtf8String(text)); |
| 409 } |
| 410 |
| 411 void CAdblockPlusClient::RemoveFilter(const std::string& text) |
401 { | 412 { |
402 Communication::OutputBuffer request; | 413 Communication::OutputBuffer request; |
403 request << Communication::PROC_REMOVE_FILTER << text; | 414 request << Communication::PROC_REMOVE_FILTER << text; |
404 CallEngine(request); | 415 CallEngine(request); |
405 } | 416 } |
406 | 417 |
407 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v
alue) | 418 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v
alue) |
408 { | 419 { |
409 Communication::OutputBuffer request; | 420 Communication::OutputBuffer request; |
410 request << Communication::PROC_SET_PREF << name << value; | 421 request << Communication::PROC_SET_PREF << name << value; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 DEBUG_GENERAL("CompareVersions"); | 562 DEBUG_GENERAL("CompareVersions"); |
552 Communication::OutputBuffer request; | 563 Communication::OutputBuffer request; |
553 request << Communication::PROC_COMPARE_VERSIONS << v1 << v2; | 564 request << Communication::PROC_COMPARE_VERSIONS << v1 << v2; |
554 Communication::InputBuffer response; | 565 Communication::InputBuffer response; |
555 if (!CallEngine(request, response)) | 566 if (!CallEngine(request, response)) |
556 return 0; | 567 return 0; |
557 int result; | 568 int result; |
558 response >> result; | 569 response >> result; |
559 return result; | 570 return result; |
560 } | 571 } |
LEFT | RIGHT |