From 2eb9b726a59e4959f40e487d00c595660d41b3fe Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 3 Jun 2019 06:37:39 -0400 Subject: [PATCH] Fix `generichide` not being evaluated for local context Related issue: - https://github.com/uBlockOrigin/uAssets/issues/5704 --- src/js/messaging.js | 36 +++++++++++++++++++++++++----------- src/js/pagestore.js | 27 --------------------------- 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/js/messaging.js b/src/js/messaging.js index 9cd166741..b824924f9 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -547,12 +547,29 @@ var onMessage = function(request, sender, callback) { ) { break; } + const noCosmeticFiltering = pageStore.noCosmeticFiltering === true; response = { collapseBlocked: µb.userSettings.collapseBlocked, - noCosmeticFiltering: pageStore.noCosmeticFiltering === true, - noGenericCosmeticFiltering: - pageStore.noGenericCosmeticFiltering === true + noCosmeticFiltering, + noGenericCosmeticFiltering: noCosmeticFiltering, }; + // https://github.com/uBlockOrigin/uAssets/issues/5704 + // `generichide` must be evaluated in the frame context. + if ( noCosmeticFiltering === false ) { + const genericHide = + µb.staticNetFilteringEngine.matchStringGenericHide(request.url); + response.noGenericCosmeticFiltering = genericHide === 2; + if ( genericHide !== 0 && µb.logger.enabled ) { + µBlock.filteringContext + .duplicate() + .fromTabId(tabId) + .setURL(request.url) + .setRealm('network') + .setType('generichide') + .setFilter(µb.staticNetFilteringEngine.toLogData()) + .toLogger(); + } + } request.tabId = tabId; request.frameId = frameId; request.hostname = µb.URI.hostnameFromURI(request.url); @@ -572,14 +589,11 @@ var onMessage = function(request, sender, callback) { break; case 'retrieveGenericCosmeticSelectors': - if ( pageStore && pageStore.getGenericCosmeticFilteringSwitch() ) { - request.tabId = tabId; - request.frameId = frameId; - response = { - result: µb.cosmeticFilteringEngine - .retrieveGenericSelectors(request) - }; - } + request.tabId = tabId; + request.frameId = frameId; + response = { + result: µb.cosmeticFilteringEngine.retrieveGenericSelectors(request) + }; break; default: diff --git a/src/js/pagestore.js b/src/js/pagestore.js index 7f582d902..06570cb90 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -310,28 +310,6 @@ PageStore.prototype.init = function(tabId, context) { .toLogger(); } - // Support `generichide` filter option. - this.noGenericCosmeticFiltering = masterSwitch !== true; - if ( this.noGenericCosmeticFiltering !== true ) { - this.noGenericCosmeticFiltering = this.noCosmeticFiltering; - if ( this.noGenericCosmeticFiltering !== true ) { - let result = µb.staticNetFilteringEngine.matchStringGenericHide( - tabContext.normalURL - ); - this.noGenericCosmeticFiltering = result === 2; - if ( - result !== 0 && - µb.logger.enabled && - context === 'tabCommitted' - ) { - fctxt.setRealm('network') - .setType('generichide') - .setFilter(µb.staticNetFilteringEngine.toLogData()) - .toLogger(); - } - } - } - return this; }; @@ -429,11 +407,6 @@ PageStore.prototype.getSpecificCosmeticFilteringSwitch = function() { return this.noCosmeticFiltering !== true; }; -PageStore.prototype.getGenericCosmeticFilteringSwitch = function() { - return this.noGenericCosmeticFiltering !== true && - this.noCosmeticFiltering !== true; -}; - PageStore.prototype.toggleNetFilteringSwitch = function(url, scope, state) { µb.toggleNetFilteringSwitch(url, scope, state); this.netFilteringCache.empty();