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

Delta Between Two Patch Sets: lib/elemHide.js

Issue 29757591: Issue 6562 - Remove filter keys from the element hiding code (Closed)
Left Patch Set: Don't note if a filter is genericly disabled Created May 1, 2018, 4:11 p.m.
Right Patch Set: == instead of === Created May 4, 2018, 12:05 p.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 | test/filterListener.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 // Whitelisting filters 154 // Whitelisting filters
155 if (filter instanceof ElemHideException) 155 if (filter instanceof ElemHideException)
156 { 156 {
157 let list = exceptions.get(filter.selector); 157 let list = exceptions.get(filter.selector);
158 let index = list.indexOf(filter); 158 let index = list.indexOf(filter);
159 if (index >= 0) 159 if (index >= 0)
160 list.splice(index, 1); 160 list.splice(index, 1);
161 } 161 }
162 // Unconditially applied element hiding filters 162 // Unconditially applied element hiding filters
163 else if (filterBySelector.get(filter.selector) === filter) 163 else if (filterBySelector.get(filter.selector) == filter)
164 { 164 {
165 filterBySelector.delete(filter.selector); 165 filterBySelector.delete(filter.selector);
166 unconditionalSelectors = null; 166 unconditionalSelectors = null;
167 } 167 }
168 // Conditionally applied element hiding filters 168 // Conditionally applied element hiding filters
169 else 169 else
170 { 170 {
171 let domains = filter.domains || defaultDomains; 171 let domains = filter.domains || defaultDomains;
172 for (let domain of domains.keys()) 172 for (let domain of domains.keys())
173 { 173 {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 getSelectorsForDomain(domain, criteria) 245 getSelectorsForDomain(domain, criteria)
246 { 246 {
247 let selectors = []; 247 let selectors = [];
248 248
249 if (typeof criteria == "undefined") 249 if (typeof criteria == "undefined")
250 criteria = ElemHide.ALL_MATCHING; 250 criteria = ElemHide.ALL_MATCHING;
251 if (criteria < ElemHide.NO_UNCONDITIONAL) 251 if (criteria < ElemHide.NO_UNCONDITIONAL)
252 selectors = this.getUnconditionalSelectors(); 252 selectors = this.getUnconditionalSelectors();
253 253
254 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); 254 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY);
255 let seenFilters = new Set(); 255 let excluded = new Set();
256 let currentDomain = domain ? domain.toUpperCase() : ""; 256 let currentDomain = domain ? domain.toUpperCase() : "";
257
258 // This code is a performance hot-spot, which is why we've made certain
259 // micro-optimisations. Please be careful before making changes.
257 while (true) 260 while (true)
258 { 261 {
259 if (specificOnly && currentDomain == "") 262 if (specificOnly && currentDomain == "")
260 break; 263 break;
261 264
262 let filters = filtersByDomain.get(currentDomain); 265 let filters = filtersByDomain.get(currentDomain);
263 if (filters) 266 if (filters)
264 { 267 {
265 for (let [filter, isIncluded] of filters) 268 for (let [filter, isIncluded] of filters)
266 { 269 {
267 if (seenFilters.has(filter)) 270 if (!isIncluded)
268 continue; 271 {
269 seenFilters.add(filter); 272 excluded.add(filter);
270 273 }
271 if (isIncluded && !this.getException(filter, domain)) 274 else if ((excluded.size == 0 || !excluded.has(filter)) &&
275 !this.getException(filter, domain))
276 {
272 selectors.push(filter.selector); 277 selectors.push(filter.selector);
278 }
273 } 279 }
274 } 280 }
275 281
276 if (currentDomain == "") 282 if (currentDomain == "")
277 break; 283 break;
278 284
279 let nextDot = currentDomain.indexOf("."); 285 let nextDot = currentDomain.indexOf(".");
280 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 286 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
281 } 287 }
282 288
283 return selectors; 289 return selectors;
284 } 290 }
285 }; 291 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld