OLD | NEW |
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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 CONTENT_TYPE_DOCUMENT, | 318 CONTENT_TYPE_DOCUMENT, |
319 lastDocumentUrl); | 319 lastDocumentUrl); |
320 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) | 320 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
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, |
| 329 const std::vector<std::string>& documentUrls) const |
| 330 { |
| 331 return !GetWhitelistingFilter(url, documentUrls, |
| 332 CONTENT_TYPE_DOCUMENT).empty(); |
| 333 } |
| 334 |
| 335 bool FilterEngine::IsElemhideWhitelisted(const std::string& url, |
| 336 const std::vector<std::string>& documentUrls) const |
| 337 { |
| 338 return !GetWhitelistingFilter(url, documentUrls, |
| 339 CONTENT_TYPE_ELEMHIDE).empty(); |
| 340 } |
| 341 |
328 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, | 342 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, |
329 ContentType contentType, | 343 ContentType contentType, |
330 const std::string& documentUrl) const | 344 const std::string& documentUrl) const |
331 { | 345 { |
332 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); | 346 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); |
333 JsValueList params; | 347 JsValueList params; |
334 params.push_back(jsEngine->NewValue(url)); | 348 params.push_back(jsEngine->NewValue(url)); |
335 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); | 349 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); |
336 params.push_back(jsEngine->NewValue(documentUrl)); | 350 params.push_back(jsEngine->NewValue(documentUrl)); |
337 JsValuePtr result = func->Call(params); | 351 JsValuePtr result = func->Call(params); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 469 |
456 | 470 |
457 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 471 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
458 { | 472 { |
459 JsValueList params; | 473 JsValueList params; |
460 params.push_back(jsEngine->NewValue(v1)); | 474 params.push_back(jsEngine->NewValue(v1)); |
461 params.push_back(jsEngine->NewValue(v2)); | 475 params.push_back(jsEngine->NewValue(v2)); |
462 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 476 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
463 return func->Call(params)->AsInt(); | 477 return func->Call(params)->AsInt(); |
464 } | 478 } |
| 479 |
| 480 std::string FilterEngine::GetWhitelistingFilter(const std::string& url, |
| 481 const std::string& parent, ContentType contentType) const |
| 482 { |
| 483 FilterPtr match = Matches(url, contentType, parent); |
| 484 |
| 485 if (match && match->GetType() == Filter::TYPE_EXCEPTION) |
| 486 { |
| 487 return match->GetProperty("text")->AsString(); |
| 488 } |
| 489 return ""; |
| 490 } |
| 491 |
| 492 std::string FilterEngine::GetWhitelistingFilter(const std::string& urlArg, |
| 493 const std::vector<std::string>& documentUrls, |
| 494 ContentType contentType) const |
| 495 { |
| 496 if (documentUrls.empty()) |
| 497 { |
| 498 return GetWhitelistingFilter(urlArg, "", contentType); |
| 499 } |
| 500 |
| 501 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin(); |
| 502 std::string url = urlArg; |
| 503 do |
| 504 { |
| 505 std::string parentUrl = *urlIterator++; |
| 506 std::string filterText = GetWhitelistingFilter(url, parentUrl, contentType); |
| 507 if (!filterText.empty()) |
| 508 { |
| 509 return filterText; |
| 510 } |
| 511 url = parentUrl; |
| 512 } |
| 513 while (urlIterator != documentUrls.end()); |
| 514 return ""; |
| 515 } |
OLD | NEW |