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: Address review comment. Reworked the conversion Created Feb. 7, 2018, 4:13 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/filter/ElemHideBase.cpp ('k') | meson.build » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (text.empty()) 97 if (text.empty())
98 return nullptr; 98 return nullptr;
99 99
100 // Parsing also normalizes the filter text, so it has to be done before the 100 // Parsing also normalizes the filter text, so it has to be done before the
101 // lookup in knownFilters. 101 // lookup in knownFilters.
102 union 102 union
103 { 103 {
104 RegExpFilterData regexp; 104 RegExpFilterData regexp;
105 ElemHideData elemhide; 105 ElemHideData elemhide;
106 } data; 106 } data;
107 bool needConversion = false;
107 DependentString error; 108 DependentString error;
108 109
109 Filter::Type type = CommentFilter::Parse(text); 110 Filter::Type type = CommentFilter::Parse(text);
110 if (type == Filter::Type::UNKNOWN) 111 if (type == Filter::Type::UNKNOWN)
111 type = ElemHideBase::Parse(text, data.elemhide); 112 type = ElemHideBase::Parse(text, data.elemhide, needConversion);
112 if (type == Filter::Type::UNKNOWN) 113 if (type == Filter::Type::UNKNOWN)
113 type = RegExpFilter::Parse(text, error, data.regexp); 114 type = RegExpFilter::Parse(text, error, data.regexp);
114 115
116 if (needConversion && (type == ElemHideException::classType || type == ElemHid eEmulationFilter::classType))
117 text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart);
118
119 // At that point we failed the conversion.
120 if (text.empty())
121 return nullptr;
122
115 auto knownFilter = knownFilters.find(text); 123 auto knownFilter = knownFilters.find(text);
116 if (knownFilter) 124 if (knownFilter)
117 { 125 {
118 knownFilter->second->AddRef(); 126 knownFilter->second->AddRef();
119 return knownFilter->second; 127 return knownFilter->second;
120 } 128 }
121 129
122 FilterPtr filter; 130 FilterPtr filter;
123 switch (type) 131 switch (type)
124 { 132 {
(...skipping 18 matching lines...) Expand all
143 case ElemHideEmulationFilter::classType: 151 case ElemHideEmulationFilter::classType:
144 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false ); 152 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false );
145 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) 153 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric())
146 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no domain"_str), false); 154 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no domain"_str), false);
147 break; 155 break;
148 default: 156 default:
149 // This should never happen but just in case 157 // This should never happen but just in case
150 return nullptr; 158 return nullptr;
151 } 159 }
152 160
153 // This is a hack: we looked up the entry using text but create it using
154 // filter->mText. This works because both are equal at this point. However,
155 // text refers to a temporary buffer which will go away.
156 enter_context("Adding to known filters"); 161 enter_context("Adding to known filters");
157 knownFilter.assign(filter->mText, filter.get()); 162 if (text != filter->mText)
163 knownFilters[filter->mText] = filter.get();
164 else
165 // 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,
167 // text refers to a temporary buffer which will go away.
168 knownFilter.assign(filter->mText, filter.get());
158 exit_context(); 169 exit_context();
159 170
160 return filter.release(); 171 return filter.release();
161 } 172 }
OLDNEW
« no previous file with comments | « compiled/filter/ElemHideBase.cpp ('k') | meson.build » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld