| Index: chrome/content/elemHideEmulation.js |
| =================================================================== |
| rename from chrome/content/cssProperties.js |
| rename to chrome/content/elemHideEmulation.js |
| --- a/chrome/content/cssProperties.js |
| +++ b/chrome/content/elemHideEmulation.js |
| @@ -31,24 +31,24 @@ |
| } |
| } |
| } |
| selectors.push(selector.substring(start)); |
| return selectors; |
| } |
| -function CSSPropertyFilters(window, getFiltersFunc, addSelectorsFunc) |
| +function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc) |
| { |
| this.window = window; |
| this.getFiltersFunc = getFiltersFunc; |
| this.addSelectorsFunc = addSelectorsFunc; |
| } |
| -CSSPropertyFilters.prototype = { |
| +ElemHideEmulation.prototype = { |
| stringifyStyle: function(style) |
| { |
| var styles = []; |
| for (var i = 0; i < style.length; i++) |
| { |
| var property = style.item(i); |
| var value = style.getPropertyValue(property); |
| var priority = style.getPropertyPriority(property); |
| @@ -87,22 +87,17 @@ |
| var rule = rules[i]; |
| if (rule.type != rule.STYLE_RULE) |
| continue; |
| var style = this.stringifyStyle(rule.style); |
| for (var j = 0; j < this.patterns.length; j++) |
| { |
| var pattern = this.patterns[j]; |
| - var regexp = pattern.regexp; |
| - |
| - if (typeof regexp == "string") |
| - regexp = pattern.regexp = new RegExp(regexp); |
| - |
| - if (regexp.test(style)) |
| + if (pattern.regexp.test(style)) |
| { |
| var subSelectors = splitSelector(rule.selectorText); |
| for (var k = 0; k < subSelectors.length; k++) |
| selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); |
| filters[pattern.text] = true; |
| } |
| } |
| } |
| @@ -123,17 +118,40 @@ |
| if (stylesheet) |
| this.addSelectors([stylesheet]); |
| }, |
| load: function(callback) |
| { |
| this.getFiltersFunc(function(patterns) |
| { |
| - this.patterns = patterns; |
| + this.patterns = []; |
| + for (var i = 0; i < patterns.length; i++) |
| + { |
| + var pattern = patterns[i]; |
| + |
| + // We currently don't support any element hiding emulation feature |
| + // except for property selectors, so we remove rules that use other |
| + // features. See https://issues.adblockplus.org/ticket/3143. |
| + if (pattern.features != elemHideEmulationFeatureMap.PROPERTY_SELECTOR) |
| + continue; |
| + |
| + var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/; |
| + var match = propertySelectorRegExp.exec(pattern.selector); |
| + if (!match) |
| + continue; |
| + |
| + this.patterns.push({ |
| + text: pattern.text, |
| + regexp: new RegExp(filterToRegExp(match[2])), |
| + prefix: pattern.selector.substr(0, match.index), |
| + suffix: pattern.selector.substr(match.index + match[0].length) |
| + }); |
| + } |
| + |
| callback(); |
| }.bind(this)); |
| }, |
| apply: function() |
| { |
| if (this.patterns.length > 0) |
| { |