Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: compiled/filter/Filter.cpp

Issue 29595633: Issue 5870 - Implement the new ElemHideEmulation filter type (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Address review comment. Reworked the conversion Created Feb. 7, 2018, 4:13 a.m.
Right Patch Set: Deal with ill formed filters. Created Feb. 14, 2018, 5:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } data; 108 } data;
107 bool needConversion = false; 109 bool needConversion = false;
108 DependentString error; 110 DependentString error;
109 111
110 Filter::Type type = CommentFilter::Parse(text); 112 Filter::Type type = CommentFilter::Parse(text);
111 if (type == Filter::Type::UNKNOWN) 113 if (type == Filter::Type::UNKNOWN)
112 type = ElemHideBase::Parse(text, data.elemhide, needConversion); 114 type = ElemHideBase::Parse(text, data.elemhide, needConversion);
113 if (type == Filter::Type::UNKNOWN) 115 if (type == Filter::Type::UNKNOWN)
114 type = RegExpFilter::Parse(text, error, data.regexp); 116 type = RegExpFilter::Parse(text, error, data.regexp);
115 117
116 if (needConversion && (type == ElemHideException::classType || type == ElemHid eEmulationFilter::classType)) 118 if (needConversion)
117 text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart); 119 text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart);
118 120
119 // At that point we failed the conversion. 121 // At that point we failed the conversion.
120 if (text.empty()) 122 if (text.empty())
121 return nullptr; 123 return nullptr;
122 124
123 auto knownFilter = knownFilters.find(text); 125 auto knownFilter = knownFilters.find(text);
124 if (knownFilter) 126 if (knownFilter)
125 { 127 {
126 knownFilter->second->AddRef(); 128 knownFilter->second->AddRef();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 knownFilters[filter->mText] = filter.get(); 165 knownFilters[filter->mText] = filter.get();
164 else 166 else
165 // 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
166 // 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,
167 // text refers to a temporary buffer which will go away. 169 // text refers to a temporary buffer which will go away.
168 knownFilter.assign(filter->mText, filter.get()); 170 knownFilter.assign(filter->mText, filter.get());
169 exit_context(); 171 exit_context();
170 172
171 return filter.release(); 173 return filter.release();
172 } 174 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld