Left: | ||
Right: |
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 params.push_back(shared_from_this()); | 127 params.push_back(shared_from_this()); |
128 JsValuePtr result = func->Call(params); | 128 JsValuePtr result = func->Call(params); |
129 return result->AsBool(); | 129 return result->AsBool(); |
130 } | 130 } |
131 | 131 |
132 bool Subscription::operator==(const Subscription& subscription) const | 132 bool Subscription::operator==(const Subscription& subscription) const |
133 { | 133 { |
134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring(); | 134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring(); |
135 } | 135 } |
136 | 136 |
137 FilterEngine::FilterEngine(JsEnginePtr jsEngine, | 137 FilterEngine::FilterEngine(JsEnginePtr jsEngine, |
Felix Dahlke
2015/12/03 20:34:18
Nit: Entirely unrelated, separate noissue commit p
René Jeschke
2015/12/03 20:39:59
Done.
| |
138 const FilterEngine::Prefs& preconfiguredPrefs) | 138 const FilterEngine::Prefs& preconfiguredPrefs) |
139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) | 139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) |
140 { | 140 { |
141 jsEngine->SetEventCallback("_init", std::bind(&FilterEngine::InitDone, | 141 jsEngine->SetEventCallback("_init", std::bind(&FilterEngine::InitDone, |
142 this, std::placeholders::_1)); | 142 this, std::placeholders::_1)); |
143 | 143 |
144 { | 144 { |
145 // Lock the JS engine while we are loading scripts, no timeouts should fire | 145 // Lock the JS engine while we are loading scripts, no timeouts should fire |
146 // until we are done. | 146 // until we are done. |
147 const JsContext context(jsEngine); | 147 const JsContext context(jsEngine); |
(...skipping 170 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, CONTENT_TYPE_DOCUMENT, documentUrls); | |
332 } | |
333 | |
334 bool FilterEngine::IsElemhideWhitelisted(const std::string& url, | |
335 const std::vector<std::string>& documentUrls) const | |
336 { | |
337 return !!GetWhitelistingFilter(url, CONTENT_TYPE_ELEMHIDE, documentUrls); | |
338 } | |
339 | |
328 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, | 340 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, |
329 ContentType contentType, | 341 ContentType contentType, |
330 const std::string& documentUrl) const | 342 const std::string& documentUrl) const |
331 { | 343 { |
332 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); | 344 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); |
333 JsValueList params; | 345 JsValueList params; |
334 params.push_back(jsEngine->NewValue(url)); | 346 params.push_back(jsEngine->NewValue(url)); |
335 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); | 347 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); |
336 params.push_back(jsEngine->NewValue(documentUrl)); | 348 params.push_back(jsEngine->NewValue(documentUrl)); |
337 JsValuePtr result = func->Call(params); | 349 JsValuePtr result = func->Call(params); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 | 467 |
456 | 468 |
457 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 469 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
458 { | 470 { |
459 JsValueList params; | 471 JsValueList params; |
460 params.push_back(jsEngine->NewValue(v1)); | 472 params.push_back(jsEngine->NewValue(v1)); |
461 params.push_back(jsEngine->NewValue(v2)); | 473 params.push_back(jsEngine->NewValue(v2)); |
462 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 474 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
463 return func->Call(params)->AsInt(); | 475 return func->Call(params)->AsInt(); |
464 } | 476 } |
477 | |
478 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, | |
479 ContentType contentType, const std::string& documentUrl) const | |
480 { | |
481 FilterPtr match = Matches(url, contentType, documentUrl); | |
482 if (match && match->GetType() == Filter::TYPE_EXCEPTION) | |
483 { | |
484 return match; | |
485 } | |
486 return FilterPtr(); | |
487 } | |
488 | |
489 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, | |
490 ContentType contentType, | |
491 const std::vector<std::string>& documentUrls) const | |
492 { | |
493 if (documentUrls.empty()) | |
494 { | |
495 return GetWhitelistingFilter(url, contentType, ""); | |
496 } | |
497 | |
498 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin(); | |
499 std::string currentUrl = url; | |
500 do | |
501 { | |
502 std::string parentUrl = *urlIterator++; | |
503 FilterPtr filter = GetWhitelistingFilter( | |
504 currentUrl, contentType, parentUrl); | |
505 if (filter) | |
506 { | |
507 return filter; | |
508 } | |
509 currentUrl = parentUrl; | |
510 } | |
511 while (urlIterator != documentUrls.end()); | |
512 return FilterPtr(); | |
513 } | |
OLD | NEW |