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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 (auto it = contentTypes.cbegin(); it != contentTypes.cend(); it++) |
279 it != contentTypes.end(); it++) | |
280 { | 279 { |
281 if (it->second == contentTypeUpper) | 280 if (it->second == contentTypeUpper) |
282 return it->first; | 281 return it->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; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 (auto it = documentUrls.cbegin(); it != documentUrls.cend(); it++) { |
382 it != documentUrls.end(); it++) { | |
383 const std::string documentUrl = *it; | 381 const std::string documentUrl = *it; |
384 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, | 382 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, |
385 CONTENT_TYPE_DOCUMENT, | 383 CONTENT_TYPE_DOCUMENT, |
386 lastDocumentUrl); | 384 lastDocumentUrl); |
387 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) | 385 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
388 return match; | 386 return match; |
389 lastDocumentUrl = documentUrl; | 387 lastDocumentUrl = documentUrl; |
390 } | 388 } |
391 | 389 |
392 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl); | 390 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl); |
(...skipping 27 matching lines...) Expand all Loading... |
420 return FilterPtr(); | 418 return FilterPtr(); |
421 } | 419 } |
422 | 420 |
423 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const | 421 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const |
424 { | 422 { |
425 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); | 423 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); |
426 JsValueList params; | 424 JsValueList params; |
427 params.push_back(jsEngine->NewValue(domain)); | 425 params.push_back(jsEngine->NewValue(domain)); |
428 JsValueList result = func->Call(params)->AsList(); | 426 JsValueList result = func->Call(params)->AsList(); |
429 std::vector<std::string> selectors; | 427 std::vector<std::string> selectors; |
430 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) | 428 for (auto it = result.cbegin(); it != result.cend(); ++it) |
431 selectors.push_back((*it)->AsString()); | 429 selectors.push_back((*it)->AsString()); |
432 return selectors; | 430 return selectors; |
433 } | 431 } |
434 | 432 |
435 JsValuePtr FilterEngine::GetPref(const std::string& pref) const | 433 JsValuePtr FilterEngine::GetPref(const std::string& pref) const |
436 { | 434 { |
437 JsValuePtr func = jsEngine->Evaluate("API.getPref"); | 435 JsValuePtr func = jsEngine->Evaluate("API.getPref"); |
438 JsValueList params; | 436 JsValueList params; |
439 params.push_back(jsEngine->NewValue(pref)); | 437 params.push_back(jsEngine->NewValue(pref)); |
440 return func->Call(params); | 438 return func->Call(params); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); | 582 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); |
585 if (filter) | 583 if (filter) |
586 { | 584 { |
587 return filter; | 585 return filter; |
588 } | 586 } |
589 currentUrl = parentUrl; | 587 currentUrl = parentUrl; |
590 } | 588 } |
591 while (urlIterator != documentUrls.end()); | 589 while (urlIterator != documentUrls.end()); |
592 return FilterPtr(); | 590 return FilterPtr(); |
593 } | 591 } |
OLD | NEW |