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

Unified Diff: include.preload.js

Issue 29714638: Issue 6446 - Ignore emulated selectors if unchanged (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Make emulatedSelectors member of ElemHide Created March 7, 2018, 6:21 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
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -30,16 +30,24 @@
["audio", "MEDIA"],
["video", "MEDIA"],
["frame", "SUBDOCUMENT"],
["iframe", "SUBDOCUMENT"],
["object", "OBJECT"],
["embed", "OBJECT"]
]);
+function haveSelectorsChanged(selectors, oldSelectors)
+{
+ if (selectors.length != oldSelectors.length)
+ return true;
+
+ return !selectors.every((selector, index) => selector == oldSelectors[index]);
+}
+
function getURLsFromObjectElement(element)
{
let url = element.getAttribute("data");
if (url)
return [url];
for (let child of element.children)
{
@@ -342,16 +350,17 @@
function ElemHide()
{
this.shadow = this.createShadowTree();
this.styles = new Map();
this.tracer = null;
this.inline = true;
this.inlineEmulated = true;
this.emulatedPatterns = null;
+ this.emulatedSelectors = [];
this.elemHideEmulation = new ElemHideEmulation(
this.addSelectors.bind(this),
this.hideElements.bind(this)
);
}
ElemHide.prototype = {
selectorGroupSize: 1024,
@@ -449,16 +458,21 @@
).join(", ");
style.sheet.insertRule(selector + "{display: none !important;}",
style.sheet.cssRules.length);
}
},
addSelectors(selectors, filters)
{
+ if (!haveSelectorsChanged(selectors, this.emulatedSelectors))
+ return;
+
+ this.emulatedSelectors = selectors;
+
if (this.inline || this.inlineEmulated)
{
// Insert the style rules inline if we have been instructed by the
// background page to do so. This is usually the case, except on platforms
// that do support user stylesheets via the browser.tabs.insertCSS API
// (Firefox 53 onwards for now and possibly Chrome in the near future).
// Once all supported platforms have implemented this API, we can remove
// the code below. See issue #5090.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld