OLD | NEW |
1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
2 | 2 |
3 #include "PluginSettings.h" | 3 #include "PluginSettings.h" |
4 #include "PluginSystem.h" | 4 #include "PluginSystem.h" |
5 #include "PluginFilter.h" | 5 #include "PluginFilter.h" |
6 #include "PluginClientFactory.h" | 6 #include "PluginClientFactory.h" |
7 #include "PluginHttpRequest.h" | |
8 #include "PluginMutex.h" | 7 #include "PluginMutex.h" |
9 #include "PluginClass.h" | 8 #include "PluginClass.h" |
10 | 9 |
11 #include "AdblockPlusClient.h" | 10 #include "AdblockPlusClient.h" |
12 | 11 |
13 #include "../shared/Communication.h" | |
14 #include "../shared/Utils.h" | 12 #include "../shared/Utils.h" |
15 | 13 |
16 namespace | 14 namespace |
17 { | 15 { |
18 void SpawnAdblockPlusEngine() | 16 void SpawnAdblockPlusEngine() |
19 { | 17 { |
20 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; | 18 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; |
21 CString params = L"AdblockPlusEngine.exe " + CPluginSystem::GetInstance()->G
etBrowserLanguage(); | 19 CString params = L"AdblockPlusEngine.exe " + CPluginSystem::GetInstance()->G
etBrowserLanguage(); |
22 | 20 |
23 STARTUPINFO startupInfo = {}; | 21 STARTUPINFO startupInfo = {}; |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi
cation::PROC_GET_EXCEPTION_DOMAINS); | 347 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi
cation::PROC_GET_EXCEPTION_DOMAINS); |
350 return ReadStrings(response); | 348 return ReadStrings(response); |
351 } | 349 } |
352 catch (const std::exception& e) | 350 catch (const std::exception& e) |
353 { | 351 { |
354 DEBUG_GENERAL(e.what()); | 352 DEBUG_GENERAL(e.what()); |
355 return std::vector<std::wstring>(); | 353 return std::vector<std::wstring>(); |
356 } | 354 } |
357 } | 355 } |
358 | 356 |
359 void CAdblockPlusClient::AddFilter(const std::wstring& text) | 357 // A helper method to reuse the code |
| 358 void CAdblockPlusClient::PostRequest(Communication::OutputBuffer request) |
360 { | 359 { |
361 Communication::OutputBuffer request; | |
362 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); | |
363 | |
364 try | 360 try |
365 { | 361 { |
366 CallAdblockPlusEngineProcedure(request); | 362 CallAdblockPlusEngineProcedure(request); |
367 } | 363 } |
368 catch (const std::exception& e) | 364 catch (const std::exception& e) |
369 { | 365 { |
370 DEBUG_GENERAL(e.what()); | 366 DEBUG_GENERAL(e.what()); |
371 } | 367 } |
372 } | 368 } |
373 | 369 |
| 370 void CAdblockPlusClient::AddFilter(const std::wstring& text) |
| 371 { |
| 372 Communication::OutputBuffer request; |
| 373 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); |
| 374 PostRequest(request); |
| 375 } |
| 376 |
374 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) | 377 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) |
375 { | 378 { |
376 Communication::OutputBuffer request; | 379 Communication::OutputBuffer request; |
377 request << Communication::PROC_REMOVE_FILTER << ToUtf8String(text); | 380 request << Communication::PROC_REMOVE_FILTER << ToUtf8String(text); |
| 381 PostRequest(request); |
| 382 } |
| 383 |
| 384 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v
alue) |
| 385 { |
| 386 Communication::OutputBuffer request; |
| 387 request << Communication::PROC_SET_PREF << ToUtf8String(name) << ToUtf8String(
value); |
| 388 PostRequest(request); |
| 389 } |
| 390 |
| 391 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value
) |
| 392 { |
| 393 Communication::OutputBuffer request; |
| 394 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; |
| 395 PostRequest(request); |
| 396 } |
| 397 |
| 398 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value) |
| 399 { |
| 400 Communication::OutputBuffer request; |
| 401 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; |
| 402 PostRequest(request); |
| 403 } |
| 404 |
| 405 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t
* defaultValue) |
| 406 { |
| 407 return GetPref(name, std::wstring(defaultValue)); |
| 408 } |
| 409 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws
tring& defaultValue) |
| 410 { |
| 411 Communication::OutputBuffer request; |
| 412 request << Communication::PROC_GET_PREF << ToUtf8String(name); |
378 | 413 |
379 try | 414 try |
380 { | 415 { |
381 CallAdblockPlusEngineProcedure(request); | 416 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); |
| 417 bool success; |
| 418 response >> success; |
| 419 if (success) |
| 420 { |
| 421 std::string value; |
| 422 response >> value; |
| 423 return ToUtf16String(value); |
| 424 } |
| 425 else |
| 426 return defaultValue; |
382 } | 427 } |
383 catch (const std::exception& e) | 428 catch (const std::exception& e) |
384 { | 429 { |
385 DEBUG_GENERAL(e.what()); | 430 DEBUG_GENERAL(e.what()); |
| 431 return defaultValue; |
386 } | 432 } |
387 } | 433 } |
| 434 |
| 435 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) |
| 436 { |
| 437 Communication::OutputBuffer request; |
| 438 request << Communication::PROC_GET_PREF << ToUtf8String(name); |
| 439 |
| 440 try |
| 441 { |
| 442 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); |
| 443 bool success; |
| 444 response >> success; |
| 445 if (success) |
| 446 { |
| 447 bool value; |
| 448 response >> value; |
| 449 return value; |
| 450 } |
| 451 else |
| 452 return defaultValue; |
| 453 } |
| 454 catch (const std::exception& e) |
| 455 { |
| 456 DEBUG_GENERAL(e.what()); |
| 457 return defaultValue; |
| 458 } |
| 459 } |
| 460 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal
ue) |
| 461 { |
| 462 Communication::OutputBuffer request; |
| 463 request << Communication::PROC_GET_PREF << ToUtf8String(name); |
| 464 |
| 465 try |
| 466 { |
| 467 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); |
| 468 bool success; |
| 469 response >> success; |
| 470 if (success) |
| 471 { |
| 472 int64_t value; |
| 473 response >> value; |
| 474 return value; |
| 475 } |
| 476 else |
| 477 return defaultValue; |
| 478 } |
| 479 catch (const std::exception& e) |
| 480 { |
| 481 DEBUG_GENERAL(e.what()); |
| 482 return defaultValue; |
| 483 } |
| 484 } |
OLD | NEW |