| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 #include "ElemHideBase.h" | 1 #include "ElemHideBase.h" |
| 2 #include "CSSPropertyFilter.h" | 2 #include "CSSPropertyFilter.h" |
| 3 #include "StringScanner.h" | 3 #include "StringScanner.h" |
| 4 | 4 |
| 5 namespace | 5 namespace |
| 6 { | 6 { |
| 7 void NormalizeWhitespace(DependentString& text, String::size_type& domainsEnd, | 7 void NormalizeWhitespace(DependentString& text, String::size_type& domainsEnd, |
| 8 String::size_type& selectorStart) | 8 String::size_type& selectorStart) |
| 9 { | 9 { |
| 10 // For element hiding filters we only want to remove spaces preceding the | 10 // For element hiding filters we only want to remove spaces preceding the |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 { | 93 { |
| 94 case u'{': | 94 case u'{': |
| 95 case u'}': | 95 case u'}': |
| 96 return Type::UNKNOWN; | 96 return Type::UNKNOWN; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 // We are done validating, now we can normalize whitespace and the domain part | 100 // We are done validating, now we can normalize whitespace and the domain part |
| 101 if (seenSpaces) | 101 if (seenSpaces) |
| 102 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); | 102 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); |
| 103 DependentString(text, 0, data.mDomainsEnd).tolower(); | 103 DependentString(text, 0, data.mDomainsEnd).toLower(); |
| 104 | 104 |
| 105 if (exception) | 105 if (exception) |
| 106 return Type::ELEMHIDEEXCEPTION; | 106 return Type::ELEMHIDEEXCEPTION; |
| 107 | 107 |
| 108 do | 108 do |
| 109 { | 109 { |
| 110 // Is this a CSS property rule maybe? | 110 // Is this a CSS property rule maybe? |
| 111 DependentString searchString(u"[-abp-properties="_str); | 111 DependentString searchString(u"[-abp-properties="_str); |
| 112 data.mPrefixEnd = text.find(searchString, data.mSelectorStart); | 112 data.mPrefixEnd = text.find(searchString, data.mSelectorStart); |
| 113 if (data.mPrefixEnd == text.npos || | 113 if (data.mPrefixEnd == text.npos || |
| 114 data.mPrefixEnd + searchString.length() + 1 >= text.length()) | 114 data.mPrefixEnd + searchString.length() + 1 >= text.length()) |
| 115 { | 115 { |
| 116 break; | 116 break; |
| 117 } | 117 } |
| 118 | 118 |
| 119 data.mRegexpStart = data.mPrefixEnd + searchString.length() + 1; | 119 data.mRegexpStart = data.mPrefixEnd + searchString.length() + 1; |
| 120 char16_t quotation = text[data.mRegexpStart - 1]; | 120 char16_t quotation = text[data.mRegexpStart - 1]; |
| 121 if (quotation != u'\'' && quotation != u'"') | 121 if (quotation != u'\'' && quotation != u'"') |
| 122 break; | 122 break; |
| 123 | 123 |
| 124 data.mRegexpEnd = text.find(quotation, data.mRegexpStart); | 124 data.mRegexpEnd = text.find(quotation, data.mRegexpStart); |
| 125 if (data.mRegexpEnd == text.npos || data.mRegexpEnd + 1 >= text.length() || | 125 if (data.mRegexpEnd == text.npos || data.mRegexpEnd + 1 >= text.length() || |
| 126 text[data.mRegexpEnd + 1] != u']') | 126 text[data.mRegexpEnd + 1] != u']') |
| 127 { | 127 { |
| 128 break; | 128 break; |
|
sergei
2017/01/10 15:57:38
Should not we rather return Type::UNKNOWN if the f
Wladimir Palant
2017/03/13 17:41:58
No, a CSS property filter is an element hiding fil
| |
| 129 } | 129 } |
| 130 | 130 |
| 131 data.mSuffixStart = data.mRegexpEnd + 2; | 131 data.mSuffixStart = data.mRegexpEnd + 2; |
| 132 return Type::CSSPROPERTY; | 132 return Type::CSSPROPERTY; |
|
sergei
2017/01/10 15:57:40
Just in case, do we plan to add any information ab
Wladimir Palant
2017/03/13 17:41:56
We do, once we don't consider them experimental an
| |
| 133 } while (false); | 133 } while (false); |
| 134 | 134 |
| 135 return Type::ELEMHIDE; | 135 return Type::ELEMHIDE; |
| 136 } | 136 } |
| 137 | 137 |
| 138 OwnedString ElemHideBase::GetSelectorDomain() const | 138 OwnedString ElemHideBase::GetSelectorDomain() const |
| 139 { | 139 { |
| 140 /* TODO this is inefficient */ | 140 /* TODO this is inefficient */ |
| 141 OwnedString result; | 141 OwnedString result; |
| 142 if (mDomains) | 142 if (mDomains) |
| 143 { | 143 { |
| 144 for (auto it = mDomains->begin(); it != mDomains->end(); ++it) | 144 for (auto it = mDomains->begin(); it != mDomains->end(); ++it) |
| 145 { | 145 { |
| 146 if (it->second && !it->first.empty()) | 146 if (it->second && !it->first.empty()) |
| 147 { | 147 { |
| 148 if (!result.empty()) | 148 if (!result.empty()) |
| 149 result.append(u','); | 149 result.append(u','); |
| 150 result.append(it->first); | 150 result.append(it->first); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 return result; | 154 return result; |
| 155 } | 155 } |
| LEFT | RIGHT |