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

Unified Diff: lib/elemHideExceptions.js

Issue 29893618: Issue 6957 - Return common style sheet for unknown domains (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 27, 2018, 9:18 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 | « lib/elemHide.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/elemHideExceptions.js
===================================================================
--- a/lib/elemHideExceptions.js
+++ b/lib/elemHideExceptions.js
@@ -26,16 +26,22 @@
/**
* Lookup table, lists of element hiding exceptions by selector
* @type {Map.<string,ElemHideException[]>}
*/
let exceptions = new Map();
/**
+ * Set containing all known domains
+ * @type {Set.<string>}
+ */
+let knownDomains = new Set();
+
+/**
* Set containing known element exceptions
* @type {Set.<ElemHideException>}
*/
let knownExceptions = new Set();
/**
* Container for element hiding exceptions
* @class
@@ -56,17 +62,30 @@
* Add a new element hiding exception
* @param {ElemHideException} exception
*/
add(exception)
{
if (knownExceptions.has(exception))
return;
- let {selector} = exception;
+ let {domains, selector} = exception;
+
+ if (domains)
+ {
+ for (let domain of domains.keys())
+ {
+ // Note: Once a domain is known it never becomes unknown, even when all
+ // the filters containing that domain are removed. This is a best-case
+ // optimization.
+ if (domain != "")
+ knownDomains.add(domain);
+ }
+ }
+
let list = exceptions.get(selector);
if (list)
list.push(exception);
else
exceptions.set(selector, [exception]);
knownExceptions.add(exception);
@@ -92,16 +111,26 @@
knownExceptions.delete(exception);
this.emit("removed", exception);
filterNotifier.emit("elemhideupdate");
},
/**
+ * Checks whether a given domain is known.
+ * @param {string} domain
+ * @returns {boolean}
+ */
+ isKnownDomain(domain)
+ {
+ return knownDomains.has(domain);
+ },
+
+ /**
* Checks whether any exception rules are registered for a selector
* @param {string} selector
* @returns {boolean}
*/
hasExceptions(selector)
{
return exceptions.has(selector);
},
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld