Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/AdblockPlusClient.cpp

Issue 4882650246414336: Issue 2005 - Refactor working with strings in InputBuffer and OutputBuffer
Patch Set: address some comments Created Feb. 18, 2015, 2:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/shared/Communication.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 #include "PluginSettings.h" 2 #include "PluginSettings.h"
3 #include "PluginSystem.h" 3 #include "PluginSystem.h"
4 #include "PluginFilter.h" 4 #include "PluginFilter.h"
5 #include "PluginClientFactory.h" 5 #include "PluginClientFactory.h"
6 #include "PluginMutex.h" 6 #include "PluginMutex.h"
7 #include "PluginClass.h" 7 #include "PluginClass.h"
8 8
9 #include "AdblockPlusClient.h" 9 #include "AdblockPlusClient.h"
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf fer& message) 111 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf fer& message)
112 { 112 {
113 int32_t count; 113 int32_t count;
114 message >> count; 114 message >> count;
115 115
116 std::vector<SubscriptionDescription> result; 116 std::vector<SubscriptionDescription> result;
117 for (int32_t i = 0; i < count; i++) 117 for (int32_t i = 0; i < count; i++)
118 { 118 {
119 SubscriptionDescription description; 119 SubscriptionDescription description;
120 std::string url; 120 message >> description.url;
121 message >> url; 121 message >> description.title;
122 description.url = ToUtf16String(url); 122 message >> description.specialization;
123 std::string title;
124 message >> title;
125 description.title = ToUtf16String(title);
126 std::string specialization;
127 message >> specialization;
128 description.specialization = ToUtf16String(specialization);
129 message >> description.listed; 123 message >> description.listed;
130 result.push_back(description); 124 result.push_back(description);
131 } 125 }
132 return result; 126 return result;
133 } 127 }
134 } 128 }
135 129
136 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; 130 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL;
137 131
138 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() 132 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase()
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent); 232 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent);
239 } 233 }
240 m_criticalSectionFilter.Unlock(); 234 m_criticalSectionFilter.Unlock();
241 return isHidden; 235 return isHidden;
242 } 236 }
243 237
244 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) 238 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url)
245 { 239 {
246 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str()); 240 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
247 Communication::OutputBuffer request; 241 Communication::OutputBuffer request;
248 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url); 242 request << Communication::PROC_IS_WHITELISTED_URL << url;
249 243
250 Communication::InputBuffer response; 244 Communication::InputBuffer response;
251 if (!CallEngine(request, response)) 245 if (!CallEngine(request, response))
252 return false; 246 return false;
253 247
254 bool isWhitelisted; 248 bool isWhitelisted;
255 response >> isWhitelisted; 249 response >> isWhitelisted;
256 250
257 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str()); 251 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str());
258 return isWhitelisted; 252 return isWhitelisted;
259 } 253 }
260 254
261 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url) 255 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url)
262 { 256 {
263 Communication::OutputBuffer request; 257 Communication::OutputBuffer request;
264 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << ToUtf8String( url); 258 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << url;
265 259
266 Communication::InputBuffer response; 260 Communication::InputBuffer response;
267 if (!CallEngine(request, response)) 261 if (!CallEngine(request, response))
268 return false; 262 return false;
269 263
270 bool isWhitelisted; 264 bool isWhitelisted;
271 response >> isWhitelisted; 265 response >> isWhitelisted;
272 return isWhitelisted; 266 return isWhitelisted;
273 } 267 }
274 268
275 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain) 269 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain)
276 { 270 {
277 Communication::OutputBuffer request; 271 Communication::OutputBuffer request;
278 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain); 272 request << Communication::PROC_MATCHES << url << contentType << domain;
279 273
280 Communication::InputBuffer response; 274 Communication::InputBuffer response;
281 if (!CallEngine(request, response)) 275 if (!CallEngine(request, response))
282 return false; 276 return false;
283 277
284 bool match; 278 bool match;
285 response >> match; 279 response >> match;
286 return match; 280 return match;
287 } 281 }
288 282
289 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain) 283 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain)
290 { 284 {
291 Communication::OutputBuffer request; 285 Communication::OutputBuffer request;
292 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain); 286 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << domain;
293 287
294 Communication::InputBuffer response; 288 Communication::InputBuffer response;
295 if (!CallEngine(request, response)) 289 if (!CallEngine(request, response))
296 return std::vector<std::wstring>(); 290 return std::vector<std::wstring>();
297 291
298 std::vector<std::string> selectors; 292 std::vector<std::wstring> selectors;
299 response >> selectors; 293 response >> selectors;
300 return ToUtf16Strings(selectors); 294 return selectors;
301 } 295 }
302 296
303 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions() 297 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions()
304 { 298 {
305 Communication::InputBuffer response; 299 Communication::InputBuffer response;
306 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response)) 300 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response))
307 return std::vector<SubscriptionDescription>(); 301 return std::vector<SubscriptionDescription>();
308 return ReadSubscriptions(response); 302 return ReadSubscriptions(response);
309 } 303 }
310 304
(...skipping 16 matching lines...) Expand all
327 { 321 {
328 return true; 322 return true;
329 } 323 }
330 } 324 }
331 return false; 325 return false;
332 } 326 }
333 327
334 void CAdblockPlusClient::SetSubscription(const std::wstring& url) 328 void CAdblockPlusClient::SetSubscription(const std::wstring& url)
335 { 329 {
336 Communication::OutputBuffer request; 330 Communication::OutputBuffer request;
337 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url); 331 request << Communication::PROC_SET_SUBSCRIPTION << url;
338 CallEngine(request); 332 CallEngine(request);
339 } 333 }
340 334
341 void CAdblockPlusClient::AddSubscription(const std::wstring& url) 335 void CAdblockPlusClient::AddSubscription(const std::wstring& url)
342 { 336 {
343 Communication::OutputBuffer request; 337 Communication::OutputBuffer request;
344 request << Communication::PROC_ADD_SUBSCRIPTION << ToUtf8String(url); 338 request << Communication::PROC_ADD_SUBSCRIPTION << url;
345 CallEngine(request); 339 CallEngine(request);
346 } 340 }
347 341
348 void CAdblockPlusClient::RemoveSubscription(const std::wstring& url) 342 void CAdblockPlusClient::RemoveSubscription(const std::wstring& url)
349 { 343 {
350 Communication::OutputBuffer request; 344 Communication::OutputBuffer request;
351 request << Communication::PROC_REMOVE_SUBSCRIPTION << ToUtf8String(url); 345 request << Communication::PROC_REMOVE_SUBSCRIPTION << url;
352 CallEngine(request); 346 CallEngine(request);
353 } 347 }
354 348
355 349
356 void CAdblockPlusClient::UpdateAllSubscriptions() 350 void CAdblockPlusClient::UpdateAllSubscriptions()
357 { 351 {
358 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS); 352 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS);
359 } 353 }
360 354
361 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains() 355 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains()
362 { 356 {
363 Communication::InputBuffer response; 357 Communication::InputBuffer response;
364 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response)) 358 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response))
365 return std::vector<std::wstring>(); 359 return std::vector<std::wstring>();
366 360
367 std::vector<std::string> domains; 361 std::vector<std::wstring> domains;
368 response >> domains; 362 response >> domains;
369 return ToUtf16Strings(domains); 363 return domains;
370 } 364 }
371 365
372 bool CAdblockPlusClient::IsFirstRun() 366 bool CAdblockPlusClient::IsFirstRun()
373 { 367 {
374 DEBUG_GENERAL("IsFirstRun"); 368 DEBUG_GENERAL("IsFirstRun");
375 Communication::InputBuffer response; 369 Communication::InputBuffer response;
376 if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) ret urn false; 370 if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) ret urn false;
377 bool res; 371 bool res;
378 response >> res; 372 response >> res;
379 return res; 373 return res;
380 } 374 }
381 375
382 void CAdblockPlusClient::AddFilter(const std::wstring& text) 376 void CAdblockPlusClient::AddFilter(const std::wstring& text)
383 { 377 {
384 Communication::OutputBuffer request; 378 Communication::OutputBuffer request;
385 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); 379 request << Communication::PROC_ADD_FILTER << text;
386 CallEngine(request); 380 CallEngine(request);
387 } 381 }
388 382
389 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) 383 void CAdblockPlusClient::RemoveFilter(const std::wstring& text)
390 { 384 {
391 Communication::OutputBuffer request; 385 Communication::OutputBuffer request;
392 request << Communication::PROC_REMOVE_FILTER << ToUtf8String(text); 386 request << Communication::PROC_REMOVE_FILTER << text;
393 CallEngine(request); 387 CallEngine(request);
394 } 388 }
395 389
396 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v alue) 390 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v alue)
397 { 391 {
398 Communication::OutputBuffer request; 392 Communication::OutputBuffer request;
399 request << Communication::PROC_SET_PREF << ToUtf8String(name) << ToUtf8String( value); 393 request << Communication::PROC_SET_PREF << name << value;
400 CallEngine(request); 394 CallEngine(request);
401 } 395 }
402 396
403 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value ) 397 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value )
404 { 398 {
405 Communication::OutputBuffer request; 399 Communication::OutputBuffer request;
406 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; 400 request << Communication::PROC_SET_PREF << name << value;
407 CallEngine(request); 401 CallEngine(request);
408 } 402 }
409 403
410 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value) 404 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value)
411 { 405 {
412 Communication::OutputBuffer request; 406 Communication::OutputBuffer request;
413 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; 407 request << Communication::PROC_SET_PREF << name << value;
414 CallEngine(request); 408 CallEngine(request);
415 } 409 }
416 410
417 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue) 411 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue)
418 { 412 {
419 return GetPref(name, std::wstring(defaultValue)); 413 return GetPref(name, std::wstring(defaultValue));
420 } 414 }
421 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue) 415 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue)
422 { 416 {
423 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 417 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
424 Communication::OutputBuffer request; 418 Communication::OutputBuffer request;
425 request << Communication::PROC_GET_PREF << ToUtf8String(name); 419 request << Communication::PROC_GET_PREF << name;
426 420
427 Communication::InputBuffer response; 421 Communication::InputBuffer response;
428 if (!CallEngine(request, response)) 422 if (!CallEngine(request, response))
429 return defaultValue; 423 return defaultValue;
430 bool success; 424 bool success;
431 response >> success; 425 response >> success;
432 if (success) 426 if (success)
433 { 427 {
434 std::string value; 428 std::wstring value;
435 response >> value; 429 response >> value;
436 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 430 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
437 return ToUtf16String(value); 431 return value;
438 } 432 }
439 else 433 else
440 { 434 {
441 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 435 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
442 return defaultValue; 436 return defaultValue;
443 } 437 }
444 } 438 }
445 439
446 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) 440 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue)
447 { 441 {
448 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 442 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
449 Communication::OutputBuffer request; 443 Communication::OutputBuffer request;
450 request << Communication::PROC_GET_PREF << ToUtf8String(name); 444 request << Communication::PROC_GET_PREF << name;
451 445
452 Communication::InputBuffer response; 446 Communication::InputBuffer response;
453 if (!CallEngine(request, response)) 447 if (!CallEngine(request, response))
454 return defaultValue; 448 return defaultValue;
455 bool success; 449 bool success;
456 response >> success; 450 response >> success;
457 if (success) 451 if (success)
458 { 452 {
459 bool value; 453 bool value;
460 response >> value; 454 response >> value;
461 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 455 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
462 return value; 456 return value;
463 } 457 }
464 else 458 else
465 { 459 {
466 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 460 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
467 return defaultValue; 461 return defaultValue;
468 } 462 }
469 } 463 }
470 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue) 464 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue)
471 { 465 {
472 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 466 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
473 Communication::OutputBuffer request; 467 Communication::OutputBuffer request;
474 request << Communication::PROC_GET_PREF << ToUtf8String(name); 468 request << Communication::PROC_GET_PREF << name;
475 469
476 Communication::InputBuffer response; 470 Communication::InputBuffer response;
477 if (!CallEngine(request, response)) 471 if (!CallEngine(request, response))
478 return defaultValue; 472 return defaultValue;
479 bool success; 473 bool success;
480 response >> success; 474 response >> success;
481 if (success) 475 if (success)
482 { 476 {
483 int64_t value; 477 int64_t value;
484 response >> value; 478 response >> value;
(...skipping 13 matching lines...) Expand all
498 request << Communication::PROC_CHECK_FOR_UPDATES << reinterpret_cast<int32_t>( callbackWindow); 492 request << Communication::PROC_CHECK_FOR_UPDATES << reinterpret_cast<int32_t>( callbackWindow);
499 CallEngine(request); 493 CallEngine(request);
500 } 494 }
501 495
502 std::wstring CAdblockPlusClient::GetDocumentationLink() 496 std::wstring CAdblockPlusClient::GetDocumentationLink()
503 { 497 {
504 DEBUG_GENERAL("GetDocumentationLink"); 498 DEBUG_GENERAL("GetDocumentationLink");
505 Communication::InputBuffer response; 499 Communication::InputBuffer response;
506 if (!CallEngine(Communication::PROC_GET_DOCUMENTATION_LINK, response)) 500 if (!CallEngine(Communication::PROC_GET_DOCUMENTATION_LINK, response))
507 return L""; 501 return L"";
508 std::string docLink; 502 std::wstring docLink;
509 response >> docLink; 503 response >> docLink;
510 return ToUtf16String(docLink); 504 return docLink;
511 } 505 }
512 506
513 bool CAdblockPlusClient::TogglePluginEnabled() 507 bool CAdblockPlusClient::TogglePluginEnabled()
514 { 508 {
515 DEBUG_GENERAL("TogglePluginEnabled"); 509 DEBUG_GENERAL("TogglePluginEnabled");
516 Communication::InputBuffer response; 510 Communication::InputBuffer response;
517 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response)) 511 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response))
518 return false; 512 return false;
519 bool currentEnabledState; 513 bool currentEnabledState;
520 response >> currentEnabledState; 514 response >> currentEnabledState;
521 return currentEnabledState; 515 return currentEnabledState;
522 } 516 }
523 517
524 std::wstring CAdblockPlusClient::GetHostFromUrl(const std::wstring& url) 518 std::wstring CAdblockPlusClient::GetHostFromUrl(const std::wstring& url)
525 { 519 {
526 DEBUG_GENERAL("GetHostFromUrl"); 520 DEBUG_GENERAL("GetHostFromUrl");
527 Communication::OutputBuffer request; 521 Communication::OutputBuffer request;
528 request << Communication::PROC_GET_HOST << ToUtf8String(url); 522 request << Communication::PROC_GET_HOST << url;
529 523
530 Communication::InputBuffer response; 524 Communication::InputBuffer response;
531 if (!CallEngine(request, response)) 525 if (!CallEngine(request, response))
532 return L""; 526 return L"";
533 std::string host; 527 std::wstring host;
534 response >> host; 528 response >> host;
535 return ToUtf16String(host); 529 return host;
536 } 530 }
537 531
538 int CAdblockPlusClient::CompareVersions(const std::wstring& v1, const std::wstri ng& v2) 532 int CAdblockPlusClient::CompareVersions(const std::wstring& v1, const std::wstri ng& v2)
539 { 533 {
540 DEBUG_GENERAL("CompareVersions"); 534 DEBUG_GENERAL("CompareVersions");
541 Communication::OutputBuffer request; 535 Communication::OutputBuffer request;
542 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2); 536 request << Communication::PROC_COMPARE_VERSIONS << v1 << v2;
543 Communication::InputBuffer response; 537 Communication::InputBuffer response;
544 if (!CallEngine(request, response)) 538 if (!CallEngine(request, response))
545 return 0; 539 return 0;
546 int result; 540 int result;
547 response >> result; 541 response >> result;
548 return result; 542 return result;
549 } 543 }
OLDNEW
« no previous file with comments | « no previous file | src/shared/Communication.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld