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

Side by Side Diff: compiled/ElemHideBase.cpp

Issue 29383799: Issue 4988 - [emscripten] Adjust API for Element Hiding Emulation filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created March 14, 2017, 2:42 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 #include "ElemHideBase.h" 1 #include "ElemHideBase.h"
2 #include "CSSPropertyFilter.h"
3 #include "StringScanner.h" 2 #include "StringScanner.h"
4 3
5 namespace 4 namespace
6 { 5 {
7 void NormalizeWhitespace(DependentString& text, String::size_type& domainsEnd, 6 void NormalizeWhitespace(DependentString& text, String::size_type& domainsEnd,
8 String::size_type& selectorStart) 7 String::size_type& selectorStart)
9 { 8 {
10 // For element hiding filters we only want to remove spaces preceding the 9 // For element hiding filters we only want to remove spaces preceding the
11 // selector part. The positions we've determined already have to be adjusted 10 // selector part. The positions we've determined already have to be adjusted
12 // accordingly. 11 // accordingly.
(...skipping 13 matching lines...) Expand all
26 delta++; 25 delta++;
27 else 26 else
28 text[pos - delta] = text[pos]; 27 text[pos - delta] = text[pos];
29 } 28 }
30 selectorStart -= delta; 29 selectorStart -= delta;
31 30
32 text.reset(text, 0, len - delta); 31 text.reset(text, 0, len - delta);
33 } 32 }
34 } 33 }
35 34
36 ElemHideBase::ElemHideBase(Type type, const String& text, const ElemHideBaseData & data) 35 ElemHideBase::ElemHideBase(Type type, const String& text, const ElemHideData& da ta)
37 : ActiveFilter(type, text, false), mData(data) 36 : ActiveFilter(type, text, false), mData(data)
38 { 37 {
39 if (mData.HasDomains()) 38 if (mData.HasDomains())
40 ParseDomains(mData.GetDomainsSource(mText), u','); 39 ParseDomains(mData.GetDomainsSource(mText), u',');
41 } 40 }
42 41
43 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data) 42 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data)
44 { 43 {
45 StringScanner scanner(text); 44 StringScanner scanner(text);
46 45
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 97 }
99 98
100 // We are done validating, now we can normalize whitespace and the domain part 99 // We are done validating, now we can normalize whitespace and the domain part
101 if (seenSpaces) 100 if (seenSpaces)
102 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); 101 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart);
103 DependentString(text, 0, data.mDomainsEnd).toLower(); 102 DependentString(text, 0, data.mDomainsEnd).toLower();
104 103
105 if (exception) 104 if (exception)
106 return Type::ELEMHIDEEXCEPTION; 105 return Type::ELEMHIDEEXCEPTION;
107 106
108 do 107 if (text.find(u"[-abp-properties="_str, data.mSelectorStart) != text.npos)
sergei 2017/03/24 11:59:26 Nit: issue says "[-abp-properties" but here we use
Wladimir Palant 2017/03/25 18:48:19 Nice catch. Actually, what I wrote in the issue ma
Wladimir Palant 2017/03/27 07:58:00 The conclusion is: I've modified the issue, and we
109 { 108 return Type::ELEMHIDEEMULATION;
110 // Is this a CSS property rule maybe?
111 DependentString searchString(u"[-abp-properties="_str);
112 data.mPrefixEnd = text.find(searchString, data.mSelectorStart);
113 if (data.mPrefixEnd == text.npos ||
114 data.mPrefixEnd + searchString.length() + 1 >= text.length())
115 {
116 break;
117 }
118
119 data.mRegexpStart = data.mPrefixEnd + searchString.length() + 1;
120 char16_t quotation = text[data.mRegexpStart - 1];
121 if (quotation != u'\'' && quotation != u'"')
122 break;
123
124 data.mRegexpEnd = text.find(quotation, data.mRegexpStart);
125 if (data.mRegexpEnd == text.npos || data.mRegexpEnd + 1 >= text.length() ||
126 text[data.mRegexpEnd + 1] != u']')
127 {
128 break;
129 }
130
131 data.mSuffixStart = data.mRegexpEnd + 2;
132 return Type::CSSPROPERTY;
133 } while (false);
134 109
135 return Type::ELEMHIDE; 110 return Type::ELEMHIDE;
136 } 111 }
137 112
138 OwnedString ElemHideBase::GetSelectorDomain() const 113 OwnedString ElemHideBase::GetSelectorDomain() const
139 { 114 {
140 /* TODO this is inefficient */ 115 /* TODO this is inefficient */
141 OwnedString result; 116 OwnedString result;
142 if (mDomains) 117 if (mDomains)
143 { 118 {
144 for (auto it = mDomains->begin(); it != mDomains->end(); ++it) 119 for (auto it = mDomains->begin(); it != mDomains->end(); ++it)
145 { 120 {
146 if (it->second && !it->first.empty()) 121 if (it->second && !it->first.empty())
147 { 122 {
148 if (!result.empty()) 123 if (!result.empty())
149 result.append(u','); 124 result.append(u',');
150 result.append(it->first); 125 result.append(it->first);
151 } 126 }
152 } 127 }
153 } 128 }
154 return result; 129 return result;
155 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld