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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 29391775: Issue 5013 - Improve some const-correctness (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Created March 22, 2017, 3:37 p.m.
Right Patch Set: Removed GetType() const-ness change Created March 23, 2017, 12:57 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/DefaultWebRequestCurl.cpp ('k') | src/JsValue.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 254 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 (auto it = contentTypes.cbegin(); it != contentTypes.cend(); it++) 278 for (const auto& contentType : contentTypes)
279 { 279 {
280 if (it->second == contentTypeUpper) 280 if (contentType.second == contentTypeUpper)
281 return it->first; 281 return contentType.first;
282 } 282 }
283 throw std::invalid_argument("Cannot convert argument to ContentType"); 283 throw std::invalid_argument("Cannot convert argument to ContentType");
284 } 284 }
285 285
286 bool FilterEngine::IsFirstRun() const 286 bool FilterEngine::IsFirstRun() const
287 { 287 {
288 return firstRun; 288 return firstRun;
289 } 289 }
290 290
291 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
370 } 370 }
371 371
372 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 372 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
373 ContentTypeMask contentTypeMask, 373 ContentTypeMask contentTypeMask,
374 const std::vector<std::string>& documentUrls) const 374 const std::vector<std::string>& documentUrls) const
375 { 375 {
376 if (documentUrls.empty()) 376 if (documentUrls.empty())
377 return CheckFilterMatch(url, contentTypeMask, ""); 377 return CheckFilterMatch(url, contentTypeMask, "");
378 378
379 std::string lastDocumentUrl = documentUrls.front(); 379 std::string lastDocumentUrl = documentUrls.front();
380 for (auto it = documentUrls.cbegin(); it != documentUrls.cend(); it++) { 380 for (const auto& documentUrl : documentUrls) {
381 const std::string documentUrl = *it;
382 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, 381 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl,
383 CONTENT_TYPE_DOCUMENT, 382 CONTENT_TYPE_DOCUMENT,
384 lastDocumentUrl); 383 lastDocumentUrl);
385 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) 384 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
386 return match; 385 return match;
387 lastDocumentUrl = documentUrl; 386 lastDocumentUrl = documentUrl;
388 } 387 }
389 388
390 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl); 389 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl);
391 } 390 }
(...skipping 26 matching lines...) Expand all
418 return FilterPtr(); 417 return FilterPtr();
419 } 418 }
420 419
421 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
422 { 421 {
423 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 422 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
424 JsValueList params; 423 JsValueList params;
425 params.push_back(jsEngine->NewValue(domain)); 424 params.push_back(jsEngine->NewValue(domain));
426 JsValueList result = func->Call(params)->AsList(); 425 JsValueList result = func->Call(params)->AsList();
427 std::vector<std::string> selectors; 426 std::vector<std::string> selectors;
428 for (auto it = result.cbegin(); it != result.cend(); ++it) 427 for (const auto& r: result)
429 selectors.push_back((*it)->AsString()); 428 selectors.push_back(r->AsString());
430 return selectors; 429 return selectors;
431 } 430 }
432 431
433 JsValuePtr FilterEngine::GetPref(const std::string& pref) const 432 JsValuePtr FilterEngine::GetPref(const std::string& pref) const
434 { 433 {
435 JsValuePtr func = jsEngine->Evaluate("API.getPref"); 434 JsValuePtr func = jsEngine->Evaluate("API.getPref");
436 JsValueList params; 435 JsValueList params;
437 params.push_back(jsEngine->NewValue(pref)); 436 params.push_back(jsEngine->NewValue(pref));
438 return func->Call(params); 437 return func->Call(params);
439 } 438 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 581 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
583 if (filter) 582 if (filter)
584 { 583 {
585 return filter; 584 return filter;
586 } 585 }
587 currentUrl = parentUrl; 586 currentUrl = parentUrl;
588 } 587 }
589 while (urlIterator != documentUrls.end()); 588 while (urlIterator != documentUrls.end());
590 return FilterPtr(); 589 return FilterPtr();
591 } 590 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld