From d5c3c2d6a6b7c292473ebd43dcfd69d0c0af99d6 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 07:42:37 -0500 Subject: [PATCH 1/4] new revision --- platform/chromium/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index 303490272..2adc90084 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "µBlock", - "version": "0.8.2.3", + "version": "0.8.2.4", "default_locale": "en", "description": "__MSG_extShortDesc__", From 4c7533b786cbea6f8261477a0f1d18cdb1c6d176 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 07:46:33 -0500 Subject: [PATCH 2/4] code review for #452 --- src/js/contentscript-end.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index 7f8f1b7ad..04d62901f 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -80,7 +80,7 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); // to force them to be seen as "already injected". selectors = vAPI.donthideCosmeticFilters; if ( typeof selectors === 'object' ) { - for ( selector in selectors ) { + for ( var selector in selectors ) { if ( selectors.hasOwnProperty(selector) ) { injectedSelectors[selector] = true; } From aca35e4cbc3edd9b75175ee4a6588255bc4c5a7f Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 08:09:44 -0500 Subject: [PATCH 3/4] code review for #452: avoid if'ing each time --- src/js/contentscript-end.js | 67 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index 04d62901f..e12549e04 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -59,6 +59,31 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); idsFromNodeList(document.querySelectorAll('[id]')); classesFromNodeList(document.querySelectorAll('[class]')); retrieveGenericSelectors(); + + // Flush dead code from memory (does this work?) + domLoaded = null; + }; + + var retrieveGenericSelectors = function() { + var selectors = classSelectors !== null ? Object.keys(classSelectors) : []; + if ( idSelectors !== null ) { + selectors = selectors.concat(idSelectors); + } + if ( selectors.length > 0 || highGenerics === null ) { + //console.log('µBlock> ABP cosmetic filters: retrieving CSS rules using %d selectors', selectors.length); + messager.send({ + what: 'retrieveGenericCosmeticSelectors', + pageURL: window.location.href, + selectors: selectors, + highGenerics: highGenerics === null + }, + retrieveHandler + ); + } else { + otherRetrieveHandler(null); + } + idSelectors = null; + classSelectors = null; }; // https://github.com/gorhill/uBlock/issues/452 @@ -66,7 +91,7 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); // received, not at `DOMContentLoaded` time, or else there is a good // likeliness to outrun contentscript-start.js, which may still be waiting // on a response from its own query. - var firstRunHandler = function() { + var firstRetrieveHandler = function(response) { // https://github.com/gorhill/uBlock/issues/158 // Ensure injected styles are enforced // rhill 2014-11-16: not sure this is needed anymore. Test case in @@ -86,37 +111,17 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); } } } + + // There is only one first.. + retrieveHandler = otherRetrieveHandler; + + // Flush dead code from memory (does this work?) + firstRetrieveHandler = null; + + otherRetrieveHandler(response); }; - var retrieveGenericSelectors = function() { - var selectors = classSelectors !== null ? Object.keys(classSelectors) : []; - if ( idSelectors !== null ) { - selectors = selectors.concat(idSelectors); - } - if ( selectors.length > 0 || highGenerics === null ) { - //console.log('µBlock> ABP cosmetic filters: retrieving CSS rules using %d selectors', selectors.length); - messager.send({ - what: 'retrieveGenericCosmeticSelectors', - pageURL: window.location.href, - selectors: selectors, - highGenerics: highGenerics === null - }, - retrieveHandler - ); - } else { - retrieveHandler(null); - } - idSelectors = null; - classSelectors = null; - }; - - var retrieveHandler = function(selectors) { - // https://github.com/gorhill/uBlock/issues/452 - // See above. - if ( typeof firstRunHandler === 'function' ) { - firstRunHandler(); - firstRunHandler = undefined; - } + var otherRetrieveHandler = function(selectors) { //console.debug('µBlock> contextNodes = %o', contextNodes); if ( selectors && selectors.highGenerics ) { highGenerics = selectors.highGenerics; @@ -157,6 +162,8 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); contextNodes.length = 0; }; + var retrieveHandler = firstRetrieveHandler; + // Ensure elements matching a set of selectors are visually removed // from the page, by: // - Modifying the style property on the elements themselves From 8562f701443d553af7f3c2199df2f1fb36da3d59 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 09:15:37 -0500 Subject: [PATCH 4/4] avoid potential double execution of firstRetrieveHandler (because mutations observer) --- src/js/contentscript-end.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index e12549e04..518f83e0f 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -79,6 +79,9 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); }, retrieveHandler ); + // https://github.com/gorhill/uBlock/issues/452 + // There is only one first.. + retrieveHandler = otherRetrieveHandler; } else { otherRetrieveHandler(null); } @@ -111,10 +114,6 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); } } } - - // There is only one first.. - retrieveHandler = otherRetrieveHandler; - // Flush dead code from memory (does this work?) firstRetrieveHandler = null;