| 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-present eyeo GmbH | 3  * Copyright (C) 2006-present 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 "Filter.h" | 18 #include "Filter.h" | 
| 19 #include "CommentFilter.h" | 19 #include "CommentFilter.h" | 
| 20 #include "InvalidFilter.h" | 20 #include "InvalidFilter.h" | 
| 21 #include "RegExpFilter.h" | 21 #include "RegExpFilter.h" | 
| 22 #include "BlockingFilter.h" | 22 #include "BlockingFilter.h" | 
| 23 #include "WhitelistFilter.h" | 23 #include "WhitelistFilter.h" | 
| 24 #include "ElemHideBase.h" | 24 #include "ElemHideBase.h" | 
| 25 #include "ElemHideFilter.h" | 25 #include "ElemHideFilter.h" | 
| 26 #include "ElemHideException.h" | 26 #include "ElemHideException.h" | 
| 27 #include "ElemHideEmulationFilter.h" | 27 #include "ElemHideEmulationFilter.h" | 
| 28 #include "../StringMap.h" | 28 #include "../StringMap.h" | 
|  | 29 | 
|  | 30 ABP_NS_USING | 
| 29 | 31 | 
| 30 namespace | 32 namespace | 
| 31 { | 33 { | 
| 32   StringMap<Filter*> knownFilters(8192); | 34   StringMap<Filter*> knownFilters(8192); | 
| 33 | 35 | 
| 34   void NormalizeWhitespace(DependentString& text) | 36   void NormalizeWhitespace(DependentString& text) | 
| 35   { | 37   { | 
| 36     String::size_type start = 0; | 38     String::size_type start = 0; | 
| 37     String::size_type end = text.length(); | 39     String::size_type end = text.length(); | 
| 38 | 40 | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 97   if (text.empty()) | 99   if (text.empty()) | 
| 98     return nullptr; | 100     return nullptr; | 
| 99 | 101 | 
| 100   // Parsing also normalizes the filter text, so it has to be done before the | 102   // Parsing also normalizes the filter text, so it has to be done before the | 
| 101   // lookup in knownFilters. | 103   // lookup in knownFilters. | 
| 102   union | 104   union | 
| 103   { | 105   { | 
| 104     RegExpFilterData regexp; | 106     RegExpFilterData regexp; | 
| 105     ElemHideData elemhide; | 107     ElemHideData elemhide; | 
| 106   } data; | 108   } data; | 
|  | 109   bool needConversion = false; | 
| 107   DependentString error; | 110   DependentString error; | 
| 108 | 111 | 
| 109   Filter::Type type = CommentFilter::Parse(text); | 112   Filter::Type type = CommentFilter::Parse(text); | 
| 110   if (type == Filter::Type::UNKNOWN) | 113   if (type == Filter::Type::UNKNOWN) | 
| 111     type = ElemHideBase::Parse(text, data.elemhide); | 114     type = ElemHideBase::Parse(text, data.elemhide, needConversion); | 
| 112   if (type == Filter::Type::UNKNOWN) | 115   if (type == Filter::Type::UNKNOWN) | 
| 113     type = RegExpFilter::Parse(text, error, data.regexp); | 116     type = RegExpFilter::Parse(text, error, data.regexp); | 
|  | 117 | 
|  | 118   if (needConversion) | 
|  | 119     text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart); | 
|  | 120 | 
|  | 121   // At that point we failed the conversion. | 
|  | 122   if (text.empty()) | 
|  | 123     return nullptr; | 
| 114 | 124 | 
| 115   auto knownFilter = knownFilters.find(text); | 125   auto knownFilter = knownFilters.find(text); | 
| 116   if (knownFilter) | 126   if (knownFilter) | 
| 117   { | 127   { | 
| 118     knownFilter->second->AddRef(); | 128     knownFilter->second->AddRef(); | 
| 119     return knownFilter->second; | 129     return knownFilter->second; | 
| 120   } | 130   } | 
| 121 | 131 | 
| 122   FilterPtr filter; | 132   FilterPtr filter; | 
| 123   switch (type) | 133   switch (type) | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 155     knownFilters[filter->mText] = filter.get(); | 165     knownFilters[filter->mText] = filter.get(); | 
| 156   else | 166   else | 
| 157     // This is a hack: we looked up the entry using text but create it using | 167     // This is a hack: we looked up the entry using text but create it using | 
| 158     // filter->mText. This works because both are equal at this point. However, | 168     // filter->mText. This works because both are equal at this point. However, | 
| 159     // text refers to a temporary buffer which will go away. | 169     // text refers to a temporary buffer which will go away. | 
| 160     knownFilter.assign(filter->mText, filter.get()); | 170     knownFilter.assign(filter->mText, filter.get()); | 
| 161   exit_context(); | 171   exit_context(); | 
| 162 | 172 | 
| 163   return filter.release(); | 173   return filter.release(); | 
| 164 } | 174 } | 
| LEFT | RIGHT | 
|---|