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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 29331737: Issue 3363 - Implement IsDocumentWhitelisted and IsElemhideWhitelisted (Closed)
Left Patch Set: Addressed some issues. Created Dec. 2, 2015, 5:33 p.m.
Right Patch Set: Reverted a whitespace removal Created Dec. 3, 2015, 8:39 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 | « include/AdblockPlus/FilterEngine.h ('k') | test/FilterEngine.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-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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 return match; 321 return match;
322 lastDocumentUrl = documentUrl; 322 lastDocumentUrl = documentUrl;
323 } 323 }
324 324
325 return CheckFilterMatch(url, contentType, lastDocumentUrl); 325 return CheckFilterMatch(url, contentType, lastDocumentUrl);
326 } 326 }
327 327
328 bool FilterEngine::IsDocumentWhitelisted(const std::string& url, 328 bool FilterEngine::IsDocumentWhitelisted(const std::string& url,
329 const std::vector<std::string>& documentUrls) const 329 const std::vector<std::string>& documentUrls) const
330 { 330 {
331 return GetWhitelistingFilter(url, documentUrls, 331 return !!GetWhitelistingFilter(url, CONTENT_TYPE_DOCUMENT, documentUrls);
332 CONTENT_TYPE_DOCUMENT) != 0;
333 } 332 }
334 333
335 bool FilterEngine::IsElemhideWhitelisted(const std::string& url, 334 bool FilterEngine::IsElemhideWhitelisted(const std::string& url,
336 const std::vector<std::string>& documentUrls) const 335 const std::vector<std::string>& documentUrls) const
337 { 336 {
338 return GetWhitelistingFilter(url, documentUrls, 337 return !!GetWhitelistingFilter(url, CONTENT_TYPE_ELEMHIDE, documentUrls);
339 CONTENT_TYPE_ELEMHIDE) != 0;
340 } 338 }
341 339
342 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, 340 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url,
343 ContentType contentType, 341 ContentType contentType,
344 const std::string& documentUrl) const 342 const std::string& documentUrl) const
345 { 343 {
346 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); 344 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch");
347 JsValueList params; 345 JsValueList params;
348 params.push_back(jsEngine->NewValue(url)); 346 params.push_back(jsEngine->NewValue(url));
349 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); 347 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType)));
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 469 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
472 { 470 {
473 JsValueList params; 471 JsValueList params;
474 params.push_back(jsEngine->NewValue(v1)); 472 params.push_back(jsEngine->NewValue(v1));
475 params.push_back(jsEngine->NewValue(v2)); 473 params.push_back(jsEngine->NewValue(v2));
476 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 474 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
477 return func->Call(params)->AsInt(); 475 return func->Call(params)->AsInt();
478 } 476 }
479 477
480 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, 478 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url,
481 const std::string& parent, ContentType contentType) const 479 ContentType contentType, const std::string& documentUrl) const
482 { 480 {
483 FilterPtr match = Matches(url, contentType, parent); 481 FilterPtr match = Matches(url, contentType, documentUrl);
484
485 if (match && match->GetType() == Filter::TYPE_EXCEPTION) 482 if (match && match->GetType() == Filter::TYPE_EXCEPTION)
486 { 483 {
487 return match; 484 return match;
488 } 485 }
489 return FilterPtr(); 486 return FilterPtr();
490 } 487 }
491 488
492 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, 489 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url,
493 const std::vector<std::string>& documentUrls, 490 ContentType contentType,
494 ContentType contentType) const 491 const std::vector<std::string>& documentUrls) const
495 { 492 {
496 if (documentUrls.empty()) 493 if (documentUrls.empty())
497 { 494 {
498 return GetWhitelistingFilter(url, "", contentType); 495 return GetWhitelistingFilter(url, contentType, "");
499 } 496 }
500 497
501 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin(); 498 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin();
502 std::string currentUrl = url; 499 std::string currentUrl = url;
503 do 500 do
504 { 501 {
505 std::string parentUrl = *urlIterator++; 502 std::string parentUrl = *urlIterator++;
506 FilterPtr filter = GetWhitelistingFilter( 503 FilterPtr filter = GetWhitelistingFilter(
507 currentUrl, parentUrl, contentType); 504 currentUrl, contentType, parentUrl);
508 if (filter) 505 if (filter)
509 { 506 {
510 return filter; 507 return filter;
511 } 508 }
512 currentUrl = parentUrl; 509 currentUrl = parentUrl;
513 } 510 }
514 while (urlIterator != documentUrls.end()); 511 while (urlIterator != documentUrls.end());
515 return FilterPtr(); 512 return FilterPtr();
516 } 513 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld