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-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 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 return nullptr; | 100 return nullptr; |
101 | 101 |
102 // 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 |
103 // lookup in knownFilters. | 103 // lookup in knownFilters. |
104 union | 104 union |
105 { | 105 { |
106 RegExpFilterData regexp; | 106 RegExpFilterData regexp; |
107 ElemHideData elemhide; | 107 ElemHideData elemhide; |
108 } data; | 108 } data; |
109 bool needConversion = false; | 109 bool needConversion = false; |
| 110 ParsedDomains parsedDomains; |
110 DependentString error; | 111 DependentString error; |
111 | 112 |
112 Filter::Type type = CommentFilter::Parse(text); | 113 Filter::Type type = CommentFilter::Parse(text); |
113 if (type == Filter::Type::UNKNOWN) | 114 if (type == Filter::Type::UNKNOWN) |
114 type = ElemHideBase::Parse(text, data.elemhide, needConversion); | 115 type = ElemHideBase::Parse(text, error, data.elemhide, needConversion, parse
dDomains); |
115 if (type == Filter::Type::UNKNOWN) | 116 if (type == Filter::Type::UNKNOWN) |
116 type = RegExpFilter::Parse(text, error, data.regexp); | 117 type = RegExpFilter::Parse(text, error, data.regexp); |
117 | 118 |
118 if (needConversion) | 119 if (needConversion) |
119 text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart); | 120 text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart); |
120 | 121 |
121 // At that point we failed the conversion. | 122 // At that point we failed the conversion. |
122 if (text.empty()) | 123 if (text.empty()) |
123 return nullptr; | 124 return nullptr; |
124 | 125 |
(...skipping 13 matching lines...) Expand all Loading... |
138 case InvalidFilter::classType: | 139 case InvalidFilter::classType: |
139 filter = FilterPtr(new InvalidFilter(text, error), false); | 140 filter = FilterPtr(new InvalidFilter(text, error), false); |
140 break; | 141 break; |
141 case BlockingFilter::classType: | 142 case BlockingFilter::classType: |
142 filter = FilterPtr(new BlockingFilter(text, data.regexp), false); | 143 filter = FilterPtr(new BlockingFilter(text, data.regexp), false); |
143 break; | 144 break; |
144 case WhitelistFilter::classType: | 145 case WhitelistFilter::classType: |
145 filter = FilterPtr(new WhitelistFilter(text, data.regexp), false); | 146 filter = FilterPtr(new WhitelistFilter(text, data.regexp), false); |
146 break; | 147 break; |
147 case ElemHideFilter::classType: | 148 case ElemHideFilter::classType: |
148 filter = FilterPtr(new ElemHideFilter(text, data.elemhide), false); | 149 filter = FilterPtr(new ElemHideFilter(text, data.elemhide, |
| 150 parsedDomains), false); |
149 break; | 151 break; |
150 case ElemHideException::classType: | 152 case ElemHideException::classType: |
151 filter = FilterPtr(new ElemHideException(text, data.elemhide), false); | 153 filter = FilterPtr(new ElemHideException(text, data.elemhide, parsedDomain
s), false); |
152 break; | 154 break; |
153 case ElemHideEmulationFilter::classType: | 155 case ElemHideEmulationFilter::classType: |
154 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false
); | 156 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide, parsed
Domains), false); |
155 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) | 157 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) |
156 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no
domain"_str), false); | 158 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no
domain"_str), false); |
157 break; | 159 break; |
158 default: | 160 default: |
159 // This should never happen but just in case | 161 // This should never happen but just in case |
160 return nullptr; | 162 return nullptr; |
161 } | 163 } |
162 | 164 |
163 enter_context("Adding to known filters"); | 165 enter_context("Adding to known filters"); |
164 if (text != filter->mText) | 166 if (text != filter->mText) |
165 knownFilters[filter->mText] = filter.get(); | 167 knownFilters[filter->mText] = filter.get(); |
166 else | 168 else |
167 // This is a hack: we looked up the entry using text but create it using | 169 // This is a hack: we looked up the entry using text but create it using |
168 // filter->mText. This works because both are equal at this point. However, | 170 // filter->mText. This works because both are equal at this point. However, |
169 // text refers to a temporary buffer which will go away. | 171 // text refers to a temporary buffer which will go away. |
170 knownFilter.assign(filter->mText, filter.get()); | 172 knownFilter.assign(filter->mText, filter.get()); |
171 exit_context(); | 173 exit_context(); |
172 | 174 |
173 return filter.release(); | 175 return filter.release(); |
174 } | 176 } |
OLD | NEW |