| 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-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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
| 19 #include "AdblockPlusClient.h" | 19 #include "AdblockPlusClient.h" |
| 20 #include "PluginFilter.h" | 20 #include "PluginFilter.h" |
| 21 #include "PluginSettings.h" | 21 #include "PluginSettings.h" |
| 22 #include "PluginMutex.h" | 22 #include "PluginMutex.h" |
| 23 #include "PluginSettings.h" | 23 #include "PluginSettings.h" |
| 24 #include "PluginSystem.h" | 24 #include "PluginSystem.h" |
| 25 #include "PluginClass.h" | 25 #include "PluginClass.h" |
| 26 #include "PluginUtil.h" | 26 #include "PluginUtil.h" |
| 27 #include "mlang.h" | 27 #include "mlang.h" |
| 28 #include "TokenSequence.h" | |
| 29 #include "..\shared\CriticalSection.h" | 28 #include "..\shared\CriticalSection.h" |
| 30 #include "..\shared\Utils.h" | 29 #include "..\shared\Utils.h" |
| 31 #include "..\shared\MsHTMLUtils.h" | 30 #include "..\shared\MsHTMLUtils.h" |
| 32 | 31 |
| 33 // The filters are described at http://adblockplus.org/en/filters | 32 // The filters are described at http://adblockplus.org/en/filters |
| 34 | 33 |
| 35 static CriticalSection s_criticalSectionFilterMap; | 34 static CriticalSection s_criticalSectionFilterMap; |
| 36 | 35 |
| 37 // ============================================================================ | 36 // ============================================================================ |
| 38 // CFilterElementHide | 37 // CFilterElementHide |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // Any tag | 69 // Any tag |
| 71 filterSuffix = filterSuffix.substr(1); | 70 filterSuffix = filterSuffix.substr(1); |
| 72 } | 71 } |
| 73 else if (firstTag == '[' || firstTag == '.' || firstTag == '#') | 72 else if (firstTag == '[' || firstTag == '.' || firstTag == '#') |
| 74 { | 73 { |
| 75 // Any tag (implicitly) | 74 // Any tag (implicitly) |
| 76 } | 75 } |
| 77 else if (isalnum(firstTag)) | 76 else if (isalnum(firstTag)) |
| 78 { | 77 { |
| 79 // Real tag | 78 // Real tag |
| 80 //TODO: Add support for descendant selectors | 79 // TODO: Add support for descendant selectors |
| 81 auto pos = filterSuffix.find_first_of(L".#[("); | 80 auto pos = filterSuffix.find_first_of(L".#[("); |
| 82 if (pos == std::wstring::npos) | 81 if (pos == std::wstring::npos) |
| 83 { | 82 { |
| 84 pos = filterSuffix.length(); | 83 pos = filterSuffix.length(); |
| 85 } | 84 } |
| 86 m_tag = ToLowerString(filterSuffix.substr(0, pos)); | 85 m_tag = ToLowerString(filterSuffix.substr(0, pos)); |
| 87 filterSuffix = filterSuffix.substr(pos); | 86 filterSuffix = filterSuffix.substr(pos); |
| 88 } | 87 } |
| 89 else | 88 else |
| 90 { | 89 { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 std::wstring classNameList(ToWstring(classNameListBstr)); | 277 std::wstring classNameList(ToWstring(classNameListBstr)); |
| 279 if (classNameList.empty()) | 278 if (classNameList.empty()) |
| 280 { | 279 { |
| 281 return false; | 280 return false; |
| 282 } | 281 } |
| 283 // TODO: Consider case of multiple classes. (m_tagClassName can be something
like "foo.bar") | 282 // TODO: Consider case of multiple classes. (m_tagClassName can be something
like "foo.bar") |
| 284 /* | 283 /* |
| 285 * Match when 'm_tagClassName' appears as a token within classNameList | 284 * Match when 'm_tagClassName' appears as a token within classNameList |
| 286 */ | 285 */ |
| 287 bool foundMatch = false; | 286 bool foundMatch = false; |
| 288 TokenSequence<std::wstring> ts(classNameList, L" "); | 287 wchar_t* nextToken = nullptr; |
| 289 for (auto iterClassName = ts.cbegin(); iterClassName != ts.cend(); ++iterCla
ssName) | 288 const wchar_t* token = wcstok_s(&classNameList[0], L" ", &nextToken); |
| 290 { | 289 while (token != nullptr) |
| 291 if (*iterClassName == m_tagClassName) | 290 { |
| 291 if (std::wstring(token) == m_tagClassName) |
| 292 { | 292 { |
| 293 foundMatch = true; | 293 foundMatch = true; |
| 294 break; | 294 break; |
| 295 } | 295 } |
| 296 token = wcstok_s(nullptr, L" ", &nextToken); |
| 296 } | 297 } |
| 297 if (!foundMatch) | 298 if (!foundMatch) |
| 298 { | 299 { |
| 299 return false; | 300 return false; |
| 300 } | 301 } |
| 301 } | 302 } |
| 302 /* | 303 /* |
| 303 * If a tag name is specified, it must match | 304 * If a tag name is specified, it must match |
| 304 */ | 305 */ |
| 305 if (!m_tag.empty()) | 306 if (!m_tag.empty()) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 CPluginDebug::DebugResultHiding(tag, L"id:" + id, idIt->second.m_filte
rText); | 552 CPluginDebug::DebugResultHiding(tag, L"id:" + id, idIt->second.m_filte
rText); |
| 552 #endif | 553 #endif |
| 553 return true; | 554 return true; |
| 554 } | 555 } |
| 555 } | 556 } |
| 556 } | 557 } |
| 557 | 558 |
| 558 // Search tag/className filters | 559 // Search tag/className filters |
| 559 if (!classNames.empty()) | 560 if (!classNames.empty()) |
| 560 { | 561 { |
| 561 TokenSequence<std::wstring> ts(classNames, L" \t\n\r"); | 562 wchar_t* nextToken = nullptr; |
| 562 for (auto iterClassName = ts.cbegin(); iterClassName != ts.cend(); ++iterC
lassName) | 563 const wchar_t* token = wcstok_s(&classNames[0], L" \t\n\r", &nextToken); |
| 563 { | 564 while (token != nullptr) |
| 564 std::wstring className = *iterClassName; | 565 { |
| 566 std::wstring className(token); |
| 565 auto classItEnum = m_elementHideTagsClass.equal_range(std::make_pair(tag
, className)); | 567 auto classItEnum = m_elementHideTagsClass.equal_range(std::make_pair(tag
, className)); |
| 566 for (auto classIt = classItEnum.first; classIt != classItEnum.second; ++
classIt) | 568 for (auto classIt = classItEnum.first; classIt != classItEnum.second; ++
classIt) |
| 567 { | 569 { |
| 568 if (classIt->second.IsMatchFilterElementHide(pEl)) | 570 if (classIt->second.IsMatchFilterElementHide(pEl)) |
| 569 { | 571 { |
| 570 #ifdef ENABLE_DEBUG_RESULT | 572 #ifdef ENABLE_DEBUG_RESULT |
| 571 DEBUG_HIDE_EL(indent + L"HideEl::Found (tag/class) filter:" + classI
t->second.m_filterText); | 573 DEBUG_HIDE_EL(indent + L"HideEl::Found (tag/class) filter:" + classI
t->second.m_filterText); |
| 572 CPluginDebug::DebugResultHiding(tag, L"class:" + className, classIt-
>second.m_filterText); | 574 CPluginDebug::DebugResultHiding(tag, L"class:" + className, classIt-
>second.m_filterText); |
| 573 #endif | 575 #endif |
| 574 return true; | 576 return true; |
| 575 } | 577 } |
| 576 } | 578 } |
| 577 | 579 |
| 578 // Search general class name | 580 // Search general class name |
| 579 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair(L"", cla
ssName)); | 581 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair(L"", cla
ssName)); |
| 580 for (auto classIt = classItEnum.first; classIt != classItEnum.second; ++
classIt) | 582 for (auto classIt = classItEnum.first; classIt != classItEnum.second; ++
classIt) |
| 581 { | 583 { |
| 582 if (classIt->second.IsMatchFilterElementHide(pEl)) | 584 if (classIt->second.IsMatchFilterElementHide(pEl)) |
| 583 { | 585 { |
| 584 #ifdef ENABLE_DEBUG_RESULT | 586 #ifdef ENABLE_DEBUG_RESULT |
| 585 DEBUG_HIDE_EL(indent + L"HideEl::Found (?/class) filter:" + classIt-
>second.m_filterText); | 587 DEBUG_HIDE_EL(indent + L"HideEl::Found (?/class) filter:" + classIt-
>second.m_filterText); |
| 586 CPluginDebug::DebugResultHiding(tag, L"class:" + className, classIt-
>second.m_filterText); | 588 CPluginDebug::DebugResultHiding(tag, L"class:" + className, classIt-
>second.m_filterText); |
| 587 #endif | 589 #endif |
| 588 return true; | 590 return true; |
| 589 } | 591 } |
| 590 } | 592 } |
| 593 token = wcstok_s(nullptr, L" \t\n\r", &nextToken); |
| 591 } | 594 } |
| 592 } | 595 } |
| 593 | 596 |
| 594 // Search tag filters | 597 // Search tag filters |
| 595 auto tagItEnum = m_elementHideTags.equal_range(tag); | 598 auto tagItEnum = m_elementHideTags.equal_range(tag); |
| 596 for (auto tagIt = tagItEnum.first; tagIt != tagItEnum.second; ++tagIt) | 599 for (auto tagIt = tagItEnum.first; tagIt != tagItEnum.second; ++tagIt) |
| 597 { | 600 { |
| 598 if (tagIt->second.IsMatchFilterElementHide(pEl)) | 601 if (tagIt->second.IsMatchFilterElementHide(pEl)) |
| 599 { | 602 { |
| 600 #ifdef ENABLE_DEBUG_RESULT | 603 #ifdef ENABLE_DEBUG_RESULT |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 | 651 |
| 649 void CPluginFilter::ClearFilters() | 652 void CPluginFilter::ClearFilters() |
| 650 { | 653 { |
| 651 // Clear filter maps | 654 // Clear filter maps |
| 652 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | 655 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
| 653 m_elementHideTags.clear(); | 656 m_elementHideTags.clear(); |
| 654 m_elementHideTagsId.clear(); | 657 m_elementHideTagsId.clear(); |
| 655 m_elementHideTagsClass.clear(); | 658 m_elementHideTagsClass.clear(); |
| 656 } | 659 } |
| 657 | 660 |
| LEFT | RIGHT |