| LEFT | RIGHT |
| 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 "PluginMutex.h" | 7 #include "PluginMutex.h" |
| 8 #include "PluginClass.h" | 8 #include "PluginClass.h" |
| 9 | 9 |
| 10 #include "AdblockPlusClient.h" | 10 #include "AdblockPlusClient.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 description.title = ToUtf16String(title); | 96 description.title = ToUtf16String(title); |
| 97 std::string specialization; | 97 std::string specialization; |
| 98 message >> specialization; | 98 message >> specialization; |
| 99 description.specialization = ToUtf16String(specialization); | 99 description.specialization = ToUtf16String(specialization); |
| 100 message >> description.listed; | 100 message >> description.listed; |
| 101 result.push_back(description); | 101 result.push_back(description); |
| 102 } | 102 } |
| 103 return result; | 103 return result; |
| 104 } | 104 } |
| 105 | 105 |
| 106 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::Outpu
tBuffer& message) | 106 bool CallEngine(Communication::OutputBuffer& message, Communication::InputBuff
er& inputBuffer = Communication::InputBuffer()) |
| 107 { | 107 { |
| 108 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe(); | 108 try |
| 109 pipe->WriteMessage(message); | 109 { |
| 110 return pipe->ReadMessage(); | 110 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe(); |
| 111 } | 111 pipe->WriteMessage(message); |
| 112 | 112 inputBuffer = pipe->ReadMessage(); |
| 113 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::ProcT
ype proc) | 113 } |
| 114 catch (const std::exception& e) |
| 115 { |
| 116 DEBUG_GENERAL(e.what()); |
| 117 return false; |
| 118 } |
| 119 return true; |
| 120 } |
| 121 |
| 122 bool CallEngine(Communication::ProcType proc, Communication::InputBuffer& inpu
tBuffer = Communication::InputBuffer()) |
| 114 { | 123 { |
| 115 Communication::OutputBuffer message; | 124 Communication::OutputBuffer message; |
| 116 message << proc; | 125 message << proc; |
| 117 return CallAdblockPlusEngineProcedure(message); | 126 return CallEngine(message, inputBuffer); |
| 118 } | 127 } |
| 119 } | 128 } |
| 120 | 129 |
| 121 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; | 130 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; |
| 122 | 131 |
| 123 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() | 132 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() |
| 124 { | 133 { |
| 125 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); | 134 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); |
| 126 } | 135 } |
| 127 | 136 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 214 } |
| 206 m_criticalSectionFilter.Unlock(); | 215 m_criticalSectionFilter.Unlock(); |
| 207 return isHidden; | 216 return isHidden; |
| 208 } | 217 } |
| 209 | 218 |
| 210 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) | 219 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) |
| 211 { | 220 { |
| 212 Communication::OutputBuffer request; | 221 Communication::OutputBuffer request; |
| 213 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url); | 222 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url); |
| 214 | 223 |
| 215 try | 224 Communication::InputBuffer response; |
| 216 { | 225 if (!CallEngine(request, response)) |
| 217 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); | |
| 218 | |
| 219 bool isWhitelisted; | |
| 220 response >> isWhitelisted; | |
| 221 return isWhitelisted; | |
| 222 } | |
| 223 catch (const std::exception& e) | |
| 224 { | |
| 225 DEBUG_GENERAL(e.what()); | |
| 226 return false; | 226 return false; |
| 227 } | 227 |
| 228 bool isWhitelisted; |
| 229 response >> isWhitelisted; |
| 230 return isWhitelisted; |
| 228 } | 231 } |
| 229 | 232 |
| 230 int CAdblockPlusClient::GetIEVersion() | 233 int CAdblockPlusClient::GetIEVersion() |
| 231 { | 234 { |
| 232 //HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer | 235 //HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer |
| 233 HKEY hKey; | 236 HKEY hKey; |
| 234 LSTATUS status = RegOpenKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Interne
t Explorer", &hKey); | 237 LSTATUS status = RegOpenKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Interne
t Explorer", &hKey); |
| 235 if (status != 0) | 238 if (status != 0) |
| 236 { | 239 { |
| 237 return 0; | 240 return 0; |
| 238 } | 241 } |
| 239 DWORD type, cbData; | 242 DWORD type, cbData; |
| 240 BYTE version[50]; | 243 BYTE version[50]; |
| 241 cbData = 50; | 244 cbData = 50; |
| 242 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat
a); | 245 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat
a); |
| 243 if (status != 0) | 246 if (status != 0) |
| 244 { | 247 { |
| 245 return 0; | 248 return 0; |
| 246 } | 249 } |
| 247 RegCloseKey(hKey); | 250 RegCloseKey(hKey); |
| 248 return (int)(version[0] - 48); | 251 return (int)(version[0] - 48); |
| 249 } | 252 } |
| 250 | 253 |
| 251 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co
ntentType, const std::wstring& domain) | 254 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co
ntentType, const std::wstring& domain) |
| 252 { | 255 { |
| 253 Communication::OutputBuffer request; | 256 Communication::OutputBuffer request; |
| 254 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co
ntentType) << ToUtf8String(domain); | 257 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co
ntentType) << ToUtf8String(domain); |
| 255 | 258 |
| 256 try | 259 Communication::InputBuffer response; |
| 257 { | 260 if (!CallEngine(request, response)) |
| 258 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); | |
| 259 | |
| 260 bool match; | |
| 261 response >> match; | |
| 262 return match; | |
| 263 } | |
| 264 catch (const std::exception& e) | |
| 265 { | |
| 266 DEBUG_GENERAL(e.what()); | |
| 267 return false; | 261 return false; |
| 268 } | 262 |
| 263 bool match; |
| 264 response >> match; |
| 265 return match; |
| 269 } | 266 } |
| 270 | 267 |
| 271 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st
d::wstring& domain) | 268 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st
d::wstring& domain) |
| 272 { | 269 { |
| 273 Communication::OutputBuffer request; | 270 Communication::OutputBuffer request; |
| 274 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain); | 271 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain); |
| 275 | 272 |
| 276 try | 273 Communication::InputBuffer response; |
| 277 { | 274 if (!CallEngine(request, response)) |
| 278 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); | |
| 279 return ReadStrings(response); | |
| 280 } | |
| 281 catch (const std::exception& e) | |
| 282 { | |
| 283 DEBUG_GENERAL(e.what()); | |
| 284 return std::vector<std::wstring>(); | 275 return std::vector<std::wstring>(); |
| 285 } | 276 return ReadStrings(response); |
| 286 } | 277 } |
| 287 | 278 |
| 288 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript
ions() | 279 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript
ions() |
| 289 { | 280 { |
| 290 try | 281 Communication::InputBuffer response; |
| 291 { | 282 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response)) |
| 292 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi
cation::PROC_AVAILABLE_SUBSCRIPTIONS); | |
| 293 return ReadSubscriptions(response); | |
| 294 } | |
| 295 catch (const std::exception& e) | |
| 296 { | |
| 297 DEBUG_GENERAL(e.what()); | |
| 298 return std::vector<SubscriptionDescription>(); | 283 return std::vector<SubscriptionDescription>(); |
| 299 } | 284 return ReadSubscriptions(response); |
| 300 } | 285 } |
| 301 | 286 |
| 302 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions(
) | 287 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions(
) |
| 303 { | 288 { |
| 304 try | 289 Communication::InputBuffer response; |
| 305 { | 290 if (!CallEngine(Communication::PROC_LISTED_SUBSCRIPTIONS, response)) |
| 306 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi
cation::PROC_LISTED_SUBSCRIPTIONS); | |
| 307 return ReadSubscriptions(response); | |
| 308 } | |
| 309 catch (const std::exception& e) | |
| 310 { | |
| 311 DEBUG_GENERAL(e.what()); | |
| 312 return std::vector<SubscriptionDescription>(); | 291 return std::vector<SubscriptionDescription>(); |
| 313 } | 292 return ReadSubscriptions(response); |
| 314 } | 293 } |
| 315 | 294 |
| 316 void CAdblockPlusClient::SetSubscription(const std::wstring& url) | 295 void CAdblockPlusClient::SetSubscription(const std::wstring& url) |
| 317 { | 296 { |
| 318 Communication::OutputBuffer request; | 297 Communication::OutputBuffer request; |
| 319 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url); | 298 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url); |
| 320 | 299 CallEngine(request); |
| 321 try | |
| 322 { | |
| 323 CallAdblockPlusEngineProcedure(request); | |
| 324 } | |
| 325 catch (const std::exception& e) | |
| 326 { | |
| 327 DEBUG_GENERAL(e.what()); | |
| 328 } | |
| 329 } | 300 } |
| 330 | 301 |
| 331 void CAdblockPlusClient::UpdateAllSubscriptions() | 302 void CAdblockPlusClient::UpdateAllSubscriptions() |
| 332 { | 303 { |
| 333 try | 304 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS); |
| 334 { | |
| 335 CallAdblockPlusEngineProcedure(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS)
; | |
| 336 } | |
| 337 catch (const std::exception& e) | |
| 338 { | |
| 339 DEBUG_GENERAL(e.what()); | |
| 340 } | |
| 341 } | 305 } |
| 342 | 306 |
| 343 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains() | 307 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains() |
| 344 { | 308 { |
| 345 try | 309 Communication::InputBuffer response; |
| 346 { | 310 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS)) |
| 347 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi
cation::PROC_GET_EXCEPTION_DOMAINS); | |
| 348 return ReadStrings(response); | |
| 349 } | |
| 350 catch (const std::exception& e) | |
| 351 { | |
| 352 DEBUG_GENERAL(e.what()); | |
| 353 return std::vector<std::wstring>(); | 311 return std::vector<std::wstring>(); |
| 354 } | 312 return ReadStrings(response); |
| 355 } | |
| 356 | |
| 357 // A helper method to reuse the code | |
| 358 void CAdblockPlusClient::PostRequest(Communication::OutputBuffer request) | |
| 359 { | |
| 360 try | |
| 361 { | |
| 362 CallAdblockPlusEngineProcedure(request); | |
| 363 } | |
| 364 catch (const std::exception& e) | |
| 365 { | |
| 366 DEBUG_GENERAL(e.what()); | |
| 367 } | |
| 368 } | 313 } |
| 369 | 314 |
| 370 void CAdblockPlusClient::AddFilter(const std::wstring& text) | 315 void CAdblockPlusClient::AddFilter(const std::wstring& text) |
| 371 { | 316 { |
| 372 Communication::OutputBuffer request; | 317 Communication::OutputBuffer request; |
| 373 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); | 318 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); |
| 374 PostRequest(request); | 319 CallEngine(request); |
| 375 } | 320 } |
| 376 | 321 |
| 377 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) | 322 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) |
| 378 { | 323 { |
| 379 Communication::OutputBuffer request; | 324 Communication::OutputBuffer request; |
| 380 request << Communication::PROC_REMOVE_FILTER << ToUtf8String(text); | 325 request << Communication::PROC_REMOVE_FILTER << ToUtf8String(text); |
| 381 PostRequest(request); | 326 CallEngine(request); |
| 382 } | 327 } |
| 383 | 328 |
| 384 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v
alue) | 329 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v
alue) |
| 385 { | 330 { |
| 386 Communication::OutputBuffer request; | 331 Communication::OutputBuffer request; |
| 387 request << Communication::PROC_SET_PREF << ToUtf8String(name) << ToUtf8String(
value); | 332 request << Communication::PROC_SET_PREF << ToUtf8String(name) << ToUtf8String(
value); |
| 388 PostRequest(request); | 333 CallEngine(request); |
| 389 } | 334 } |
| 390 | 335 |
| 391 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value
) | 336 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value
) |
| 392 { | 337 { |
| 393 Communication::OutputBuffer request; | 338 Communication::OutputBuffer request; |
| 394 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; | 339 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; |
| 395 PostRequest(request); | 340 CallEngine(request); |
| 396 } | 341 } |
| 397 | 342 |
| 398 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value) | 343 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value) |
| 399 { | 344 { |
| 400 Communication::OutputBuffer request; | 345 Communication::OutputBuffer request; |
| 401 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; | 346 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; |
| 402 PostRequest(request); | 347 CallEngine(request); |
| 403 } | 348 } |
| 404 | 349 |
| 405 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t
* defaultValue) | 350 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t
* defaultValue) |
| 406 { | 351 { |
| 407 return GetPref(name, std::wstring(defaultValue)); | 352 return GetPref(name, std::wstring(defaultValue)); |
| 408 } | 353 } |
| 409 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws
tring& defaultValue) | 354 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws
tring& defaultValue) |
| 410 { | 355 { |
| 411 Communication::OutputBuffer request; | 356 Communication::OutputBuffer request; |
| 412 request << Communication::PROC_GET_PREF << ToUtf8String(name); | 357 request << Communication::PROC_GET_PREF << ToUtf8String(name); |
| 413 | 358 |
| 414 try | 359 Communication::InputBuffer response; |
| 415 { | 360 if (!CallEngine(request, response)) |
| 416 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); | 361 return defaultValue; |
| 417 bool success; | 362 bool success; |
| 418 response >> success; | 363 response >> success; |
| 419 if (success) | 364 if (success) |
| 420 { | 365 { |
| 421 std::string value; | 366 std::string value; |
| 422 response >> value; | 367 response >> value; |
| 423 return ToUtf16String(value); | 368 return ToUtf16String(value); |
| 424 } | 369 } |
| 425 else | 370 else |
| 426 return defaultValue; | 371 return defaultValue; |
| 427 } | |
| 428 catch (const std::exception& e) | |
| 429 { | |
| 430 DEBUG_GENERAL(e.what()); | |
| 431 return defaultValue; | |
| 432 } | |
| 433 } | 372 } |
| 434 | 373 |
| 435 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) | 374 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) |
| 436 { | 375 { |
| 437 Communication::OutputBuffer request; | 376 Communication::OutputBuffer request; |
| 438 request << Communication::PROC_GET_PREF << ToUtf8String(name); | 377 request << Communication::PROC_GET_PREF << ToUtf8String(name); |
| 439 | 378 |
| 440 try | 379 Communication::InputBuffer response; |
| 441 { | 380 if (!CallEngine(request, response)) |
| 442 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); | 381 return defaultValue; |
| 443 bool success; | 382 bool success; |
| 444 response >> success; | 383 response >> success; |
| 445 if (success) | 384 if (success) |
| 446 { | 385 { |
| 447 bool value; | 386 bool value; |
| 448 response >> value; | 387 response >> value; |
| 449 return value; | 388 return value; |
| 450 } | 389 } |
| 451 else | 390 else |
| 452 return defaultValue; | 391 return defaultValue; |
| 453 } | |
| 454 catch (const std::exception& e) | |
| 455 { | |
| 456 DEBUG_GENERAL(e.what()); | |
| 457 return defaultValue; | |
| 458 } | |
| 459 } | 392 } |
| 460 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal
ue) | 393 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal
ue) |
| 461 { | 394 { |
| 462 Communication::OutputBuffer request; | 395 Communication::OutputBuffer request; |
| 463 request << Communication::PROC_GET_PREF << ToUtf8String(name); | 396 request << Communication::PROC_GET_PREF << ToUtf8String(name); |
| 464 | 397 |
| 465 try | 398 Communication::InputBuffer response; |
| 466 { | 399 if (!CallEngine(request, response)) |
| 467 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); | 400 return defaultValue; |
| 468 bool success; | 401 bool success; |
| 469 response >> success; | 402 response >> success; |
| 470 if (success) | 403 if (success) |
| 471 { | 404 { |
| 472 int64_t value; | 405 int64_t value; |
| 473 response >> value; | 406 response >> value; |
| 474 return value; | 407 return value; |
| 475 } | 408 } |
| 476 else | 409 else |
| 477 return defaultValue; | 410 return defaultValue; |
| 478 } | 411 } |
| 479 catch (const std::exception& e) | |
| 480 { | |
| 481 DEBUG_GENERAL(e.what()); | |
| 482 return defaultValue; | |
| 483 } | |
| 484 } | |
| LEFT | RIGHT |