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

Side by Side Diff: src/FilterEngine.cpp

Issue 29409580: Issue 5013 - Make parameter const ref when applicable. (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Remove an unecessary smart pointer. Created April 11, 2017, 3:46 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 | « src/FileSystemJsObject.cpp ('k') | src/GlobalJsObject.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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 { 166 {
167 FilterEnginePtr filterEngine(new FilterEngine(jsEngine)); 167 FilterEnginePtr filterEngine(new FilterEngine(jsEngine));
168 auto sync = std::make_shared<Sync>(); 168 auto sync = std::make_shared<Sync>();
169 auto isConnectionAllowedCallback = params.isConnectionAllowedCallback; 169 auto isConnectionAllowedCallback = params.isConnectionAllowedCallback;
170 if (isConnectionAllowedCallback) 170 if (isConnectionAllowedCallback)
171 jsEngine->SetIsConnectionAllowedCallback([sync, jsEngine]()->bool 171 jsEngine->SetIsConnectionAllowedCallback([sync, jsEngine]()->bool
172 { 172 {
173 sync->Wait(); 173 sync->Wait();
174 return jsEngine->IsConnectionAllowed(); 174 return jsEngine->IsConnectionAllowed();
175 }); 175 });
176 jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync, isConnectionAllowedCallback](JsValueList& params) 176 jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync, isConnectionAllowedCallback](const JsValueList& params)
177 { 177 {
178 filterEngine->firstRun = params.size() && params[0]->AsBool(); 178 filterEngine->firstRun = params.size() && params[0]->AsBool();
179 if (isConnectionAllowedCallback) 179 if (isConnectionAllowedCallback)
180 { 180 {
181 std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine; 181 std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine;
182 jsEngine->SetIsConnectionAllowedCallback([weakFilterEngine, isConnectionAl lowedCallback]()->bool 182 jsEngine->SetIsConnectionAllowedCallback([weakFilterEngine, isConnectionAl lowedCallback]()->bool
183 { 183 {
184 auto filterEngine = weakFilterEngine.lock(); 184 auto filterEngine = weakFilterEngine.lock();
185 if (!filterEngine) 185 if (!filterEngine)
186 return false; 186 return false;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 selectors.push_back(r->AsString()); 425 selectors.push_back(r->AsString());
426 return selectors; 426 return selectors;
427 } 427 }
428 428
429 JsValuePtr FilterEngine::GetPref(const std::string& pref) const 429 JsValuePtr FilterEngine::GetPref(const std::string& pref) const
430 { 430 {
431 JsValuePtr func = jsEngine->Evaluate("API.getPref"); 431 JsValuePtr func = jsEngine->Evaluate("API.getPref");
432 return std::make_shared<JsValue>(func->Call(*jsEngine->NewValue(pref))); 432 return std::make_shared<JsValue>(func->Call(*jsEngine->NewValue(pref)));
433 } 433 }
434 434
435 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value) 435 void FilterEngine::SetPref(const std::string& pref, const JsValuePtr& value)
436 { 436 {
437 JsValuePtr func = jsEngine->Evaluate("API.setPref"); 437 JsValuePtr func = jsEngine->Evaluate("API.setPref");
438 JsConstValueList params; 438 JsConstValueList params;
439 params.push_back(jsEngine->NewValue(pref)); 439 params.push_back(jsEngine->NewValue(pref));
440 if (value) 440 if (value)
441 params.push_back(value); 441 params.push_back(value);
442 func->Call(params); 442 func->Call(params);
443 } 443 }
444 444
445 std::string FilterEngine::GetHostFromURL(const std::string& url) const 445 std::string FilterEngine::GetHostFromURL(const std::string& url) const
446 { 446 {
447 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); 447 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl");
448 return func->Call(*jsEngine->NewValue(url)).AsString(); 448 return func->Call(*jsEngine->NewValue(url)).AsString();
449 } 449 }
450 450
451 void FilterEngine::SetUpdateAvailableCallback( 451 void FilterEngine::SetUpdateAvailableCallback(
452 FilterEngine::UpdateAvailableCallback callback) 452 const FilterEngine::UpdateAvailableCallback& callback)
453 { 453 {
454 jsEngine->SetEventCallback("updateAvailable", 454 jsEngine->SetEventCallback("updateAvailable",
455 std::bind(&FilterEngine::UpdateAvailable, this, callback, 455 std::bind(&FilterEngine::UpdateAvailable, this, callback,
456 std::placeholders::_1)); 456 std::placeholders::_1));
457 } 457 }
458 458
459 void FilterEngine::RemoveUpdateAvailableCallback() 459 void FilterEngine::RemoveUpdateAvailableCallback()
460 { 460 {
461 jsEngine->RemoveEventCallback("updateAvailable"); 461 jsEngine->RemoveEventCallback("updateAvailable");
462 } 462 }
463 463
464 void FilterEngine::UpdateAvailable( 464 void FilterEngine::UpdateAvailable(
465 FilterEngine::UpdateAvailableCallback callback, JsValueList& params) const 465 const FilterEngine::UpdateAvailableCallback& callback, const JsValueList& pa rams) const
466 { 466 {
467 if (params.size() >= 1 && !params[0]->IsNull()) 467 if (params.size() >= 1 && !params[0]->IsNull())
468 callback(params[0]->AsString()); 468 callback(params[0]->AsString());
469 } 469 }
470 470
471 void FilterEngine::ForceUpdateCheck( 471 void FilterEngine::ForceUpdateCheck(
472 const FilterEngine::UpdateCheckDoneCallback& callback) 472 const FilterEngine::UpdateCheckDoneCallback& callback)
473 { 473 {
474 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); 474 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck");
475 JsConstValueList params; 475 JsConstValueList params;
476 if (callback) 476 if (callback)
477 { 477 {
478 std::string eventName = "_updateCheckDone" + std::to_string(++updateCheckId) ; 478 std::string eventName = "_updateCheckDone" + std::to_string(++updateCheckId) ;
479 jsEngine->SetEventCallback(eventName, std::bind(&FilterEngine::UpdateCheckDo ne, 479 jsEngine->SetEventCallback(eventName, std::bind(&FilterEngine::UpdateCheckDo ne,
480 this, eventName, callback, std::placeholders::_1)); 480 this, eventName, callback, std::placeholders::_1));
481 params.push_back(jsEngine->NewValue(eventName)); 481 params.push_back(jsEngine->NewValue(eventName));
482 } 482 }
483 func->Call(params); 483 func->Call(params);
484 } 484 }
485 485
486 void FilterEngine::UpdateCheckDone(const std::string& eventName, 486 void FilterEngine::UpdateCheckDone(const std::string& eventName,
487 FilterEngine::UpdateCheckDoneCallback callback, JsValueList& params) 487 const FilterEngine::UpdateCheckDoneCallback& callback, const JsValueList& pa rams)
488 { 488 {
489 jsEngine->RemoveEventCallback(eventName); 489 jsEngine->RemoveEventCallback(eventName);
490 490
491 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : ""); 491 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : "");
492 callback(error); 492 callback(error);
493 } 493 }
494 494
495 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback) 495 void FilterEngine::SetFilterChangeCallback(const FilterEngine::FilterChangeCallb ack& callback)
496 { 496 {
497 jsEngine->SetEventCallback("filterChange", std::bind(&FilterEngine::FilterChan ged, 497 jsEngine->SetEventCallback("filterChange", std::bind(&FilterEngine::FilterChan ged,
498 this, callback, std::placeholders::_1)); 498 this, callback, std::placeholders::_1));
499 } 499 }
500 500
501 void FilterEngine::RemoveFilterChangeCallback() 501 void FilterEngine::RemoveFilterChangeCallback()
502 { 502 {
503 jsEngine->RemoveEventCallback("filterChange"); 503 jsEngine->RemoveEventCallback("filterChange");
504 } 504 }
505 505
506 void FilterEngine::SetAllowedConnectionType(const std::string* value) 506 void FilterEngine::SetAllowedConnectionType(const std::string* value)
507 { 507 {
508 SetPref("allowed_connection_type", value ? jsEngine->NewValue(*value) : jsEngi ne->NewValue("")); 508 SetPref("allowed_connection_type", value ? jsEngine->NewValue(*value) : jsEngi ne->NewValue(""));
509 } 509 }
510 510
511 std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType() const 511 std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType() const
512 { 512 {
513 auto prefValue = GetPref("allowed_connection_type"); 513 auto prefValue = GetPref("allowed_connection_type");
514 if (prefValue->AsString().empty()) 514 if (prefValue->AsString().empty())
515 return nullptr; 515 return nullptr;
516 return std::unique_ptr<std::string>(new std::string(prefValue->AsString())); 516 return std::unique_ptr<std::string>(new std::string(prefValue->AsString()));
517 } 517 }
518 518
519 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) const 519 void FilterEngine::FilterChanged(const FilterEngine::FilterChangeCallback& callb ack, const JsValueList& params) const
520 { 520 {
521 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : ""); 521 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : "");
522 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); 522 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false));
523 callback(action, item); 523 callback(action, *item);
524 } 524 }
525 525
526 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback, 526 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback,
527 const JsValueList& params) const 527 const JsValueList& params) const
528 { 528 {
529 if (params.size() < 1) 529 if (params.size() < 1)
530 return; 530 return;
531 531
532 if (!params[0]->IsObject()) 532 if (!params[0]->IsObject())
533 { 533 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 574 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
575 if (filter) 575 if (filter)
576 { 576 {
577 return filter; 577 return filter;
578 } 578 }
579 currentUrl = parentUrl; 579 currentUrl = parentUrl;
580 } 580 }
581 while (urlIterator != documentUrls.end()); 581 while (urlIterator != documentUrls.end());
582 return FilterPtr(); 582 return FilterPtr();
583 } 583 }
OLDNEW
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/GlobalJsObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld