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

Delta Between Two Patch Sets: chrome/content/elemHideEmulation.js

Issue 29372676: [adblockpluscore] Issue 4825 - Let ElemHideEmulation associate selector and filter when calling add… (Closed)
Left Patch Set: Removed unnecessary variable and use let instead of var Created Feb. 7, 2017, 3 p.m.
Right Patch Set: Changed map to two arrays Created Feb. 9, 2017, 8:05 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/; 1 var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/;
2 2
3 function splitSelector(selector) 3 function splitSelector(selector)
4 { 4 {
5 if (selector.indexOf(",") == -1) 5 if (selector.indexOf(",") == -1)
6 return [selector]; 6 return [selector];
7 7
8 var selectors = []; 8 var selectors = [];
9 var start = 0; 9 var start = 0;
10 var level = 0; 10 var level = 0;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 { 66 {
67 return new URL(stylesheet.href).origin == this.window.location.origin; 67 return new URL(stylesheet.href).origin == this.window.location.origin;
68 } 68 }
69 catch (e) 69 catch (e)
70 { 70 {
71 // Invalid URL, assume that it is first-party. 71 // Invalid URL, assume that it is first-party.
72 return true; 72 return true;
73 } 73 }
74 }, 74 },
75 75
76 findSelectors: function(stylesheet, filters) 76 findSelectors: function(stylesheet, selectors, filters)
77 { 77 {
78 // Explicitly ignore third-party stylesheets to ensure consistent behavior 78 // Explicitly ignore third-party stylesheets to ensure consistent behavior
79 // between Firefox and Chrome. 79 // between Firefox and Chrome.
80 if (!this.isSameOrigin(stylesheet)) 80 if (!this.isSameOrigin(stylesheet))
81 return; 81 return;
82 82
83 let rules = stylesheet.cssRules; 83 let rules = stylesheet.cssRules;
84 if (!rules) 84 if (!rules)
85 return; 85 return;
86 86
87 for (let rule of rules) 87 for (let rule of rules)
88 { 88 {
89 if (rule.type != rule.STYLE_RULE) 89 if (rule.type != rule.STYLE_RULE)
90 continue; 90 continue;
91 91
92 let style = this.stringifyStyle(rule.style); 92 let style = this.stringifyStyle(rule.style);
93
Sebastian Noack 2017/02/07 15:37:57 Nit: The blank line added here is unrelated at lea
wspee 2017/02/09 08:40:34 Done.
94 for (let pattern of this.patterns) 93 for (let pattern of this.patterns)
95 { 94 {
96 if (pattern.regexp.test(style)) 95 if (pattern.regexp.test(style))
97 { 96 {
98 let selectors = filters.get(pattern.text); 97 let subSelectors = splitSelector(rule.selectorText);
99 if (!selectors) 98 for (let subSelector of subSelectors)
100 { 99 {
101 selectors = []; 100 selectors.push(pattern.prefix + subSelector + pattern.suffix);
102 filters.set(pattern.text, selectors); 101 filters.push(pattern.text);
103 } 102 }
104
105 for (let subSelector of splitSelector(rule.selectorText))
106 selectors.push(pattern.prefix + subSelector + pattern.suffix);
107 } 103 }
108 } 104 }
109 } 105 }
110 }, 106 },
111 107
112 addSelectors: function(stylesheets) 108 addSelectors: function(stylesheets)
113 { 109 {
114 let filters = new Map(); 110 var selectors = [];
115 for (let stylesheet of stylesheets) 111 var filters = [];
116 this.findSelectors(stylesheet, filters); 112 for (var i = 0; i < stylesheets.length; i++)
117 this.addSelectorsFunc(filters); 113 this.findSelectors(stylesheets[i], selectors, filters);
Sebastian Noack 2017/02/07 15:37:57 I just realized, the implications for when this fu
Sebastian Noack 2017/02/07 15:59:56 Another advantage of this approach is, that the AP
Sebastian Noack 2017/02/08 07:12:29 Perhaps even better, just use two arrays (instead
wspee 2017/02/09 08:40:34 Done.
114 this.addSelectorsFunc(selectors, filters);
118 }, 115 },
119 116
120 onLoad: function(event) 117 onLoad: function(event)
121 { 118 {
122 var stylesheet = event.target.sheet; 119 var stylesheet = event.target.sheet;
123 if (stylesheet) 120 if (stylesheet)
124 this.addSelectors([stylesheet]); 121 this.addSelectors([stylesheet]);
125 }, 122 },
126 123
127 load: function(callback) 124 load: function(callback)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 apply: function() 157 apply: function()
161 { 158 {
162 if (this.patterns.length > 0) 159 if (this.patterns.length > 0)
163 { 160 {
164 var document = this.window.document; 161 var document = this.window.document;
165 this.addSelectors(document.styleSheets); 162 this.addSelectors(document.styleSheets);
166 document.addEventListener("load", this.onLoad.bind(this), true); 163 document.addEventListener("load", this.onLoad.bind(this), true);
167 } 164 }
168 } 165 }
169 }; 166 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld