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

Unified Diff: chrome/content/elemHideEmulation.js

Issue 29361668: Issue 4394 - Create a filter class for element hiding emulation filters (Closed) Base URL: https://bitbucket.org/fhd/adblockpluscore
Patch Set: Created Nov. 3, 2016, 3:42 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/elemHideEmulation.js » ('j') | lib/filterClasses.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,37 @@
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)
kzar 2016/11/04 15:45:56 Before I suggested adding a supportedFeatures para
Felix Dahlke 2016/11/04 16:43:35 I'm not sure. For one, I feel that logic belongs i
+ continue;
+
+ var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/;
+ var match = propertySelectorRegExp.exec(pattern.selector);
kzar 2016/11/04 15:45:56 I guess the regexp won't necessarily match and if
Felix Dahlke 2016/11/04 16:43:35 Oops, true, I'll fix that.
Felix Dahlke 2016/11/11 11:51:42 Done.
+ 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)
{
« no previous file with comments | « no previous file | lib/elemHideEmulation.js » ('j') | lib/filterClasses.js » ('J')

Powered by Google App Engine
This is Rietveld