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

Side by Side Diff: compiled/filter/Filter.cpp

Issue 29595633: Issue 5870 - Implement the new ElemHideEmulation filter type (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Added missing ABP_NS macros Created Feb. 9, 2018, 8:34 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (text.empty()) 99 if (text.empty())
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 DependentString error; 110 DependentString error;
110 111
111 Filter::Type type = CommentFilter::Parse(text); 112 Filter::Type type = CommentFilter::Parse(text);
112 if (type == Filter::Type::UNKNOWN) 113 if (type == Filter::Type::UNKNOWN)
113 type = ElemHideBase::Parse(text, data.elemhide); 114 type = ElemHideBase::Parse(text, data.elemhide, needConversion);
114 if (type == Filter::Type::UNKNOWN) 115 if (type == Filter::Type::UNKNOWN)
115 type = RegExpFilter::Parse(text, error, data.regexp); 116 type = RegExpFilter::Parse(text, error, data.regexp);
116 117
118 if (needConversion && (type == ElemHideException::classType || type == ElemHid eEmulationFilter::classType))
sergei 2018/02/12 12:53:20 Firstly I thought about moving of `(type == ElemHi
hub 2018/02/12 18:14:40 I was being overly paranoid. Done.
119 text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart);
120
121 // At that point we failed the conversion.
122 if (text.empty())
123 return nullptr;
124
117 auto knownFilter = knownFilters.find(text); 125 auto knownFilter = knownFilters.find(text);
118 if (knownFilter) 126 if (knownFilter)
119 { 127 {
120 knownFilter->second->AddRef(); 128 knownFilter->second->AddRef();
121 return knownFilter->second; 129 return knownFilter->second;
122 } 130 }
123 131
124 FilterPtr filter; 132 FilterPtr filter;
125 switch (type) 133 switch (type)
126 { 134 {
(...skipping 18 matching lines...) Expand all
145 case ElemHideEmulationFilter::classType: 153 case ElemHideEmulationFilter::classType:
146 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false ); 154 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false );
147 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) 155 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric())
148 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no domain"_str), false); 156 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no domain"_str), false);
149 break; 157 break;
150 default: 158 default:
151 // This should never happen but just in case 159 // This should never happen but just in case
152 return nullptr; 160 return nullptr;
153 } 161 }
154 162
155 // This is a hack: we looked up the entry using text but create it using
156 // filter->mText. This works because both are equal at this point. However,
157 // text refers to a temporary buffer which will go away.
158 enter_context("Adding to known filters"); 163 enter_context("Adding to known filters");
159 knownFilter.assign(filter->mText, filter.get()); 164 if (text != filter->mText)
165 knownFilters[filter->mText] = filter.get();
166 else
167 // 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,
169 // text refers to a temporary buffer which will go away.
170 knownFilter.assign(filter->mText, filter.get());
160 exit_context(); 171 exit_context();
161 172
162 return filter.release(); 173 return filter.release();
163 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld