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

Side by Side Diff: src/FilterEngine.cpp

Issue 29391775: Issue 5013 - Improve some const-correctness (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Feedback + another small patch related. Created March 22, 2017, 4:50 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
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 19 matching lines...) Expand all
30 30
31 extern std::string jsSources[]; 31 extern std::string jsSources[];
32 32
33 Filter::Filter(JsValue&& value) 33 Filter::Filter(JsValue&& value)
34 : JsValue(std::move(value)) 34 : JsValue(std::move(value))
35 { 35 {
36 if (!IsObject()) 36 if (!IsObject())
37 throw std::runtime_error("JavaScript value is not an object"); 37 throw std::runtime_error("JavaScript value is not an object");
38 } 38 }
39 39
40 Filter::Type Filter::GetType() 40 Filter::Type Filter::GetType() const
41 { 41 {
42 std::string className = GetClass(); 42 std::string className = GetClass();
43 if (className == "BlockingFilter") 43 if (className == "BlockingFilter")
44 return TYPE_BLOCKING; 44 return TYPE_BLOCKING;
45 else if (className == "WhitelistFilter") 45 else if (className == "WhitelistFilter")
46 return TYPE_EXCEPTION; 46 return TYPE_EXCEPTION;
47 else if (className == "ElemHideFilter") 47 else if (className == "ElemHideFilter")
48 return TYPE_ELEMHIDE; 48 return TYPE_ELEMHIDE;
49 else if (className == "ElemHideException") 49 else if (className == "ElemHideException")
50 return TYPE_ELEMHIDE_EXCEPTION; 50 return TYPE_ELEMHIDE_EXCEPTION;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ContentTypeMap::const_iterator it = contentTypes.find(contentType); 268 ContentTypeMap::const_iterator it = contentTypes.find(contentType);
269 if (it != contentTypes.end()) 269 if (it != contentTypes.end())
270 return it->second; 270 return it->second;
271 throw std::invalid_argument("Argument is not a valid ContentType"); 271 throw std::invalid_argument("Argument is not a valid ContentType");
272 } 272 }
273 273
274 FilterEngine::ContentType FilterEngine::StringToContentType(const std::string& c ontentType) 274 FilterEngine::ContentType FilterEngine::StringToContentType(const std::string& c ontentType)
275 { 275 {
276 std::string contentTypeUpper = contentType; 276 std::string contentTypeUpper = contentType;
277 std::transform(contentType.begin(), contentType.end(), contentTypeUpper.begin( ), ::toupper); 277 std::transform(contentType.begin(), contentType.end(), contentTypeUpper.begin( ), ::toupper);
278 for (ContentTypeMap::const_iterator it = contentTypes.begin(); 278 for (const auto& contentType : contentTypes)
279 it != contentTypes.end(); it++)
280 { 279 {
281 if (it->second == contentTypeUpper) 280 if (contentType.second == contentTypeUpper)
282 return it->first; 281 return contentType.first;
283 } 282 }
284 throw std::invalid_argument("Cannot convert argument to ContentType"); 283 throw std::invalid_argument("Cannot convert argument to ContentType");
285 } 284 }
286 285
287 bool FilterEngine::IsFirstRun() const 286 bool FilterEngine::IsFirstRun() const
288 { 287 {
289 return firstRun; 288 return firstRun;
290 } 289 }
291 290
292 FilterPtr FilterEngine::GetFilter(const std::string& text) 291 FilterPtr FilterEngine::GetFilter(const std::string& text)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 370 }
372 371
373 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 372 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
374 ContentTypeMask contentTypeMask, 373 ContentTypeMask contentTypeMask,
375 const std::vector<std::string>& documentUrls) const 374 const std::vector<std::string>& documentUrls) const
376 { 375 {
377 if (documentUrls.empty()) 376 if (documentUrls.empty())
378 return CheckFilterMatch(url, contentTypeMask, ""); 377 return CheckFilterMatch(url, contentTypeMask, "");
379 378
380 std::string lastDocumentUrl = documentUrls.front(); 379 std::string lastDocumentUrl = documentUrls.front();
381 for (std::vector<std::string>::const_iterator it = documentUrls.begin(); 380 for (const auto& documentUrl : documentUrls) {
382 it != documentUrls.end(); it++) {
383 const std::string documentUrl = *it;
384 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, 381 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl,
385 CONTENT_TYPE_DOCUMENT, 382 CONTENT_TYPE_DOCUMENT,
386 lastDocumentUrl); 383 lastDocumentUrl);
387 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) 384 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
388 return match; 385 return match;
389 lastDocumentUrl = documentUrl; 386 lastDocumentUrl = documentUrl;
390 } 387 }
391 388
392 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl); 389 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl);
393 } 390 }
(...skipping 26 matching lines...) Expand all
420 return FilterPtr(); 417 return FilterPtr();
421 } 418 }
422 419
423 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const 420 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const
424 { 421 {
425 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 422 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
426 JsValueList params; 423 JsValueList params;
427 params.push_back(jsEngine->NewValue(domain)); 424 params.push_back(jsEngine->NewValue(domain));
428 JsValueList result = func->Call(params)->AsList(); 425 JsValueList result = func->Call(params)->AsList();
429 std::vector<std::string> selectors; 426 std::vector<std::string> selectors;
430 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) 427 for (const auto& r: result)
431 selectors.push_back((*it)->AsString()); 428 selectors.push_back(r->AsString());
432 return selectors; 429 return selectors;
433 } 430 }
434 431
435 JsValuePtr FilterEngine::GetPref(const std::string& pref) const 432 JsValuePtr FilterEngine::GetPref(const std::string& pref) const
436 { 433 {
437 JsValuePtr func = jsEngine->Evaluate("API.getPref"); 434 JsValuePtr func = jsEngine->Evaluate("API.getPref");
438 JsValueList params; 435 JsValueList params;
439 params.push_back(jsEngine->NewValue(pref)); 436 params.push_back(jsEngine->NewValue(pref));
440 return func->Call(params); 437 return func->Call(params);
441 } 438 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 581 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
585 if (filter) 582 if (filter)
586 { 583 {
587 return filter; 584 return filter;
588 } 585 }
589 currentUrl = parentUrl; 586 currentUrl = parentUrl;
590 } 587 }
591 while (urlIterator != documentUrls.end()); 588 while (urlIterator != documentUrls.end());
592 return FilterPtr(); 589 return FilterPtr();
593 } 590 }
OLDNEW

Powered by Google App Engine
This is Rietveld