LEFT | RIGHT |
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-2017 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 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 ContentTypeMap::const_iterator it = contentTypes.find(contentType); | 252 ContentTypeMap::const_iterator it = contentTypes.find(contentType); |
253 if (it != contentTypes.end()) | 253 if (it != contentTypes.end()) |
254 return it->second; | 254 return it->second; |
255 throw std::invalid_argument("Argument is not a valid ContentType"); | 255 throw std::invalid_argument("Argument is not a valid ContentType"); |
256 } | 256 } |
257 | 257 |
258 FilterEngine::ContentType FilterEngine::StringToContentType(const std::string& c
ontentType) | 258 FilterEngine::ContentType FilterEngine::StringToContentType(const std::string& c
ontentType) |
259 { | 259 { |
260 std::string contentTypeUpper = contentType; | 260 std::string contentTypeUpper = contentType; |
261 std::transform(contentType.begin(), contentType.end(), contentTypeUpper.begin(
), ::toupper); | 261 std::transform(contentType.begin(), contentType.end(), contentTypeUpper.begin(
), ::toupper); |
262 for (ContentTypeMap::const_iterator it = contentTypes.begin(); | 262 for (const auto& contentType : contentTypes) |
263 it != contentTypes.end(); it++) | 263 { |
264 { | 264 if (contentType.second == contentTypeUpper) |
265 if (it->second == contentTypeUpper) | 265 return contentType.first; |
266 return it->first; | |
267 } | 266 } |
268 throw std::invalid_argument("Cannot convert argument to ContentType"); | 267 throw std::invalid_argument("Cannot convert argument to ContentType"); |
269 } | 268 } |
270 | 269 |
271 bool FilterEngine::IsFirstRun() const | 270 bool FilterEngine::IsFirstRun() const |
272 { | 271 { |
273 return firstRun; | 272 return firstRun; |
274 } | 273 } |
275 | 274 |
276 FilterPtr FilterEngine::GetFilter(const std::string& text) const | 275 FilterPtr FilterEngine::GetFilter(const std::string& text) const |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 350 } |
352 | 351 |
353 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 352 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
354 ContentTypeMask contentTypeMask, | 353 ContentTypeMask contentTypeMask, |
355 const std::vector<std::string>& documentUrls) const | 354 const std::vector<std::string>& documentUrls) const |
356 { | 355 { |
357 if (documentUrls.empty()) | 356 if (documentUrls.empty()) |
358 return CheckFilterMatch(url, contentTypeMask, ""); | 357 return CheckFilterMatch(url, contentTypeMask, ""); |
359 | 358 |
360 std::string lastDocumentUrl = documentUrls.front(); | 359 std::string lastDocumentUrl = documentUrls.front(); |
361 for (std::vector<std::string>::const_iterator it = documentUrls.begin(); | 360 for (const auto& documentUrl : documentUrls) { |
362 it != documentUrls.end(); it++) { | |
363 const std::string documentUrl = *it; | |
364 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, | 361 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, |
365 CONTENT_TYPE_DOCUMENT, | 362 CONTENT_TYPE_DOCUMENT, |
366 lastDocumentUrl); | 363 lastDocumentUrl); |
367 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) | 364 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
368 return match; | 365 return match; |
369 lastDocumentUrl = documentUrl; | 366 lastDocumentUrl = documentUrl; |
370 } | 367 } |
371 | 368 |
372 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl); | 369 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl); |
373 } | 370 } |
(...skipping 24 matching lines...) Expand all Loading... |
398 return FilterPtr(new Filter(std::move(*result))); | 395 return FilterPtr(new Filter(std::move(*result))); |
399 else | 396 else |
400 return FilterPtr(); | 397 return FilterPtr(); |
401 } | 398 } |
402 | 399 |
403 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const | 400 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const |
404 { | 401 { |
405 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); | 402 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); |
406 JsValueList result = func->Call(jsEngine->NewValue(domain))->AsList(); | 403 JsValueList result = func->Call(jsEngine->NewValue(domain))->AsList(); |
407 std::vector<std::string> selectors; | 404 std::vector<std::string> selectors; |
408 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) | 405 for (const auto& r: result) |
409 selectors.push_back((*it)->AsString()); | 406 selectors.push_back(r->AsString()); |
410 return selectors; | 407 return selectors; |
411 } | 408 } |
412 | 409 |
413 JsValuePtr FilterEngine::GetPref(const std::string& pref) const | 410 JsValuePtr FilterEngine::GetPref(const std::string& pref) const |
414 { | 411 { |
415 JsValuePtr func = jsEngine->Evaluate("API.getPref"); | 412 JsValuePtr func = jsEngine->Evaluate("API.getPref"); |
416 return func->Call(jsEngine->NewValue(pref)); | 413 return func->Call(jsEngine->NewValue(pref)); |
417 } | 414 } |
418 | 415 |
419 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value) | 416 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); | 555 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); |
559 if (filter) | 556 if (filter) |
560 { | 557 { |
561 return filter; | 558 return filter; |
562 } | 559 } |
563 currentUrl = parentUrl; | 560 currentUrl = parentUrl; |
564 } | 561 } |
565 while (urlIterator != documentUrls.end()); | 562 while (urlIterator != documentUrls.end()); |
566 return FilterPtr(); | 563 return FilterPtr(); |
567 } | 564 } |
LEFT | RIGHT |