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. 19, 2015, 5:21 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 /* 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf fer& message) 128 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf fer& message)
129 { 129 {
130 int32_t count; 130 int32_t count;
131 message >> count; 131 message >> count;
132 132
133 std::vector<SubscriptionDescription> result; 133 std::vector<SubscriptionDescription> result;
134 for (int32_t i = 0; i < count; i++) 134 for (int32_t i = 0; i < count; i++)
135 { 135 {
136 SubscriptionDescription description; 136 SubscriptionDescription description;
137 std::string url; 137 message >> description.url;
138 message >> url; 138 message >> description.title;
139 description.url = ToUtf16String(url); 139 message >> description.specialization;
140 std::string title;
141 message >> title;
142 description.title = ToUtf16String(title);
143 std::string specialization;
144 message >> specialization;
145 description.specialization = ToUtf16String(specialization);
146 message >> description.listed; 140 message >> description.listed;
147 result.push_back(description); 141 result.push_back(description);
148 } 142 }
149 return result; 143 return result;
150 } 144 }
151 } 145 }
152 146
153 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; 147 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL;
154 148
155 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() 149 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase()
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent); 249 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent);
256 } 250 }
257 m_criticalSectionFilter.Unlock(); 251 m_criticalSectionFilter.Unlock();
258 return isHidden; 252 return isHidden;
259 } 253 }
260 254
261 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) 255 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url)
262 { 256 {
263 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str()); 257 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
264 Communication::OutputBuffer request; 258 Communication::OutputBuffer request;
265 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url); 259 request << Communication::PROC_IS_WHITELISTED_URL << url;
266 260
267 Communication::InputBuffer response; 261 Communication::InputBuffer response;
268 if (!CallEngine(request, response)) 262 if (!CallEngine(request, response))
269 return false; 263 return false;
270 264
271 bool isWhitelisted; 265 bool isWhitelisted;
272 response >> isWhitelisted; 266 response >> isWhitelisted;
273 267
274 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str()); 268 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str());
275 return isWhitelisted; 269 return isWhitelisted;
276 } 270 }
277 271
278 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url) 272 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url)
279 { 273 {
280 Communication::OutputBuffer request; 274 Communication::OutputBuffer request;
281 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << ToUtf8String( url); 275 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << url;
282 276
283 Communication::InputBuffer response; 277 Communication::InputBuffer response;
284 if (!CallEngine(request, response)) 278 if (!CallEngine(request, response))
285 return false; 279 return false;
286 280
287 bool isWhitelisted; 281 bool isWhitelisted;
288 response >> isWhitelisted; 282 response >> isWhitelisted;
289 return isWhitelisted; 283 return isWhitelisted;
290 } 284 }
291 285
292 bool CAdblockPlusClient::Matches(const std::wstring& url, AdblockPlus::FilterEng ine::ContentType contentType, const std::wstring& domain) 286 bool CAdblockPlusClient::Matches(const std::wstring& url, AdblockPlus::FilterEng ine::ContentType contentType, const std::wstring& domain)
293 { 287 {
294 Communication::OutputBuffer request; 288 Communication::OutputBuffer request;
295 request << Communication::PROC_MATCHES << ToUtf8String(url) << static_cast<int 32_t>(contentType) << ToUtf8String(domain); 289 request << Communication::PROC_MATCHES << url << contentType << domain;
296 290
297 Communication::InputBuffer response; 291 Communication::InputBuffer response;
298 if (!CallEngine(request, response)) 292 if (!CallEngine(request, response))
299 return false; 293 return false;
300 294
301 bool match; 295 bool match;
302 response >> match; 296 response >> match;
303 return match; 297 return match;
304 } 298 }
305 299
306 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain) 300 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain)
307 { 301 {
308 Communication::OutputBuffer request; 302 Communication::OutputBuffer request;
309 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain); 303 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << domain;
310 304
311 Communication::InputBuffer response; 305 Communication::InputBuffer response;
312 if (!CallEngine(request, response)) 306 if (!CallEngine(request, response))
313 return std::vector<std::wstring>(); 307 return std::vector<std::wstring>();
314 308
315 std::vector<std::string> selectors; 309 std::vector<std::wstring> selectors;
316 response >> selectors; 310 response >> selectors;
317 return ToUtf16Strings(selectors); 311 return selectors;
318 } 312 }
319 313
320 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions() 314 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions()
321 { 315 {
322 Communication::InputBuffer response; 316 Communication::InputBuffer response;
323 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response)) 317 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response))
324 return std::vector<SubscriptionDescription>(); 318 return std::vector<SubscriptionDescription>();
325 return ReadSubscriptions(response); 319 return ReadSubscriptions(response);
326 } 320 }
327 321
(...skipping 16 matching lines...) Expand all
344 { 338 {
345 return true; 339 return true;
346 } 340 }
347 } 341 }
348 return false; 342 return false;
349 } 343 }
350 344
351 void CAdblockPlusClient::SetSubscription(const std::wstring& url) 345 void CAdblockPlusClient::SetSubscription(const std::wstring& url)
352 { 346 {
353 Communication::OutputBuffer request; 347 Communication::OutputBuffer request;
354 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url); 348 request << Communication::PROC_SET_SUBSCRIPTION << url;
355 CallEngine(request); 349 CallEngine(request);
356 } 350 }
357 351
358 void CAdblockPlusClient::AddSubscription(const std::wstring& url) 352 void CAdblockPlusClient::AddSubscription(const std::wstring& url)
359 { 353 {
360 Communication::OutputBuffer request; 354 Communication::OutputBuffer request;
361 request << Communication::PROC_ADD_SUBSCRIPTION << ToUtf8String(url); 355 request << Communication::PROC_ADD_SUBSCRIPTION << url;
362 CallEngine(request); 356 CallEngine(request);
363 } 357 }
364 358
365 void CAdblockPlusClient::RemoveSubscription(const std::wstring& url) 359 void CAdblockPlusClient::RemoveSubscription(const std::wstring& url)
366 { 360 {
367 Communication::OutputBuffer request; 361 Communication::OutputBuffer request;
368 request << Communication::PROC_REMOVE_SUBSCRIPTION << ToUtf8String(url); 362 request << Communication::PROC_REMOVE_SUBSCRIPTION << url;
369 CallEngine(request); 363 CallEngine(request);
370 } 364 }
371 365
372 366
373 void CAdblockPlusClient::UpdateAllSubscriptions() 367 void CAdblockPlusClient::UpdateAllSubscriptions()
374 { 368 {
375 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS); 369 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS);
376 } 370 }
377 371
378 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains() 372 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains()
379 { 373 {
380 Communication::InputBuffer response; 374 Communication::InputBuffer response;
381 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response)) 375 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response))
382 return std::vector<std::wstring>(); 376 return std::vector<std::wstring>();
383 377
384 std::vector<std::string> domains; 378 std::vector<std::wstring> domains;
385 response >> domains; 379 response >> domains;
386 return ToUtf16Strings(domains); 380 return domains;
387 } 381 }
388 382
389 bool CAdblockPlusClient::IsFirstRun() 383 bool CAdblockPlusClient::IsFirstRun()
390 { 384 {
391 DEBUG_GENERAL("IsFirstRun"); 385 DEBUG_GENERAL("IsFirstRun");
392 Communication::InputBuffer response; 386 Communication::InputBuffer response;
393 if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) ret urn false; 387 if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) ret urn false;
394 bool res; 388 bool res;
395 response >> res; 389 response >> res;
396 return res; 390 return res;
397 } 391 }
398 392
399 void CAdblockPlusClient::AddFilter(const std::wstring& text) 393 void CAdblockPlusClient::AddFilter(const std::wstring& text)
400 { 394 {
401 Communication::OutputBuffer request; 395 Communication::OutputBuffer request;
402 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); 396 request << Communication::PROC_ADD_FILTER << text;
403 CallEngine(request); 397 CallEngine(request);
404 } 398 }
405 399
406 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) 400 void CAdblockPlusClient::RemoveFilter(const std::wstring& text)
407 { 401 {
408 Communication::OutputBuffer request; 402 Communication::OutputBuffer request;
409 request << Communication::PROC_REMOVE_FILTER << ToUtf8String(text); 403 request << Communication::PROC_REMOVE_FILTER << text;
410 CallEngine(request); 404 CallEngine(request);
411 } 405 }
412 406
413 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v alue) 407 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v alue)
414 { 408 {
415 Communication::OutputBuffer request; 409 Communication::OutputBuffer request;
416 request << Communication::PROC_SET_PREF << ToUtf8String(name) << ToUtf8String( value); 410 request << Communication::PROC_SET_PREF << name << value;
417 CallEngine(request); 411 CallEngine(request);
418 } 412 }
419 413
420 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value ) 414 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value )
421 { 415 {
422 Communication::OutputBuffer request; 416 Communication::OutputBuffer request;
423 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; 417 request << Communication::PROC_SET_PREF << name << value;
424 CallEngine(request); 418 CallEngine(request);
425 } 419 }
426 420
427 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value) 421 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value)
428 { 422 {
429 Communication::OutputBuffer request; 423 Communication::OutputBuffer request;
430 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; 424 request << Communication::PROC_SET_PREF << name << value;
431 CallEngine(request); 425 CallEngine(request);
432 } 426 }
433 427
434 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue) 428 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue)
435 { 429 {
436 return GetPref(name, std::wstring(defaultValue)); 430 return GetPref(name, std::wstring(defaultValue));
437 } 431 }
438 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue) 432 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue)
439 { 433 {
440 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 434 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
441 Communication::OutputBuffer request; 435 Communication::OutputBuffer request;
442 request << Communication::PROC_GET_PREF << ToUtf8String(name); 436 request << Communication::PROC_GET_PREF << name;
443 437
444 Communication::InputBuffer response; 438 Communication::InputBuffer response;
445 if (!CallEngine(request, response)) 439 if (!CallEngine(request, response))
446 return defaultValue; 440 return defaultValue;
447 bool success; 441 bool success;
448 response >> success; 442 response >> success;
449 if (success) 443 if (success)
450 { 444 {
451 std::string value; 445 std::wstring value;
452 response >> value; 446 response >> value;
453 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 447 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
454 return ToUtf16String(value); 448 return value;
455 } 449 }
456 else 450 else
457 { 451 {
458 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 452 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
459 return defaultValue; 453 return defaultValue;
460 } 454 }
461 } 455 }
462 456
463 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) 457 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue)
464 { 458 {
465 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 459 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
466 Communication::OutputBuffer request; 460 Communication::OutputBuffer request;
467 request << Communication::PROC_GET_PREF << ToUtf8String(name); 461 request << Communication::PROC_GET_PREF << name;
468 462
469 Communication::InputBuffer response; 463 Communication::InputBuffer response;
470 if (!CallEngine(request, response)) 464 if (!CallEngine(request, response))
471 return defaultValue; 465 return defaultValue;
472 bool success; 466 bool success;
473 response >> success; 467 response >> success;
474 if (success) 468 if (success)
475 { 469 {
476 bool value; 470 bool value;
477 response >> value; 471 response >> value;
478 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 472 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
479 return value; 473 return value;
480 } 474 }
481 else 475 else
482 { 476 {
483 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 477 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
484 return defaultValue; 478 return defaultValue;
485 } 479 }
486 } 480 }
487 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue) 481 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue)
488 { 482 {
489 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 483 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
490 Communication::OutputBuffer request; 484 Communication::OutputBuffer request;
491 request << Communication::PROC_GET_PREF << ToUtf8String(name); 485 request << Communication::PROC_GET_PREF << name;
492 486
493 Communication::InputBuffer response; 487 Communication::InputBuffer response;
494 if (!CallEngine(request, response)) 488 if (!CallEngine(request, response))
495 return defaultValue; 489 return defaultValue;
496 bool success; 490 bool success;
497 response >> success; 491 response >> success;
498 if (success) 492 if (success)
499 { 493 {
500 int64_t value; 494 int64_t value;
501 response >> value; 495 response >> value;
(...skipping 13 matching lines...) Expand all
515 request << Communication::PROC_CHECK_FOR_UPDATES << reinterpret_cast<int32_t>( callbackWindow); 509 request << Communication::PROC_CHECK_FOR_UPDATES << reinterpret_cast<int32_t>( callbackWindow);
516 CallEngine(request); 510 CallEngine(request);
517 } 511 }
518 512
519 std::wstring CAdblockPlusClient::GetDocumentationLink() 513 std::wstring CAdblockPlusClient::GetDocumentationLink()
520 { 514 {
521 DEBUG_GENERAL("GetDocumentationLink"); 515 DEBUG_GENERAL("GetDocumentationLink");
522 Communication::InputBuffer response; 516 Communication::InputBuffer response;
523 if (!CallEngine(Communication::PROC_GET_DOCUMENTATION_LINK, response)) 517 if (!CallEngine(Communication::PROC_GET_DOCUMENTATION_LINK, response))
524 return L""; 518 return L"";
525 std::string docLink; 519 std::wstring docLink;
526 response >> docLink; 520 response >> docLink;
527 return ToUtf16String(docLink); 521 return docLink;
528 } 522 }
529 523
530 bool CAdblockPlusClient::TogglePluginEnabled() 524 bool CAdblockPlusClient::TogglePluginEnabled()
531 { 525 {
532 DEBUG_GENERAL("TogglePluginEnabled"); 526 DEBUG_GENERAL("TogglePluginEnabled");
533 Communication::InputBuffer response; 527 Communication::InputBuffer response;
534 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response)) 528 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response))
535 return false; 529 return false;
536 bool currentEnabledState; 530 bool currentEnabledState;
537 response >> currentEnabledState; 531 response >> currentEnabledState;
538 return currentEnabledState; 532 return currentEnabledState;
539 } 533 }
540 534
541 std::wstring CAdblockPlusClient::GetHostFromUrl(const std::wstring& url) 535 std::wstring CAdblockPlusClient::GetHostFromUrl(const std::wstring& url)
542 { 536 {
543 DEBUG_GENERAL("GetHostFromUrl"); 537 DEBUG_GENERAL("GetHostFromUrl");
544 Communication::OutputBuffer request; 538 Communication::OutputBuffer request;
545 request << Communication::PROC_GET_HOST << ToUtf8String(url); 539 request << Communication::PROC_GET_HOST << url;
546 540
547 Communication::InputBuffer response; 541 Communication::InputBuffer response;
548 if (!CallEngine(request, response)) 542 if (!CallEngine(request, response))
549 return L""; 543 return L"";
550 std::string host; 544 std::wstring host;
551 response >> host; 545 response >> host;
552 return ToUtf16String(host); 546 return host;
553 } 547 }
554 548
555 int CAdblockPlusClient::CompareVersions(const std::wstring& v1, const std::wstri ng& v2) 549 int CAdblockPlusClient::CompareVersions(const std::wstring& v1, const std::wstri ng& v2)
556 { 550 {
557 DEBUG_GENERAL("CompareVersions"); 551 DEBUG_GENERAL("CompareVersions");
558 Communication::OutputBuffer request; 552 Communication::OutputBuffer request;
559 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2); 553 request << Communication::PROC_COMPARE_VERSIONS << v1 << v2;
560 Communication::InputBuffer response; 554 Communication::InputBuffer response;
561 if (!CallEngine(request, response)) 555 if (!CallEngine(request, response))
562 return 0; 556 return 0;
563 int result; 557 int result;
564 response >> result; 558 response >> result;
565 return result; 559 return result;
566 } 560 }
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