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

Unified Diff: include.preload.js

Issue 29392555: Issue 5015 - Better handle broken element hide filters (Closed)
Patch Set: Created March 23, 2017, 6:24 a.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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
diff --git a/include.preload.js b/include.preload.js
index 1d4635a0da9fcda4266406564256e040e164b877..df6f9a105b52f0918f2c053a7b72dbb8f76df01b 100644
--- a/include.preload.js
+++ b/include.preload.js
@@ -482,6 +482,36 @@ ElemHide.prototype = {
return shadow;
},
+ _insertRuleForSelectors(selectors)
+ {
+ const properties = " {display: none !important;}";
+
+ try
+ {
+ this.style.sheet.insertRule(
+ selectors.join(", ") + properties,
+ this.style.sheet.cssRules.length
+ );
+ }
+ catch (batchInsertException)
+ {
+ // There is a syntax error in one or more of the selectors. Rather than
+ // dropping all of them let's add them invdividually, so that only the
+ // broken selectors are skipped.
+ for (let selector of selectors)
+ {
+ try
+ {
+ this.style.sheet.insertRule(
+ selector + properties,
+ this.style.sheet.cssRules.length
+ );
+ }
+ catch (individualInsertException) {}
+ }
+ }
+ },
+
addSelectors(selectors, filters)
{
if (selectors.length == 0)
@@ -528,11 +558,9 @@ ElemHide.prototype = {
// [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69debb75fc1de/Source/WebCore/css/RuleSet.h#L68
for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize)
{
- let selector = preparedSelectors.slice(
- i, i + this.selectorGroupSize
- ).join(", ");
- this.style.sheet.insertRule(selector + "{display: none !important;}",
- this.style.sheet.cssRules.length);
+ this._insertRuleForSelectors(
+ preparedSelectors.slice(i, i + this.selectorGroupSize)
+ );
}
if (this.tracer)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld